2016-04-30 07:38:37 +02:00
|
|
|
package eu.univento.teamvento.utils;
|
|
|
|
|
|
|
|
import com.mongodb.BasicDBObject;
|
|
|
|
import com.mongodb.CursorType;
|
|
|
|
import com.mongodb.client.FindIterable;
|
|
|
|
import eu.univento.core.Core;
|
|
|
|
import eu.univento.core.api.map.Cuboid;
|
|
|
|
import eu.univento.core.api.player.CustomPlayer;
|
2016-07-09 13:19:56 +02:00
|
|
|
import eu.univento.core.api.utils.UUIDFetcher;
|
2016-04-30 07:38:37 +02:00
|
|
|
import eu.univento.teamvento.TeamVento;
|
|
|
|
import org.bson.Document;
|
2016-07-09 13:19:56 +02:00
|
|
|
import org.bukkit.*;
|
|
|
|
import org.bukkit.block.Biome;
|
2016-04-30 07:38:37 +02:00
|
|
|
import org.bukkit.block.Block;
|
2016-07-09 13:19:56 +02:00
|
|
|
import org.bukkit.entity.Entity;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
import org.bukkit.inventory.meta.ItemMeta;
|
2016-04-30 07:38:37 +02:00
|
|
|
|
2016-07-09 13:19:56 +02:00
|
|
|
import java.util.*;
|
2016-04-30 07:38:37 +02:00
|
|
|
|
|
|
|
public class PlotManager {
|
|
|
|
|
2016-07-09 13:19:56 +02:00
|
|
|
private static boolean reset = false;
|
|
|
|
|
2016-04-30 07:38:37 +02:00
|
|
|
private static ArrayList<Plot> plots = new ArrayList<>();
|
2016-07-09 13:19:56 +02:00
|
|
|
private static Plot lastPlot;
|
|
|
|
|
|
|
|
public static ArrayList<Plot> getPlots() {
|
|
|
|
return plots;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Plot getLastPlot() {
|
|
|
|
return lastPlot;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setLastPlot(Plot plot) {
|
|
|
|
lastPlot = plot;
|
|
|
|
}
|
2016-04-30 07:38:37 +02:00
|
|
|
|
|
|
|
public static void update() {
|
|
|
|
FindIterable<Document> cursor = Core.getMongoDB().getDatabase().getCollection("plots").find();
|
2016-07-09 13:19:56 +02:00
|
|
|
for (Document doc : cursor) {
|
2016-04-30 07:38:37 +02:00
|
|
|
String uuid = doc.getString("uuid");
|
|
|
|
Plot plot = new Plot(new Cuboid(getLocation(uuid, "minPos"), getLocation(uuid, "maxPos")), UUID.fromString(uuid), getLocation(uuid, "Spawn"));
|
|
|
|
plots.add(plot);
|
2016-07-09 13:19:56 +02:00
|
|
|
plot.setBiome(plot.getBiome());
|
2016-04-30 07:38:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Plot getPlotByPlayer(CustomPlayer p) {
|
2016-07-09 13:19:56 +02:00
|
|
|
for (Plot plot : plots) {
|
|
|
|
if (plot.isOwner(p)) return plot;
|
2016-04-30 07:38:37 +02:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean hasPlot(CustomPlayer p) {
|
|
|
|
return getPlotByPlayer(p) != null;
|
|
|
|
}
|
|
|
|
|
2016-07-09 13:19:56 +02:00
|
|
|
public static void clearPlot(Plot plot) {
|
|
|
|
CustomPlayer p = CustomPlayer.getPlayer(plot.getOwner());
|
|
|
|
if(reset) {
|
|
|
|
p.sendMessage("§cEs wird bereits grade ein Plot bearbeitet.");
|
|
|
|
p.sendMessage("§cBitte versuche es später noch einmal.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
reset = true;
|
|
|
|
|
|
|
|
plot.getAnimals().forEach(plot::removeAnimal);
|
|
|
|
|
|
|
|
Cuboid area = plot.getArea();
|
|
|
|
Location lower = new Location(Bukkit.getWorld("plots"), area.getLowerX(), area.getLowerY() + 17.0D, area.getLowerZ());
|
|
|
|
Location upper = new Location(Bukkit.getWorld("plots"), area.getUpperX(), area.getLowerY() + 20.0D, area.getUpperZ());
|
|
|
|
Cuboid blocks = new Cuboid(lower, upper);
|
|
|
|
|
|
|
|
Cuboid highest = new Cuboid(upper, new Location(Bukkit.getWorld("plots"), area.getLowerX(), 250.0D, area.getLowerZ()));
|
|
|
|
Bukkit.getScheduler().runTaskAsynchronously(TeamVento.getInstance(), () -> {
|
|
|
|
long i = 0;
|
|
|
|
for (Block b : highest.getBlocks()) {
|
|
|
|
i++;
|
|
|
|
Bukkit.getScheduler().scheduleSyncDelayedTask(TeamVento.getInstance(), () -> b.setType(Material.AIR), i / 3000);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
Bukkit.getScheduler().runTaskAsynchronously(TeamVento.getInstance(), () -> {
|
|
|
|
long i = 0;
|
|
|
|
for (Block b : blocks.getBlocks()) {
|
|
|
|
i++;
|
|
|
|
Bukkit.getScheduler().scheduleSyncDelayedTask(TeamVento.getInstance(), () -> b.setType(Material.AIR), i / 45);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
Cuboid bottom = new Cuboid(new Location(Bukkit.getWorld("plots"), area.getLowerX(), 0.0D, area.getLowerZ()), new Location(Bukkit.getWorld("plots"), area.getUpperX(), 0.0D, area.getUpperZ()));
|
|
|
|
Bukkit.getScheduler().runTaskAsynchronously(TeamVento.getInstance(), () -> {
|
|
|
|
long i = 0;
|
|
|
|
for (Block b : bottom.getBlocks()) {
|
|
|
|
i++;
|
|
|
|
Bukkit.getScheduler().scheduleSyncDelayedTask(TeamVento.getInstance(), () -> b.setType(Material.AIR), i / 90);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
Cuboid between = new Cuboid(new Location(Bukkit.getWorld("plots"), bottom.getLowerX(), bottom.getLowerY() + 1.0D, bottom.getLowerZ()), new Location(Bukkit.getWorld("plots"), blocks.getUpperX(), blocks.getLowerY() - 1.0D, blocks.getUpperZ()));
|
|
|
|
Bukkit.getScheduler().runTaskAsynchronously(TeamVento.getInstance(), () -> {
|
|
|
|
long i = 0;
|
|
|
|
for (Block b : between.getBlocks()) {
|
|
|
|
i++;
|
|
|
|
Bukkit.getScheduler().scheduleSyncDelayedTask(TeamVento.getInstance(), () -> b.setType(Material.AIR), i / 200);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
Bukkit.getScheduler().runTaskLaterAsynchronously(TeamVento.getInstance(), () -> reset = false, 13 * 20L);
|
|
|
|
}
|
|
|
|
|
2016-04-30 07:38:37 +02:00
|
|
|
public static void generatePlot(Plot plot) {
|
2016-07-09 13:19:56 +02:00
|
|
|
lastPlot = plot;
|
2016-04-30 07:38:37 +02:00
|
|
|
Cuboid area = plot.getArea();
|
2016-07-09 13:19:56 +02:00
|
|
|
Location lower = new Location(Bukkit.getWorld("plots"), area.getLowerX(), area.getLowerY() + 17.0D, area.getLowerZ());
|
|
|
|
Location upper = new Location(Bukkit.getWorld("plots"), area.getUpperX(), area.getLowerY() + 20.0D, area.getUpperZ());
|
|
|
|
Cuboid blocks = new Cuboid(lower, upper);
|
|
|
|
plots.add(plot);
|
|
|
|
plot.setBiome(Biome.FOREST);
|
|
|
|
|
|
|
|
Bukkit.getScheduler().runTaskAsynchronously(TeamVento.getInstance(), () -> {
|
|
|
|
long i = 0;
|
|
|
|
for (Block b : blocks.getBlocks()) {
|
|
|
|
i++;
|
|
|
|
Bukkit.getScheduler().scheduleSyncDelayedTask(TeamVento.getInstance(), () -> {
|
|
|
|
b.setType(Material.DIRT);
|
|
|
|
Core.getOnlinePlayers().stream().filter(players -> players.hasEffects()).forEachOrdered(players -> players.playEffect(b.getLocation(), Effect.MOBSPAWNER_FLAMES, 1));
|
|
|
|
}, i / 16);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
Cuboid bottom = new Cuboid(new Location(Bukkit.getWorld("plots"), area.getLowerX(), 0.0D, area.getLowerZ()), new Location(Bukkit.getWorld("plots"), area.getUpperX(), 0.0D, area.getUpperZ()));
|
|
|
|
Bukkit.getScheduler().runTaskAsynchronously(TeamVento.getInstance(), () -> {
|
|
|
|
long i = 0;
|
|
|
|
for (Block b : bottom.getBlocks()) {
|
|
|
|
i++;
|
|
|
|
Bukkit.getScheduler().scheduleSyncDelayedTask(TeamVento.getInstance(), () -> b.setType(Material.BEDROCK), i / 100);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
Cuboid between = new Cuboid(new Location(Bukkit.getWorld("plots"), bottom.getLowerX(), bottom.getLowerY() + 1.0D, bottom.getLowerZ()), new Location(Bukkit.getWorld("plots"), blocks.getUpperX(), blocks.getLowerY() - 1.0D, blocks.getUpperZ()));
|
|
|
|
Bukkit.getScheduler().runTaskAsynchronously(TeamVento.getInstance(), () -> {
|
|
|
|
long i = 0;
|
|
|
|
for (Block b : between.getBlocks()) {
|
|
|
|
i++;
|
|
|
|
Bukkit.getScheduler().scheduleSyncDelayedTask(TeamVento.getInstance(), () -> b.setType(Material.STONE), i / 90);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
Bukkit.getScheduler().runTaskAsynchronously(TeamVento.getInstance(), () -> Bukkit.getScheduler().scheduleSyncDelayedTask(TeamVento.getInstance(), () -> blocks.getUpperLocation().getBlock().setType(Material.GRASS), 35 * 20L));
|
|
|
|
|
|
|
|
Cuboid rand1 = new Cuboid(new Location(Bukkit.getWorld("plots"), blocks.getUpperX(), blocks.getUpperY() + 1.0D, blocks.getUpperZ()), new Location(Bukkit.getWorld("plots"), blocks.getUpperX() - 50.0D, blocks.getUpperY() + 1.0D, blocks.getUpperZ()));
|
|
|
|
Bukkit.getScheduler().runTaskAsynchronously(TeamVento.getInstance(), () -> {
|
|
|
|
long i = 0;
|
|
|
|
for (Block b : rand1.getBlocks()) {
|
|
|
|
i++;
|
|
|
|
Bukkit.getScheduler().scheduleSyncDelayedTask(TeamVento.getInstance(), () -> {
|
|
|
|
b.setType(Material.WOOD_STEP);
|
|
|
|
b.setData((byte) 1);
|
|
|
|
}, i);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
Cuboid rand2 = new Cuboid(new Location(Bukkit.getWorld("plots"), blocks.getUpperX(), blocks.getUpperY() + 1.0D, blocks.getUpperZ()), new Location(Bukkit.getWorld("plots"), blocks.getUpperX(), blocks.getUpperY() + 1.0D, blocks.getUpperZ() - 50.0D));
|
|
|
|
Bukkit.getScheduler().runTaskAsynchronously(TeamVento.getInstance(), () -> {
|
|
|
|
long i = 0;
|
|
|
|
for (Block b : rand2.getBlocks()) {
|
|
|
|
i++;
|
|
|
|
Bukkit.getScheduler().scheduleSyncDelayedTask(TeamVento.getInstance(), () -> {
|
|
|
|
b.setType(Material.WOOD_STEP);
|
|
|
|
b.setData((byte) 1);
|
|
|
|
}, i);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
Cuboid rand3 = new Cuboid(new Location(Bukkit.getWorld("plots"), blocks.getLowerX(), blocks.getUpperY() + 1.0D, blocks.getLowerZ()), new Location(Bukkit.getWorld("plots"), blocks.getLowerX(), blocks.getUpperY() + 1.0D, blocks.getLowerZ() + 50.0D));
|
|
|
|
Bukkit.getScheduler().runTaskAsynchronously(TeamVento.getInstance(), () -> {
|
|
|
|
long i = 0;
|
|
|
|
for (Block b : rand3.getBlocks()) {
|
|
|
|
i++;
|
|
|
|
Bukkit.getScheduler().scheduleSyncDelayedTask(TeamVento.getInstance(), () -> {
|
|
|
|
b.setType(Material.WOOD_STEP);
|
|
|
|
b.setData((byte) 1);
|
|
|
|
}, i);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
Cuboid rand4 = new Cuboid(new Location(Bukkit.getWorld("plots"), blocks.getLowerX(), blocks.getUpperY() + 1.0D, blocks.getLowerZ()), new Location(Bukkit.getWorld("plots"), blocks.getLowerX() + 50.D, blocks.getUpperY() + 1.0D, blocks.getLowerZ()));
|
|
|
|
Bukkit.getScheduler().runTaskAsynchronously(TeamVento.getInstance(), () -> {
|
|
|
|
long i = 0;
|
|
|
|
for (Block b : rand4.getBlocks()) {
|
|
|
|
i++;
|
|
|
|
Bukkit.getScheduler().scheduleSyncDelayedTask(TeamVento.getInstance(), () -> {
|
|
|
|
b.setType(Material.WOOD_STEP);
|
|
|
|
b.setData((byte) 1);
|
|
|
|
}, i);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
Cuboid street1 = new Cuboid(new Location(Bukkit.getWorld("plots"), blocks.getUpperX() + 1.0D, blocks.getUpperY(), blocks.getUpperZ() + 4.0D), new Location(Bukkit.getWorld("plots"), blocks.getUpperX() + 4.0D, 0.0D, blocks.getUpperZ() - 54.0D));
|
|
|
|
Bukkit.getScheduler().runTaskLaterAsynchronously(TeamVento.getInstance(), () -> {
|
|
|
|
long i = 0;
|
|
|
|
for (Block b : street1.getBlocks()) {
|
|
|
|
i++;
|
|
|
|
Bukkit.getScheduler().scheduleSyncDelayedTask(TeamVento.getInstance(), () -> b.setType(Material.COAL_BLOCK), i / 16);
|
|
|
|
}
|
|
|
|
}, 35 * 20L);
|
|
|
|
Cuboid street2 = new Cuboid(new Location(Bukkit.getWorld("plots"), blocks.getLowerX() - 1.0D, blocks.getUpperY(), blocks.getLowerZ() - 4.0D), new Location(Bukkit.getWorld("plots"), blocks.getLowerX() - 4.0D, 0.0D, blocks.getLowerZ() + 54.0D));
|
|
|
|
Bukkit.getScheduler().runTaskAsynchronously(TeamVento.getInstance(), () -> {
|
|
|
|
long i = 0;
|
|
|
|
for (Block b : street2.getBlocks()) {
|
|
|
|
i++;
|
|
|
|
Bukkit.getScheduler().scheduleSyncDelayedTask(TeamVento.getInstance(), () -> b.setType(Material.COAL_BLOCK), i / 16);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
Cuboid street3 = new Cuboid(new Location(Bukkit.getWorld("plots"), blocks.getUpperX(), blocks.getUpperY(), blocks.getUpperZ() + 1.0D), new Location(Bukkit.getWorld("plots"), blocks.getLowerX(), 0.0D, blocks.getLowerZ() + 54.0D));
|
|
|
|
Bukkit.getScheduler().runTaskAsynchronously(TeamVento.getInstance(), () -> {
|
|
|
|
long i = 0;
|
|
|
|
for (Block b : street3.getBlocks()) {
|
|
|
|
i++;
|
|
|
|
Bukkit.getScheduler().scheduleSyncDelayedTask(TeamVento.getInstance(), () -> b.setType(Material.COAL_BLOCK), i / 16);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
Cuboid street4 = new Cuboid(new Location(Bukkit.getWorld("plots"), blocks.getUpperX(), blocks.getUpperY(), blocks.getUpperZ() - 54.0D), new Location(Bukkit.getWorld("plots"), blocks.getLowerX(), 0.0D, blocks.getLowerZ() - 1.0D));
|
|
|
|
Bukkit.getScheduler().runTaskAsynchronously(TeamVento.getInstance(), () -> {
|
|
|
|
long i = 0;
|
|
|
|
for (Block b : street4.getBlocks()) {
|
|
|
|
i++;
|
|
|
|
Bukkit.getScheduler().scheduleSyncDelayedTask(TeamVento.getInstance(), () -> b.setType(Material.COAL_BLOCK), i / 16);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Bukkit.getScheduler().runTaskAsynchronously(TeamVento.getInstance(), () -> Bukkit.getScheduler().scheduleSyncDelayedTask(TeamVento.getInstance(), () -> {
|
|
|
|
ItemStack menu = new ItemStack(Material.WATCH);
|
|
|
|
ItemMeta menuMeta = menu.getItemMeta();
|
|
|
|
menuMeta.setDisplayName("§eErweiterungen");
|
|
|
|
menu.setItemMeta(menuMeta);
|
|
|
|
Bukkit.getPlayer(plot.getOwner()).getInventory().setItem(8, menu);
|
|
|
|
}, 35 * 20L));
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Plot createPlot(CustomPlayer p) {
|
|
|
|
if (lastPlot == null) {
|
|
|
|
Location lower = new Location(Bukkit.getWorld("plots"), Bukkit.getWorld("plots").getSpawnLocation().getX(), Bukkit.getWorld("plots").getSpawnLocation().getY() - 20.0D, Bukkit.getWorld("plots").getSpawnLocation().getZ());
|
|
|
|
Location upper = new Location(Bukkit.getWorld("plots"), lower.getX() + 50.0D, lower.getY() + 250.0D, lower.getZ() + 50.0D);
|
|
|
|
Cuboid area = new Cuboid(upper, lower);
|
|
|
|
return new Plot(area, p.getUniqueId(), new Location(Bukkit.getWorld("plots"), upper.getX() + 1.0D, lower.getY() + 25.0D, lower.getZ() + 25.0D));
|
|
|
|
}
|
|
|
|
Location upper = lastPlot.getArea().getUpperLocation();
|
|
|
|
Location lower = lastPlot.getArea().getLowerLocation();
|
|
|
|
|
|
|
|
Location west = new Location(Bukkit.getWorld("plots"), lower.getX() - 25.0D, lower.getY() + 25.0D, lower.getZ() + 25.0D);
|
|
|
|
Location east = new Location(Bukkit.getWorld("plots"), upper.getX() + 25.0D, lower.getY() + 25.0D, lower.getZ() + 25.0D);
|
|
|
|
Location north = new Location(Bukkit.getWorld("plots"), lower.getX() + 25.0D, lower.getY() + 25.0D, lower.getZ() - 25.0D);
|
|
|
|
Location south = new Location(Bukkit.getWorld("plots"), upper.getX() - 25.0D, lower.getY() + 25.0D, lower.getZ() + 75.0D);
|
|
|
|
|
|
|
|
west.getBlock().setType(Material.GLASS);
|
|
|
|
east.getBlock().setType(Material.GRASS_PATH);
|
|
|
|
north.getBlock().setType(Material.STONE);
|
|
|
|
south.getBlock().setType(Material.ACACIA_STAIRS);
|
|
|
|
|
|
|
|
if(PlotManager.getPlotByLocation(south) == null && PlotManager.getPlotByLocation(west) == null && PlotManager.getPlotByLocation(north) == null && PlotManager.getPlotByLocation(east) == null) {
|
|
|
|
upper.setX(upper.getX() + 55);
|
|
|
|
lower.setX(lower.getX() + 55);
|
|
|
|
}
|
|
|
|
else if(PlotManager.getPlotByLocation(south) == null && PlotManager.getPlotByLocation(west) != null) {
|
|
|
|
Bukkit.broadcastMessage("Plot im Süden");
|
|
|
|
upper.setZ(upper.getZ() + 55);
|
|
|
|
lower.setZ(lower.getZ() + 55);
|
|
|
|
}
|
|
|
|
else if(PlotManager.getPlotByLocation(west) == null && PlotManager.getPlotByLocation(north) != null) {
|
|
|
|
Bukkit.broadcastMessage("Plot im Westen");
|
|
|
|
upper.setX(upper.getX() - 55);
|
|
|
|
lower.setX(lower.getX() - 55);
|
|
|
|
}
|
|
|
|
else if(PlotManager.getPlotByLocation(east) == null && PlotManager.getPlotByLocation(south) != null && PlotManager.getPlotByLocation(west) != null) {
|
|
|
|
Bukkit.broadcastMessage("Plot im Osten1");
|
|
|
|
upper.setX(upper.getX() + 55);
|
|
|
|
lower.setX(lower.getX() + 55);
|
|
|
|
}
|
|
|
|
else if(PlotManager.getPlotByLocation(east) != null && PlotManager.getPlotByLocation(south) != null && PlotManager.getPlotByLocation(north) == null) {
|
|
|
|
Bukkit.broadcastMessage("Plot im Norden1");
|
|
|
|
upper.setZ(upper.getZ() - 55);
|
|
|
|
lower.setZ(lower.getZ() - 55);
|
2016-04-30 07:38:37 +02:00
|
|
|
}
|
|
|
|
|
2016-07-09 13:19:56 +02:00
|
|
|
Cuboid area = new Cuboid(upper, lower);
|
|
|
|
Location spawn = new Location(Bukkit.getWorld("plots"), lower.getX() + 52.0D, lower.getY() + 25.0D, lower.getZ() + 25.0D);
|
|
|
|
return new Plot(area, p.getUniqueId(), spawn);
|
2016-04-30 07:38:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void createPlot(Plot plot) {
|
|
|
|
Document doc = new Document("uuid", plot.getOwner().toString());
|
2016-07-09 13:19:56 +02:00
|
|
|
Date date = new Date();
|
2016-04-30 07:38:37 +02:00
|
|
|
|
2016-07-09 13:19:56 +02:00
|
|
|
HashMap<String, Object> maxPos = new HashMap<>();
|
2016-04-30 07:38:37 +02:00
|
|
|
maxPos.put("X", plot.getArea().getUpperX());
|
|
|
|
maxPos.put("Y", plot.getArea().getUpperY());
|
|
|
|
maxPos.put("Z", plot.getArea().getUpperZ());
|
|
|
|
|
2016-07-09 13:19:56 +02:00
|
|
|
HashMap<String, Object> minPos = new HashMap<>();
|
2016-04-30 07:38:37 +02:00
|
|
|
minPos.put("X", plot.getArea().getLowerX());
|
|
|
|
minPos.put("Y", plot.getArea().getLowerY());
|
|
|
|
minPos.put("Z", plot.getArea().getLowerZ());
|
|
|
|
|
|
|
|
HashMap<String, Object> spawn = new HashMap<>();
|
|
|
|
spawn.put("X", plot.getSpawn().getX());
|
|
|
|
spawn.put("Y", plot.getSpawn().getY());
|
|
|
|
spawn.put("Z", plot.getSpawn().getZ());
|
|
|
|
|
2016-07-09 13:19:56 +02:00
|
|
|
ArrayList<Map<String, String>> animals = new ArrayList<>();
|
|
|
|
|
|
|
|
doc.put("created", date);
|
2016-04-30 07:38:37 +02:00
|
|
|
doc.put("maxPos", new BasicDBObject(maxPos));
|
|
|
|
doc.put("minPos", new BasicDBObject(minPos));
|
|
|
|
doc.put("Spawn", new BasicDBObject(spawn));
|
2016-07-09 13:19:56 +02:00
|
|
|
doc.put("time", "DAY");
|
|
|
|
doc.put("weather", "CLEAR");
|
|
|
|
doc.put("biome", "PLAINS");
|
|
|
|
doc.put("pack", "Default");
|
|
|
|
doc.put("name", "");
|
|
|
|
doc.put("contact", "");
|
|
|
|
doc.put("animals", animals);
|
|
|
|
|
2016-04-30 07:38:37 +02:00
|
|
|
|
|
|
|
Core.getMongoDB().getDatabase().getCollection("plots").insertOne(doc);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Plot getPlotByLocation(Location location) {
|
2016-07-09 13:19:56 +02:00
|
|
|
for (Plot plot : plots) {
|
|
|
|
if (plot.isInPlot(location)) return plot;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Plot getPlotByOwner(String owner) {
|
|
|
|
for (Plot plot : plots) {
|
|
|
|
if (plot.getOwner().equals(UUID.fromString(owner))) return plot;
|
2016-04-30 07:38:37 +02:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2016-07-09 13:19:56 +02:00
|
|
|
public static Date getCreatedDate(String uuid) {
|
|
|
|
return getDateFromDatabase(uuid, "created");
|
|
|
|
}
|
|
|
|
|
2016-04-30 07:38:37 +02:00
|
|
|
private static Location getLocation(String uuid, String name) {
|
2016-07-09 13:19:56 +02:00
|
|
|
Map<String, Object> map = getMapFromDatabase(uuid, name);
|
|
|
|
return new Location(Bukkit.getWorld("plots"), Double.valueOf(String.valueOf(map.get("X"))), Double.valueOf(String.valueOf(map.get("Y"))), Double.valueOf(String.valueOf(map.get("Z"))));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static Date getDateFromDatabase(String uuid, String name) {
|
|
|
|
FindIterable<Document> cursor = Core.getMongoDB().getDatabase().getCollection("plots").find(new Document("uuid", uuid));
|
|
|
|
cursor.cursorType(CursorType.NonTailable);
|
|
|
|
|
|
|
|
Document doc = cursor.first();
|
|
|
|
if (doc == null) return null;
|
|
|
|
|
|
|
|
return doc.getDate(name);
|
2016-04-30 07:38:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private static Object getObjectFromDatbase(String uuid, String name) {
|
|
|
|
FindIterable<Document> cursor = Core.getMongoDB().getDatabase().getCollection("plots").find(new Document("uuid", uuid));
|
|
|
|
cursor.cursorType(CursorType.NonTailable);
|
|
|
|
|
|
|
|
Document doc = cursor.first();
|
|
|
|
if (doc == null) return null;
|
|
|
|
|
|
|
|
return doc.get(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static Map<String, Object> getMapFromDatabase(String uuid, String name) {
|
|
|
|
return (Map<String, Object>) getObjectFromDatbase(uuid, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|