From 5d6f4c6668f075c718ab1d467d66803dae7da03b Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Thu, 23 Mar 2017 11:10:29 +1100 Subject: [PATCH] Some plot area restructuring --- .gitignore | 3 +- .../com/plotsquared/bukkit/BukkitMain.java | 12 +- .../database/plotme/PlotMeConnector_017.java | 6 +- .../bukkit/events/PlotClearEvent.java | 2 +- .../bukkit/events/PlotComponentSetEvent.java | 2 +- .../bukkit/events/PlotDeleteEvent.java | 2 +- .../bukkit/generator/BukkitPlotGenerator.java | 11 +- .../bukkit/listeners/PlayerEvents.java | 56 +++++++--- .../bukkit/listeners/WorldEvents.java | 10 ++ .../bukkit/util/BukkitEventUtil.java | 2 +- .../bukkit/util/BukkitSetupUtils.java | 69 +++++++++--- .../plotsquared/bukkit/util/BukkitUtil.java | 15 +-- .../plotsquared/bukkit/util/SendChunk.java | 2 +- .../com/intellectualcrafters/plot/PS.java | 26 ++++- .../plot/commands/Auto.java | 4 +- .../plot/commands/DebugImportWorlds.java | 60 ++++++++++ .../plot/commands/Deny.java | 15 ++- .../plot/commands/Download.java | 4 + .../plot/commands/Kick.java | 3 +- .../plot/commands/MainCommand.java | 2 +- .../plot/commands/Owner.java | 2 +- .../plot/commands/Purge.java | 2 +- .../plot/commands/Set.java | 3 + .../plot/config/Settings.java | 19 +++- .../plot/database/SQLManager.java | 4 +- .../plot/flag/FlagManager.java | 6 +- .../plot/generator/HybridUtils.java | 10 +- .../plot/generator/SquarePlotManager.java | 4 +- .../plot/object/Plot.java | 88 +++++++++------ .../plot/object/PlotArea.java | 2 +- .../plot/object/PlotId.java | 8 +- .../plot/object/PlotPlayer.java | 1 - .../object/worlds/DefaultPlotAreaManager.java | 7 +- .../plot/object/worlds/SinglePlot.java | 51 +++++++++ .../plot/object/worlds/SinglePlotArea.java | 105 +++++++++++++++++- .../object/worlds/SinglePlotAreaManager.java | 68 ++++++++++-- .../plot/object/worlds/SinglePlotManager.java | 24 ++-- .../object/worlds/SingleWorldGenerator.java | 60 ++++++++++ .../plot/util/BO3Handler.java | 10 +- .../plot/util/ChunkManager.java | 4 +- .../plot/util/MainUtil.java | 21 +++- .../plot/util/SchematicHandler.java | 6 +- .../plot/util/SetupUtils.java | 3 +- .../plot/util/UUIDHandler.java | 31 ++++++ .../plot/util/WorldUtil.java | 18 +-- .../nukkit/events/PlotClearEvent.java | 2 +- .../nukkit/events/PlotComponentSetEvent.java | 2 +- .../nukkit/events/PlotDeleteEvent.java | 2 +- .../nukkit/util/NukkitEventUtil.java | 2 +- .../nukkit/util/NukkitSetupUtils.java | 5 + .../sponge/events/PlotClearEvent.java | 2 +- .../sponge/events/PlotComponentSetEvent.java | 2 +- .../sponge/events/PlotDeleteEvent.java | 2 +- .../sponge/util/SpongeEventUtil.java | 2 +- .../sponge/util/SpongeSetupUtils.java | 8 ++ 55 files changed, 716 insertions(+), 176 deletions(-) create mode 100644 Core/src/main/java/com/intellectualcrafters/plot/commands/DebugImportWorlds.java create mode 100644 Core/src/main/java/com/intellectualcrafters/plot/object/worlds/SinglePlot.java create mode 100644 Core/src/main/java/com/intellectualcrafters/plot/object/worlds/SingleWorldGenerator.java diff --git a/.gitignore b/.gitignore index e00d4f9de..ca47bc1a6 100644 --- a/.gitignore +++ b/.gitignore @@ -136,4 +136,5 @@ Nukkit/build/classes/ Nukkit/build/dependency-cache/ checkstyle.xml classes/ -p2error.txt \ No newline at end of file +p2error.txt +*.bat \ No newline at end of file diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java index eb097a4a1..a699bcf43 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitMain.java @@ -16,6 +16,7 @@ import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.object.SetupObject; import com.intellectualcrafters.plot.object.chat.PlainChatManager; +import com.intellectualcrafters.plot.object.worlds.SingleWorldGenerator; import com.intellectualcrafters.plot.util.*; import com.intellectualcrafters.plot.util.block.QueueProvider; import com.intellectualcrafters.plot.uuid.UUIDWrapper; @@ -408,9 +409,14 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain initPlotMeConverter(); Settings.Enabled_Components.PLOTME_CONVERTER = false; } - IndependentPlotGenerator result = PS.get().IMP.getDefaultGenerator(); - if (!PS.get().setupPlotWorld(world, id, result)) { - return null; + IndependentPlotGenerator result; + if (id != null && id.equalsIgnoreCase("single")) { + result = new SingleWorldGenerator(); + } else { + result = PS.get().IMP.getDefaultGenerator(); + if (!PS.get().setupPlotWorld(world, id, result)) { + return null; + } } return (ChunkGenerator) result.specify(world); } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/database/plotme/PlotMeConnector_017.java b/Bukkit/src/main/java/com/plotsquared/bukkit/database/plotme/PlotMeConnector_017.java index 0dee64897..944e02f36 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/database/plotme/PlotMeConnector_017.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/database/plotme/PlotMeConnector_017.java @@ -126,7 +126,7 @@ public class PlotMeConnector_017 extends APlotMeConnector { plots.put(key, plot); } for (Plot plot : plots.values()) { - HashMap mergeMap = merges.get(plot.getArea().worldname); + HashMap mergeMap = merges.get(plot.getWorldName()); if (mergeMap != null) { if (mergeMap.containsKey(plot.getId())) { plot.setMerged(mergeMap.get(plot.getId())); @@ -174,10 +174,10 @@ public class PlotMeConnector_017 extends APlotMeConnector { HashMap> processed = new HashMap<>(); for (Plot plot : plots.values()) { - HashMap map = processed.get(plot.getArea().worldname); + HashMap map = processed.get(plot.getWorldName()); if (map == null) { map = new HashMap<>(); - processed.put(plot.getArea().worldname, map); + processed.put(plot.getWorldName(), map); } map.put(plot.getId(), plot); } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/events/PlotClearEvent.java b/Bukkit/src/main/java/com/plotsquared/bukkit/events/PlotClearEvent.java index ffc416a6b..20ab1d519 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/events/PlotClearEvent.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/events/PlotClearEvent.java @@ -36,7 +36,7 @@ public class PlotClearEvent extends PlotEvent implements Cancellable { * @return String */ public String getWorld() { - return getPlot().getArea().worldname; + return getPlot().getWorldName(); } @Override diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/events/PlotComponentSetEvent.java b/Bukkit/src/main/java/com/plotsquared/bukkit/events/PlotComponentSetEvent.java index 8a2d42d60..d7b33a06b 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/events/PlotComponentSetEvent.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/events/PlotComponentSetEvent.java @@ -37,7 +37,7 @@ public class PlotComponentSetEvent extends PlotEvent { * @return String */ public String getWorld() { - return getPlot().getArea().worldname; + return getPlot().getWorldName(); } /** diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/events/PlotDeleteEvent.java b/Bukkit/src/main/java/com/plotsquared/bukkit/events/PlotDeleteEvent.java index adb33f64e..126b735d7 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/events/PlotDeleteEvent.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/events/PlotDeleteEvent.java @@ -35,7 +35,7 @@ public class PlotDeleteEvent extends PlotEvent { * @return String */ public String getWorld() { - return getPlot().getArea().worldname; + return getPlot().getWorldName(); } @Override diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BukkitPlotGenerator.java b/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BukkitPlotGenerator.java index 5bb9cb1d1..747dbec58 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BukkitPlotGenerator.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/generator/BukkitPlotGenerator.java @@ -19,17 +19,16 @@ import com.intellectualcrafters.plot.util.block.LocalBlockQueue; import com.intellectualcrafters.plot.util.block.ScopedLocalBlockQueue; import com.plotsquared.bukkit.util.BukkitUtil; import com.plotsquared.bukkit.util.block.GenChunk; -import org.bukkit.Chunk; -import org.bukkit.World; -import org.bukkit.block.Biome; -import org.bukkit.generator.BlockPopulator; -import org.bukkit.generator.ChunkGenerator; - import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Random; import java.util.Set; +import org.bukkit.Chunk; +import org.bukkit.World; +import org.bukkit.block.Biome; +import org.bukkit.generator.BlockPopulator; +import org.bukkit.generator.ChunkGenerator; public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrapper { diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java index 851cfed6d..1a8000ff0 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java @@ -15,6 +15,8 @@ import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotInventory; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.StringWrapper; +import com.intellectualcrafters.plot.object.worlds.PlotAreaManager; +import com.intellectualcrafters.plot.object.worlds.SinglePlotAreaManager; import com.intellectualcrafters.plot.util.EventUtil; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MathMan; @@ -29,6 +31,18 @@ import com.plotsquared.bukkit.util.BukkitUtil; import com.plotsquared.bukkit.util.BukkitVersion; import com.plotsquared.listener.PlayerBlockEventType; import com.plotsquared.listener.PlotListener; +import java.io.File; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map.Entry; +import java.util.Objects; +import java.util.Set; +import java.util.UUID; +import java.util.regex.Pattern; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; @@ -92,6 +106,7 @@ import org.bukkit.event.hanging.HangingPlaceEvent; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.event.player.AsyncPlayerChatEvent; +import org.bukkit.event.player.AsyncPlayerPreLoginEvent; import org.bukkit.event.player.PlayerBucketEmptyEvent; import org.bukkit.event.player.PlayerBucketFillEvent; import org.bukkit.event.player.PlayerChangedWorldEvent; @@ -100,6 +115,7 @@ import org.bukkit.event.player.PlayerEggThrowEvent; import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerLoginEvent; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerRespawnEvent; @@ -116,18 +132,6 @@ import org.bukkit.projectiles.BlockProjectileSource; import org.bukkit.projectiles.ProjectileSource; import org.bukkit.util.Vector; -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map.Entry; -import java.util.Objects; -import java.util.Set; -import java.util.UUID; -import java.util.regex.Pattern; - /** * Player Events involving plots. * @@ -489,9 +493,23 @@ public class PlayerEvents extends PlotListener implements Listener { @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onTeleport(PlayerTeleportEvent event) { - if (event.getTo() == null || event.getFrom() == null) { + if (event.getTo() == null || event.getFrom() == null || !event.getFrom().getWorld().equals(event.getTo().getWorld())) { BukkitUtil.getPlayer(event.getPlayer()).deleteMeta("location"); BukkitUtil.getPlayer(event.getPlayer()).deleteMeta("lastplot"); + org.bukkit.Location to = event.getTo(); + if (to != null) { + Player player = event.getPlayer(); + PlotPlayer pp = PlotPlayer.wrap(player); + Location loc = BukkitUtil.getLocation(to); + PlotArea area = PS.get().getPlotAreaAbs(loc); + if (area == null) { + return; + } + Plot plot = area.getPlot(loc); + if (plot != null) { + plotEntry(pp, plot); + } + } return; } playerMove(event); @@ -786,15 +804,12 @@ public class PlayerEvents extends PlotListener implements Listener { public void onWorldChanged(PlayerChangedWorldEvent event) { Player player = event.getPlayer(); PlotPlayer pp = BukkitUtil.getPlayer(player); - - // Delete last location pp.deleteMeta("location"); Plot plot = (Plot) pp.deleteMeta("lastplot"); if (plot != null) { plotExit(pp, plot); } - if (PS.get().worldedit != null) { if (!Permissions.hasPermission(pp, C.PERMISSION_WORLDEDIT_BYPASS)) { if (pp.getAttribute("worldedit")) { @@ -805,6 +820,15 @@ public class PlayerEvents extends PlotListener implements Listener { if (Settings.Enabled_Components.PERMISSION_CACHE) { pp.deleteMeta("perm"); } + Location loc = pp.getLocation(); + PlotArea area = PS.get().getPlotAreaAbs(loc); + if (area == null) { + return; + } + plot = area.getPlot(loc); + if (plot != null) { + plotEntry(pp, plot); + } } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/WorldEvents.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/WorldEvents.java index 49ce15eb9..1e80cc19b 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/WorldEvents.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/WorldEvents.java @@ -2,6 +2,8 @@ package com.plotsquared.bukkit.listeners; import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.generator.GeneratorWrapper; +import com.intellectualcrafters.plot.object.worlds.PlotAreaManager; +import com.intellectualcrafters.plot.object.worlds.SinglePlotAreaManager; import com.plotsquared.bukkit.generator.BukkitPlotGenerator; import org.bukkit.World; import org.bukkit.event.EventHandler; @@ -16,6 +18,14 @@ public class WorldEvents implements Listener { public void onWorldInit(WorldInitEvent event) { World world = event.getWorld(); String name = world.getName(); + PlotAreaManager manager = PS.get().getPlotAreaManager(); + if (manager instanceof SinglePlotAreaManager) { + SinglePlotAreaManager single = (SinglePlotAreaManager) manager; + if (single.isWorld(name)) { + world.setKeepSpawnInMemory(false); + return; + } + } ChunkGenerator gen = world.getGenerator(); if (gen instanceof GeneratorWrapper) { PS.get().loadWorld(name, (GeneratorWrapper) gen); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEventUtil.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEventUtil.java index 31adf2aad..b004e6ff4 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEventUtil.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEventUtil.java @@ -85,7 +85,7 @@ public class BukkitEventUtil extends EventUtil { @Override public boolean callMerge(Plot plot, ArrayList plots) { - return callEvent(new PlotMergeEvent(BukkitUtil.getWorld(plot.getArea().worldname), plot, plots)); + return callEvent(new PlotMergeEvent(BukkitUtil.getWorld(plot.getWorldName()), plot, plots)); } @Override diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitSetupUtils.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitSetupUtils.java index 4056103f8..04d1b2d07 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitSetupUtils.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitSetupUtils.java @@ -9,18 +9,20 @@ import com.intellectualcrafters.plot.object.PlotArea; import com.intellectualcrafters.plot.object.SetupObject; import com.intellectualcrafters.plot.util.SetupUtils; import com.plotsquared.bukkit.generator.BukkitPlotGenerator; -import org.bukkit.Bukkit; -import org.bukkit.World; -import org.bukkit.World.Environment; -import org.bukkit.WorldCreator; -import org.bukkit.generator.ChunkGenerator; -import org.bukkit.plugin.Plugin; - import java.io.File; import java.io.IOException; import java.util.HashMap; import java.util.Map.Entry; import java.util.Objects; +import org.bukkit.Bukkit; +import org.bukkit.Chunk; +import org.bukkit.World; +import org.bukkit.World.Environment; +import org.bukkit.WorldCreator; +import org.bukkit.WorldType; +import org.bukkit.entity.Player; +import org.bukkit.generator.ChunkGenerator; +import org.bukkit.plugin.Plugin; public class BukkitSetupUtils extends SetupUtils { @@ -52,6 +54,28 @@ public class BukkitSetupUtils extends SetupUtils { } } + @Override + public void unload(String worldName, boolean save) { + World world = Bukkit.getWorld(worldName); + if (world == null) { + return; + } + World dw = Bukkit.getWorlds().get(0); + for (Player player : world.getPlayers()) { + player.teleport(dw.getSpawnLocation()); + } + if (save) { + for (Chunk chunk : world.getLoadedChunks()) { + chunk.unload(true, false); + } + } else { + for (Chunk chunk : world.getLoadedChunks()) { + chunk.unload(false, false); + } + } + Bukkit.unloadWorld(world, false); + } + @Override public String setupWorld(SetupObject object) { SetupUtils.manager.updateGenerators(); @@ -59,13 +83,13 @@ public class BukkitSetupUtils extends SetupUtils { String world = object.world; int type = object.type; String worldPath = "worlds." + object.world; - if (!PS.get().worlds.contains(worldPath)) { - PS.get().worlds.createSection(worldPath); - } - ConfigurationSection worldSection = PS.get().worlds.getConfigurationSection(worldPath); switch (type) { case 2: { if (object.id != null) { + if (!PS.get().worlds.contains(worldPath)) { + PS.get().worlds.createSection(worldPath); + } + ConfigurationSection worldSection = PS.get().worlds.getConfigurationSection(worldPath); String areaName = object.id + "-" + object.min + "-" + object.max; String areaPath = "areas." + areaName; if (!worldSection.contains(areaPath)) { @@ -101,7 +125,11 @@ public class BukkitSetupUtils extends SetupUtils { } break; } - case 1: + case 1: { + if (!PS.get().worlds.contains(worldPath)) { + PS.get().worlds.createSection(worldPath); + } + ConfigurationSection worldSection = PS.get().worlds.getConfigurationSection(worldPath); for (ConfigurationNode step : steps) { worldSection.set(step.getConstant(), step.getValue()); } @@ -116,11 +144,19 @@ public class BukkitSetupUtils extends SetupUtils { object.setupGenerator = null; } break; - case 0: - for (ConfigurationNode step : steps) { - worldSection.set(step.getConstant(), step.getValue()); + } + case 0: { + if (steps.length != 0) { + if (!PS.get().worlds.contains(worldPath)) { + PS.get().worlds.createSection(worldPath); + } + ConfigurationSection worldSection = PS.get().worlds.getConfigurationSection(worldPath); + for (ConfigurationNode step : steps) { + worldSection.set(step.getConstant(), step.getValue()); + } } break; + } } try { PS.get().worlds.save(PS.get().worldsFile); @@ -147,6 +183,7 @@ public class BukkitSetupUtils extends SetupUtils { WorldCreator wc = new WorldCreator(object.world); wc.generator(object.setupGenerator); wc.environment(Environment.NORMAL); + wc.type(WorldType.FLAT); Bukkit.createWorld(wc); setGenerator(world, object.setupGenerator); } else { @@ -163,7 +200,7 @@ public class BukkitSetupUtils extends SetupUtils { return world; } } - Bukkit.createWorld(new WorldCreator(object.world).environment(World.Environment.NORMAL)); + World bw = Bukkit.createWorld(new WorldCreator(object.world).environment(Environment.NORMAL)); } return object.world; } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java index a06888751..0ce12e618 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java @@ -7,10 +7,10 @@ import com.intellectualcrafters.plot.object.RegionWrapper; import com.intellectualcrafters.plot.object.schematic.PlotItem; import com.intellectualcrafters.plot.util.MathMan; import com.intellectualcrafters.plot.util.StringComparison; -import com.intellectualcrafters.plot.util.StringMan; import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualcrafters.plot.util.WorldUtil; import com.plotsquared.bukkit.object.BukkitPlayer; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; import org.bukkit.Bukkit; @@ -80,15 +80,7 @@ public class BukkitUtil extends WorldUtil { } public static World getWorld(String string) { - if (StringMan.isEqual(string, lastString)) { - if (lastWorld != null) { - return lastWorld; - } - } - World world = Bukkit.getWorld(string); - lastString = string; - lastWorld = world; - return world; + return Bukkit.getWorld(string); } public static String getWorld(Entity entity) { @@ -96,7 +88,8 @@ public class BukkitUtil extends WorldUtil { } public static List getEntities(String worldName) { - return getWorld(worldName).getEntities(); + World world = getWorld(worldName); + return world != null ? world.getEntities() : new ArrayList(); } public static Location getLocation(Entity entity) { diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/SendChunk.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/SendChunk.java index 0ed341469..2a68579ce 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/SendChunk.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/SendChunk.java @@ -89,7 +89,7 @@ public class SendChunk { Location location = null; String world; if (plot != null) { - world = plot.getArea().worldname; + world = plot.getWorldName(); } else { location = pp.getLocation(); world = location.getWorld(); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/PS.java b/Core/src/main/java/com/intellectualcrafters/plot/PS.java index c3d2db9f5..a6af0ccc9 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/PS.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/PS.java @@ -30,6 +30,8 @@ import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.object.StringWrapper; import com.intellectualcrafters.plot.object.worlds.DefaultPlotAreaManager; import com.intellectualcrafters.plot.object.worlds.PlotAreaManager; +import com.intellectualcrafters.plot.object.worlds.SinglePlotArea; +import com.intellectualcrafters.plot.object.worlds.SinglePlotAreaManager; import com.intellectualcrafters.plot.util.AbstractTitle; import com.intellectualcrafters.plot.util.ChatManager; import com.intellectualcrafters.plot.util.ChunkManager; @@ -125,7 +127,6 @@ public class PS{ */ public PS(IPlotMain iPlotMain, String platform) { PS.instance = this; - this.manager = new DefaultPlotAreaManager(); this.thread = Thread.currentThread(); this.IMP = iPlotMain; this.logger = iPlotMain; @@ -152,6 +153,13 @@ public class PS{ MainUtil.getFile(this.IMP.getDirectory(), Settings.Paths.TRANSLATIONS + File.separator + IMP.getPluginName() + ".use_THIS.yml"); C.load(this.translationFile); + // Setup manager + if (Settings.Enabled_Components.WORLDS) { + this.manager = new SinglePlotAreaManager(); + } else { + this.manager = new DefaultPlotAreaManager(); + } + // Database if (Settings.Enabled_Components.DATABASE) { setupDatabase(); @@ -275,11 +283,9 @@ public class PS{ if (world.equals("CheckingPlotSquaredGenerator")) { continue; } - if (!WorldUtil.IMP.isWorld(world)) { + if (!WorldUtil.IMP.isWorld(world) && !world.equals("*")) { debug("&c`" + world + "` was not properly loaded - " + IMP.getPluginName() + " will now try to load it properly: "); - debug( - "&8 - &7Are you trying to delete this world? Remember to remove it from the settings.yml, bukkit.yml and " - + "multiverse worlds.yml"); + debug("&8 - &7Are you trying to delete this world? Remember to remove it from the settings.yml, bukkit.yml and multiverse worlds.yml"); debug("&8 - &7Your world management plugin may be faulty (or non existent)"); PS.this.IMP.setGenerator(world); } @@ -1599,6 +1605,16 @@ public class PS{ } DBFunc.dbManager = new SQLManager(database, Storage.PREFIX, false); this.plots_tmp = DBFunc.getPlots(); + if (manager instanceof SinglePlotAreaManager) { + SinglePlotArea area = ((SinglePlotAreaManager) manager).getArea(); + addPlotArea(area); + ConfigurationSection section = worlds.getConfigurationSection("worlds.*"); + if (section == null) { + section = worlds.createSection("worlds.*"); + } + area.saveConfiguration(section); + area.loadDefaultConfiguration(section); + } this.clusters_tmp = DBFunc.getClusters(); } catch (ClassNotFoundException | SQLException e) { PS.log(C.PREFIX + "&cFailed to open DATABASE connection. The plugin will disable itself."); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Auto.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Auto.java index 78a1e57a3..27f950b09 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Auto.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Auto.java @@ -110,7 +110,7 @@ public class Auto extends SubCommand { int diff = currentPlots - player.getAllowedPlots(); if (diff + size_x * size_z > 0) { if (diff < 0) { - MainUtil.sendMessage(player, C.CANT_CLAIM_MORE_PLOTS_NUM, -diff + ""); + MainUtil.sendMessage(player, C.CANT_CLAIM_MORE_PLOTS_NUM, -diff + ""); return false; } else if (player.hasPersistentMeta("grantedPlots")) { int grantedPlots = ByteArrayUtilities.bytesToInteger(player.getPersistentMeta("grantedPlots")); @@ -176,7 +176,6 @@ public class Auto extends SubCommand { MainUtil.sendMessage(player, C.NO_FREE_PLOTS); return false; } - plotarea.setMeta("lastPlot", new PlotId(0, 0)); while (true) { PlotId start = getNextPlotId(getLastPlotId(plotarea), 1); PlotId end = new PlotId(start.x + size_x - 1, start.y + size_z - 1); @@ -197,7 +196,6 @@ public class Auto extends SubCommand { break; } } - plotarea.setMeta("lastPlot", new PlotId(0, 0)); return true; } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/DebugImportWorlds.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/DebugImportWorlds.java new file mode 100644 index 000000000..e7618a14e --- /dev/null +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/DebugImportWorlds.java @@ -0,0 +1,60 @@ +package com.intellectualcrafters.plot.commands; + +import com.google.common.base.Charsets; +import com.intellectualcrafters.plot.PS; +import com.intellectualcrafters.plot.object.PlotId; +import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.object.RunnableVal2; +import com.intellectualcrafters.plot.object.RunnableVal3; +import com.intellectualcrafters.plot.object.worlds.PlotAreaManager; +import com.intellectualcrafters.plot.object.worlds.SinglePlotArea; +import com.intellectualcrafters.plot.object.worlds.SinglePlotAreaManager; +import com.intellectualcrafters.plot.util.UUIDHandler; +import com.intellectualcrafters.plot.util.WorldUtil; +import com.plotsquared.general.commands.Command; +import com.plotsquared.general.commands.CommandDeclaration; +import java.io.File; +import java.util.UUID; +import java.util.zip.DeflaterOutputStream; + +@CommandDeclaration( + command = "debugimportworlds", + permission = "plots.admin", + description = "Import worlds by player name", + requiredType = RequiredType.CONSOLE, + category = CommandCategory.TELEPORT) +public class DebugImportWorlds extends Command { + public DebugImportWorlds() { + super(MainCommand.getInstance(), true); + } + + @Override + public void execute(PlotPlayer player, String[] args, RunnableVal3 confirm, RunnableVal2 whenDone) throws CommandException { + // UUID.nameUUIDFromBytes(("OfflinePlayer:" + player.getName()).getBytes(Charsets.UTF_8)) + PlotAreaManager pam = PS.get().getPlotAreaManager(); + if (!(pam instanceof SinglePlotAreaManager)) { + player.sendMessage("Must be a single plot area!"); + return; + } + SinglePlotArea area = ((SinglePlotAreaManager) pam).getArea(); + PlotId id = new PlotId(0, 0); + File container = PS.imp().getWorldContainer(); + for (File folder : container.listFiles()) { + String name = folder.getName(); + if (!WorldUtil.IMP.isWorld(name) && PlotId.fromString(name) == null) { + UUID uuid = UUIDHandler.getUUID(name, null); + if (uuid == null) { + uuid = UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(Charsets.UTF_8)); + } + while (new File(container, id.toCommaSeparatedString()).exists()) { + id = Auto.getNextPlotId(id, 1); + } + File newDir = new File(container, id.toCommaSeparatedString()); + if (folder.renameTo(newDir)) { + area.getPlot(id).setOwner(uuid); + } + } + } + player.sendMessage("Done!"); + } +} diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Deny.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Deny.java index e1e4c36e4..bf8ba64d3 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Deny.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Deny.java @@ -1,5 +1,6 @@ package com.intellectualcrafters.plot.commands; +import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.object.Location; @@ -98,7 +99,19 @@ public class Deny extends SubCommand { if (player.getGameMode() == PlotGameMode.SPECTATOR) { player.stopSpectating(); } - player.teleport(WorldUtil.IMP.getSpawn(player.getLocation().getWorld())); + Location loc = player.getLocation(); + Location spawn = WorldUtil.IMP.getSpawn(loc.getWorld()); MainUtil.sendMessage(player, C.YOU_GOT_DENIED); + if (plot.equals(spawn.getPlot())) { + Location newSpawn = WorldUtil.IMP.getSpawn(PS.get().getPlotAreaManager().getAllWorlds()[0]); + if (plot.equals(newSpawn.getPlot())) { + // Kick from server if you can't be teleported to spawn + player.kick(C.YOU_GOT_DENIED.s()); + } else { + player.teleport(newSpawn); + } + } else { + player.teleport(spawn); + } } } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Download.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Download.java index e4bdc7d02..d8165138e 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Download.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Download.java @@ -55,6 +55,10 @@ public class Download extends SubCommand { return false; } if (args.length == 0 || (args.length == 1 && StringMan.isEqualIgnoreCaseToAny(args[0], "sch", "schem", "schematic"))) { + if (plot.getVolume() > Integer.MAX_VALUE) { + C.SCHEMATIC_TOO_LARGE.send(player); + return false; + } plot.addRunning(); SchematicHandler.manager.getCompoundTag(plot, new RunnableVal() { @Override diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Kick.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Kick.java index d2eb27bd0..18a7af200 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Kick.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Kick.java @@ -1,5 +1,6 @@ package com.intellectualcrafters.plot.commands; +import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.object.Location; @@ -78,7 +79,7 @@ public class Kick extends SubCommand { Location spawn = WorldUtil.IMP.getSpawn(location.getWorld()); C.YOU_GOT_KICKED.send(player2); if (plot.equals(spawn.getPlot())) { - Location newSpawn = WorldUtil.IMP.getSpawn(player2); + Location newSpawn = WorldUtil.IMP.getSpawn(PS.get().getPlotAreaManager().getAllWorlds()[0]); if (plot.equals(newSpawn.getPlot())) { // Kick from server if you can't be teleported to spawn player2.kick(C.YOU_GOT_KICKED.s()); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java index 34cea9087..d0f77bcbd 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java @@ -91,7 +91,6 @@ public class MainCommand extends Command { new DebugFixFlags(); new Move(); new Condense(); - new Condense(); new Copy(); new Chat(); new Trim(); @@ -107,6 +106,7 @@ public class MainCommand extends Command { new Alias(); new SetHome(); new Cluster(); + new DebugImportWorlds(); // Referenced commands instance.toggle = new Toggle(); instance.help = new Help(instance); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Owner.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Owner.java index c7d4092d1..fa460871a 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Owner.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Owner.java @@ -65,7 +65,7 @@ public class Owner extends SetCommand { return false; } int size = plots.size(); - int currentPlots = (Settings.Limit.GLOBAL ? other.getPlotCount() : other.getPlotCount(plot.getArea().worldname)) + size; + int currentPlots = (Settings.Limit.GLOBAL ? other.getPlotCount() : other.getPlotCount(plot.getWorldName())) + size; if (currentPlots > other.getAllowedPlots()) { sendMessage(player, C.CANT_TRANSFER_MORE_PLOTS); return false; diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Purge.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Purge.java index 474621804..31a6a60fc 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Purge.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Purge.java @@ -92,7 +92,7 @@ public class Purge extends SubCommand { } final HashSet toDelete = new HashSet<>(); for (Plot plot : PS.get().getBasePlots()) { - if (world != null && !plot.getArea().worldname.equalsIgnoreCase(world)) { + if (world != null && !plot.getWorldName().equalsIgnoreCase(world)) { continue; } if (area != null && !plot.getArea().equals(area)) { diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Set.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Set.java index 7b7b7505d..3ad2f995c 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Set.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Set.java @@ -146,6 +146,9 @@ public class Set extends SubCommand { } Command cmd = MainCommand.getInstance().getCommand("set" + args[0]); if (cmd != null) { + if (!Permissions.hasPermission(player, cmd.getPermission(), true)) { + return false; + } cmd.execute(player, Arrays.copyOfRange(args, 1, args.length), null, null); return true; } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/config/Settings.java b/Core/src/main/java/com/intellectualcrafters/plot/config/Settings.java index 07a4f4001..9dfd7ae8f 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/config/Settings.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/config/Settings.java @@ -100,7 +100,6 @@ public class Settings extends Config { // Web Web.URL = config.getString("web.url", Web.URL); - Web.SERVER_IP = config.getString("web.server-ip", Web.SERVER_IP); // Caching Enabled_Components.PERMISSION_CACHE = config.getBoolean("cache.permissions", Enabled_Components.PERMISSION_CACHE); @@ -204,10 +203,20 @@ public class Settings extends Config { } public static class Web { - @Comment("We are already hosting a web interface for you:") + @Comment({ + "The web interface for schematics", + " - All schematics are anonymous and private", + " - Downloads can be deleted by the user", + " - Supports plot uploads, downloads and saves", + }) public static String URL = "http://empcraft.com/plots/"; - @Comment("The ip that will show up in the interface") - public static String SERVER_IP = "your.ip.here"; + @Comment({ + "The web interface for assets", + " - All schematics are organized and public", + " - Assets can be searched, selected and downloaded", + }) + public static String ASSETS = "http://empcraft.com/assetpack/"; + } public static final class Done { @@ -306,6 +315,8 @@ public class Settings extends Config { public static boolean KILL_ROAD_VEHICLES = false; @Comment("Notify a player of any missed comments upon plot entry") public static boolean COMMENT_NOTIFIER = false; + @Comment("Let player's claim entire worlds with PlotSquared") + public static boolean WORLDS = false; @Comment("Actively purge invalid database entries") public static boolean DATABASE_PURGER = false; @Comment("Delete plots when a player is banned") diff --git a/Core/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java b/Core/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java index 005a932e6..eca6f9dc4 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java @@ -152,7 +152,7 @@ public class SQLManager implements AbstractDB { } } else { try { - Thread.sleep(5000); + Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } @@ -1040,7 +1040,7 @@ public class SQLManager implements AbstractDB { stmt.setInt(1, plot.getId().x); stmt.setInt(2, plot.getId().y); stmt.setString(3, plot.owner.toString()); - stmt.setString(4, plot.getArea().toString()); + stmt.setString(4, plot.getArea().worldname); stmt.setTimestamp(5, new Timestamp(plot.getTimestamp())); } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java b/Core/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java index 7436e02c2..0ed463c29 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/flag/FlagManager.java @@ -208,8 +208,12 @@ public class FlagManager { flags.put(flag.getKey(), flag.getValue()); } return flags; + } else if (flags == null) { + return settings.flags; + } else { + flags.putAll(settings.flags); } - return settings.flags; + return flags; } public static Map, Object> getSettingFlags(PlotArea area, PlotSettings settings) { diff --git a/Core/src/main/java/com/intellectualcrafters/plot/generator/HybridUtils.java b/Core/src/main/java/com/intellectualcrafters/plot/generator/HybridUtils.java index 67880d360..1eadb54b4 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/generator/HybridUtils.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/generator/HybridUtils.java @@ -93,7 +93,7 @@ public abstract class HybridUtils { } RegionWrapper region = zones.poll(); final Runnable task = this; - analyzeRegion(origin.getArea().worldname, region, new RunnableVal() { + analyzeRegion(origin.getWorldName(), region, new RunnableVal() { @Override public void run(PlotAnalysis value) { analysis.add(value); @@ -167,13 +167,13 @@ public abstract class HybridUtils { return; } RegionWrapper region = zones.poll(); - Location pos1 = new Location(plot.getArea().worldname, region.minX, region.minY, region.minZ); - Location pos2 = new Location(plot.getArea().worldname, region.maxX, region.maxY, region.maxZ); + Location pos1 = new Location(plot.getWorldName(), region.minX, region.minY, region.minZ); + Location pos2 = new Location(plot.getWorldName(), region.maxX, region.maxY, region.maxZ); ChunkManager.chunkTask(pos1, pos2, new RunnableVal() { @Override public void run(int[] value) { ChunkLoc loc = new ChunkLoc(value[0], value[1]); - ChunkManager.manager.loadChunk(plot.getArea().worldname, loc, false); + ChunkManager.manager.loadChunk(plot.getWorldName(), loc, false); int bx = value[2]; int bz = value[3]; int ex = value[4]; @@ -314,7 +314,7 @@ public abstract class HybridUtils { } public boolean setupRoadSchematic(Plot plot) { - final String world = plot.getArea().worldname; + final String world = plot.getWorldName(); final LocalBlockQueue queue = GlobalBlockQueue.IMP.getNewQueue(world, false); Location bot = plot.getBottomAbs().subtract(1, 0, 1); Location top = plot.getTopAbs(); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/generator/SquarePlotManager.java b/Core/src/main/java/com/intellectualcrafters/plot/generator/SquarePlotManager.java index 978e2873a..bea05ebe0 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/generator/SquarePlotManager.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/generator/SquarePlotManager.java @@ -31,8 +31,8 @@ public abstract class SquarePlotManager extends GridPlotManager { Iterator iterator = regions.iterator(); RegionWrapper region = iterator.next(); iterator.remove(); - Location pos1 = new Location(plot.getArea().worldname, region.minX, region.minY, region.minZ); - Location pos2 = new Location(plot.getArea().worldname, region.maxX, region.maxY, region.maxZ); + Location pos1 = new Location(plot.getWorldName(), region.minX, region.minY, region.minZ); + Location pos2 = new Location(plot.getWorldName(), region.maxX, region.maxY, region.maxZ); ChunkManager.manager.regenerateRegion(pos1, pos2, false, this); } }; diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java b/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java index 74746c172..c0615864e 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java @@ -209,6 +209,10 @@ public class Plot { this.temp = temp; } + public String getWorldName() { + return area.worldname; + } + /** * Get a plot from a string e.g. [area];[id] * @param defaultArea If no area is specified @@ -771,7 +775,7 @@ public class Plot { @Override public void run() { for (RegionWrapper region : regions) { - Location[] corners = region.getCorners(Plot.this.area.worldname); + Location[] corners = region.getCorners(getWorldName()); ChunkManager.manager.clearAllEntities(corners[0], corners[1]); } TaskManager.runTask(whenDone); @@ -797,7 +801,7 @@ public class Plot { }; if (!isMerged() && this.area.getRegion().equals(getLargestRegion())) { final LocalBlockQueue blockQueue = area.getQueue(false); - ChunkManager.largeRegionTask(this.area.worldname, this.area.getRegion(), new RunnableVal() { + ChunkManager.largeRegionTask(this.getWorldName(), this.area.getRegion(), new RunnableVal() { @Override public void run(ChunkLoc value) { blockQueue.regenChunk(value.x, value.z); @@ -831,15 +835,15 @@ public class Plot { return; } RegionWrapper region = regions.poll(); - Location pos1 = new Location(Plot.this.area.worldname, region.minX - extendBiome, region.minY, region.minZ - extendBiome); - Location pos2 = new Location(Plot.this.area.worldname, region.maxX + extendBiome, region.maxY, region.maxZ + extendBiome); + Location pos1 = new Location(getWorldName(), region.minX - extendBiome, region.minY, region.minZ - extendBiome); + Location pos2 = new Location(getWorldName(), region.maxX + extendBiome, region.maxY, region.maxZ + extendBiome); ChunkManager.chunkTask(pos1, pos2, new RunnableVal() { @Override public void run(int[] value) { ChunkLoc loc = new ChunkLoc(value[0], value[1]); - ChunkManager.manager.loadChunk(Plot.this.area.worldname, loc, false); - MainUtil.setBiome(Plot.this.area.worldname, value[2], value[3], value[4], value[5], biome); - ChunkManager.manager.unloadChunk(Plot.this.area.worldname, loc, true, true); + ChunkManager.manager.loadChunk(getWorldName(), loc, false); + MainUtil.setBiome(getWorldName(), value[2], value[3], value[4], value[5], biome); + ChunkManager.manager.unloadChunk(getWorldName(), loc, true, true); } }, this, 5); @@ -916,6 +920,7 @@ public class Plot { * @param name */ public void setSign(final String name) { + if (!isLoaded()) return; if (!PS.get().isMainThread(Thread.currentThread())) { TaskManager.runTask(new Runnable() { @Override @@ -934,10 +939,14 @@ public class Plot { C.OWNER_SIGN_LINE_2.formatted().replaceAll("%id%", id).replaceAll("%plr%", name), C.OWNER_SIGN_LINE_3.formatted().replaceAll("%id%", id).replaceAll("%plr%", name), C.OWNER_SIGN_LINE_4.formatted().replaceAll("%id%", id).replaceAll("%plr%", name)}; - WorldUtil.IMP.setSign(this.area.worldname, loc.getX(), loc.getY(), loc.getZ(), lines); + WorldUtil.IMP.setSign(this.getWorldName(), loc.getX(), loc.getY(), loc.getZ(), lines); } } + protected boolean isLoaded() { + return WorldUtil.IMP.isWorld(getWorldName()); + } + /** * This will return null if the plot hasn't been analyzed * @return analysis of plot @@ -1118,9 +1127,13 @@ public class Plot { Location[] corners = getCorners(); Location top = corners[0]; Location bot = corners[1]; - Location loc = new Location(this.area.worldname, MathMan.average(bot.getX(), top.getX()), MathMan.average(bot.getY(), top.getY()), MathMan.average(bot.getZ(), top.getZ())); - loc.setY(1 + Math.max(WorldUtil.IMP.getHighestBlock(this.area.worldname, loc.getX(), loc.getZ()), - getManager().getSignLoc(this.area, this).getY())); + Location loc = new Location(this.getWorldName(), MathMan.average(bot.getX(), top.getX()), MathMan.average(bot.getY(), top.getY()), MathMan.average(bot.getZ(), top.getZ())); + if (!isLoaded()) return loc; + int y = isLoaded() ? WorldUtil.IMP.getHighestBlock(getWorldName(), loc.getX(), loc.getZ()) : 64; + if (area.ALLOW_SIGNS) { + y = Math.max(y, getManager().getSignLoc(area, this).getY()); + } + loc.setY(1 + y); return loc; } @@ -1129,8 +1142,11 @@ public class Plot { int x = (largest.maxX >> 1) - (largest.minX >> 1) + largest.minX; int z = largest.minZ - 1; PlotManager manager = getManager(); - int y = Math.max(WorldUtil.IMP.getHighestBlock(area.worldname, x, z), manager.getSignLoc(area, this).getY()); - return new Location(area.worldname, x, y + 1, z); + int y = isLoaded() ? WorldUtil.IMP.getHighestBlock(getWorldName(), x, z) : 64; + if (area.ALLOW_SIGNS) { + y = Math.max(y, manager.getSignLoc(area, this).getY()); + } + return new Location(getWorldName(), x, y + 1, z); } /** @@ -1144,8 +1160,9 @@ public class Plot { } else { Location bot = this.getBottomAbs(); Location loc = new Location(bot.getWorld(), bot.getX() + home.x, bot.getY() + home.y, bot.getZ() + home.z, home.yaw, home.pitch); + if (!isLoaded()) return loc; if (WorldUtil.IMP.getBlock(loc).id != 0) { - loc.setY(Math.max(WorldUtil.IMP.getHighestBlock(this.area.worldname, loc.getX(), loc.getZ()), bot.getY())); + loc.setY(Math.max(WorldUtil.IMP.getHighestBlock(this.getWorldName(), loc.getX(), loc.getZ()), bot.getY())); } return loc; } @@ -1189,8 +1206,8 @@ public class Plot { x = bot.getX() + this.area.DEFAULT_HOME.x; z = bot.getZ() + this.area.DEFAULT_HOME.z; } - int y = WorldUtil.IMP.getHighestBlock(plot.area.worldname, x, z); - return new Location(plot.area.worldname, x, y + 1, z); + int y = isLoaded() ? WorldUtil.IMP.getHighestBlock(plot.getWorldName(), x, z) : 64; + return new Location(plot.getWorldName(), x, y + 1, z); } // Side return plot.getSide(); @@ -1273,7 +1290,7 @@ public class Plot { * This should not need to be called */ public void refreshChunks() { - LocalBlockQueue queue = GlobalBlockQueue.IMP.getNewQueue(area.worldname, false); + LocalBlockQueue queue = GlobalBlockQueue.IMP.getNewQueue(getWorldName(), false); HashSet chunks = new HashSet<>(); for (RegionWrapper region : Plot.this.getRegions()) { for (int x = region.minX >> 4; x <= region.maxX >> 4; x++) { @@ -1293,7 +1310,7 @@ public class Plot { return; } Location loc = manager.getSignLoc(this.area, this); - LocalBlockQueue queue = GlobalBlockQueue.IMP.getNewQueue(area.worldname, false); + LocalBlockQueue queue = GlobalBlockQueue.IMP.getNewQueue(getWorldName(), false); queue.setBlock(loc.getX(), loc.getY(), loc.getZ(), 0); queue.flush(); } @@ -1425,7 +1442,9 @@ public class Plot { * @return */ public Location getTopAbs() { - return this.area.getPlotManager().getPlotTopLocAbs(this.area, this.id); + Location top = this.area.getPlotManager().getPlotTopLocAbs(this.area, this.id); + top.setWorld(getWorldName()); + return top; } /** @@ -1433,7 +1452,9 @@ public class Plot { * @return */ public Location getBottomAbs() { - return this.area.getPlotManager().getPlotBottomLocAbs(this.area, this.id); + Location loc = this.area.getPlotManager().getPlotBottomLocAbs(this.area, this.id); + loc.setWorld(getWorldName()); + return loc; } /** @@ -1552,7 +1573,7 @@ public class Plot { if (!this.isMerged()) { return new Location[]{this.getBottomAbs(), this.getTopAbs()}; } - return MainUtil.getCorners(this.area.worldname, this.getRegions()); + return MainUtil.getCorners(this.getWorldName(), this.getRegions()); } /** @@ -1567,8 +1588,8 @@ public class Plot { Plot other = this.getRelative(1); Location bot = other.getBottomAbs(); Location top = this.getTopAbs(); - Location pos1 = new Location(this.area.worldname, top.getX(), 0, bot.getZ()); - Location pos2 = new Location(this.area.worldname, bot.getX(), 256, top.getZ()); + Location pos1 = new Location(this.getWorldName(), top.getX(), 0, bot.getZ()); + Location pos2 = new Location(this.getWorldName(), bot.getX(), 256, top.getZ()); ChunkManager.manager.regenerateRegion(pos1, pos2, true, null); } else { this.area.getPlotManager().removeRoadEast(this.area, this); @@ -1660,6 +1681,7 @@ public class Plot { return this.area + ";" + this.id.x + ";" + this.id.y; } + /** * Remove a denied player (use DBFunc as well)
* Using the * uuid will remove all users @@ -2070,8 +2092,8 @@ public class Plot { Plot other = this.getRelative(2); Location bot = other.getBottomAbs(); Location top = this.getTopAbs(); - Location pos1 = new Location(this.area.worldname, bot.getX(), 0, top.getZ()); - Location pos2 = new Location(this.area.worldname, top.getX(), 256, bot.getZ()); + Location pos1 = new Location(this.getWorldName(), bot.getX(), 0, top.getZ()); + Location pos2 = new Location(this.getWorldName(), top.getX(), 256, bot.getZ()); ChunkManager.manager.regenerateRegion(pos1, pos2, true, null); } else { this.getManager().removeRoadSouth(this.area, this); @@ -2555,7 +2577,7 @@ public class Plot { int x = (int) MathMan.inverseRound(coords[0]); int z = (int) MathMan.inverseRound(coords[1]); if (type != 4) { - locs.add(new Location(this.area.worldname, x, 0, z)); + locs.add(new Location(this.getWorldName(), x, 0, z)); } } return locs; @@ -2772,11 +2794,11 @@ public class Plot { } final Runnable task = this; RegionWrapper region = regions.poll(); - Location[] corners = region.getCorners(Plot.this.area.worldname); + Location[] corners = region.getCorners(getWorldName()); final Location pos1 = corners[0]; final Location pos2 = corners[1]; Location newPos = pos1.clone().add(offsetX, 0, offsetZ); - newPos.setWorld(destination.area.worldname); + newPos.setWorld(destination.getWorldName()); ChunkManager.manager.copyRegion(pos1, pos2, newPos, new Runnable() { @Override public void run() { @@ -2793,13 +2815,13 @@ public class Plot { return; } RegionWrapper region = regions.poll(); - Location[] corners = region.getCorners(Plot.this.area.worldname); + Location[] corners = region.getCorners(getWorldName()); Location pos1 = corners[0]; Location pos2 = corners[1]; Location pos3 = pos1.clone().add(offsetX, 0, offsetZ); Location pos4 = pos2.clone().add(offsetX, 0, offsetZ); - pos3.setWorld(destination.area.worldname); - pos4.setWorld(destination.area.worldname); + pos3.setWorld(destination.getWorldName()); + pos4.setWorld(destination.getWorldName()); ChunkManager.manager.swap(pos1, pos2, pos3, pos4, this); } }; @@ -2881,11 +2903,11 @@ public class Plot { return; } RegionWrapper region = regions.poll(); - Location[] corners = region.getCorners(Plot.this.area.worldname); + Location[] corners = region.getCorners(getWorldName()); Location pos1 = corners[0]; Location pos2 = corners[1]; Location newPos = pos1.clone().add(offsetX, 0, offsetZ); - newPos.setWorld(destination.area.worldname); + newPos.setWorld(destination.getWorldName()); ChunkManager.manager.copyRegion(pos1, pos2, newPos, this); } }; diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/PlotArea.java b/Core/src/main/java/com/intellectualcrafters/plot/object/PlotArea.java index c1aba3526..2cc5beb2b 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/PlotArea.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/PlotArea.java @@ -43,7 +43,7 @@ public abstract class PlotArea { public final int worldhash; private final PlotId min; private final PlotId max; - private final ConcurrentHashMap plots = new ConcurrentHashMap<>(); + protected final ConcurrentHashMap plots = new ConcurrentHashMap<>(); private final IndependentPlotGenerator generator; public int MAX_PLOT_MEMBERS = 128; public boolean AUTO_MERGE = false; diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/PlotId.java b/Core/src/main/java/com/intellectualcrafters/plot/object/PlotId.java index dfb6b791a..97d2ac8bd 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/PlotId.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/PlotId.java @@ -33,7 +33,7 @@ public class PlotId { if (string == null) { return null; } - String[] parts = string.split(";"); + String[] parts = string.split("[;|,]"); if (parts.length < 2) { return null; } @@ -119,6 +119,12 @@ public class PlotId { return this.x + ";" + this.y; } + public String toCommaSeparatedString() { + return this.x + "," + this.y; + } + + + /** * The PlotId object caches the hashcode for faster mapping/fetching/sorting
* - Recalculation is required if the x/y values change diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/PlotPlayer.java b/Core/src/main/java/com/intellectualcrafters/plot/object/PlotPlayer.java index e0bced8e4..cc3241e4c 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/PlotPlayer.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/PlotPlayer.java @@ -13,7 +13,6 @@ import com.intellectualcrafters.plot.util.PlotWeather; import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualcrafters.plot.util.expiry.ExpireManager; import com.plotsquared.general.commands.CommandCaller; - import java.util.HashMap; import java.util.HashSet; import java.util.Map; diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/worlds/DefaultPlotAreaManager.java b/Core/src/main/java/com/intellectualcrafters/plot/object/worlds/DefaultPlotAreaManager.java index ba7440b57..efad97221 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/worlds/DefaultPlotAreaManager.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/worlds/DefaultPlotAreaManager.java @@ -10,6 +10,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.Set; public class DefaultPlotAreaManager implements PlotAreaManager { @@ -23,7 +24,7 @@ public class DefaultPlotAreaManager implements PlotAreaManager { // Optimization if there are no hash collisions private boolean plotAreaHasCollision = false; private final HashSet plotAreaHashCheck = new HashSet<>(); - private final PlotArea[] noPlotAreas = new PlotArea[0]; + protected final PlotArea[] noPlotAreas = new PlotArea[0]; private String[] worlds = new String[0]; @Override @@ -222,7 +223,7 @@ public class DefaultPlotAreaManager implements PlotAreaManager { if (!this.plotAreaHasCollision && !this.plotAreaHashCheck.add(worldName.hashCode())) { this.plotAreaHasCollision = true; } - Set tmp = new HashSet<>(); + Set tmp = new LinkedHashSet<>(); Collections.addAll(tmp, worlds); tmp.add(worldName); worlds = tmp.toArray(new String[tmp.size()]); @@ -230,7 +231,7 @@ public class DefaultPlotAreaManager implements PlotAreaManager { @Override public void removeWorld(String worldName) { - Set tmp = new HashSet<>(); + Set tmp = new LinkedHashSet<>(); Collections.addAll(tmp, worlds); tmp.remove(worldName); worlds = tmp.toArray(new String[tmp.size()]); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/worlds/SinglePlot.java b/Core/src/main/java/com/intellectualcrafters/plot/object/worlds/SinglePlot.java new file mode 100644 index 000000000..6ed39c281 --- /dev/null +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/worlds/SinglePlot.java @@ -0,0 +1,51 @@ +package com.intellectualcrafters.plot.object.worlds; + +import com.intellectualcrafters.plot.flag.Flag; +import com.intellectualcrafters.plot.object.BlockLoc; +import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotArea; +import com.intellectualcrafters.plot.object.PlotId; +import com.intellectualcrafters.plot.object.PlotPlayer; +import java.util.Collection; +import java.util.HashSet; +import java.util.UUID; + +public class SinglePlot extends Plot { + public SinglePlot(PlotArea area, PlotId id, UUID owner) { + super(area, id, owner); + } + + public SinglePlot(PlotArea area, PlotId id) { + super(area, id); + } + + public SinglePlot(PlotArea area, PlotId id, UUID owner, int temp) { + super(area, id, owner, temp); + } + + public SinglePlot(PlotId id, UUID owner, HashSet trusted, HashSet members, HashSet denied, String alias, BlockLoc position, Collection flags, PlotArea area, boolean[] merged, long timestamp, int temp) { + super(id, owner, trusted, members, denied, alias, position, flags, area, merged, timestamp, temp); + } + + @Override + public String getWorldName() { + return getId().toCommaSeparatedString(); + } + + @Override + public SinglePlotArea getArea() { + return (SinglePlotArea) super.getArea(); + } + + public boolean teleportPlayer(final PlotPlayer player) { + getArea().loadWorld(getId()); + return super.teleportPlayer(player); + } + + @Override + protected boolean isLoaded() { + getArea().loadWorld(getId()); + return super.isLoaded(); + } + // getCenter getSide getHome getDefaultHome getBiome +} diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/worlds/SinglePlotArea.java b/Core/src/main/java/com/intellectualcrafters/plot/object/worlds/SinglePlotArea.java index b953b9151..678642382 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/worlds/SinglePlotArea.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/worlds/SinglePlotArea.java @@ -1,23 +1,116 @@ package com.intellectualcrafters.plot.object.worlds; import com.intellectualcrafters.configuration.ConfigurationSection; +import com.intellectualcrafters.plot.config.Configuration; import com.intellectualcrafters.plot.config.ConfigurationNode; -import com.intellectualcrafters.plot.generator.IndependentPlotGenerator; -import com.intellectualcrafters.plot.object.PlotArea; +import com.intellectualcrafters.plot.generator.GridPlotWorld; +import com.intellectualcrafters.plot.object.Location; +import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotId; +import com.intellectualcrafters.plot.object.PlotLoc; +import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.object.PlotSettings; +import com.intellectualcrafters.plot.object.SetupObject; +import com.intellectualcrafters.plot.util.SetupUtils; +import com.intellectualcrafters.plot.util.WorldUtil; -public class SinglePlotArea extends PlotArea { - public SinglePlotArea(String worldName, String id, IndependentPlotGenerator generator, PlotId min, PlotId max) { - super(worldName, id, generator, min, max); +public class SinglePlotArea extends GridPlotWorld { + + private final SinglePlotArea instance; + public boolean VOID = false; + + public SinglePlotArea() { + super("*", null, new SingleWorldGenerator(), null, null); + instance = this; + this.ALLOW_SIGNS = false; + this.DEFAULT_HOME = new PlotLoc(Integer.MAX_VALUE, Integer.MAX_VALUE); } @Override public void loadConfiguration(ConfigurationSection config) { + VOID = config.getBoolean("void", false); + } + public void loadWorld(PlotId id) { + String worldName = id.toCommaSeparatedString(); + if (WorldUtil.IMP.isWorld(worldName)) return; + SetupObject setup = new SetupObject(); + setup.plotManager = "PlotSquared:single"; + setup.setupGenerator = "PlotSquared:single"; + setup.type = 0; + setup.terrain = 0; + setup.step = new ConfigurationNode[0]; + setup.world = worldName; + SetupUtils.manager.setupWorld(setup); } @Override public ConfigurationNode[] getSettingNodes() { - return new ConfigurationNode[0]; + return new ConfigurationNode[] { + new ConfigurationNode("void", this.VOID, "Void world", Configuration.BOOLEAN) }; + } + + @Override + public Plot getOwnedPlot(Location location) { + PlotId pid = PlotId.fromString(location.getWorld()); + if (pid == null) { + return null; + } + Plot plot = this.plots.get(pid); + return plot == null ? null : plot.getBasePlot(false); + } + + @Override + public Plot getOwnedPlotAbs(Location location) { + PlotId pid = PlotId.fromString(location.getWorld()); + if (pid == null) { + return null; + } + return plots.get(pid); + } + + @Override + public Plot getPlot(Location location) { + PlotId pid = PlotId.fromString(location.getWorld()); + if (pid == null) { + return null; + } + return getPlot(pid); + } + + @Override + public Plot getPlotAbs(Location location) { + PlotId pid = PlotId.fromString(location.getWorld()); + if (pid == null) { + return null; + } + return getPlotAbs(pid); + } + + public boolean addPlot(Plot p) { + PlotSettings s = p.getSettings(); + p = new SinglePlot(p.getId(), p.owner, p.getTrusted(), p.getMembers(), p.getDenied(), s.alias, s.getPosition(), null, this, s.merged, p.getTimestamp(), p.temp); + p.getSettings().flags = s.flags; + for (PlotPlayer pp : p.getPlayersInPlot()) { + pp.setMeta("lastplot", p); + } + return this.plots.put(p.getId(), p) == null; + } + + public Plot getPlotAbs(PlotId id) { + Plot plot = getOwnedPlotAbs(id); + if (plot == null) { + return new SinglePlot(this, id); + } + return plot; + } + + public Plot getPlot(PlotId id) { + // TODO + Plot plot = getOwnedPlotAbs(id); + if (plot == null) { + return new SinglePlot(this, id); + } + return plot.getBasePlot(false); } } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/worlds/SinglePlotAreaManager.java b/Core/src/main/java/com/intellectualcrafters/plot/object/worlds/SinglePlotAreaManager.java index d5e66d2c6..4c323df57 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/worlds/SinglePlotAreaManager.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/worlds/SinglePlotAreaManager.java @@ -4,40 +4,90 @@ import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.PlotArea; import com.intellectualcrafters.plot.object.RegionWrapper; import com.intellectualcrafters.plot.util.ArrayUtil; +import com.intellectualcrafters.plot.util.SetupUtils; public class SinglePlotAreaManager extends DefaultPlotAreaManager { private final SinglePlotArea area; private final SinglePlotArea[] array; private PlotArea[] all; - public SinglePlotAreaManager(SinglePlotArea area) { - this.area = area; + public SinglePlotAreaManager() { + this.area = new SinglePlotArea(); this.array = new SinglePlotArea[] { area }; this.all = new PlotArea[] { area }; + SetupUtils.generators.put("PlotSquared:single", new SingleWorldGenerator().specify("CheckingPlotSquaredGenerator")); + } + + public SinglePlotArea getArea() { + return area; + } + + public boolean isWorld(String id) { + int mode = 0; + char[] chars = id.toCharArray(); + if (chars.length == 1 && chars[0] == '*') { + return true; + } + for (int i = 0; i < chars.length; i++) { + char c = chars[i]; + switch (mode) { + case 0: + mode = 1; + if (c == '-') { + continue; + } + case 1: + if ((c <= '/') || (c >= ':')) { + if (c == ';' || c == ',') { + mode = 2; + continue; + } + return false; + } else { + continue; + } + case 2: + mode = 3; + if (c == '-') { + continue; + } + case 3: + if ((c <= '/') || (c >= ':')) { + return false; + } + continue; + } + } + return true; } @Override public PlotArea getApplicablePlotArea(Location location) { PlotArea found = super.getApplicablePlotArea(location); - return found != null ? found : area; + if (found != null) return found; + String world = location.getWorld(); + return isWorld(world) || world.equals("*") || super.getAllPlotAreas().length == 0 ? area : null; } @Override public PlotArea getPlotArea(Location location) { PlotArea found = super.getPlotArea(location); - return found != null ? found : area; + if (found != null) return found; + return isWorld(location.getWorld()) ? area : null; } @Override public PlotArea getPlotArea(String world, String id) { PlotArea found = super.getPlotArea(world, id); - return found != null ? found : area; + if (found != null) return found; + return isWorld(world) || world.equals("*") ? area : null; } @Override public PlotArea[] getPlotAreas(String world, RegionWrapper region) { PlotArea[] found = super.getPlotAreas(world, region); - return found != null ? found : array; + if (found != null && found.length != 0) return found; + return isWorld(world) || world.equals("*") ? array : noPlotAreas; } @Override @@ -52,6 +102,9 @@ public class SinglePlotAreaManager extends DefaultPlotAreaManager { @Override public void addPlotArea(PlotArea area) { + if(area == this.area) { + return; + } super.addPlotArea(area); all = ArrayUtil.concatAll(super.getAllPlotAreas(), array); } @@ -73,5 +126,4 @@ public class SinglePlotAreaManager extends DefaultPlotAreaManager { public void removeWorld(String worldName) { super.removeWorld(worldName); } - -} +} \ No newline at end of file diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/worlds/SinglePlotManager.java b/Core/src/main/java/com/intellectualcrafters/plot/object/worlds/SinglePlotManager.java index c88fe2972..a94d4d087 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/worlds/SinglePlotManager.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/worlds/SinglePlotManager.java @@ -1,47 +1,57 @@ package com.intellectualcrafters.plot.object.worlds; +import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotArea; import com.intellectualcrafters.plot.object.PlotBlock; import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotManager; +import com.intellectualcrafters.plot.util.MainUtil; +import com.intellectualcrafters.plot.util.SetupUtils; +import java.io.File; import java.util.ArrayList; public class SinglePlotManager extends PlotManager { @Override public PlotId getPlotIdAbs(PlotArea plotArea, int x, int y, int z) { - return null; + return new PlotId(0, 0); } @Override public PlotId getPlotId(PlotArea plotArea, int x, int y, int z) { - return null; + return new PlotId(0, 0); } @Override public Location getPlotBottomLocAbs(PlotArea plotArea, PlotId plotId) { - return null; + return new Location(plotId.toCommaSeparatedString(), -30000000, 0, -30000000); } @Override public Location getPlotTopLocAbs(PlotArea plotArea, PlotId plotId) { - return null; + return new Location(plotId.toCommaSeparatedString(), 30000000, 0, 30000000); } @Override public boolean clearPlot(PlotArea plotArea, Plot plot, Runnable whenDone) { - return false; + SetupUtils.manager.unload(plot.getWorldName(), false); + File worldFolder = new File(PS.get().IMP.getWorldContainer(), plot.getWorldName()); + MainUtil.deleteDirectory(worldFolder); + if (whenDone != null) whenDone.run(); + return true; } @Override public boolean claimPlot(PlotArea plotArea, Plot plot) { - return false; + // TODO + return true; } @Override public boolean unclaimPlot(PlotArea plotArea, Plot plot, Runnable whenDone) { - return false; + if (whenDone != null) whenDone.run(); + return true; } @Override diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/worlds/SingleWorldGenerator.java b/Core/src/main/java/com/intellectualcrafters/plot/object/worlds/SingleWorldGenerator.java new file mode 100644 index 000000000..499378296 --- /dev/null +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/worlds/SingleWorldGenerator.java @@ -0,0 +1,60 @@ +package com.intellectualcrafters.plot.object.worlds; + +import com.intellectualcrafters.plot.PS; +import com.intellectualcrafters.plot.generator.IndependentPlotGenerator; +import com.intellectualcrafters.plot.object.Location; +import com.intellectualcrafters.plot.object.PlotArea; +import com.intellectualcrafters.plot.object.PlotBlock; +import com.intellectualcrafters.plot.object.PlotId; +import com.intellectualcrafters.plot.object.PlotManager; +import com.intellectualcrafters.plot.object.PseudoRandom; +import com.intellectualcrafters.plot.util.block.ScopedLocalBlockQueue; + +public class SingleWorldGenerator extends IndependentPlotGenerator { + private Location bedrock1 = new Location(null, 0, 0, 0); + private Location bedrock2 = new Location(null, 15, 0, 15); + private Location dirt1 = new Location(null, 0, 1, 0); + private Location dirt2 = new Location(null, 15, 2, 15); + private Location grass1 = new Location(null, 0, 3, 0); + private Location grass2 = new Location(null, 15, 3, 15); + + @Override + public String getName() { + return "PlotSquared:single"; + } + + @Override + public void generateChunk(ScopedLocalBlockQueue result, PlotArea settings, PseudoRandom random) { + SinglePlotArea area = (SinglePlotArea) settings; + if (area.VOID) { + Location min = result.getMin(); + if (min.getX() == 0 && min.getZ() == 0) { + result.setBlock(0, 0, 0, 7, 0); + } + } else { + result.setCuboid(bedrock1, bedrock2, PlotBlock.get(7, 0)); + result.setCuboid(dirt1, dirt2, PlotBlock.get(3, 0)); + result.setCuboid(grass1, grass2, PlotBlock.get(2, 0)); + } + for (int x = 0; x < 16; x++) { + for (int z = 0; z < 16; z++) { + result.setBiome(x, z, "PLAINS"); + } + } + } + + @Override + public PlotArea getNewPlotArea(String world, String id, PlotId min, PlotId max) { + return ((SinglePlotAreaManager) PS.get().getPlotAreaManager()).getArea(); + } + + @Override + public PlotManager getNewPlotManager() { + return new SinglePlotManager(); + } + + @Override + public void initialize(PlotArea area) { + + } +} \ No newline at end of file diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/BO3Handler.java b/Core/src/main/java/com/intellectualcrafters/plot/util/BO3Handler.java index a12335903..0bd783c38 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/BO3Handler.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/BO3Handler.java @@ -99,7 +99,7 @@ public class BO3Handler { } } for (ChunkLoc loc : chunks) { - ChunkManager.manager.loadChunk(plot.getArea().worldname, loc, false); + ChunkManager.manager.loadChunk(plot.getWorldName(), loc, false); } boolean content = false; @@ -115,7 +115,7 @@ public class BO3Handler { ChunkLoc loc = new ChunkLoc(X, Z); BO3 bo3 = map.get(loc); for (int y = 1; y < height; y++) { - PlotBlock block = WorldUtil.IMP.getBlock(new Location(plot.getArea().worldname, x, y, z)); + PlotBlock block = WorldUtil.IMP.getBlock(new Location(plot.getWorldName(), x, y, z)); if (!contains(cpw.MAIN_BLOCK, block)) { if (bo3 == null) { bo3 = new BO3(alias, plotworld.worldname, loc); @@ -125,7 +125,7 @@ public class BO3Handler { bo3.addBlock(xx, y - height - 1, zz, block); } } - PlotBlock floor = WorldUtil.IMP.getBlock(new Location(plot.getArea().worldname, x, height, z)); + PlotBlock floor = WorldUtil.IMP.getBlock(new Location(plot.getWorldName(), x, height, z)); if (!contains(cpw.TOP_BLOCK, floor)) { if (bo3 == null) { bo3 = new BO3(alias, plotworld.worldname, loc); @@ -135,7 +135,7 @@ public class BO3Handler { bo3.addBlock(xx, -1, zz, floor); } for (int y = height + 1; y < 256; y++) { - PlotBlock block = WorldUtil.IMP.getBlock(new Location(plot.getArea().worldname, x, y, z)); + PlotBlock block = WorldUtil.IMP.getBlock(new Location(plot.getWorldName(), x, y, z)); if (block.id != 0) { if (bo3 == null) { bo3 = new BO3(alias, plotworld.worldname, loc); @@ -265,7 +265,7 @@ public class BO3Handler { return false; } - File base = getBaseFile(plot.getArea().worldname); + File base = getBaseFile(plot.getWorldName()); try { List lines = Files.readAllLines(base.toPath(), StandardCharsets.UTF_8); for (int i = 0; i < lines.size(); i++) { diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java b/Core/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java index df973e3af..66ade1b21 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java @@ -119,8 +119,8 @@ public abstract class ChunkManager { return; } RegionWrapper value = regions.remove(0); - Location pos1 = new Location(plot.getArea().worldname, value.minX, 0, value.minZ); - Location pos2 = new Location(plot.getArea().worldname, value.maxX, 0, value.maxZ); + Location pos1 = new Location(plot.getWorldName(), value.minX, 0, value.minZ); + Location pos2 = new Location(plot.getWorldName(), value.maxX, 0, value.maxZ); chunkTask(pos1, pos2, task, this, allocate); } }; diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java b/Core/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java index ada44ca17..9e8dec3bb 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java @@ -130,7 +130,7 @@ public class MainUtil { } final URL url; try { - url = new URL(Settings.Web.URL + "?key=" + uuid + "&ip=" + Settings.Web.SERVER_IP + "&type=" + extension); + url = new URL(Settings.Web.URL + "?key=" + uuid + "&type=" + extension); } catch (MalformedURLException e) { e.printStackTrace(); whenDone.run(); @@ -720,7 +720,7 @@ public class MainUtil { int num = plot.getConnectedPlots().size(); String alias = !plot.getAlias().isEmpty() ? plot.getAlias() : C.NONE.s(); Location bot = plot.getCorners()[0]; - String biome = WorldUtil.IMP.getBiome(plot.getArea().worldname, bot.getX(), bot.getZ()); + String biome = WorldUtil.IMP.getBiome(plot.getWorldName(), bot.getX(), bot.getZ()); String trusted = getPlayerList(plot.getTrusted()); String members = getPlayerList(plot.getMembers()); String denied = getPlayerList(plot.getDenied()); @@ -800,6 +800,23 @@ public class MainUtil { whenDone.run(info); } + public static boolean deleteDirectory(File directory) { + if (directory.exists()) { + File[] files = directory.listFiles(); + if (null != files) { + for (int i = 0; i < files.length; i++) { + File file = files[i]; + if (file.isDirectory()) { + deleteDirectory(files[i]); + } else { + PS.debug("Deleting file: " + file + " | " + file.delete()); + } + } + } + } + return (directory.delete()); + } + /** * Get a list of names given a list of uuids.
* - Uses the format {@link C#PLOT_USER_LIST} for the returned string diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java b/Core/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java index 811ae8d23..4457d25d9 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/SchematicHandler.java @@ -185,14 +185,14 @@ public abstract class SchematicHandler { if (pw instanceof ClassicPlotWorld) { y_offset_actual = yOffset + ((ClassicPlotWorld) pw).PLOT_HEIGHT; } else { - y_offset_actual = yOffset + MainUtil.getHeighestBlock(plot.getArea().worldname, region.minX + 1, region.minZ + 1); + y_offset_actual = yOffset + MainUtil.getHeighestBlock(plot.getWorldName(), region.minX + 1, region.minZ + 1); } } } else { y_offset_actual = yOffset; } - Location pos1 = new Location(plot.getArea().worldname, region.minX + xOffset, y_offset_actual, region.minZ + zOffset); + Location pos1 = new Location(plot.getWorldName(), region.minX + xOffset, y_offset_actual, region.minZ + zOffset); Location pos2 = pos1.clone().add(WIDTH - 1, HEIGHT - 1, LENGTH - 1); // TODO switch to ChunkManager.chunkTask(pos1, pos2, task, whenDone, allocate); final int p1x = pos1.getX(); @@ -597,7 +597,7 @@ public abstract class SchematicHandler { public abstract void getCompoundTag(String world, Set regions, RunnableVal whenDone); public void getCompoundTag(final Plot plot, final RunnableVal whenDone) { - getCompoundTag(plot.getArea().worldname, plot.getRegions(), new RunnableVal() { + getCompoundTag(plot.getWorldName(), plot.getRegions(), new RunnableVal() { @Override public void run(CompoundTag value) { if (!plot.getFlags().isEmpty()) { diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/SetupUtils.java b/Core/src/main/java/com/intellectualcrafters/plot/util/SetupUtils.java index 39c076e72..b284831d3 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/SetupUtils.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/SetupUtils.java @@ -3,7 +3,6 @@ package com.intellectualcrafters.plot.util; import com.intellectualcrafters.plot.generator.GeneratorWrapper; import com.intellectualcrafters.plot.object.PlotArea; import com.intellectualcrafters.plot.object.SetupObject; - import java.util.HashMap; public abstract class SetupUtils { @@ -17,4 +16,6 @@ public abstract class SetupUtils { public abstract String getGenerator(final PlotArea plotArea); public abstract String setupWorld(final SetupObject object); + + public abstract void unload(String world, boolean save); } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/UUIDHandler.java b/Core/src/main/java/com/intellectualcrafters/plot/util/UUIDHandler.java index 89e7edde3..20a92eba9 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/UUIDHandler.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/UUIDHandler.java @@ -9,6 +9,7 @@ import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.object.StringWrapper; import com.intellectualcrafters.plot.uuid.UUIDWrapper; +import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.UUID; @@ -91,26 +92,44 @@ public class UUIDHandler { } public static UUID getUUID(PlotPlayer player) { + if (implementation == null) { + return null; + } return implementation.getUUID(player); } public static UUID getUUID(OfflinePlotPlayer player) { + if (implementation == null) { + return null; + } return implementation.getUUID(player); } public static String getName(UUID uuid) { + if (implementation == null) { + return null; + } return implementation.getName(uuid); } public static PlotPlayer getPlayer(UUID uuid) { + if (implementation == null) { + return null; + } return implementation.getPlayer(uuid); } public static PlotPlayer getPlayer(String name) { + if (implementation == null) { + return null; + } return implementation.getPlayer(name); } public static UUID getUUIDFromString(String nameOrUUIDString) { + if (implementation == null) { + return null; + } if (nameOrUUIDString.length() > 16) { return UUID.fromString(nameOrUUIDString); } @@ -118,18 +137,30 @@ public class UUIDHandler { } public static UUID getUUID(String name, RunnableVal ifFetch) { + if (implementation == null) { + return null; + } return implementation.getUUID(name, ifFetch); } public static UUID getCachedUUID(String name, RunnableVal ifFetch) { + if (implementation == null) { + return null; + } return implementation.getUUIDMap().get(new StringWrapper(name)); } public static Map getPlayers() { + if (implementation == null) { + return new HashMap<>(); + } return implementation.getPlayers(); } public static void handleShutdown() { + if (implementation == null) { + return; + } implementation.handleShutdown(); } } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/WorldUtil.java b/Core/src/main/java/com/intellectualcrafters/plot/util/WorldUtil.java index 20ffd9228..1652c562c 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/WorldUtil.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/WorldUtil.java @@ -1,6 +1,7 @@ package com.intellectualcrafters.plot.util; import com.intellectualcrafters.plot.PS; +import com.intellectualcrafters.plot.object.ChunkLoc; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotBlock; @@ -14,6 +15,7 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.OutputStream; import java.net.URL; +import java.util.Set; import java.util.UUID; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; @@ -66,8 +68,8 @@ public abstract class WorldUtil { @Override public void run(OutputStream output) { try (final ZipOutputStream zos = new ZipOutputStream(output)) { - File dat = getDat(plot.getArea().worldname); - Location spawn = getSpawn(plot.getArea().worldname); + File dat = getDat(plot.getWorldName()); + Location spawn = getSpawn(plot.getWorldName()); setSpawn(home); byte[] buffer = new byte[1024]; if (dat != null) { @@ -87,20 +89,22 @@ public abstract class WorldUtil { int brz = bot.getZ() >> 9; int trx = top.getX() >> 9; int trz = top.getZ() >> 9; - for (int x = brx; x <= trx; x++) { - for (int z = brz; z <= trz; z++) { - File file = getMcr(plot.getArea().worldname, x, z); + Set files = ChunkManager.manager.getChunkChunks(bot.getWorld()); + for (ChunkLoc mca : files) { + if (mca.x >= brx && mca.x <= trx && mca.z >= brz && mca.z <= trz) { + final File file = getMcr(plot.getWorldName(), mca.x, mca.z); if (file != null) { //final String name = "r." + (x - cx) + "." + (z - cz) + ".mca"; String name = file.getName(); - ZipEntry ze = new ZipEntry("world" + File.separator + "region" + File.separator + name); + final ZipEntry ze = new ZipEntry("world" + File.separator + "region" + File.separator + name); zos.putNextEntry(ze); - FileInputStream in = new FileInputStream(file); + final FileInputStream in = new FileInputStream(file); int len; while ((len = in.read(buffer)) > 0) { zos.write(buffer, 0, len); } in.close(); + zos.closeEntry(); } } } diff --git a/Nukkit/src/main/java/com/plotsquared/nukkit/events/PlotClearEvent.java b/Nukkit/src/main/java/com/plotsquared/nukkit/events/PlotClearEvent.java index 47e5ddcf8..7a59d13b4 100644 --- a/Nukkit/src/main/java/com/plotsquared/nukkit/events/PlotClearEvent.java +++ b/Nukkit/src/main/java/com/plotsquared/nukkit/events/PlotClearEvent.java @@ -36,7 +36,7 @@ public class PlotClearEvent extends PlotEvent implements Cancellable { * @return String */ public String getWorld() { - return getPlot().getArea().worldname; + return getPlot().getWorldName(); } diff --git a/Nukkit/src/main/java/com/plotsquared/nukkit/events/PlotComponentSetEvent.java b/Nukkit/src/main/java/com/plotsquared/nukkit/events/PlotComponentSetEvent.java index 5a3515342..c241d137b 100644 --- a/Nukkit/src/main/java/com/plotsquared/nukkit/events/PlotComponentSetEvent.java +++ b/Nukkit/src/main/java/com/plotsquared/nukkit/events/PlotComponentSetEvent.java @@ -37,7 +37,7 @@ public class PlotComponentSetEvent extends PlotEvent { * @return String */ public String getWorld() { - return getPlot().getArea().worldname; + return getPlot().getWorldName(); } /** diff --git a/Nukkit/src/main/java/com/plotsquared/nukkit/events/PlotDeleteEvent.java b/Nukkit/src/main/java/com/plotsquared/nukkit/events/PlotDeleteEvent.java index 223eb5251..8885a26fe 100644 --- a/Nukkit/src/main/java/com/plotsquared/nukkit/events/PlotDeleteEvent.java +++ b/Nukkit/src/main/java/com/plotsquared/nukkit/events/PlotDeleteEvent.java @@ -35,7 +35,7 @@ public class PlotDeleteEvent extends PlotEvent { * @return String */ public String getWorld() { - return getPlot().getArea().worldname; + return getPlot().getWorldName(); } } diff --git a/Nukkit/src/main/java/com/plotsquared/nukkit/util/NukkitEventUtil.java b/Nukkit/src/main/java/com/plotsquared/nukkit/util/NukkitEventUtil.java index 8254af2d1..fdb1135ea 100644 --- a/Nukkit/src/main/java/com/plotsquared/nukkit/util/NukkitEventUtil.java +++ b/Nukkit/src/main/java/com/plotsquared/nukkit/util/NukkitEventUtil.java @@ -90,7 +90,7 @@ public class NukkitEventUtil extends EventUtil { @Override public boolean callMerge(Plot plot, ArrayList plots) { - return callEvent(new PlotMergeEvent(NukkitUtil.getWorld(plot.getArea().worldname), plot, plots)); + return callEvent(new PlotMergeEvent(NukkitUtil.getWorld(plot.getWorldName()), plot, plots)); } @Override diff --git a/Nukkit/src/main/java/com/plotsquared/nukkit/util/NukkitSetupUtils.java b/Nukkit/src/main/java/com/plotsquared/nukkit/util/NukkitSetupUtils.java index 53530b260..155e4e91f 100644 --- a/Nukkit/src/main/java/com/plotsquared/nukkit/util/NukkitSetupUtils.java +++ b/Nukkit/src/main/java/com/plotsquared/nukkit/util/NukkitSetupUtils.java @@ -27,6 +27,11 @@ public class NukkitSetupUtils extends SetupUtils { Generator.addGenerator(NukkitHybridGen.class, "PlotSquared", 1); } + @Override + public void unload(String world, boolean save) { + plugin.getServer().unloadLevel(plugin.getServer().getLevelByName(world), save); + } + @Override public void updateGenerators() { if (!SetupUtils.generators.isEmpty()) { diff --git a/Sponge/src/main/java/com/plotsquared/sponge/events/PlotClearEvent.java b/Sponge/src/main/java/com/plotsquared/sponge/events/PlotClearEvent.java index 8e545e84c..865cc292d 100644 --- a/Sponge/src/main/java/com/plotsquared/sponge/events/PlotClearEvent.java +++ b/Sponge/src/main/java/com/plotsquared/sponge/events/PlotClearEvent.java @@ -36,7 +36,7 @@ public class PlotClearEvent extends AbstractEvent implements Cancellable { * @return String */ public String getWorld() { - return this.plot.getArea().worldname; + return this.plot.getWorldName(); } @Override diff --git a/Sponge/src/main/java/com/plotsquared/sponge/events/PlotComponentSetEvent.java b/Sponge/src/main/java/com/plotsquared/sponge/events/PlotComponentSetEvent.java index d0cdd4e1d..30aa2a4be 100644 --- a/Sponge/src/main/java/com/plotsquared/sponge/events/PlotComponentSetEvent.java +++ b/Sponge/src/main/java/com/plotsquared/sponge/events/PlotComponentSetEvent.java @@ -36,7 +36,7 @@ public class PlotComponentSetEvent extends AbstractEvent { * @return String */ public String getWorld() { - return this.plot.getArea().worldname; + return this.plot.getWorldName(); } /** diff --git a/Sponge/src/main/java/com/plotsquared/sponge/events/PlotDeleteEvent.java b/Sponge/src/main/java/com/plotsquared/sponge/events/PlotDeleteEvent.java index 2a7477312..72efad2f7 100644 --- a/Sponge/src/main/java/com/plotsquared/sponge/events/PlotDeleteEvent.java +++ b/Sponge/src/main/java/com/plotsquared/sponge/events/PlotDeleteEvent.java @@ -33,7 +33,7 @@ public class PlotDeleteEvent extends AbstractEvent { * @return String */ public String getWorld() { - return plot.getArea().worldname; + return plot.getWorldName(); } @Override diff --git a/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeEventUtil.java b/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeEventUtil.java index 5dcc80c67..48dfde521 100644 --- a/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeEventUtil.java +++ b/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeEventUtil.java @@ -81,7 +81,7 @@ public class SpongeEventUtil extends EventUtil { @Override public boolean callMerge(Plot plot, ArrayList plots) { - return callEvent(new PlotMergeEvent(SpongeUtil.getWorld(plot.getArea().worldname), plot, plots)); + return callEvent(new PlotMergeEvent(SpongeUtil.getWorld(plot.getWorldName()), plot, plots)); } @Override diff --git a/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeSetupUtils.java b/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeSetupUtils.java index bb9c4a2d5..d6843d317 100644 --- a/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeSetupUtils.java +++ b/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeSetupUtils.java @@ -47,6 +47,14 @@ public class SpongeSetupUtils extends SetupUtils { } } + @Override + public void unload(String worldName, boolean safe) { + Optional world = Sponge.getServer().getWorld(worldName); + if (world.isPresent()) { + Sponge.getServer().unloadWorld(world.get()); + } + } + @Override public String getGenerator(PlotArea plotArea) { if (SetupUtils.generators.isEmpty()) {