From c83378a91b52237e677c63d768c54c0f8d23ff00 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Thu, 11 Feb 2016 05:59:51 +1100 Subject: [PATCH] Refactor / Cleanup / Optimizations --- pom.xml | 15 +- .../configuration/file/FileConfiguration.java | 11 +- .../intellectualcrafters/plot/IPlotMain.java | 26 +- .../com/intellectualcrafters/plot/PS.java | 1146 +++++--- .../plot/api/PlotAPI.java | 219 +- .../plot/commands/Add.java | 8 +- .../plot/commands/Alias.java | 4 +- .../plot/commands/Auto.java | 107 +- .../plot/commands/BO3.java | 2 +- .../plot/commands/Biome.java | 6 +- .../plot/commands/Buy.java | 24 +- .../plot/commands/Claim.java | 39 +- .../plot/commands/Clear.java | 10 +- .../plot/commands/Cluster.java | 228 +- .../plot/commands/Comment.java | 11 +- .../plot/commands/Condense.java | 33 +- .../plot/commands/Continue.java | 4 +- .../plot/commands/Copy.java | 6 +- .../plot/commands/CreateRoadSchematic.java | 4 +- .../plot/commands/Database.java | 54 +- .../plot/commands/Debug.java | 13 +- .../plot/commands/DebugClaimTest.java | 30 +- .../plot/commands/DebugExec.java | 98 +- .../plot/commands/DebugFixFlags.java | 9 +- .../plot/commands/DebugPaste.java | 26 +- .../plot/commands/DebugRoadRegen.java | 10 +- .../plot/commands/DebugUUID.java | 7 +- .../plot/commands/Delete.java | 12 +- .../plot/commands/Deny.java | 8 +- .../plot/commands/Done.java | 4 +- .../plot/commands/Download.java | 8 +- .../plot/commands/FlagCmd.java | 2 +- .../plot/commands/Inbox.java | 20 +- .../plot/commands/Info.java | 17 +- .../plot/commands/Kick.java | 10 +- .../plot/commands/Load.java | 6 +- .../plot/commands/MainCommand.java | 22 +- .../plot/commands/Merge.java | 20 +- .../plot/commands/Middle.java | 12 +- .../plot/commands/Move.java | 6 +- .../plot/commands/MusicSubcommand.java | 6 +- .../plot/commands/Owner.java | 10 +- .../plot/commands/Purge.java | 248 +- .../plot/commands/Rate.java | 6 +- .../plot/commands/RegenAllRoads.java | 11 +- .../plot/commands/Reload.java | 59 +- .../plot/commands/Remove.java | 2 +- .../plot/commands/Save.java | 12 +- .../plot/commands/SchematicCmd.java | 18 +- .../plot/commands/Set.java | 32 +- .../plot/commands/SetCommand.java | 2 +- .../plot/commands/Setup.java | 143 +- .../plot/commands/Swap.java | 6 +- .../plot/commands/TP.java | 99 - .../plot/commands/Target.java | 35 +- .../plot/commands/Template.java | 22 +- .../plot/commands/Trim.java | 36 +- .../plot/commands/Trust.java | 8 +- .../plot/commands/Unclaim.java | 2 +- .../plot/commands/Undeny.java | 2 +- .../plot/commands/Unlink.java | 15 +- .../plot/commands/Untrust.java | 2 +- .../plot/commands/Visit.java | 24 +- .../plot/commands/list.java | 57 +- .../intellectualcrafters/plot/config/C.java | 12 +- .../plot/config/Configuration.java | 12 +- .../plot/config/Settings.java | 29 +- .../plot/database/AbstractDB.java | 33 +- .../plot/database/DBFunc.java | 27 +- .../plot/database/SQLManager.java | 204 +- .../plot/flag/FlagManager.java | 64 +- .../plot/flag/FlagValue.java | 6 +- .../plot/generator/AugmentedUtils.java | 161 ++ .../plot/generator/ClassicPlotManager.java | 140 +- .../plot/generator/ClassicPlotWorld.java | 10 +- .../plot/generator/GeneratorWrapper.java | 39 + .../plot/generator/GridPlotWorld.java | 14 +- .../plot/generator/HybridGen.java | 187 ++ .../plot/generator/HybridPlotManager.java | 92 +- .../plot/generator/HybridPlotWorld.java | 48 +- .../plot/generator/HybridUtils.java | 134 +- .../generator/IndependentPlotGenerator.java | 72 + .../plot/generator/PlotGenerator.java | 26 +- .../plot/generator/SquarePlotManager.java | 38 +- .../plot/generator/SquarePlotWorld.java | 10 +- .../plot/object/ConsolePlayer.java | 15 +- .../plot/object/Location.java | 85 +- .../plot/object/Plot.java | 1595 +++++++++-- .../plot/object/PlotAnalysis.java | 2 +- .../plot/object/PlotArea.java | 883 +++++++ .../plot/object/PlotCluster.java | 86 +- .../plot/object/PlotClusterId.java | 11 - .../plot/object/PlotFilter.java | 2 +- .../plot/object/PlotHandler.java | 38 +- .../plot/object/PlotId.java | 21 + .../plot/object/PlotItemStack.java | 6 +- .../plot/object/PlotManager.java | 46 +- .../plot/object/PlotPlayer.java | 119 +- .../plot/object/PlotSettings.java | 8 +- .../plot/object/PlotWorld.java | 290 -- .../plot/object/PseudoRandom.java | 2 + .../plot/object/RegionWrapper.java | 10 + .../plot/object/RunnableVal.java | 13 +- .../plot/object/SetupObject.java | 15 + .../plot/object/comment/CommentInbox.java | 4 +- .../plot/object/comment/InboxOwner.java | 5 +- .../plot/object/comment/InboxPublic.java | 5 +- .../plot/object/comment/InboxReport.java | 6 +- .../plot/util/BO3Handler.java | 51 +- .../plot/util/BlockManager.java | 78 - .../plot/util/BlockUpdateUtil.java | 11 - .../plot/util/ChunkManager.java | 101 +- .../plot/util/ClusterManager.java | 315 --- .../plot/util/CommentManager.java | 2 +- .../plot/util/EventUtil.java | 15 +- .../plot/util/ExpireManager.java | 103 +- .../plot/util/HastebinUtility.java | 3 +- .../plot/util/MainUtil.java | 2333 +---------------- .../plot/util/MathMan.java | 12 + .../plot/util/Permissions.java | 2 +- .../plot/util/PlotChunk.java | 95 + .../plot/util/PlotQueue.java | 29 + .../plot/util/ReflectionUtils.java | 14 +- .../plot/util/SchematicHandler.java | 82 +- .../plot/util/SetBlockQueue.java | 333 --- .../plot/util/SetQueue.java | 190 ++ .../plot/util/SetupUtils.java | 10 +- .../plot/util/TaskManager.java | 29 + .../plot/util/UUIDHandler.java | 2 +- .../plot/util/UUIDHandlerImplementation.java | 2 +- .../plot/util/WorldUtil.java | 40 + .../plot/util/area/QuadMap.java | 291 ++ .../plot/uuid/NameFetcher.java | 44 - .../plot/uuid/UUIDFetcher.java | 102 - .../plot/uuid/UUIDWrapper.java | 2 + .../com/plotsquared/bukkit/BukkitMain.java | 439 ++-- .../plotsquared/bukkit/chat/FancyMessage.java | 37 +- .../database/plotme/APlotMeConnector.java | 15 +- .../plotme/ClassicPlotMeConnector.java | 3 +- .../database/plotme/LikePlotMeConverter.java | 52 +- .../database/plotme/PlotMeConnector_017.java | 9 +- .../bukkit/events/PlotClearEvent.java | 27 +- .../bukkit/events/PlotDeleteEvent.java | 25 +- .../bukkit/events/PlotUnlinkEvent.java | 9 +- .../bukkit/generator/AugmentedPopulator.java | 256 -- .../generator/BukkitAugmentedGenerator.java | 34 + .../generator/BukkitGeneratorWrapper.java | 88 - .../bukkit/generator/BukkitPlotGenerator.java | 428 +-- .../bukkit/generator/BukkitPlotPopulator.java | 138 - .../bukkit/generator/HybridGen.java | 297 --- .../bukkit/generator/HybridPop.java | 212 -- .../bukkit/listeners/ChunkListener.java | 24 +- .../bukkit/listeners/PlayerEvents.java | 1033 ++++---- .../bukkit/listeners/PlayerEvents_1_8.java | 21 +- .../bukkit/listeners/PlayerEvents_1_8_3.java | 43 +- .../bukkit/listeners/PlotPlusListener.java | 9 +- .../bukkit/listeners/WorldEvents.java | 8 +- .../listeners/worldedit/WEListener.java | 10 +- .../bukkit/util/BukkitChunkManager.java | 380 +-- .../bukkit/util/BukkitEconHandler.java | 2 +- .../bukkit/util/BukkitEventUtil.java | 17 +- .../bukkit/util/BukkitHybridUtils.java | 4 +- .../bukkit/util/BukkitSetBlockManager.java | 39 - .../bukkit/util/BukkitSetupUtils.java | 104 +- .../plotsquared/bukkit/util/BukkitUtil.java | 139 +- .../bukkit}/util/NbtFactory.java | 33 +- .../plotsquared/bukkit/util/SendChunk.java | 2 +- .../plotsquared/bukkit/util/SetBlockFast.java | 136 - .../bukkit/util/SetBlockFast_1_8.java | 356 --- .../plotsquared/bukkit/util/SetBlockSlow.java | 34 - .../com/plotsquared/bukkit/util/SetGenCB.java | 22 +- .../bukkit/util/block/FastChunk_1_8_3.java | 250 ++ .../bukkit/util/block/FastQueue_1_7.java | 180 ++ .../bukkit/util/block/FastQueue_1_8.java | 386 +++ .../bukkit/util/block/FastQueue_1_8_3.java | 430 +++ .../bukkit/util/block/GenChunk.java | 109 + .../bukkit/util/block/SlowChunk.java | 67 + .../bukkit/util/block/SlowQueue.java | 282 ++ .../bukkit/uuid/DefaultUUIDWrapper.java | 5 + .../bukkit/uuid/FileUUIDHandler.java | 2 +- .../bukkit/uuid/OfflineUUIDWrapper.java | 5 + .../bukkit/uuid/SQLUUIDHandler.java | 33 +- .../general/commands/Argument.java | 3 +- .../plotsquared/listener/PlotListener.java | 14 +- .../listener/ProcessedWEExtent.java | 8 +- .../com/plotsquared/listener/WEManager.java | 14 +- .../plotsquared/listener/WESubscriber.java | 8 +- .../com/plotsquared/sponge/SpongeMain.java | 7 +- .../plotsquared/sponge/SpongeSetupUtils.java | 4 +- .../sponge/generator/AugmentedPopulator.java | 16 +- .../generator/SpongeBasicBiomeProvider.java | 6 +- .../sponge/generator/SpongeBasicGen.java | 8 +- .../sponge/generator/SpongeBasicPop.java | 4 +- .../generator/SpongeGeneratorWrapper.java | 8 +- .../sponge/generator/SpongePlotGenerator.java | 10 +- .../sponge/generator/WorldModify.java | 4 +- .../sponge/listener/MainListener.java | 27 +- .../sponge/object/SpongePlayer.java | 1 - .../sponge/util/SpongeChatManager.java | 2 - .../sponge/util/SpongeChunkManager.java | 2 +- .../sponge/util/SpongeCommand.java | 24 +- .../sponge/util/SpongeTitleManager.java | 1 - .../uuid/SpongeLowerOfflineUUIDWrapper.java | 11 +- 203 files changed, 9785 insertions(+), 8701 deletions(-) delete mode 100644 src/main/java/com/intellectualcrafters/plot/commands/TP.java create mode 100644 src/main/java/com/intellectualcrafters/plot/generator/AugmentedUtils.java create mode 100644 src/main/java/com/intellectualcrafters/plot/generator/GeneratorWrapper.java create mode 100644 src/main/java/com/intellectualcrafters/plot/generator/HybridGen.java create mode 100644 src/main/java/com/intellectualcrafters/plot/generator/IndependentPlotGenerator.java create mode 100644 src/main/java/com/intellectualcrafters/plot/object/PlotArea.java delete mode 100644 src/main/java/com/intellectualcrafters/plot/object/PlotClusterId.java delete mode 100644 src/main/java/com/intellectualcrafters/plot/object/PlotWorld.java delete mode 100644 src/main/java/com/intellectualcrafters/plot/util/BlockManager.java delete mode 100644 src/main/java/com/intellectualcrafters/plot/util/BlockUpdateUtil.java delete mode 100644 src/main/java/com/intellectualcrafters/plot/util/ClusterManager.java create mode 100644 src/main/java/com/intellectualcrafters/plot/util/PlotChunk.java create mode 100644 src/main/java/com/intellectualcrafters/plot/util/PlotQueue.java delete mode 100644 src/main/java/com/intellectualcrafters/plot/util/SetBlockQueue.java create mode 100644 src/main/java/com/intellectualcrafters/plot/util/SetQueue.java create mode 100644 src/main/java/com/intellectualcrafters/plot/util/WorldUtil.java create mode 100644 src/main/java/com/intellectualcrafters/plot/util/area/QuadMap.java delete mode 100644 src/main/java/com/intellectualcrafters/plot/uuid/NameFetcher.java delete mode 100644 src/main/java/com/intellectualcrafters/plot/uuid/UUIDFetcher.java delete mode 100644 src/main/java/com/plotsquared/bukkit/generator/AugmentedPopulator.java create mode 100644 src/main/java/com/plotsquared/bukkit/generator/BukkitAugmentedGenerator.java delete mode 100644 src/main/java/com/plotsquared/bukkit/generator/BukkitGeneratorWrapper.java delete mode 100644 src/main/java/com/plotsquared/bukkit/generator/BukkitPlotPopulator.java delete mode 100644 src/main/java/com/plotsquared/bukkit/generator/HybridGen.java delete mode 100644 src/main/java/com/plotsquared/bukkit/generator/HybridPop.java delete mode 100644 src/main/java/com/plotsquared/bukkit/util/BukkitSetBlockManager.java rename src/main/java/com/{intellectualcrafters/plot => plotsquared/bukkit}/util/NbtFactory.java (99%) delete mode 100644 src/main/java/com/plotsquared/bukkit/util/SetBlockFast.java delete mode 100644 src/main/java/com/plotsquared/bukkit/util/SetBlockFast_1_8.java delete mode 100644 src/main/java/com/plotsquared/bukkit/util/SetBlockSlow.java create mode 100644 src/main/java/com/plotsquared/bukkit/util/block/FastChunk_1_8_3.java create mode 100644 src/main/java/com/plotsquared/bukkit/util/block/FastQueue_1_7.java create mode 100644 src/main/java/com/plotsquared/bukkit/util/block/FastQueue_1_8.java create mode 100644 src/main/java/com/plotsquared/bukkit/util/block/FastQueue_1_8_3.java create mode 100644 src/main/java/com/plotsquared/bukkit/util/block/GenChunk.java create mode 100644 src/main/java/com/plotsquared/bukkit/util/block/SlowChunk.java create mode 100644 src/main/java/com/plotsquared/bukkit/util/block/SlowQueue.java diff --git a/pom.xml b/pom.xml index 8f22652e0..89234726f 100644 --- a/pom.xml +++ b/pom.xml @@ -190,9 +190,13 @@ + + empcraft-repo + http://empcraft.com/maven2 + spigot-repo - http://hub.spigotmc.org/nexus/content/groups/public/ + https://hub.spigotmc.org/nexus/content/groups/public/ - javax.websocket - javax.websocket-api - 1.1 - compile - true + org.bukkit + bukkit + 1.8.8-R0.1-SNAPSHOT - com.sk89q worldedit diff --git a/src/main/java/com/intellectualcrafters/configuration/file/FileConfiguration.java b/src/main/java/com/intellectualcrafters/configuration/file/FileConfiguration.java index 2a4a14889..1d9ccf232 100644 --- a/src/main/java/com/intellectualcrafters/configuration/file/FileConfiguration.java +++ b/src/main/java/com/intellectualcrafters/configuration/file/FileConfiguration.java @@ -1,10 +1,5 @@ package com.intellectualcrafters.configuration.file; -import com.intellectualcrafters.configuration.Configuration; -import com.intellectualcrafters.configuration.InvalidConfigurationException; -import com.intellectualcrafters.configuration.MemoryConfiguration; -import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder; - import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; @@ -19,6 +14,12 @@ import java.io.Writer; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; +import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder; + +import com.intellectualcrafters.configuration.Configuration; +import com.intellectualcrafters.configuration.InvalidConfigurationException; +import com.intellectualcrafters.configuration.MemoryConfiguration; + /** * This is a base class for all File based implementations of {@link * Configuration} diff --git a/src/main/java/com/intellectualcrafters/plot/IPlotMain.java b/src/main/java/com/intellectualcrafters/plot/IPlotMain.java index 5e333a6f2..f8112e478 100644 --- a/src/main/java/com/intellectualcrafters/plot/IPlotMain.java +++ b/src/main/java/com/intellectualcrafters/plot/IPlotMain.java @@ -1,21 +1,24 @@ package com.intellectualcrafters.plot; import java.io.File; +import java.util.List; +import com.intellectualcrafters.plot.generator.GeneratorWrapper; import com.intellectualcrafters.plot.generator.HybridUtils; -import com.intellectualcrafters.plot.generator.PlotGenerator; +import com.intellectualcrafters.plot.generator.IndependentPlotGenerator; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.AbstractTitle; -import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.ChatManager; import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.EconHandler; import com.intellectualcrafters.plot.util.EventUtil; import com.intellectualcrafters.plot.util.InventoryUtil; +import com.intellectualcrafters.plot.util.PlotQueue; import com.intellectualcrafters.plot.util.SchematicHandler; import com.intellectualcrafters.plot.util.SetupUtils; import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.UUIDHandlerImplementation; +import com.intellectualcrafters.plot.util.WorldUtil; public interface IPlotMain { @@ -129,10 +132,16 @@ public interface IPlotMain { EconHandler getEconomyHandler(); /** - * Get the block manager + * Get the Plot Queue class * @return */ - BlockManager initBlockManager(); + PlotQueue initPlotQueue(); + + /** + * Get the World Util class + * @return + */ + WorldUtil initWorldUtil(); /** * Get the EventUtil class @@ -199,7 +208,12 @@ public interface IPlotMain { * @param name * @return */ - PlotGenerator getGenerator(final String world, final String name); + GeneratorWrapper getGenerator(final String world, final String name); + + /** + * + */ + GeneratorWrapper wrapPlotGenerator(String world, IndependentPlotGenerator generator); /** * Register the chunk processor which will clean out chunks that have too many blockstates or entities @@ -222,4 +236,6 @@ public interface IPlotMain { * @return */ AbstractTitle initTitleManager(); + + List getPluginIds(); } diff --git a/src/main/java/com/intellectualcrafters/plot/PS.java b/src/main/java/com/intellectualcrafters/plot/PS.java index 726bd5fe7..08f79a151 100644 --- a/src/main/java/com/intellectualcrafters/plot/PS.java +++ b/src/main/java/com/intellectualcrafters/plot/PS.java @@ -21,14 +21,15 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.Objects; import java.util.Set; import java.util.UUID; -import java.util.concurrent.ConcurrentHashMap; import java.util.regex.Pattern; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; import com.intellectualcrafters.configuration.ConfigurationSection; +import com.intellectualcrafters.configuration.MemorySection; import com.intellectualcrafters.configuration.file.YamlConfiguration; import com.intellectualcrafters.plot.commands.MainCommand; import com.intellectualcrafters.plot.commands.WE_Anywhere; @@ -43,24 +44,25 @@ import com.intellectualcrafters.plot.database.SQLite; import com.intellectualcrafters.plot.flag.AbstractFlag; import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.flag.FlagValue; +import com.intellectualcrafters.plot.generator.GeneratorWrapper; import com.intellectualcrafters.plot.generator.HybridPlotWorld; import com.intellectualcrafters.plot.generator.HybridUtils; -import com.intellectualcrafters.plot.generator.PlotGenerator; -import com.intellectualcrafters.plot.generator.SquarePlotManager; +import com.intellectualcrafters.plot.generator.IndependentPlotGenerator; +import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotAnalysis; +import com.intellectualcrafters.plot.object.PlotArea; import com.intellectualcrafters.plot.object.PlotCluster; import com.intellectualcrafters.plot.object.PlotFilter; import com.intellectualcrafters.plot.object.PlotHandler; import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotManager; import com.intellectualcrafters.plot.object.PlotPlayer; -import com.intellectualcrafters.plot.object.PlotWorld; +import com.intellectualcrafters.plot.object.RegionWrapper; +import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.util.AbstractTitle; -import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.ChatManager; import com.intellectualcrafters.plot.util.ChunkManager; -import com.intellectualcrafters.plot.util.ClusterManager; import com.intellectualcrafters.plot.util.CommentManager; import com.intellectualcrafters.plot.util.EconHandler; import com.intellectualcrafters.plot.util.EventUtil; @@ -72,10 +74,13 @@ import com.intellectualcrafters.plot.util.PlotGamemode; import com.intellectualcrafters.plot.util.PlotWeather; import com.intellectualcrafters.plot.util.ReflectionUtils; import com.intellectualcrafters.plot.util.SchematicHandler; +import com.intellectualcrafters.plot.util.SetQueue; import com.intellectualcrafters.plot.util.SetupUtils; import com.intellectualcrafters.plot.util.StringMan; import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.UUIDHandler; +import com.intellectualcrafters.plot.util.WorldUtil; +import com.intellectualcrafters.plot.util.area.QuadMap; import com.plotsquared.listener.WESubscriber; import com.sk89q.worldedit.WorldEdit; @@ -91,10 +96,23 @@ public class PS { // protected static: private static PS instance; - // private final: - private final HashMap plotworlds = new HashMap<>(); - private final HashMap plotmanagers = new HashMap<>(); + /** + * All plot areas (quick global access) + */ + private PlotArea[] plotareas = new PlotArea[0]; + /** + * All plot areas mapped by world (quick world access) + */ + private final HashMap plotareamap = new HashMap<>(); + /** + * All plot areas mapped by location (quick location based access) + */ + private final HashMap> plotareagrid = new HashMap<>(); + public HashMap> clusters_tmp; + + public HashMap> plots_tmp; + // public: public File styleFile; public File configFile; @@ -113,8 +131,6 @@ public class PS { private int[] VERSION = null; private String PLATFORM = null; private String LAST_VERSION; - private boolean LOADING_WORLD = false; - private ConcurrentHashMap> plots; private Database database; private Connection connection; private Thread thread; @@ -238,8 +254,10 @@ public class PS { InventoryUtil.manager = IMP.initInventoryUtil(); // create setup util class SetupUtils.manager = IMP.initSetupUtils(); + // World Util + WorldUtil.IMP = IMP.initWorldUtil(); // Set block - BlockManager.manager = IMP.initBlockManager(); + SetQueue.IMP.queue = IMP.initPlotQueue(); // Set chunk ChunkManager.manager = IMP.initChunkManager(); // Schematic handler @@ -269,7 +287,7 @@ public class PS { if (world.equals("CheckingPlotSquaredGenerator")) { continue; } - if (BlockManager.manager.isWorld(world)) { + if (WorldUtil.IMP.isWorld(world)) { IMP.setGenerator(world); } } @@ -280,7 +298,7 @@ public class PS { if (world.equals("CheckingPlotSquaredGenerator")) { continue; } - if (!BlockManager.manager.isWorld(world) || (BlockManager.manager.isWorld(world) && !isPlotWorld(world))) { + if (!WorldUtil.IMP.isWorld(world)) { PS.debug("&c`" + world + "` was not properly loaded - PlotSquared will now try to load it properly: "); PS.debug("&8 - &7Are you trying to delete this world? Remember to remove it from the settings.yml, bukkit.yml and multiverse worlds.yml"); PS.debug("&8 - &7Your world management plugin may be faulty (or non existant)"); @@ -356,6 +374,10 @@ public class PS { get().IMP.log(StringMan.getString(message)); } + public static void stacktrace() { + System.err.println(StringMan.join(new Exception().getStackTrace(), "\n\tat ")); + } + /** * Log a message to the IPlotMain logger * @@ -385,48 +407,243 @@ public class PS { * @param plot Plot Object to update */ public boolean updatePlot(final Plot plot) { - for (PlotPlayer pp : plot.getPlayersInPlot()) { - pp.setMeta("lastplot", plot); - } - ConcurrentHashMap map = plots.get(plot.world); - if (map == null) { - map = new ConcurrentHashMap(); - map.put(plot.id, plot); - plots.put(plot.world, map); - return true; - } else { - return map.put(plot.id, plot) == null; - } + return plot.area.addPlot(plot); } /** - * Get the plot world based on the - * name identifier - * - * @param world World Name - * @return plot world | null if not existing - * @see #getPlotWorldsString() Get all plot world names + * Get the relevant plot area for a location.
+ * - If there is only one plot area globally that will be returned
+ * - If there is only one plot area in the world, it will return that
+ * - If the plot area for a location cannot be unambiguously resolved; null will be returned
+ *
+ * Note: An applicable plot area may not include the location i.e. clusters + * @param loc + * @return */ - public PlotWorld getPlotWorld(final String world) { - if (plotworlds.containsKey(world)) { - return plotworlds.get(world); + public PlotArea getApplicablePlotArea(Location loc) { + switch (plotareas.length) { + case 0: + return null; + case 1: + return plotareas[0]; + case 2: + case 3: + case 4: + case 5: + case 6: + case 7: + case 8: + String world = loc.getWorld(); + PlotArea last = null; + int count = 0; + int x = loc.getX(); + int y = loc.getY(); + int hash = world.hashCode(); + for (PlotArea area : plotareas) { + if (hash == area.worldhash && world.equals(area.worldname)) { + if (area.contains(loc)) { + return area; + } + count++; + last = area; + } + } + return count == 1 ? last : null; + default: + PlotArea[] areas = plotareamap.get(loc.getWorld()); + if (areas == null) { + return null; + } + switch (areas.length) { + case 1: + return areas[0]; + case 2: + case 3: + case 4: + case 5: + case 6: + case 7: + case 8: + x = loc.getX(); + y = loc.getY(); + for (PlotArea area : areas) { + if (area.contains(x, y)) { + return area; + } + } + return null; + default: + QuadMap search = plotareagrid.get(loc.getWorld()); + return search.get(loc.getX(), loc.getZ()); + } } - return null; } + public PlotArea getPlotArea(String world, String id) { + PlotArea[] areas = plotareamap.get(world); + if (areas == null) { + return null; + } + if (areas.length == 1) { + return areas[0]; + } else if (id == null) { + return null; + } else { + for (PlotArea area : areas) { + if (StringMan.isEqual(id, area.id)) { + return area; + } + } + return null; + } + } + + public PlotArea getPlotAreaByString(String search) { + String[] split = search.split(";|,"); + PlotArea[] areas = plotareamap.get(split[0]); + if (areas == null) { + for (PlotArea area : plotareas) { + if (area.worldname.equalsIgnoreCase(split[0])) { + if (area.id == null || (split.length == 2 && area.id.equalsIgnoreCase(split[1]))) { + return area; + } + } + } + } + if (areas.length == 1) { + return areas[0]; + } else if (split.length == 1) { + return null; + } else { + for (PlotArea area : areas) { + if (StringMan.isEqual(split[1], area.id)) { + return area; + } + } + return null; + } + } + + public Set getPlotAreas(String world, RegionWrapper region) { + QuadMap areas = plotareagrid.get(world); + return areas != null ? areas.get(region) : new HashSet(); + } + + /** + * Get the plot area which contains a location.
+ * - If the plot area does not contain a location, null will be returned + * + * @param loc + * @return + */ + public PlotArea getPlotAreaAbs(Location loc) { + switch (plotareas.length) { + case 0: + return null; + case 1: + PlotArea pa = plotareas[0]; + return pa.contains(loc) ? pa : null; + case 2: + case 3: + case 4: + case 5: + case 6: + case 7: + case 8: + String world = loc.getWorld(); + int x = loc.getX(); + int y = loc.getY(); + int hash = world.hashCode(); + for (PlotArea area : plotareas) { + if (hash == area.worldhash && world.equals(area.worldname)) { + if (area.contains(loc)) { + return area; + } + } + } + return null; + default: + PlotArea[] areas = plotareamap.get(loc.getWorld()); + if (areas == null) { + return null; + } + switch (areas.length) { + case 0: + PlotArea a = areas[0]; + return a.contains(loc) ? a : null; + case 2: + case 3: + case 4: + case 5: + case 6: + case 7: + case 8: + x = loc.getX(); + y = loc.getY(); + for (PlotArea area : areas) { + if (area.contains(x, y)) { + return area; + } + } + return null; + default: + QuadMap search = plotareagrid.get(loc.getWorld()); + return search.get(loc.getX(), loc.getZ()); + } + } + } + + public PlotManager getPlotManager(Plot plot) { + return plot.area.manager; + } + + public PlotManager getPlotManager(Location loc) { + PlotArea pa = getPlotAreaAbs(loc); + return pa != null ? pa.manager : null; + } + /** * Add a global reference to a plot world * * @param world World Name - * @param plotworld PlotWorld Instance + * @param plotworld PlotArea Instance * @param manager PlotManager * @see #removePlotWorld(String) To remove the reference */ - public void addPlotWorld(final String world, final PlotWorld plotworld, final PlotManager manager) { - plotworlds.put(world, plotworld); - plotmanagers.put(world, manager); - if (!plots.containsKey(world)) { - plots.put(world, new ConcurrentHashMap()); + public void addPlotArea(final PlotArea plotarea) { + HashMap plots = plots_tmp.remove(plotarea.toString()); + if (plots != null) { + for (Entry entry : plots.entrySet()) { + Plot plot = entry.getValue(); + plot.setArea(plotarea); + } + } + if (Settings.ENABLE_CLUSTERS) { + Set clusters = clusters_tmp.remove(plotarea.toString()); + if (clusters != null) { + for (PlotCluster cluster : clusters) { + cluster.setArea(plotarea); + } + } + } + Set localAreas = getPlotAreas(plotarea.worldname); + Set globalAreas = getPlotAreas(); + localAreas.add(plotarea); + globalAreas.add(plotarea); + plotareas = globalAreas.toArray(new PlotArea[0]); + plotareamap.put(plotarea.worldname, localAreas.toArray(new PlotArea[0])); + if (plotarea.TYPE == 2) { + QuadMap map = plotareagrid.get(plotarea.worldname); + if (map == null) { + map = new QuadMap(Integer.MAX_VALUE, 0, 0) { + @Override + public RegionWrapper getRegion(PlotArea value) { + return value.getRegion(); + } + }; + plotareagrid.put(plotarea.worldname, map); + } + map.add(plotarea); } } @@ -434,35 +651,81 @@ public class PS { * Remove a plot world reference * * @param world World name - * @see #addPlotWorld(String, PlotWorld, PlotManager) To add a reference + * @see #addPlotWorld(String, PlotArea, PlotManager) To add a reference */ - public void removePlotWorld(final String world) { - plots.remove(world); - plotmanagers.remove(world); - plotworlds.remove(world); + public void removePlotArea(final PlotArea area) { + Set areas = getPlotAreas(area.worldname); + areas.remove(area); + plotareas = areas.toArray(new PlotArea[0]); + if (areas.size() == 0) { + plotareamap.remove(area.worldname); + plotareagrid.remove(area.worldname); + } else { + plotareamap.put(area.worldname, areas.toArray(new PlotArea[areas.size()])); + plotareagrid.get(area.worldname).remove(area); + } + setPlotsTmp(area); } - /** - * @param world World Name - */ - public void removePlotWorldAbs(final String world) { - plotmanagers.remove(world); - plotworlds.remove(world); + public void removePlotAreas(String world) { + for (PlotArea area : getPlotAreas(world)) { + removePlotArea(area); + } + } + + private void setPlotsTmp(PlotArea area) { + if (plots_tmp == null) { + plots_tmp = new HashMap>(); + } + HashMap map = plots_tmp.get(area.toString()); + if (map == null) { + map = new HashMap<>(); + plots_tmp.put(area.toString(), map); + } + for (Plot plot : area.getPlots()) { + map.put(plot.getId(), plot); + } + if (clusters_tmp == null) { + clusters_tmp = new HashMap<>(); + } + clusters_tmp.put(area.toString(), area.getClusters()); } - /** - * Get all plots as raw objects - * - * @see #getPlots() To get the plot objects - * @see #getPlotsRaw() To get the plot objects - * - * @return HashMap containing the world name, and another map with the plot id and the plot object - */ - @Deprecated - public Map> getAllPlotsRaw() { - return plots; + public void setPlots(HashMap> plots) { + if (plots_tmp == null) { + plots_tmp = new HashMap<>(); + } + for (Entry> entry : plots.entrySet()) { + String world = entry.getKey(); + PlotArea area = getPlotArea(world, null); + if (area == null) { + HashMap map = plots_tmp.get(world); + if (map == null) { + map = new HashMap<>(); + plots_tmp.put(world, map); + } + map.putAll(entry.getValue()); + } else { + for (Entry entry2 : entry.getValue().entrySet()) { + Plot plot = entry2.getValue(); + plot.setArea(area); + area.addPlot(plot); + } + } + } } - + + public Set getClusters(String world) { + HashSet set = new HashSet<>(); + if (Settings.ENABLE_CLUSTERS) { + for (PlotArea area : getPlotAreas(world)) { + set.addAll(area.getClusters()); + } + } + return set; + + } + /** * A more generic way to filter plots - make your own method if you need complex filters * @param filters @@ -470,52 +733,41 @@ public class PS { */ public Set getPlots(final PlotFilter... filters) { final HashSet set = new HashSet<>(); - for (final Entry> entry : plots.entrySet()) { - for (final PlotFilter filter : filters) { - if (!filter.allowsWorld(entry.getKey())) { - continue; - } - } - for (Entry entry2: entry.getValue().entrySet()) { - Plot plot = entry2.getValue(); + foreachPlotArea(new RunnableVal() { + @Override + public void run(PlotArea value) { for (final PlotFilter filter : filters) { - if (!filter.allowsPlot(plot)) { + if (!filter.allowsArea(value)) { continue; } } - set.add(plot); + for (Entry entry2 : value.getPlotEntries()) { + Plot plot = entry2.getValue(); + for (final PlotFilter filter : filters) { + if (!filter.allowsPlot(plot)) { + continue; + } + } + set.add(plot); + } } - } + }); return set; } - /** - * Set all the plots as a raw object - * @see #getAllPlotsRaw() to get the raw plot object - * @param plots - */ - @Deprecated - public void setAllPlotsRaw(final ConcurrentHashMap> plots) { - this.plots = plots; - } - /** * Get all the plots in a single set * @return Set of Plot */ public Set getPlots() { - int size = 0; - for (final Entry> entry : plots.entrySet()) { - if (isPlotWorld(entry.getKey())) { - size += entry.getValue().size(); - } - } + int size = getPlotCount(); final Set result = new HashSet<>(size); - for (final Entry> entry : plots.entrySet()) { - if (isPlotWorld(entry.getKey())) { - result.addAll(entry.getValue().values()); + foreachPlotArea(new RunnableVal() { + @Override + public void run(PlotArea value) { + result.addAll(value.getPlots()); } - } + }); return result; } @@ -524,44 +776,19 @@ public class PS { * @return Set of base Plot */ public Set getBasePlots() { - int size = 0; - for (final Entry> entry : plots.entrySet()) { - if (isPlotWorld(entry.getKey())) { - size += entry.getValue().size(); - } - } + int size = getPlotCount(); final Set result = new HashSet<>(size); - for (final Entry> entry : plots.entrySet()) { - if (isPlotWorld(entry.getKey())) { - for (final Entry entry2 : entry.getValue().entrySet()) { - final Plot plot = entry2.getValue(); + foreachPlotArea(new RunnableVal() { + @Override + public void run(PlotArea value) { + for (Plot plot : value.getPlots()) { if (plot.getMerged(0) || plot.getMerged(3)) { continue; } result.add(plot); } } - } - return result; - } - - /** - * Get the raw plot object - * @return set of plot - * @see #setAllPlotsRaw(ConcurrentHashMap) to set the raw plot object - */ - @Deprecated - public Set getPlotsRaw() { - int size = 0; - for (final Entry> entry : plots.entrySet()) { - size += entry.getValue().size(); - } - final Set result = new HashSet<>(size); - for (final Entry> entry : plots.entrySet()) { - for (Entry entry2 : entry.getValue().entrySet()) { - result.add(entry2.getValue()); - } - } + }); return result; } @@ -914,59 +1141,56 @@ public class PS { * @param priorityWorld - Use null, "world" or "gibberish" if you want default world order * @return ArrayList of plot */ - public ArrayList sortPlots(final Collection plots, final SortType type, final String priorityWorld) { + public ArrayList sortPlots(final Collection myplots, final SortType type, final PlotArea priorityArea) { // group by world // sort each - final HashMap> map = new HashMap<>(); - final ArrayList worlds = new ArrayList<>(getPlotWorlds()); - int totalSize = 0; - for (final Entry> entry : this.plots.entrySet()) { - totalSize += entry.getValue().size(); - } - if (plots.size() == totalSize) { - for (final Entry> entry : this.plots.entrySet()) { - map.put(entry.getKey(), entry.getValue().values()); + final HashMap> map = new HashMap<>(); + int totalSize = getPlotCount(); + if (myplots.size() == totalSize) { + for (PlotArea area : plotareas) { + map.put(area, area.getPlots()); } } else { - for (final String world : worlds) { - map.put(world, new ArrayList(plots.size() / worlds.size())); + int size = plotareas.length; + for (PlotArea area : plotareas) { + map.put(area, new ArrayList(0)); } Collection lastList = null; - String lastWorld = ""; - for (final Plot plot : plots) { - if (StringMan.isEqual(lastWorld, plot.world)) { + PlotArea lastWorld = null; + for (final Plot plot : myplots) { + if (lastWorld == plot.area) { lastList.add(plot); } else { - lastWorld = plot.world; + lastWorld = plot.area; lastList = map.get(lastWorld); lastList.add(plot); } } } - Collections.sort(worlds, new Comparator() { + ArrayList areas = new ArrayList<>(Arrays.asList(plotareas)); + Collections.sort(areas, new Comparator() { @Override - public int compare(final String a, final String b) { - if ((priorityWorld != null) && StringMan.isEqual(a, priorityWorld)) { + public int compare(final PlotArea a, final PlotArea b) { + if ((priorityArea != null) && StringMan.isEqual(a.toString(), b.toString())) { return -1; } return a.hashCode() - b.hashCode(); } }); - final ArrayList toReturn = new ArrayList<>(plots.size()); - for (final String world : worlds) { + final ArrayList toReturn = new ArrayList<>(myplots.size()); + for (final PlotArea area : areas) { switch (type) { case CREATION_DATE: - toReturn.addAll(sortPlotsByTemp(map.get(world))); + toReturn.addAll(sortPlotsByTemp(map.get(area))); break; case CREATION_DATE_TIMESTAMP: - toReturn.addAll(sortPlotsByTimestamp(map.get(world))); + toReturn.addAll(sortPlotsByTimestamp(map.get(area))); break; case DISTANCE_FROM_ORIGIN: - toReturn.addAll(sortPlotsByHash(map.get(world))); + toReturn.addAll(sortPlotsByHash(map.get(area))); break; default: break; - } } return toReturn; @@ -979,18 +1203,26 @@ public class PS { * @return ArrayList of plot */ @Deprecated - public ArrayList sortPlotsByWorld(final Collection plots) { + public ArrayList sortPlotsByArea(final Collection plots) { final ArrayList newPlots = new ArrayList<>(); - final ArrayList worlds = new ArrayList<>(plotworlds.keySet()); + ArrayList areas = new ArrayList(Arrays.asList(plotareas)); + Collections.sort(areas, new Comparator() { + @Override + public int compare(final PlotArea a, final PlotArea b) { + return a.hashCode() - b.hashCode(); + } + }); final HashSet set = new HashSet<>(plots); - Collections.sort(worlds); - for (final String world : worlds) { - for (final Plot plot : this.plots.get(world).values()) { - if (set.contains(plot)) { - newPlots.add(plot); + foreachPlotArea(new RunnableVal() { + @Override + public void run(PlotArea value) { + for (Plot plot : value.getPlots()) { + if (set.contains(plot)) { + newPlots.add(plot); + } } } - } + }); return newPlots; } @@ -1005,6 +1237,17 @@ public class PS { return getPlots(world, uuid); } + /** + * Get all the plots owned by a player name + * @param world + * @param player + * @return Set of Plot + */ + public Set getPlots(final PlotArea area, final String player) { + final UUID uuid = UUIDHandler.getUUID(player, null); + return getPlots(area, uuid); + } + /** * Get all plots by a PlotPlayer * @param world @@ -1016,6 +1259,17 @@ public class PS { return getPlots(world, uuid); } + /** + * Get all plots by a PlotPlayer + * @param world + * @param player + * @return Set of plot + */ + public Set getPlots(final PlotArea area, final PlotPlayer player) { + final UUID uuid = player.getUUID(); + return getPlots(area, uuid); + } + /** * Get all plots by a UUID in a world * @param world @@ -1024,7 +1278,25 @@ public class PS { */ public Set getPlots(final String world, final UUID uuid) { final ArrayList myplots = new ArrayList<>(); - for (final Plot plot : getPlotsInWorld(world)) { + for (final Plot plot : getPlots(world)) { + if (plot.hasOwner()) { + if (PlotHandler.isOwner(plot, uuid)) { + myplots.add(plot); + } + } + } + return new HashSet<>(myplots); + } + + /** + * Get all plots by a UUID in an area + * @param world + * @param uuid + * @return Set of plot + */ + public Set getPlots(final PlotArea area, final UUID uuid) { + final ArrayList myplots = new ArrayList<>(); + for (final Plot plot : getPlots(area)) { if (plot.hasOwner()) { if (PlotHandler.isOwner(plot, uuid)) { myplots.add(plot); @@ -1037,70 +1309,53 @@ public class PS { /** * Check if a plot world * @param world - * @see #getPlotWorld(String) to get the PlotWorld object + * @see #getPlotArea(String) to get the PlotArea object * @return if a plot world is registered */ - public boolean isPlotWorld(final String world) { - return (plotworlds.containsKey(world)); + public boolean hasPlotArea(final String world) { + switch (plotareas.length) { + case 0: + return false; + case 1: + PlotArea a = plotareas[0]; + return world.hashCode() == a.worldhash && a.worldname.equals(world); + case 2: + case 3: + case 4: + case 5: + case 6: + case 7: + case 8: + int hash = world.hashCode(); + for (PlotArea area : plotareas) { + if (area.worldhash == hash && area.worldname.equals(world)) { + return true; + } + } + return false; + default: + return plotareamap.containsKey(world); + } } - /** - * Get the plot manager for a world - * @param world - * @return the PlotManager object, or null if no registered PlotManager - */ - public PlotManager getPlotManager(final String world) { - if (plotmanagers.containsKey(world)) { - return plotmanagers.get(world); - } - return null; + public Collection getPlots(final String world) { + final HashSet set = new HashSet<>(); + foreachPlotArea(null); + foreachPlotArea(world, new RunnableVal() { + @Override + public void run(PlotArea value) { + set.addAll(value.getPlots()); + } + }); + return set; } - /** - * Get a list of the plot worlds - * @return A String array of the plot world names - */ - public String[] getPlotWorldsString() { - final Set strings = plotworlds.keySet(); - return strings.toArray(new String[strings.size()]); + public Collection getPlots(final PlotArea area) { + return area == null ? new HashSet() : area.getPlots(); } - /** - * Get a map of the plots for a world - * @param world - * @return HashMap of PlotId to Plot - */ - @Deprecated - public HashMap getPlots(final String world) { - final ConcurrentHashMap myplots = plots.get(world); - if (myplots != null) { - return new HashMap<>(myplots); - } - return new HashMap<>(0); - } - - public Collection getPlotsInWorld(final String world) { - final ConcurrentHashMap map = plots.get(world); - if (map == null) { - return new HashSet<>(0); - } - try { - return map.values(); - } - catch (Throwable e) {e.printStackTrace();} - HashSet toReturn = new HashSet<>(map.entrySet().size()); - for (Entry entry : map.entrySet()) { - toReturn.add(entry.getValue()); - } - return toReturn; - } - - public Plot getPlot(final String world, final PlotId id) { - ConcurrentHashMap map = plots.get(world); - if (map != null) { - return map.get(id); - } - return null; + public Plot getPlot(PlotArea area, final PlotId id) { + return area == null ? null : (id == null ? null : area.getPlot(id)); } /** @@ -1119,18 +1374,32 @@ public class PS { */ public Set getPlots(final UUID uuid) { final ArrayList myplots = new ArrayList<>(); - for (final Entry> entry : plots.entrySet()) { - if (isPlotWorld(entry.getKey())) { - for (final Entry entry2 : entry.getValue().entrySet()) { - final Plot plot = entry2.getValue(); - if (plot.hasOwner()) { - if (PlotHandler.isOwner(plot, uuid)) { - myplots.add(plot); - } - } + foreachPlot(new RunnableVal() { + @Override + public void run(Plot value) { + if (PlotHandler.isOwner(value, uuid)) { + myplots.add(value); } } - } + }); + return new HashSet<>(myplots); + } + + /** + * Get the plots for a UUID + * @param uuid + * @return Set of Plot + */ + public Set getPlotsAbs(final UUID uuid) { + final ArrayList myplots = new ArrayList<>(); + foreachPlot(new RunnableVal() { + @Override + public void run(Plot value) { + if (value.owner.equals(uuid)) { + myplots.add(value); + } + } + }); return new HashSet<>(myplots); } @@ -1141,31 +1410,30 @@ public class PS { * @param callEvent If to call an event about the plot being removed * @return true if plot existed | false if it didn't */ - public boolean removePlot(final String world, final PlotId id, final boolean callEvent) { - if (callEvent) { - EventUtil.manager.callDelete(world, id); - } - final ConcurrentHashMap allPlots = plots.get(world); - if (allPlots == null) { + public boolean removePlot(Plot plot, final boolean callEvent) { + if (plot == null) { return false; } - final Plot plot = allPlots.remove(id); - if (MainUtil.lastPlot.containsKey(world)) { - final PlotId last = MainUtil.lastPlot.get(world); - final int last_max = Math.max(last.x, last.y); - final int this_max = Math.max(id.x, id.y); - if (this_max < last_max) { - MainUtil.lastPlot.put(world, id); - } + if (callEvent) { + EventUtil.manager.callDelete(plot); } - return plot != null; + if (plot.area.removePlot(plot.id)) { + PlotId last = (PlotId) plot.area.getMeta("lastPlot"); + final int last_max = Math.max(Math.abs(last.x), Math.abs(last.y)); + final int this_max = Math.max(Math.abs(plot.id.x), Math.abs(plot.id.y)); + if (this_max < last_max) { + plot.area.setMeta("lastPlot", plot.id); + } + return true; + } + return false; } /** * This method is called by the PlotGenerator class normally
- * - Initializes the PlotWorld and PlotManager classes
- * - Registers the PlotWorld and PlotManager classes
- * - Loads (and/or generates) the PlotWorld configuration
+ * - Initializes the PlotArea and PlotManager classes
+ * - Registers the PlotArea and PlotManager classes
+ * - Loads (and/or generates) the PlotArea configuration
* - Sets up the world border if configured
* If loading an augmented plot world:
* - Creates the AugmentedPopulator classes
@@ -1173,107 +1441,199 @@ public class PS { * @param world The world to load * @param generator The generator for that world, or null if no generator */ - public void loadWorld(final String world, final PlotGenerator generator) { - PlotWorld plotWorld = getPlotWorld(world); - if (plotWorld != null) { - if (generator != null) { - generator.initialize(plotWorld); - } + public void loadWorld(final String world, final GeneratorWrapper baseGenerator) { + if (world.equals("CheckingPlotSquaredGenerator")) { + return; + } + PlotArea[] areas = plotareamap.get(world); + if (areas != null) { + PS.debug("World already loaded: " + world); return; } final Set worlds = (config.contains("worlds") ? config.getConfigurationSection("worlds").getKeys(false) : new HashSet()); - final PlotGenerator plotGenerator; - final PlotManager plotManager; final String path = "worlds." + world; - if (!LOADING_WORLD && (generator.isFull())) { - plotGenerator = generator; - plotWorld = plotGenerator.getNewPlotWorld(world); - plotManager = plotGenerator.getPlotManager(); - if (!world.equals("CheckingPlotSquaredGenerator")) { - log(C.PREFIX.s() + "&aDetected world load for '" + world + "'"); - log(C.PREFIX.s() + "&3 - generator: &7" + plotGenerator.getClass().getName()); - log(C.PREFIX.s() + "&3 - plotworld: &7" + plotWorld.getClass().getName()); - log(C.PREFIX.s() + "&3 - manager: &7" + plotManager.getClass().getName()); + ConfigurationSection worldSection = config.getConfigurationSection(path); + int type = worldSection != null ? worldSection.getInt("generator.type") : 0; + if (type == 0) { + IndependentPlotGenerator pg; + if (baseGenerator != null && baseGenerator.isFull()) { + pg = baseGenerator.getPlotGenerator(); } + else if (worldSection != null) { + String secondaryGeneratorName = worldSection.getString("generator.plugin"); + GeneratorWrapper secondaryGenerator = IMP.getGenerator(world, secondaryGeneratorName); + if (secondaryGenerator != null && secondaryGenerator.isFull()) { + pg = secondaryGenerator.getPlotGenerator(); + } + else { + String primaryGeneratorName = worldSection.getString("generator.init"); + GeneratorWrapper primaryGenerator = IMP.getGenerator(world, primaryGeneratorName); + if (primaryGenerator != null && primaryGenerator.isFull()) { + pg = primaryGenerator.getPlotGenerator(); + } + else { + return; + } + } + } + else { + return; + } + // Conventional plot generator + PlotArea plotArea = pg.getNewPlotArea(world, null, null, null); + PlotManager plotManager = pg.getNewPlotManager(); + log(C.PREFIX.s() + "&aDetected world load for '" + world + "'"); + log(C.PREFIX.s() + "&3 - generator: &7" + baseGenerator + ">" + pg); + log(C.PREFIX.s() + "&3 - plotworld: &7" + plotArea.getClass().getName()); + log(C.PREFIX.s() + "&3 - manager: &7" + plotManager.getClass().getName()); if (!config.contains(path)) { config.createSection(path); + worldSection = config.getConfigurationSection(path); } - plotWorld.saveConfiguration(config.getConfigurationSection(path)); - plotWorld.loadDefaultConfiguration(config.getConfigurationSection(path)); + plotArea.saveConfiguration(worldSection); + plotArea.loadDefaultConfiguration(worldSection); try { config.save(configFile); } catch (final IOException e) { e.printStackTrace(); } // Now add it - addPlotWorld(world, plotWorld, plotManager); - generator.initialize(plotWorld); - MainUtil.setupBorder(world); + addPlotArea(plotArea); + pg.initialize(plotArea); + plotArea.setupBorder(); } else { + // Augmented / Partial if (!worlds.contains(world)) { return; } - if (!LOADING_WORLD) { - LOADING_WORLD = true; - try { - final String gen_string = config.getString("worlds." + world + "." + "generator.plugin"); - generator.setGenerator(gen_string); - // if (gen_string == null) { - // generator = new HybridGen(world); - // } else { - // generator = (PlotGenerator) IMP.getGenerator(world, gen_string); - // } - loadWorld(world, generator); - } catch (final Exception e) { - log("&d=== Oh no! Please set the generator for the " + world + " ==="); - e.printStackTrace(); - LOADING_WORLD = false; - removePlotWorld(world); - } finally { - LOADING_WORLD = false; + log(C.PREFIX.s() + "&aDetected world load for '" + world + "'"); + ConfigurationSection areasSection = worldSection.getConfigurationSection("areas"); + if (areasSection == null) { + String gen_string = worldSection.getString("generator.plugin"); + if (gen_string == null) { + gen_string = "PlotSquared"; } - } else { - LOADING_WORLD = false; - plotWorld = generator.getNewPlotWorld(world); - plotManager = generator.getPlotManager(); - if (!config.contains(path)) { - config.createSection(path); + if (type == 2) { + Set clusters = clusters_tmp != null ? clusters_tmp.get(world) : new HashSet(); + if (clusters == null) { + throw new IllegalArgumentException("No cluster exists for world: " + world); + } + for (PlotCluster cluster : clusters) { + PlotId pos1 = cluster.getP1(); // Cluster pos1 + PlotId pos2 = cluster.getP2(); // Cluster pos2 + String name = cluster.getName(); // Cluster name + log(C.PREFIX.s() + "&3 - " + name + "-" + pos1 + "-" + pos2); + GeneratorWrapper areaGen = IMP.getGenerator(world, gen_string); + if (areaGen == null) { + throw new IllegalArgumentException("Invalid Generator: " + gen_string); + } + PlotArea pa = areaGen.getPlotGenerator().getNewPlotArea(world, name, pos1, pos2); + pa.setCompatibility("3.2.X"); + pa.saveConfiguration(worldSection); + pa.loadDefaultConfiguration(worldSection); + try { + config.save(configFile); + } catch (final IOException e) { + e.printStackTrace(); + } + log(C.PREFIX.s() + "&c | &9generator: &7" + baseGenerator + ">" + areaGen); + log(C.PREFIX.s() + "&c | &9plotworld: &7" + pa); + log(C.PREFIX.s() + "&c | &9manager: &7" + pa); + areaGen.getPlotGenerator().initialize(pa); + areaGen.augment(pa); + addPlotArea(pa); + } + return; } - plotWorld.TYPE = generator.isFull() ? 0 : 2; - plotWorld.TERRAIN = 0; - plotWorld.saveConfiguration(config.getConfigurationSection(path)); - plotWorld.loadDefaultConfiguration(config.getConfigurationSection(path)); - + GeneratorWrapper areaGen = IMP.getGenerator(world, gen_string); + if (areaGen == null) { + throw new IllegalArgumentException("Invalid Generator: " + gen_string); + } + PlotArea pa = areaGen.getPlotGenerator().getNewPlotArea(world, null, null, null); + pa.saveConfiguration(worldSection); + pa.loadDefaultConfiguration(worldSection); try { config.save(configFile); } catch (final IOException e) { e.printStackTrace(); } - if (((plotWorld.TYPE == 2) && !Settings.ENABLE_CLUSTERS) || !(plotManager instanceof SquarePlotManager)) { - log("&c[ERROR] World '" + world + "' in settings.yml is not using PlotSquared generator! Please set the generator correctly or delete the world from the 'settings.yml'! (https://github.com/IntellectualSites/PlotSquared/wiki/Manual-generator-setting)"); - return; + log(C.PREFIX.s() + "&3 - generator: &7" + baseGenerator + ">" + areaGen); + log(C.PREFIX.s() + "&3 - plotworld: &7" + pa); + log(C.PREFIX.s() + "&3 - manager: &7" + pa.getPlotManager()); + areaGen.getPlotGenerator().initialize(pa); + areaGen.augment(pa); + addPlotArea(pa); + return; + } + if (type == 1) { + throw new IllegalArgumentException("Invalid type for multi-area world. Expected `2`, got `" + type + "`"); + } + for (String areaId : areasSection.getKeys(false)) { + log(C.PREFIX.s() + "&3 - " + areaId); + String[] split = areaId.split("-"); + if (split.length != 3) { + throw new IllegalArgumentException("Invalid Area identifier: " + areaId + ". Expected form `--`"); } - log(C.PREFIX.s() + "&aDetected world load for '" + world + "'"); - log(C.PREFIX.s() + "&3 - generator: &7" + generator.getName()); - log(C.PREFIX.s() + "&3 - plotworld: &7" + plotWorld.getClass().getName()); - log(C.PREFIX.s() + "&3 - manager: &7" + plotManager.getClass().getName()); - log(C.PREFIX.s() + "&3 - | terrain: &7" + plotWorld.TERRAIN); - log(C.PREFIX.s() + "&3 - | type: &7" + plotWorld.TYPE); - - addPlotWorld(world, plotWorld, plotManager); - if (plotWorld.TYPE == 2) { - if (ClusterManager.getClusters(world).size() > 0) { - for (final PlotCluster cluster : ClusterManager.getClusters(world)) { - log(C.PREFIX.s() + "&3 - &7| cluster: " + cluster); - generator.augment(cluster, plotWorld); - // new AugmentedPopulator(world, generator, cluster, plotWorld.TERRAIN == 2, plotWorld.TERRAIN != 2); + String name = split[0]; + PlotId pos1 = PlotId.fromString(split[1]); + PlotId pos2 = PlotId.fromString(split[2]); + if (pos1 == null || pos2 == null || name.length() == 0) { + throw new IllegalArgumentException("Invalid Area identifier: " + areaId + ". Expected form `--`"); + } + ConfigurationSection section = areasSection.getConfigurationSection(areaId); + YamlConfiguration clone = new YamlConfiguration(); + for (String key : section.getKeys(true)) { + if (section.get(key) instanceof MemorySection) { + continue; + } + if (!clone.contains(key)) { + clone.set(key, section.get(key)); + } + } + for (String key : worldSection.getKeys(true)) { + if (worldSection.get(key) instanceof MemorySection) { + continue; + } + if (!key.startsWith("areas") && !clone.contains(key)) { + clone.set(key, worldSection.get(key)); + } + } + String gen_string = clone.getString("generator.plugin"); + if (gen_string == null) { + gen_string = "PlotSquared"; + } + GeneratorWrapper areaGen = IMP.getGenerator(world, gen_string); + if (areaGen == null) { + throw new IllegalArgumentException("Invalid Generator: " + gen_string); + } + PlotArea pa = areaGen.getPlotGenerator().getNewPlotArea(world, name, pos1, pos2); + pa.saveConfiguration(clone); + // netSections is the combination of + for (String key : clone.getKeys(true)) { + if (clone.get(key) instanceof MemorySection) { + continue; + } + if (!worldSection.contains(key)) { + worldSection.set(key, clone.get(key)); + } else { + Object value = worldSection.get(key); + if (!Objects.equals(value, clone.get(key))) { + section.set(key, clone.get(key)); } } - } else if (plotWorld.TYPE == 1) { - generator.augment(null, plotWorld); - // new AugmentedPopulator(world, gen_class, null, plotWorld.TERRAIN == 2, plotWorld.TERRAIN != 2); } - generator.initialize(plotWorld); + pa.loadDefaultConfiguration(clone); + try { + config.save(configFile); + } catch (final IOException e) { + e.printStackTrace(); + } + log(C.PREFIX.s() + "&c | &9generator: &7" + baseGenerator + ">" + areaGen); + log(C.PREFIX.s() + "&c | &9plotworld: &7" + pa); + log(C.PREFIX.s() + "&c | &9manager: &7" + pa.getPlotManager()); + areaGen.getPlotGenerator().initialize(pa); + areaGen.augment(pa); + addPlotArea(pa); } } } @@ -1285,11 +1645,11 @@ public class PS { * @param args The arguments * @return boolean | if valid arguments were provided */ - public boolean setupPlotWorld(final String world, final String args) { + public boolean setupPlotWorld(final String world, final String args, IndependentPlotGenerator generator) { if ((args != null) && (args.length() > 0)) { // save configuration final String[] split = args.split(","); - final HybridPlotWorld plotworld = new HybridPlotWorld(world); + final HybridPlotWorld plotworld = new HybridPlotWorld(world, null, generator, null, null); for (final String element : split) { final String[] pair = element.split("="); if (pair.length != 2) { @@ -1515,6 +1875,19 @@ public class PS { } } + private Map> getPlotsRaw() { + HashMap> map = new HashMap<>(); + for (PlotArea area : plotareas) { + Map map2 = map.get(area.toString()); + if (map2 == null) { + map.put(area.toString(), area.getPlotsRaw()); + } else { + map2.putAll(area.getPlotsRaw()); + } + } + return map; + } + /** * Close the database connection */ @@ -1523,7 +1896,7 @@ public class PS { TASK = null; database = null; // Validate that all data in the db is correct - DBFunc.validatePlots(getPlotsRaw()); + DBFunc.validatePlots(getPlots()); // Close the connection DBFunc.close(); @@ -1556,9 +1929,9 @@ public class PS { } } DBFunc.dbManager = new SQLManager(database, Settings.DB.PREFIX, false); - plots = DBFunc.getPlots(); + this.plots_tmp = DBFunc.getPlots(); if (Settings.ENABLE_CLUSTERS) { - ClusterManager.clusters = DBFunc.getClusters(); + this.clusters_tmp = DBFunc.getClusters(); } } catch (final Exception e) { log(C.PREFIX.s() + "&cFailed to open DATABASE connection. The plugin will disable itself."); @@ -1601,13 +1974,6 @@ public class PS { for (final String flag : intFlags) { FlagManager.addFlag(new AbstractFlag(flag, new FlagValue.UnsignedIntegerValue())); } - FlagManager.addFlag(new AbstractFlag("cluster") { - @Override - public Object parseValueRaw(final String value) { - final String[] split = value.split(";"); - return ClusterManager.getCluster(split[0], split[1]); - } - }, true); FlagManager.addFlag(new AbstractFlag("done", new FlagValue.StringValue()), true); FlagManager.addFlag(new AbstractFlag("analysis", new FlagValue.IntegerListValue()), true); FlagManager.addFlag(new AbstractFlag("disable-physics", new FlagValue.BooleanValue())); @@ -1713,11 +2079,10 @@ public class PS { // Protection options.put("protection.redstone.disable-offline", Settings.REDSTONE_DISABLER); options.put("protection.redstone.disable-unoccupied", Settings.REDSTONE_DISABLER_UNOCCUPIED); - options.put("protection.piston.falling-blocks", Settings.PISTON_FALLING_BLOCK_CHECK); // Clusters options.put("clusters.enabled", Settings.ENABLE_CLUSTERS); - + // PlotMe options.put("plotme-alias", Settings.USE_PLOTME_ALIAS); options.put("plotme-convert.enabled", Settings.CONVERT_PLOTME); @@ -1731,11 +2096,10 @@ public class PS { // Mob stuff options.put("kill_road_vehicles", Settings.KILL_ROAD_VEHICLES); - options.put("kill_road_mobs", Settings.KILL_ROAD_MOBS_DEFAULT); - options.put("mob_pathfinding", Settings.MOB_PATHFINDING_DEFAULT); + options.put("kill_road_mobs", Settings.KILL_ROAD_MOBS); // Clearing + Expiry - options.put("clear.fastmode", Settings.ENABLE_CLUSTERS); + options.put("clear.fastmode", false); options.put("clear.on.ban", false); options.put("clear.auto.enabled", true); options.put("clear.auto.days", 7); @@ -1820,6 +2184,7 @@ public class PS { options.put("global_limit", Settings.GLOBAL_LIMIT); options.put("max_plots", Settings.MAX_PLOTS); options.put("claim.max-auto-area", Settings.MAX_AUTO_SIZE); + options.put("merge.remove-terrain", Settings.MERGE_REMOVES_ROADS); // Misc options.put("console.color", Settings.CONSOLE_COLOR); @@ -1827,7 +2192,6 @@ public class PS { options.put("metrics", true); options.put("debug", true); options.put("update-notifications", Settings.UPDATE_NOTIFICATIONS); - options.put("merge.remove-terrain", Settings.MERGE_REMOVES_ROADS); for (final Entry node : options.entrySet()) { if (!config.contains(node.getKey())) { @@ -1844,11 +2208,9 @@ public class PS { Settings.REDSTONE_DISABLER = config.getBoolean("protection.redstone.disable-offline"); Settings.REDSTONE_DISABLER_UNOCCUPIED = config.getBoolean("protection.redstone.disable-unoccupied"); - Settings.PISTON_FALLING_BLOCK_CHECK = config.getBoolean("protection.piston.falling-blocks"); - // Clusters Settings.ENABLE_CLUSTERS = config.getBoolean("clusters.enabled"); - + // PlotMe Settings.USE_PLOTME_ALIAS = config.getBoolean("plotme-alias"); Settings.CONVERT_PLOTME = config.getBoolean("plotme-convert.enabled"); @@ -1863,7 +2225,6 @@ public class PS { // Mob stuff Settings.KILL_ROAD_MOBS = config.getBoolean("kill_road_mobs"); Settings.KILL_ROAD_VEHICLES = config.getBoolean("kill_road_vehicles"); - Settings.MOB_PATHFINDING = config.getBoolean("mob_pathfinding"); // Clearing + Expiry Settings.FAST_CLEAR = config.getBoolean("clear.fastmode"); @@ -2047,10 +2408,6 @@ public class PS { Settings.DB.USE_SQLITE = storage.getBoolean("sqlite.use"); Settings.DB.SQLITE_DB = storage.getString("sqlite.db"); Settings.DB.PREFIX = storage.getString("prefix"); - Settings.METRICS = config.getBoolean("metrics"); - Settings.AUTO_CLEAR = config.getBoolean("clear.auto.enabled"); - Settings.AUTO_CLEAR_DAYS = config.getInt("clear.auto.days"); - Settings.DELETE_PLOTS_ON_BAN = config.getBoolean("clear.on.ban"); } /** @@ -2062,7 +2419,6 @@ public class PS { settings.put("Kill Road Mobs", "" + Settings.KILL_ROAD_MOBS); settings.put("Use Metrics", "" + Settings.METRICS); settings.put("Delete Plots On Ban", "" + Settings.DELETE_PLOTS_ON_BAN); - settings.put("Mob Pathfinding", "" + Settings.MOB_PATHFINDING); settings.put("DB Mysql Enabled", "" + Settings.DB.USE_MYSQL); settings.put("DB SQLite Enabled", "" + Settings.DB.USE_SQLITE); settings.put("Auto Clear Enabled", "" + Settings.AUTO_CLEAR); @@ -2100,19 +2456,101 @@ public class PS { return Double.parseDouble(System.getProperty("java.specification.version")); } - /** - * Get the list of plot world names - * @return Set of world names (String) - */ - public Set getPlotWorlds() { - return plotworlds.keySet(); + public void foreachPlotArea(RunnableVal runnable) { + for (PlotArea area : plotareas) { + runnable.run(area); + } + } + + public void foreachPlot(final RunnableVal runnable) { + for (PlotArea area : plotareas) { + for (Plot plot : area.getPlots()) { + runnable.run(plot); + } + } + } + + public void foreachBasePlot(RunnableVal run) { + for (PlotArea area : plotareas) { + area.foreachBasePlot(run); + } + } + + public void foreachPlotArea(String world, RunnableVal runnable) { + PlotArea[] array = plotareamap.get(world); + if (array == null) { + return; + } + for (PlotArea area : array) { + runnable.run(area); + } + } + + public PlotArea getFirstPlotArea() { + return plotareas.length > 0 ? plotareas[0] : null; + } + + public int getPlotAreaCount() { + return plotareas.length; + } + + public int getPlotCount() { + int count = 0; + for (PlotArea area : plotareas) { + count += area.getPlotCount(); + } + return count; + } + + public int getPlotAreaCount(String world) { + return plotareamap.size(); + } + + public Set getPlotAreas() { + HashSet set = new HashSet<>(plotareas.length); + for (PlotArea area : plotareas) { + set.add(area); + } + return set; } /** - * Get a list of PlotWorld objects - * @return Collection of PlotWorld objects + * @deprecated Since worlds can have multiple plot areas + * @return Set of world names */ - public Collection getPlotWorldObjects() { - return plotworlds.values(); + @Deprecated + public Set getPlotWorldStrings() { + HashSet set = new HashSet<>(plotareamap.size()); + for (Entry entry : plotareamap.entrySet()) { + set.add(entry.getKey()); + } + return set; + } + + public boolean isAugmented(String world) { + PlotArea[] areas = plotareamap.get(world); + if (areas == null) { + return false; + } + if (areas.length > 1) { + return true; + } + return areas[0].TYPE != 0; + } + + /** + * Get a list of PlotArea objects + * @return Collection of PlotArea objects + */ + public Set getPlotAreas(String world) { + PlotArea[] areas = plotareamap.get(world); + if (areas == null) { + return new HashSet<>(0); + } + HashSet set = new HashSet<>(areas.length); + for (PlotArea area : areas) { + set.add(area); + } + return set; } } diff --git a/src/main/java/com/intellectualcrafters/plot/api/PlotAPI.java b/src/main/java/com/intellectualcrafters/plot/api/PlotAPI.java index ea9e8cacc..874fee301 100644 --- a/src/main/java/com/intellectualcrafters/plot/api/PlotAPI.java +++ b/src/main/java/com/intellectualcrafters/plot/api/PlotAPI.java @@ -21,6 +21,17 @@ package com.intellectualcrafters.plot.api; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Set; +import java.util.UUID; + +import org.bukkit.Location; +import org.bukkit.OfflinePlayer; +import org.bukkit.World; +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; + import com.intellectualcrafters.configuration.file.YamlConfiguration; import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.commands.MainCommand; @@ -29,29 +40,17 @@ import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.flag.AbstractFlag; import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotArea; import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotManager; import com.intellectualcrafters.plot.object.PlotPlayer; -import com.intellectualcrafters.plot.object.PlotWorld; -import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.ChunkManager; -import com.intellectualcrafters.plot.util.ClusterManager; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.SchematicHandler; +import com.intellectualcrafters.plot.util.SetQueue; import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualcrafters.plot.uuid.UUIDWrapper; -import com.plotsquared.bukkit.util.BukkitSetBlockManager; import com.plotsquared.bukkit.util.BukkitUtil; -import org.bukkit.Location; -import org.bukkit.OfflinePlayer; -import org.bukkit.World; -import org.bukkit.entity.Player; -import org.bukkit.plugin.java.JavaPlugin; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Set; -import java.util.UUID; /** * PlotSquared API @@ -117,14 +116,14 @@ public class PlotAPI { * Add a plot world * * @param world World Name - * @param plotWorld Plot World Object + * @param plotArea Plot World Object * @param manager World Manager * - * @see PS#addPlotWorld(String, com.intellectualcrafters.plot.object.PlotWorld, + * @see PS#addPlotWorld(String, com.intellectualcrafters.plot.object.PlotArea, * com.intellectualcrafters.plot.object.PlotManager) */ - public void addPlotWorld(final String world, final PlotWorld plotWorld, final PlotManager manager) { - PS.get().addPlotWorld(world, plotWorld, manager); + public void addPlotArea(final PlotArea plotArea) { + PS.get().addPlotArea(plotArea); } /** @@ -172,27 +171,13 @@ public class PlotAPI { public ChunkManager getChunkManager() { return ChunkManager.manager; } - + /** - * BlockManager class contains useful methods relating to blocks. - * - * @return BlockManager - * - * @see com.intellectualcrafters.plot.util.BlockManager + * Get the block/biome set queue + * @return SetQueue.IMP */ - public BlockManager getBlockManager() { - return BlockManager.manager; - } - - /** - * BukkitSetBlockManager class contains useful methods relating to bukkit blocks. - * - * @return BukkitSetBlockManager - * - * @see com.plotsquared.bukkit.util.BukkitSetBlockManager - */ - public BukkitSetBlockManager getBukkitBlockManager() { - return BukkitSetBlockManager.setBlockManager; + public SetQueue getSetQueue() { + return SetQueue.IMP; } /** @@ -219,19 +204,6 @@ public class PlotAPI { return new FlagManager(); } - /** - * Do not use this. Instead use ClusterManager.[method] in your code. - * - Plot cluster related stuff - * - * @return ClusterManager - * - * @see com.intellectualcrafters.plot.util.ClusterManager - */ - @Deprecated - public ClusterManager getClusterManager() { - return new ClusterManager(); - } - /** * Do not use this. Instead use MainUtil.[method] in your code. * - Basic plot management stuff @@ -297,10 +269,21 @@ public class PlotAPI { * @see com.intellectualcrafters.plot.object.PlotManager * @see PS#getPlotManager(String) */ + @Deprecated public PlotManager getPlotManager(final World world) { - return PS.get().getPlotManager(world.getName()); + if (world == null) { + return null; + } + return getPlotManager(world.getName()); } + public Set getPlotAreas(World world) { + if (world == null) { + return new HashSet<>(); + } + return PS.get().getPlotAreas(world.getName()); + } + /** * Get the plot manager for a world. - Contains useful low level methods for plot merging, clearing, and * tessellation @@ -312,37 +295,64 @@ public class PlotAPI { * @see PS#getPlotManager(String) * @see com.intellectualcrafters.plot.object.PlotManager */ + @Deprecated public PlotManager getPlotManager(final String world) { - return PS.get().getPlotManager(world); + Set areas = PS.get().getPlotAreas(world); + switch (areas.size()) { + case 0: + return null; + case 1: + return areas.iterator().next().manager; + default: + PS.debug("PlotAPI#getPlotManager(org.bukkit.World) is deprecated and doesn't support multi plot area worlds."); + return null; + } } /** - * Get the settings for a world (settings bundled in PlotWorld class) - You will need to downcast for the specific - * settings a Generator has. e.g. DefaultPlotWorld class implements PlotWorld + * Get the settings for a world (settings bundled in PlotArea class) - You will need to downcast for the specific + * settings a Generator has. e.g. DefaultPlotWorld class implements PlotArea * * @param world (to get settings of) * - * @return PlotWorld class for that world ! will return null if not a plot world world + * @return PlotArea class for that world ! will return null if not a plot world world * - * @see PS#getPlotWorld(String) - * @see com.intellectualcrafters.plot.object.PlotWorld + * @see #getPlotAreas(World) + * @see com.intellectualcrafters.plot.object.PlotArea */ - public PlotWorld getWorldSettings(final World world) { - return PS.get().getPlotWorld(world.getName()); + @Deprecated + public PlotArea getWorldSettings(final World world) { + if (world == null) { + return null; + } + return getWorldSettings(world.getName()); } /** - * Get the settings for a world (settings bundled in PlotWorld class) + * Get the settings for a world (settings bundled in PlotArea class) * * @param world (to get settings of) * - * @return PlotWorld class for that world ! will return null if not a plot world world + * @return PlotArea class for that world ! will return null if not a plot world world * - * @see PS#getPlotWorld(String) - * @see com.intellectualcrafters.plot.object.PlotWorld + * @see PS#getPlotArea(String) + * @see com.intellectualcrafters.plot.object.PlotArea */ - public PlotWorld getWorldSettings(final String world) { - return PS.get().getPlotWorld(world); + @Deprecated + public PlotArea getWorldSettings(final String world) { + if (world == null) { + return null; + } + Set areas = PS.get().getPlotAreas(world); + switch (areas.size()) { + case 0: + return null; + case 1: + return areas.iterator().next(); + default: + PS.debug("PlotAPI#getWorldSettings(org.bukkit.World) is deprecated and doesn't support multi plot area worlds."); + return null; + } } /** @@ -426,11 +436,18 @@ public class PlotAPI { * * @return plot, null if ID is wrong * - * @see MainUtil#getPlotAbs(String, com.intellectualcrafters.plot.object.PlotId) - * @see Plot + * @see PlotArea#getPlot(PlotId) */ + @Deprecated public Plot getPlot(final World world, final int x, final int z) { - return MainUtil.getPlotAbs(world.getName(), new PlotId(x, z)); + if (world == null) { + return null; + } + PlotArea area = getWorldSettings(world); + if (area == null) { + return null; + } + return area.getPlot(new PlotId(x, z)); } /** @@ -444,7 +461,10 @@ public class PlotAPI { * @see Plot */ public Plot getPlot(final Location l) { - return MainUtil.getPlotAbs(BukkitUtil.getLocation(l)); + if (l == null) { + return null; + } + return BukkitUtil.getLocation(l).getPlot(); } /** @@ -470,6 +490,7 @@ public class PlotAPI { * * @see #getPlots(World, Player, boolean) */ + @Deprecated public boolean hasPlot(final World world, final Player player) { return (getPlots(world, player, true) != null) && (getPlots(world, player, true).length > 0); } @@ -479,18 +500,18 @@ public class PlotAPI { * * @param plr to search for * @param just_owner should we just search for owner? Or with rights? - * - * @see Plot */ + @Deprecated public Plot[] getPlots(final World world, final Player plr, final boolean just_owner) { final ArrayList pPlots = new ArrayList<>(); - for (final Plot plot : PS.get().getPlotsInWorld(world.getName())) { + UUID uuid = BukkitUtil.getPlayer(plr).getUUID(); + for (final Plot plot : PS.get().getPlots(world.getName())) { if (just_owner) { - if ((plot.owner != null) && (plot.owner.equals(UUIDHandler.getUUID(BukkitUtil.getPlayer(plr))))) { + if ((plot.owner != null) && (plot.owner.equals(uuid))) { pPlots.add(plot); } } else { - if (plot.isAdded(UUIDHandler.getUUID(BukkitUtil.getPlayer(plr)))) { + if (plot.isAdded(uuid)) { pPlots.add(plot); } } @@ -508,9 +529,12 @@ public class PlotAPI { * @see PS#getPlots(String) * @see Plot */ + @Deprecated public Plot[] getPlots(final World world) { - final Collection plots = PS.get().getPlotsInWorld(world.getName()); - return plots.toArray(new Plot[plots.size()]); + if (world == null) { + return new Plot[0]; + } + return PS.get().getPlots(world.getName()).toArray(new Plot[0]); } /** @@ -520,9 +544,9 @@ public class PlotAPI { * * @see PS#getPlotWorlds() */ + @Deprecated public String[] getPlotWorlds() { - final Set worlds = PS.get().getPlotWorlds(); - return worlds.toArray(new String[worlds.size()]); + return PS.get().getPlotWorldStrings().toArray(new String[0]); } /** @@ -532,10 +556,11 @@ public class PlotAPI { * * @return boolean (if plot world or not) * - * @see PS#isPlotWorld(String) + * @see PS#hasPlotArea(String) */ + @Deprecated public boolean isPlotWorld(final World world) { - return PS.get().isPlotWorld(world.getName()); + return PS.get().hasPlotArea(world.getName()); } /** @@ -545,16 +570,16 @@ public class PlotAPI { * * @return [0] = bottomLc, [1] = topLoc, [2] = home * + * @deprecated As merged plots may not have a rectangular shape + * * @see MainUtil#getPlotBottomLocAbs(String, PlotId) * @see MainUtil#getPlotTopLocAbs(String, PlotId) * @see MainUtil#getPlotHome(String, PlotId) * @see Plot */ + @Deprecated public Location[] getLocations(final Plot p) { - return new Location[] { - BukkitUtil.getLocation(MainUtil.getPlotBottomLocAbs(p.world, p.getId()).subtract(1, 0, 1)), - BukkitUtil.getLocation(MainUtil.getPlotTopLocAbs(p.world, p.getId())), - BukkitUtil.getLocation(MainUtil.getPlotHome(p.world, p.getId())) }; + return new Location[] { BukkitUtil.getLocation(p.getBottom()), BukkitUtil.getLocation(p.getTop()), BukkitUtil.getLocation(p.getHome()) }; } /** @@ -568,7 +593,7 @@ public class PlotAPI { * @see Plot */ public Location getHomeLocation(final Plot p) { - return BukkitUtil.getLocation(MainUtil.getPlotHome(p.world, p.getId())); + return BukkitUtil.getLocation(p.getHome()); } /** @@ -578,11 +603,14 @@ public class PlotAPI { * * @return plot bottom location * + * @deprecated As merged plots may not have a rectangular shape + * * @see MainUtil#getPlotBottomLocAbs(String, PlotId) * @see Plot */ + @Deprecated public Location getBottomLocation(final Plot p) { - return BukkitUtil.getLocation(MainUtil.getPlotBottomLocAbs(p.world, p.getId()).subtract(1, 0, 1)); + return BukkitUtil.getLocation(p.getBottom()); } /** @@ -591,12 +619,15 @@ public class PlotAPI { * @param p Plot that you want to get the location for * * @return plot top location + * + * @deprecated As merged plots may not have a rectangular shape * * @see MainUtil#getPlotTopLocAbs(String, PlotId) * @see Plot */ + @Deprecated public Location getTopLocation(final Plot p) { - return BukkitUtil.getLocation(MainUtil.getPlotTopLocAbs(p.world, p.getId())); + return BukkitUtil.getLocation(p.getTop()); } /** @@ -609,7 +640,7 @@ public class PlotAPI { * @see MainUtil#getPlotAbs(com.intellectualcrafters.plot.object.Location) */ public boolean isInPlot(final Player player) { - return MainUtil.getPlotAbs(BukkitUtil.getLocation(player)) != null; + return getPlot(player) != null; } /** @@ -649,7 +680,10 @@ public class PlotAPI { * @see MainUtil#getPlayerPlotCount(String, PlotPlayer) */ public int getPlayerPlotCount(final World world, final Player player) { - return MainUtil.getPlayerPlotCount(world.getName(), BukkitUtil.getPlayer(player)); + if (world == null) { + return 0; + } + return BukkitUtil.getPlayer(player).getPlotCount(world.getName()); } /** @@ -665,7 +699,10 @@ public class PlotAPI { * @see Plot */ public Set getPlayerPlots(final World world, final Player player) { - return PS.get().getPlots(world.getName(), BukkitUtil.getPlayer(player)); + if (world == null) { + return new HashSet<>(); + } + return BukkitUtil.getPlayer(player).getPlots(world.getName()); } /** @@ -678,7 +715,7 @@ public class PlotAPI { */ public int getAllowedPlots(final Player player) { final PlotPlayer pp = BukkitUtil.getPlayer(player); - return MainUtil.getAllowedPlots(pp); + return pp.getAllowedPlots(); } /** diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Add.java b/src/main/java/com/intellectualcrafters/plot/commands/Add.java index dc8a15a7d..f41a1d625 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Add.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Add.java @@ -20,6 +20,8 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// package com.intellectualcrafters.plot.commands; +import java.util.UUID; + import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.object.Location; @@ -32,8 +34,6 @@ import com.intellectualcrafters.plot.util.UUIDHandler; import com.plotsquared.general.commands.Argument; import com.plotsquared.general.commands.CommandDeclaration; -import java.util.UUID; - @CommandDeclaration( command = "add", aliases = { "a" }, @@ -51,7 +51,7 @@ public class Add extends SubCommand { @Override public boolean onCommand(final PlotPlayer plr, final String[] args) { final Location loc = plr.getLocation(); - final Plot plot = MainUtil.getPlotAbs(loc); + final Plot plot = loc.getPlotAbs(); if (plot == null) { return !sendMessage(plr, C.NOT_IN_PLOT); } @@ -86,7 +86,7 @@ public class Add extends SubCommand { if (plot.removeTrusted(uuid)) { plot.addMember(uuid); } else { - if ((plot.getMembers().size() + plot.getTrusted().size()) >= plot.getWorld().MAX_PLOT_MEMBERS) { + if ((plot.getMembers().size() + plot.getTrusted().size()) >= plot.getArea().MAX_PLOT_MEMBERS) { MainUtil.sendMessage(plr, C.PLOT_MAX_MEMBERS); return false; } diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Alias.java b/src/main/java/com/intellectualcrafters/plot/commands/Alias.java index 81051fe4b..295da9af3 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Alias.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Alias.java @@ -54,13 +54,13 @@ public class Alias extends SetCommand { C.NOT_VALID_VALUE.send(plr); return false; } - for (final Plot p : PS.get().getPlotsInWorld(plr.getLocation().getWorld())) { + for (final Plot p : PS.get().getPlots(plot.area)) { if (p.getAlias().equalsIgnoreCase(alias)) { MainUtil.sendMessage(plr, C.ALIAS_IS_TAKEN); return false; } } - if (UUIDHandler.nameExists(new StringWrapper(alias)) || PS.get().isPlotWorld(alias)) { + if (UUIDHandler.nameExists(new StringWrapper(alias)) || PS.get().hasPlotArea(alias)) { MainUtil.sendMessage(plr, C.ALIAS_IS_TAKEN); return false; } diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Auto.java b/src/main/java/com/intellectualcrafters/plot/commands/Auto.java index 64695768f..a37d0146e 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Auto.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Auto.java @@ -20,15 +20,12 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// package com.intellectualcrafters.plot.commands; -import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.Settings; -import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; -import com.intellectualcrafters.plot.object.PlotCluster; +import com.intellectualcrafters.plot.object.PlotArea; import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotPlayer; -import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.util.ByteArrayUtilities; import com.intellectualcrafters.plot.util.EconHandler; import com.intellectualcrafters.plot.util.MainUtil; @@ -42,10 +39,10 @@ category = CommandCategory.CLAIMING, requiredType = RequiredType.NONE, description = "Claim the nearest plot", aliases = { "a" }, -usage = "/plot auto") +usage = "/plot auto [length,width]") public class Auto extends SubCommand { - public static PlotId getNextPlot(final PlotId id, final int step) { + public static PlotId getNextPlotId(final PlotId id, final int step) { final int absX = Math.abs(id.x); final int absY = Math.abs(id.y); if (absX > absY) { @@ -76,32 +73,23 @@ public class Auto extends SubCommand { @Override public boolean onCommand(final PlotPlayer plr, final String[] args) { - - String world; + PlotArea plotarea = plr.getApplicablePlotArea(); + if (plotarea == null) { + MainUtil.sendMessage(plr, C.NOT_IN_PLOT_WORLD); + return false; + } int size_x = 1; int size_z = 1; - String schematic = ""; - if (PS.get().getPlotWorlds().size() == 1) { - world = PS.get().getPlotWorlds().iterator().next(); - } else { - world = plr.getLocation().getWorld(); - if (!PS.get().isPlotWorld(world)) { - MainUtil.sendMessage(plr, C.NOT_IN_PLOT_WORLD); - return false; - } - } + String schematic = null; if (args.length > 0) { if (Permissions.hasPermission(plr, "plots.auto.mega")) { try { - final String[] split = args[0].split(","); + final String[] split = args[0].split(",|;"); size_x = Integer.parseInt(split[0]); size_z = Integer.parseInt(split[1]); if ((size_x < 1) || (size_z < 1)) { MainUtil.sendMessage(plr, "&cError: size<=0"); } - if ((size_x > 4) || (size_z > 4)) { - MainUtil.sendMessage(plr, "&cError: size>4"); - } if (args.length > 1) { schematic = args[1]; } @@ -123,11 +111,9 @@ public class Auto extends SubCommand { MainUtil.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS_NUM, Settings.MAX_AUTO_SIZE + ""); return false; } - int removeGrants = 0; - - final int currentPlots = Settings.GLOBAL_LIMIT ? MainUtil.getPlayerPlotCount(plr) : MainUtil.getPlayerPlotCount(world, plr); - final int diff = currentPlots - MainUtil.getAllowedPlots(plr); + final int currentPlots = Settings.GLOBAL_LIMIT ? plr.getPlotCount() : plr.getPlotCount(plotarea.worldname); + final int diff = currentPlots - plr.getAllowedPlots(); if ((diff + (size_x * size_z)) > 0) { if (diff < 0) { MainUtil.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS_NUM, (-diff) + ""); @@ -148,9 +134,8 @@ public class Auto extends SubCommand { return false; } } - final PlotWorld pWorld = PS.get().getPlotWorld(world); - if ((EconHandler.manager != null) && pWorld.USE_ECONOMY) { - double cost = pWorld.PLOT_PRICE; + if ((EconHandler.manager != null) && plotarea.USE_ECONOMY) { + double cost = plotarea.PLOT_PRICE; cost = (size_x * size_z) * cost; if (cost > 0d) { if (EconHandler.manager.getMoney(plr) < cost) { @@ -166,9 +151,8 @@ public class Auto extends SubCommand { plr.setPersistentMeta("grantedPlots", ByteArrayUtilities.integerToBytes(grantedPlots - removeGrants)); sendMessage(plr, C.REMOVED_GRANTED_PLOT, "" + removeGrants, "" + (grantedPlots - removeGrants)); } - if (!schematic.equals("")) { - // if (pWorld.SCHEMATIC_CLAIM_SPECIFY) { - if (!pWorld.SCHEMATICS.contains(schematic.toLowerCase())) { + if (schematic != null && !schematic.equals("")) { + if (!plotarea.SCHEMATICS.contains(schematic.toLowerCase())) { sendMessage(plr, C.SCHEMATIC_INVALID, "non-existent: " + schematic); return true; } @@ -176,24 +160,10 @@ public class Auto extends SubCommand { MainUtil.sendMessage(plr, C.NO_SCHEMATIC_PERMISSION, schematic); return true; } - // } } - final String worldname = world; - final PlotWorld plotworld = PS.get().getPlotWorld(worldname); - if (plotworld.TYPE == 2) { - final Location loc = plr.getLocation(); - final Plot plot = MainUtil.getPlotAbs(new Location(worldname, loc.getX(), loc.getY(), loc.getZ())); - if (plot == null) { - return sendMessage(plr, C.NOT_IN_PLOT); - } - final PlotCluster cluster = plot.getCluster(); - // Must be standing in a cluster - if (cluster == null) { - MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER); - return false; - } - final PlotId bot = cluster.getP1(); - final PlotId top = cluster.getP2(); + if (plotarea.TYPE == 2) { + final PlotId bot = plotarea.getMin(); + final PlotId top = plotarea.getMax(); final PlotId origin = new PlotId((bot.x + top.x) / 2, (bot.y + top.y) / 2); PlotId id = new PlotId(0, 0); final int width = Math.max((top.x - bot.x) + 1, (top.y - bot.y) + 1); @@ -201,12 +171,12 @@ public class Auto extends SubCommand { // for (int i = 0; i <= max; i++) { final PlotId currentId = new PlotId(origin.x + id.x, origin.y + id.y); - final Plot current = MainUtil.getPlotAbs(worldname, currentId); - if (MainUtil.canClaim(plr, current) && (current.isMerged() == false) && cluster.equals(current.getCluster())) { + Plot current = plotarea.getPlotAbs(currentId); + if (current.canClaim(plr)) { Claim.claimPlot(plr, current, true, true); return true; } - id = getNextPlot(id, 1); + id = getNextPlotId(id, 1); } // no free plots MainUtil.sendMessage(plr, C.NO_FREE_PLOTS); @@ -215,45 +185,44 @@ public class Auto extends SubCommand { boolean br = false; if ((size_x == 1) && (size_z == 1)) { while (!br) { - final Plot plot = MainUtil.getPlotAbs(worldname, getLastPlot(worldname)); - if (MainUtil.canClaim(plr, plot)) { + Plot plot = plotarea.getPlotAbs(getLastPlotId(plotarea)); + if (plot.canClaim(plr)) { Claim.claimPlot(plr, plot, true, true); br = true; } - MainUtil.lastPlot.put(worldname, getNextPlot(getLastPlot(worldname), 1)); + plotarea.setMeta("lastPlot", getNextPlotId(plot.id, 1)); } } else { while (!br) { - final PlotId start = getNextPlot(getLastPlot(worldname), 1); - // Checking if the current set of plots is a viable option. - MainUtil.lastPlot.put(worldname, start); - if ((PS.get().getPlot(worldname, start) != null) && (PS.get().getPlot(worldname, start).owner != null)) { - continue; - } + final PlotId start = getNextPlotId(getLastPlotId(plotarea), 1); final PlotId end = new PlotId((start.x + size_x) - 1, (start.y + size_z) - 1); - if (MainUtil.canClaim(plr, worldname, start, end)) { + plotarea.setMeta("lastPlot", start); + if (plotarea.canClaim(plr, start, end)) { for (int i = start.x; i <= end.x; i++) { for (int j = start.y; j <= end.y; j++) { - final Plot plot = MainUtil.getPlotAbs(worldname, new PlotId(i, j)); + Plot plot = plotarea.getPlotAbs(new PlotId(i, j)); final boolean teleport = ((i == end.x) && (j == end.y)); Claim.claimPlot(plr, plot, teleport, true); } } - if (!MainUtil.mergePlots(worldname, MainUtil.getPlotSelectionIds(start, end), true, true)) { + if (!plotarea.mergePlots(MainUtil.getPlotSelectionIds(start, end), Settings.MERGE_REMOVES_ROADS, true)) { return false; } br = true; } } } - MainUtil.lastPlot.put(worldname, new PlotId(0, 0)); + plotarea.setMeta("lastPlot", new PlotId(0, 0)); return true; } - public PlotId getLastPlot(final String world) { - if ((MainUtil.lastPlot == null) || !MainUtil.lastPlot.containsKey(world)) { - MainUtil.lastPlot.put(world, new PlotId(0, 0)); + public PlotId getLastPlotId(final PlotArea area) { + PlotId value = (PlotId) area.getMeta("lastPlot"); + if (value == null) { + value = new PlotId(0, 0); + area.setMeta("lastPlot", value); + return value; } - return MainUtil.lastPlot.get(world); + return value; } } diff --git a/src/main/java/com/intellectualcrafters/plot/commands/BO3.java b/src/main/java/com/intellectualcrafters/plot/commands/BO3.java index dd07c1979..d797212e3 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/BO3.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/BO3.java @@ -40,7 +40,7 @@ public class BO3 extends SubCommand { @Override public boolean onCommand(final PlotPlayer plr, final String[] args) { final Location loc = plr.getLocation(); - final Plot plot = MainUtil.getPlotAbs(loc); + final Plot plot = loc.getPlotAbs(); if ((plot == null) || !plot.hasOwner()) { return !sendMessage(plr, C.NOT_IN_PLOT); } diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Biome.java b/src/main/java/com/intellectualcrafters/plot/commands/Biome.java index a66bf1749..7b8123a5d 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Biome.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Biome.java @@ -23,9 +23,9 @@ package com.intellectualcrafters.plot.commands; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotPlayer; -import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.StringMan; +import com.intellectualcrafters.plot.util.WorldUtil; import com.plotsquared.general.commands.CommandDeclaration; @CommandDeclaration( @@ -40,9 +40,9 @@ public class Biome extends SetCommand { @Override public boolean set(final PlotPlayer plr, final Plot plot, final String value) { - final int biome = BlockManager.manager.getBiomeFromString(value); + final int biome = WorldUtil.IMP.getBiomeFromString(value); if (biome == -1) { - String biomes = StringMan.join(BlockManager.manager.getBiomeList(), C.BLOCK_LIST_SEPARATER.s()); + String biomes = StringMan.join(WorldUtil.IMP.getBiomeList(), C.BLOCK_LIST_SEPARATER.s()); C.NEED_BIOME.send(plr); MainUtil.sendMessage(plr, C.SUBCOMMAND_SET_OPTIONS_HEADER.s() + biomes); return false; diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Buy.java b/src/main/java/com/intellectualcrafters/plot/commands/Buy.java index bb9df1252..0cdeb5f5b 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Buy.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Buy.java @@ -20,21 +20,20 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// package com.intellectualcrafters.plot.commands; +import java.util.Set; + import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; -import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.EconHandler; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.UUIDHandler; import com.plotsquared.general.commands.CommandDeclaration; -import java.util.Set; - @CommandDeclaration( command = "buy", aliases = { "b" }, @@ -52,23 +51,24 @@ public class Buy extends SubCommand { } final Location loc = plr.getLocation(); final String world = loc.getWorld(); - if (!PS.get().isPlotWorld(world)) { + if (!PS.get().hasPlotArea(world)) { return sendMessage(plr, C.NOT_IN_PLOT_WORLD); } Set plots; Plot plot; if (args.length > 0) { try { - final String[] split = args[0].split(";"); - final PlotId id = new PlotId(Integer.parseInt(split[0]), Integer.parseInt(split[1])); - plot = MainUtil.getPlotAbs(world, id); - plots = MainUtil.getConnectedPlots(plot); + plot = MainUtil.getPlotFromString(plr, world, true); + if (plot == null) { + return false; + } + plots = plot.getConnectedPlots(); } catch (final Exception e) { return sendMessage(plr, C.NOT_VALID_PLOT_ID); } } else { - plot = MainUtil.getPlotAbs(loc); - plots = MainUtil.getConnectedPlots(plot); + plot = loc.getPlotAbs(); + plots = plot.getConnectedPlots(); } if (plots == null) { return sendMessage(plr, C.NOT_IN_PLOT); @@ -76,8 +76,8 @@ public class Buy extends SubCommand { if (!plot.hasOwner()) { return sendMessage(plr, C.PLOT_UNOWNED); } - final int currentPlots = MainUtil.getPlayerPlotCount(plr) + plots.size(); - if (currentPlots > MainUtil.getAllowedPlots(plr)) { + final int currentPlots = plr.getPlotCount() + plots.size(); + if (currentPlots > plr.getAllowedPlots()) { return sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS); } final Flag flag = FlagManager.getPlotFlagRaw(plot, "price"); diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Claim.java b/src/main/java/com/intellectualcrafters/plot/commands/Claim.java index 921204b6b..ef3f3ccc8 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Claim.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Claim.java @@ -20,15 +20,19 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// package com.intellectualcrafters.plot.commands; -import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotArea; import com.intellectualcrafters.plot.object.PlotPlayer; -import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.object.RunnableVal; -import com.intellectualcrafters.plot.util.*; +import com.intellectualcrafters.plot.util.ByteArrayUtilities; +import com.intellectualcrafters.plot.util.EconHandler; +import com.intellectualcrafters.plot.util.EventUtil; +import com.intellectualcrafters.plot.util.MainUtil; +import com.intellectualcrafters.plot.util.Permissions; +import com.intellectualcrafters.plot.util.SchematicHandler; import com.intellectualcrafters.plot.util.SchematicHandler.Schematic; import com.plotsquared.general.commands.CommandDeclaration; @@ -52,16 +56,13 @@ public class Claim extends SubCommand { } final boolean result = EventUtil.manager.callClaim(player, plot, false); if (result) { - MainUtil.createPlot(player.getUUID(), plot); - MainUtil.setSign(player.getName(), plot); + plot.create(player.getUUID(), true); + plot.setSign(player.getName()); MainUtil.sendMessage(player, C.CLAIMED); - final Location loc = player.getLocation(); if (teleport) { - MainUtil.teleportPlayer(player, loc, plot); + plot.teleportPlayer(player); } - final String world = plot.world; - final PlotWorld plotworld = plot.getWorld(); - final Plot plot2 = PS.get().getPlot(world, plot.getId()); + final PlotArea plotworld = plot.getArea(); if (plotworld.SCHEMATIC_ON_CLAIM) { Schematic sch; if (schematic.isEmpty()) { @@ -72,9 +73,9 @@ public class Claim extends SubCommand { sch = SchematicHandler.manager.getSchematic(plotworld.SCHEMATIC_FILE); } } - SchematicHandler.manager.paste(sch, plot2, 0, 0, new RunnableVal() { + SchematicHandler.manager.paste(sch, plot, 0, 0, new RunnableVal() { @Override - public void run() { + public void run(Boolean value) { if (value) { MainUtil.sendMessage(player, C.SCHEMATIC_PASTE_SUCCESS); } else { @@ -83,7 +84,7 @@ public class Claim extends SubCommand { } }); } - PS.get().getPlotManager(world).claimPlot(plotworld, plot); + plotworld.getPlotManager().claimPlot(plotworld, plot); } return result; } @@ -95,15 +96,13 @@ public class Claim extends SubCommand { schematic = args[0]; } final Location loc = plr.getLocation(); - final Plot plot = MainUtil.getPlotAbs(loc); + final Plot plot = loc.getPlotAbs(); if (plot == null) { return sendMessage(plr, C.NOT_IN_PLOT); } - final int currentPlots = Settings.GLOBAL_LIMIT ? MainUtil.getPlayerPlotCount(plr) : MainUtil.getPlayerPlotCount(loc.getWorld(), plr); - + final int currentPlots = Settings.GLOBAL_LIMIT ? plr.getPlotCount() : plr.getPlotCount(loc.getWorld()); boolean removeGrantedPlot = false; - - if (currentPlots >= MainUtil.getAllowedPlots(plr)) { + if (currentPlots >= plr.getAllowedPlots()) { if (plr.hasPersistentMeta("grantedPlots")) { int grantedPlots = ByteArrayUtilities.bytesToInteger(plr.getPersistentMeta("grantedPlots")); if (grantedPlots < 1) { @@ -116,10 +115,10 @@ public class Claim extends SubCommand { return sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS); } } - if (!MainUtil.canClaim(plr, plot)) { + if (!plot.canClaim(plr)) { return sendMessage(plr, C.PLOT_IS_CLAIMED); } - final PlotWorld world = plot.getWorld(); + final PlotArea world = plot.getArea(); if ((EconHandler.manager != null) && world.USE_ECONOMY) { final double cost = world.PLOT_PRICE; if (cost > 0d) { diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Clear.java b/src/main/java/com/intellectualcrafters/plot/commands/Clear.java index de6a28025..b3fbd3603 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Clear.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Clear.java @@ -31,7 +31,7 @@ import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.CmdConfirm; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; -import com.intellectualcrafters.plot.util.SetBlockQueue; +import com.intellectualcrafters.plot.util.SetQueue; import com.intellectualcrafters.plot.util.TaskManager; import com.plotsquared.general.commands.CommandDeclaration; @@ -59,7 +59,7 @@ public class Clear extends SubCommand { return false; } } else if (args.length == 0) { - plot = MainUtil.getPlotAbs(loc); + plot = loc.getPlotAbs(); if (plot == null) { MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot clear [X;Z|mine]"); C.NOT_IN_PLOT.send(plr); @@ -77,7 +77,7 @@ public class Clear extends SubCommand { return false; } if ((FlagManager.getPlotFlagRaw(plot, "done") != null) - && (!Permissions.hasPermission(plr, "plots.continue") || (Settings.DONE_COUNTS_TOWARDS_LIMIT && (MainUtil.getAllowedPlots(plr) >= MainUtil.getPlayerPlotCount(plr))))) { + && (!Permissions.hasPermission(plr, "plots.continue") || (Settings.DONE_COUNTS_TOWARDS_LIMIT && (plr.getAllowedPlots() >= plr.getPlotCount())))) { MainUtil.sendMessage(plr, C.DONE_ALREADY_DONE); return false; } @@ -85,11 +85,11 @@ public class Clear extends SubCommand { @Override public void run() { final long start = System.currentTimeMillis(); - final boolean result = MainUtil.clearAsPlayer(plot, plot.owner == null, new Runnable() { + final boolean result = plot.clear(true, false, new Runnable() { @Override public void run() { plot.unlink(); - SetBlockQueue.addNotify(new Runnable() { + SetQueue.IMP.addTask(new Runnable() { @Override public void run() { plot.removeRunning(); diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Cluster.java b/src/main/java/com/intellectualcrafters/plot/commands/Cluster.java index 6372ee330..458d2aeda 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Cluster.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Cluster.java @@ -31,20 +31,15 @@ import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.FlagManager; -import com.intellectualcrafters.plot.generator.PlotGenerator; import com.intellectualcrafters.plot.object.BlockLoc; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotArea; import com.intellectualcrafters.plot.object.PlotCluster; -import com.intellectualcrafters.plot.object.PlotClusterId; import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotPlayer; -import com.intellectualcrafters.plot.object.PlotWorld; -import com.intellectualcrafters.plot.util.ClusterManager; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; -import com.intellectualcrafters.plot.util.SetupUtils; -import com.intellectualcrafters.plot.util.StringMan; import com.intellectualcrafters.plot.util.UUIDHandler; //import com.plotsquared.bukkit.generator.AugmentedPopulator; //import com.plotsquared.bukkit.generator.AugmentedPopulator; @@ -82,7 +77,8 @@ public class Cluster extends SubCommand { MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster list"); return false; } - final HashSet clusters = ClusterManager.getClusters(plr.getLocation().getWorld()); + PlotArea area = plr.getApplicablePlotArea(); + final Set clusters = area.getClusters(); MainUtil.sendMessage(plr, C.CLUSTER_LIST_HEADING, clusters.size() + ""); for (final PlotCluster cluster : clusters) { // Ignore unmanaged clusters @@ -105,10 +101,13 @@ public class Cluster extends SubCommand { MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.create"); return false; } + PlotArea area = plr.getApplicablePlotArea(); + if (area == null) { + C.NOT_IN_PLOT_WORLD.send(plr); + return false; + } if (args.length != 4) { - final PlotId id = ClusterManager.estimatePlotId(plr.getLocation()); MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster create "); - MainUtil.sendMessage(plr, C.CLUSTER_CURRENT_PLOTID, "" + id); return false; } // check pos1 / pos2 @@ -120,11 +119,9 @@ public class Cluster extends SubCommand { } // check if name is taken final String name = args[1]; - for (final PlotCluster cluster : ClusterManager.getClusters(plr.getLocation().getWorld())) { - if (name.equals(cluster.getName())) { - MainUtil.sendMessage(plr, C.ALIAS_IS_TAKEN); - return false; - } + if (area.getCluster(name) != null) { + MainUtil.sendMessage(plr, C.ALIAS_IS_TAKEN); + return false; } if ((pos2.x < pos1.x) || (pos2.y < pos1.y)) { PlotId tmp = new PlotId(Math.min(pos1.x, pos2.x), Math.min(pos1.y, pos2.y)); @@ -132,15 +129,13 @@ public class Cluster extends SubCommand { pos1 = tmp; } //check if overlap - final String world = plr.getLocation().getWorld(); - final PlotClusterId id = new PlotClusterId(pos1, pos2); - final HashSet intersects = ClusterManager.getIntersects(world, id); - if ((intersects.size() > 0)) { - MainUtil.sendMessage(plr, C.CLUSTER_INTERSECTION, intersects.size() + ""); + PlotCluster cluster = area.getFirstIntersectingCluster(pos1, pos2); + if (cluster != null) { + MainUtil.sendMessage(plr, C.CLUSTER_INTERSECTION, cluster.getName()); return false; } // Check if it occupies existing plots - final Set plots = MainUtil.getPlotSelectionOwned(world, pos1, pos2); + final Set plots = area.getPlotSelectionOwned(pos1, pos2); if (plots.size() > 0) { if (!Permissions.hasPermission(plr, "plots.cluster.create.other")) { final UUID uuid = plr.getUUID(); @@ -153,57 +148,22 @@ public class Cluster extends SubCommand { } } // Check allowed cluster size - final PlotCluster cluster = new PlotCluster(world, pos1, pos2, plr.getUUID()); + cluster = new PlotCluster(area, pos1, pos2, plr.getUUID()); int current; if (Settings.GLOBAL_LIMIT) { - current = ClusterManager.getPlayerClusterCount(plr); + current = plr.getPlayerClusterCount(); } else { - current = ClusterManager.getPlayerClusterCount(world, plr); + current = plr.getPlayerClusterCount(plr.getLocation().getWorld()); } final int allowed = Permissions.hasPermissionRange(plr, "plots.cluster", Settings.MAX_PLOTS); if ((current + cluster.getArea()) > allowed) { MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster." + (current + cluster.getArea())); return false; } - // Set the generator (if applicable) - final PlotWorld plotworld = PS.get().getPlotWorld(world); - if (plotworld == null) { - PS.get().config.createSection("worlds." + world); - PS.get().loadWorld(world, PS.get().IMP.getGenerator(world, null)); - } else { - String gen_string = PS.get().config.getString("worlds." + world + "." + "generator.plugin"); - if (gen_string == null) { - gen_string = "PlotSquared"; - } - final PlotGenerator wrapper = PS.get().IMP.getGenerator(world, gen_string); - if (wrapper.isFull()) { - wrapper.augment(cluster, plotworld); - } else { - MainUtil.sendMessage(plr, C.SETUP_INVALID_GENERATOR, StringMan.join(SetupUtils.generators.keySet(), ",")); - return false; - } - // BukkitPlotGenerator generator; - // if (gen_string == null) { - // generator = new HybridGen(world); - // } else { - // ChunkGenerator chunkgen = (ChunkGenerator) PS.get().IMP.getGenerator(world, gen_string).generator; - // if (chunkgen instanceof BukkitPlotGenerator) { - // generator = (BukkitPlotGenerator) chunkgen; - // } - // else { - // MainUtil.sendMessage(plr, C.SETUP_INVALID_GENERATOR, StringMan.join(SetupUtils.generators.keySet(), ",")); - // return false; - // } - // } - // new AugmentedPopulator(world, generator, cluster, plotworld.TERRAIN == 2, plotworld.TERRAIN != 2); - } // create cluster cluster.settings.setAlias(name); - DBFunc.createCluster(world, cluster); - if (!ClusterManager.clusters.containsKey(world)) { - ClusterManager.clusters.put(world, new HashSet()); - } - ClusterManager.clusters.get(world).add(cluster); + area.addCluster(cluster); + DBFunc.createCluster(cluster); // Add any existing plots to the current cluster for (final Plot plot : plots) { if (plot.hasOwner()) { @@ -211,7 +171,7 @@ public class Cluster extends SubCommand { FlagManager.addPlotFlag(plot, flag); if (!cluster.isAdded(plot.owner)) { cluster.invited.add(plot.owner); - DBFunc.setInvited(world, cluster, plot.owner); + DBFunc.setInvited(cluster, plot.owner); } } } @@ -229,15 +189,20 @@ public class Cluster extends SubCommand { MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster delete [name]"); return false; } + PlotArea area = plr.getApplicablePlotArea(); + if (area == null) { + C.NOT_IN_PLOT_WORLD.send(plr); + return false; + } PlotCluster cluster; if (args.length == 2) { - cluster = ClusterManager.getCluster(plr.getLocation().getWorld(), args[1]); + cluster = area.getCluster(args[1]); if (cluster == null) { MainUtil.sendMessage(plr, C.INVALID_CLUSTER, args[1]); return false; } } else { - cluster = ClusterManager.getCluster(plr.getLocation()); + cluster = area.getCluster(plr.getLocation()); if (cluster == null) { MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER); return false; @@ -249,26 +214,7 @@ public class Cluster extends SubCommand { return false; } } - final PlotWorld plotworld = plr.getLocation().getPlotWorld(); - if (plotworld.TYPE == 2) { - final ArrayList toRemove = new ArrayList<>(); - for (final Plot plot : PS.get().getPlotsInWorld(plr.getLocation().getWorld())) { - final PlotCluster other = ClusterManager.getCluster(plot); - if (cluster.equals(other)) { - toRemove.add(plot); - } - } - for (final Plot plot : toRemove) { - plot.unclaim(); - } - } DBFunc.delete(cluster); - if (plotworld.TYPE == 2) { - SetupUtils.manager.removePopulator(plr.getLocation().getWorld(), cluster); - } - ClusterManager.last = null; - ClusterManager.clusters.get(cluster.world).remove(cluster); - ClusterManager.regenCluster(cluster); MainUtil.sendMessage(plr, C.CLUSTER_DELETED); return true; } @@ -294,9 +240,12 @@ public class Cluster extends SubCommand { pos2 = new PlotId(Math.max(pos1.x, pos2.x), Math.max(pos1.y, pos2.y)); } // check if in cluster - final Location loc = plr.getLocation(); - final String world = loc.getWorld(); - final PlotCluster cluster = ClusterManager.getCluster(loc); + PlotArea area = plr.getApplicablePlotArea(); + if (area == null) { + C.NOT_IN_PLOT_WORLD.send(plr); + return false; + } + final PlotCluster cluster = area.getCluster(plr.getLocation()); if (cluster == null) { MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER); return false; @@ -308,14 +257,13 @@ public class Cluster extends SubCommand { } } //check if overlap - final PlotClusterId id = new PlotClusterId(pos1, pos2); - final HashSet intersects = ClusterManager.getIntersects(world, id); - if (intersects.size() > 1) { - MainUtil.sendMessage(plr, C.CLUSTER_INTERSECTION, (intersects.size() - 1) + ""); + PlotCluster intersect = area.getFirstIntersectingCluster(pos1, pos2); + if (intersect != null) { + MainUtil.sendMessage(plr, C.CLUSTER_INTERSECTION, intersect.getName()); return false; } - final HashSet existing = MainUtil.getPlotSelectionOwned(world, cluster.getP1(), cluster.getP2()); - final HashSet newplots = MainUtil.getPlotSelectionOwned(world, pos1, pos2); + final HashSet existing = area.getPlotSelectionOwned(cluster.getP1(), cluster.getP2()); + final HashSet newplots = area.getPlotSelectionOwned(pos1, pos2); final HashSet removed = ((HashSet) existing.clone()); removed.removeAll(newplots); // Check expand / shrink @@ -335,9 +283,9 @@ public class Cluster extends SubCommand { // Check allowed cluster size int current; if (Settings.GLOBAL_LIMIT) { - current = ClusterManager.getPlayerClusterCount(plr); + current = plr.getPlayerClusterCount(); } else { - current = ClusterManager.getPlayerClusterCount(world, plr); + current = plr.getPlayerClusterCount(plr.getLocation().getWorld()); } current -= cluster.getArea() + (((1 + pos2.x) - pos1.x) * ((1 + pos2.y) - pos1.y)); final int allowed = Permissions.hasPermissionRange(plr, "plots.cluster", Settings.MAX_PLOTS); @@ -352,46 +300,10 @@ public class Cluster extends SubCommand { FlagManager.addPlotFlag(plot, new Flag(FlagManager.getFlag("cluster"), cluster)); } // resize cluster - DBFunc.resizeCluster(cluster, id); + DBFunc.resizeCluster(cluster, pos1, pos2); MainUtil.sendMessage(plr, C.CLUSTER_RESIZED); return true; } - case "reg": - case "regenerate": - case "regen": { - if (!Permissions.hasPermission(plr, "plots.cluster.delete")) { - MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.regen"); - return false; - } - if ((args.length != 1) && (args.length != 2)) { - MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster regen [name]"); - return false; - } - PlotCluster cluster; - if (args.length == 2) { - cluster = ClusterManager.getCluster(plr.getLocation().getWorld(), args[1]); - if (cluster == null) { - MainUtil.sendMessage(plr, C.INVALID_CLUSTER, args[1]); - return false; - } - } else { - cluster = ClusterManager.getCluster(plr.getLocation()); - if (cluster == null) { - MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER); - return false; - } - } - if (!cluster.owner.equals(plr.getUUID())) { - if (!Permissions.hasPermission(plr, "plots.cluster.regen.other")) { - MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.regen.other"); - return false; - } - } - final long start = System.currentTimeMillis(); - ClusterManager.regenCluster(cluster); - MainUtil.sendMessage(plr, C.CLUSTER_REGENERATED, (System.currentTimeMillis() - start) + ""); - return true; - } case "add": case "inv": case "invite": { @@ -404,7 +316,11 @@ public class Cluster extends SubCommand { return false; } // check if in cluster - final PlotCluster cluster = ClusterManager.getCluster(plr.getLocation()); + PlotArea area = plr.getApplicablePlotArea(); + if (area == null) { + C.NOT_IN_PLOT_WORLD.send(plr); + } + final PlotCluster cluster = area.getCluster(plr.getLocation()); if (cluster == null) { MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER); return false; @@ -425,7 +341,7 @@ public class Cluster extends SubCommand { // add the user if not added cluster.invited.add(uuid); final String world = plr.getLocation().getWorld(); - DBFunc.setInvited(world, cluster, uuid); + DBFunc.setInvited(cluster, uuid); final PlotPlayer player = UUIDHandler.getPlayer(uuid); if (player != null) { MainUtil.sendMessage(player, C.CLUSTER_INVITED, cluster.getName()); @@ -445,7 +361,11 @@ public class Cluster extends SubCommand { MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster kick "); return false; } - final PlotCluster cluster = ClusterManager.getCluster(plr.getLocation()); + PlotArea area = plr.getApplicablePlotArea(); + if (area == null) { + C.NOT_IN_PLOT_WORLD.send(plr); + } + final PlotCluster cluster = area.getCluster(plr.getLocation()); if (cluster == null) { MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER); return false; @@ -478,7 +398,7 @@ public class Cluster extends SubCommand { MainUtil.sendMessage(player, C.CLUSTER_REMOVED, cluster.getName()); } for (final Plot plot : new ArrayList<>(PS.get().getPlots(plr.getLocation().getWorld(), uuid))) { - final PlotCluster current = ClusterManager.getCluster(plot); + final PlotCluster current = plot.getCluster(); if ((current != null) && current.equals(cluster)) { plr.getLocation().getWorld(); plot.unclaim(); @@ -497,15 +417,19 @@ public class Cluster extends SubCommand { MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster leave [name]"); return false; } + PlotArea area = plr.getApplicablePlotArea(); + if (area == null) { + C.NOT_IN_PLOT_WORLD.send(plr); + } PlotCluster cluster; if (args.length == 2) { - cluster = ClusterManager.getCluster(plr.getLocation().getWorld(), args[1]); + cluster = area.getCluster(args[1]); if (cluster == null) { MainUtil.sendMessage(plr, C.INVALID_CLUSTER, args[1]); return false; } } else { - cluster = ClusterManager.getCluster(plr.getLocation()); + cluster = area.getCluster(plr.getLocation()); if (cluster == null) { MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER); return false; @@ -528,7 +452,7 @@ public class Cluster extends SubCommand { DBFunc.removeInvited(cluster, uuid); MainUtil.sendMessage(plr, C.CLUSTER_REMOVED, cluster.getName()); for (final Plot plot : new ArrayList<>(PS.get().getPlots(plr.getLocation().getWorld(), uuid))) { - final PlotCluster current = ClusterManager.getCluster(plot); + final PlotCluster current = plot.getCluster(); if ((current != null) && current.equals(cluster)) { plr.getLocation().getWorld(); plot.unclaim(); @@ -547,7 +471,11 @@ public class Cluster extends SubCommand { MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster helpers "); return false; } - final PlotCluster cluster = ClusterManager.getCluster(plr.getLocation()); + PlotArea area = plr.getApplicablePlotArea(); + if (area == null) { + C.NOT_IN_PLOT_WORLD.send(plr); + } + final PlotCluster cluster = area.getCluster(plr.getLocation()); if (cluster == null) { MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER); return false; @@ -581,7 +509,11 @@ public class Cluster extends SubCommand { MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster tp "); return false; } - final PlotCluster cluster = ClusterManager.getCluster(plr.getLocation().getWorld(), args[1]); + PlotArea area = plr.getApplicablePlotArea(); + if (area == null) { + C.NOT_IN_PLOT_WORLD.send(plr); + } + final PlotCluster cluster = area.getCluster(args[1]); if (cluster == null) { MainUtil.sendMessage(plr, C.INVALID_CLUSTER, args[1]); return false; @@ -593,7 +525,7 @@ public class Cluster extends SubCommand { return false; } } - plr.teleport(ClusterManager.getHome(cluster)); + plr.teleport(cluster.getHome()); return MainUtil.sendMessage(plr, C.CLUSTER_TELEPORTING); } case "i": @@ -608,15 +540,19 @@ public class Cluster extends SubCommand { MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster info [name]"); return false; } + PlotArea area = plr.getApplicablePlotArea(); + if (area == null) { + C.NOT_IN_PLOT_WORLD.send(plr); + } PlotCluster cluster; if (args.length == 2) { - cluster = ClusterManager.getCluster(plr.getLocation().getWorld(), args[1]); + cluster = area.getCluster(args[1]); if (cluster == null) { MainUtil.sendMessage(plr, C.INVALID_CLUSTER, args[1]); return false; } } else { - cluster = ClusterManager.getCluster(plr.getLocation()); + cluster = area.getCluster(plr.getLocation()); if (cluster == null) { MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER); return false; @@ -650,7 +586,11 @@ public class Cluster extends SubCommand { MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot cluster sethome"); return false; } - final PlotCluster cluster = ClusterManager.getCluster(plr.getLocation()); + PlotArea area = plr.getApplicablePlotArea(); + if (area == null) { + C.NOT_IN_PLOT_WORLD.send(plr); + } + final PlotCluster cluster = area.getCluster(plr.getLocation()); if (cluster == null) { MainUtil.sendMessage(plr, C.NOT_IN_CLUSTER); return false; @@ -661,7 +601,7 @@ public class Cluster extends SubCommand { return false; } } - final Location base = ClusterManager.getClusterBottom(cluster); + final Location base = cluster.getClusterBottom(); final Location relative = plr.getLocation().subtract(base.getX(), 0, base.getZ()); final BlockLoc blockloc = new BlockLoc(relative.getX(), relative.getY(), relative.getZ()); cluster.settings.setPosition(blockloc); diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Comment.java b/src/main/java/com/intellectualcrafters/plot/commands/Comment.java index 0864e87e0..37b1a9d45 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Comment.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Comment.java @@ -50,20 +50,19 @@ public class Comment extends SubCommand { sendMessage(player, C.COMMENT_SYNTAX, StringMan.join(CommentManager.inboxes.keySet(), "|")); return false; } - Plot plot; final Location loc = player.getLocation(); final PlotId id = PlotId.fromString(args[1]); + Plot plot = MainUtil.getPlotFromString(player, args[1], false); int index; - if (id != null) { + if (plot == null) { + index = 1; + plot = loc.getPlotAbs(); + } else { if (args.length < 4) { sendMessage(player, C.COMMENT_SYNTAX, StringMan.join(CommentManager.inboxes.keySet(), "|")); return false; } index = 2; - plot = MainUtil.getPlotAbs(loc.getWorld(), id); - } else { - index = 1; - plot = MainUtil.getPlotAbs(loc); } if (!inbox.canWrite(plot, player)) { sendMessage(player, C.NO_PERM_INBOX, ""); diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Condense.java b/src/main/java/com/intellectualcrafters/plot/commands/Condense.java index db1ed6d22..e3d014e36 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Condense.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Condense.java @@ -30,12 +30,13 @@ import java.util.concurrent.atomic.AtomicBoolean; import com.intellectualcrafters.plot.PS; 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 com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MathMan; import com.intellectualcrafters.plot.util.TaskManager; +import com.intellectualcrafters.plot.util.WorldUtil; import com.plotsquared.general.commands.CommandDeclaration; @CommandDeclaration(command = "condense", permission = "plots.admin", description = "Condense a plotworld", category = CommandCategory.DEBUG, requiredType = RequiredType.CONSOLE) @@ -46,18 +47,18 @@ public class Condense extends SubCommand { @Override public boolean onCommand(final PlotPlayer plr, final String... args) { if ((args.length != 2) && (args.length != 3)) { - MainUtil.sendMessage(plr, "/plot condense [radius]"); + MainUtil.sendMessage(plr, "/plot condense [radius]"); return false; } - final String worldname = args[0]; - if (!BlockManager.manager.isWorld(worldname) || !PS.get().isPlotWorld(worldname)) { - MainUtil.sendMessage(plr, "INVALID WORLD"); + PlotArea area = PS.get().getPlotAreaByString(args[0]); + if (area == null || !WorldUtil.IMP.isWorld(area.worldname)) { + MainUtil.sendMessage(plr, "INVALID AREA"); return false; } switch (args[1].toLowerCase()) { case "start": { if (args.length == 2) { - MainUtil.sendMessage(plr, "/plot condense " + worldname + " start "); + MainUtil.sendMessage(plr, "/plot condense " + area.toString() + " start "); return false; } if (TASK) { @@ -65,7 +66,7 @@ public class Condense extends SubCommand { return false; } if (args.length == 2) { - MainUtil.sendMessage(plr, "/plot condense " + worldname + " start "); + MainUtil.sendMessage(plr, "/plot condense " + area.toString() + " start "); return false; } if (!MathMan.isInteger(args[2])) { @@ -73,7 +74,7 @@ public class Condense extends SubCommand { return false; } final int radius = Integer.parseInt(args[2]); - ArrayList plots = new ArrayList<>(PS.get().getPlotsInWorld(worldname)); + ArrayList plots = new ArrayList<>(PS.get().getPlots(area)); // remove non base plots Iterator iter = plots.iterator(); int maxSize = 0; @@ -119,11 +120,11 @@ public class Condense extends SubCommand { final List free = new ArrayList<>(); PlotId start = new PlotId(0, 0); while ((start.x <= minimum_radius) && (start.y <= minimum_radius)) { - final Plot plot = MainUtil.getPlotAbs(worldname, start); - if (!plot.hasOwner()) { + Plot plot = area.getPlotAbs(start); + if (plot != null && !plot.hasOwner()) { free.add(plot.getId()); } - start = Auto.getNextPlot(start, 1); + start = Auto.getNextPlotId(start, 1); } if ((free.size() == 0) || (to_move.size() == 0)) { MainUtil.sendMessage(plr, "NO FREE PLOTS FOUND"); @@ -145,14 +146,14 @@ public class Condense extends SubCommand { final Plot origin = allPlots.remove(0); int i = 0; while (free.size() > i) { - final Plot possible = MainUtil.getPlotAbs(origin.world, free.get(i)); + final Plot possible = origin.area.getPlotAbs(free.get(i)); if (possible.owner != null) { free.remove(i); continue; } i++; final AtomicBoolean result = new AtomicBoolean(false); - result.set(MainUtil.move(origin, possible, new Runnable() { + result.set(origin.move(possible, new Runnable() { @Override public void run() { if (result.get()) { @@ -190,7 +191,7 @@ public class Condense extends SubCommand { } case "info": { if (args.length == 2) { - MainUtil.sendMessage(plr, "/plot condense " + worldname + " info "); + MainUtil.sendMessage(plr, "/plot condense " + area.toString() + " info "); return false; } if (!MathMan.isInteger(args[2])) { @@ -198,7 +199,7 @@ public class Condense extends SubCommand { return false; } final int radius = Integer.parseInt(args[2]); - final Collection plots = PS.get().getPlotsInWorld(worldname); + final Collection plots = area.getPlots(); final int size = plots.size(); final int minimum_radius = (int) Math.ceil((Math.sqrt(size) / 2) + 1); if (radius < minimum_radius) { @@ -218,7 +219,7 @@ public class Condense extends SubCommand { return true; } } - MainUtil.sendMessage(plr, "/plot condense " + worldname + " [radius]"); + MainUtil.sendMessage(plr, "/plot condense " + area.worldname + " [radius]"); return false; } diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Continue.java b/src/main/java/com/intellectualcrafters/plot/commands/Continue.java index 409ec4c61..3dc4ef0d4 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Continue.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Continue.java @@ -41,7 +41,7 @@ public class Continue extends SubCommand { @Override public boolean onCommand(final PlotPlayer plr, final String[] args) { final Location loc = plr.getLocation(); - final Plot plot = MainUtil.getPlotAbs(loc); + final Plot plot = loc.getPlotAbs(); if ((plot == null) || !plot.hasOwner()) { return !sendMessage(plr, C.NOT_IN_PLOT); } @@ -53,7 +53,7 @@ public class Continue extends SubCommand { MainUtil.sendMessage(plr, C.DONE_NOT_DONE); return false; } - if (Settings.DONE_COUNTS_TOWARDS_LIMIT && (MainUtil.getAllowedPlots(plr) >= MainUtil.getPlayerPlotCount(plr))) { + if (Settings.DONE_COUNTS_TOWARDS_LIMIT && (plr.getAllowedPlots() >= plr.getPlotCount())) { MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.admin.command.continue"); return false; } diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Copy.java b/src/main/java/com/intellectualcrafters/plot/commands/Copy.java index 9d56b4ffb..af23bbfe2 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Copy.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Copy.java @@ -41,7 +41,7 @@ public class Copy extends SubCommand { @Override public boolean onCommand(final PlotPlayer plr, final String[] args) { final Location loc = plr.getLocation(); - final Plot plot1 = MainUtil.getPlotAbs(loc); + final Plot plot1 = loc.getPlotAbs(); if (plot1 == null) { return !MainUtil.sendMessage(plr, C.NOT_IN_PLOT); } @@ -62,11 +62,11 @@ public class Copy extends SubCommand { C.COMMAND_SYNTAX.send(plr, getUsage()); return false; } - if (!plot1.getWorld().isCompatible(plot2.getWorld())) { + if (!plot1.getArea().isCompatible(plot2.getArea())) { C.PLOTWORLD_INCOMPATIBLE.send(plr); return false; } - if (MainUtil.copy(plot1, plot2, new Runnable() { + if (plot1.copy(plot2, new Runnable() { @Override public void run() { MainUtil.sendMessage(plr, C.COPY_SUCCESS); diff --git a/src/main/java/com/intellectualcrafters/plot/commands/CreateRoadSchematic.java b/src/main/java/com/intellectualcrafters/plot/commands/CreateRoadSchematic.java index 422311a44..52049e0f1 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/CreateRoadSchematic.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/CreateRoadSchematic.java @@ -42,11 +42,11 @@ public class CreateRoadSchematic extends SubCommand { @Override public boolean onCommand(final PlotPlayer player, final String... args) { final Location loc = player.getLocation(); - final Plot plot = MainUtil.getPlotAbs(loc); + final Plot plot = loc.getPlotAbs(); if (plot == null) { return sendMessage(player, C.NOT_IN_PLOT); } - if (!(loc.getPlotWorld() instanceof HybridPlotWorld)) { + if (!(loc.getPlotArea() instanceof HybridPlotWorld)) { return sendMessage(player, C.NOT_IN_PLOT_WORLD); } HybridUtils.manager.setupRoadSchematic(plot); diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Database.java b/src/main/java/com/intellectualcrafters/plot/commands/Database.java index 4f1dee3a7..27bb1bfeb 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Database.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Database.java @@ -1,23 +1,24 @@ package com.intellectualcrafters.plot.commands; +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map.Entry; + import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.database.MySQL; import com.intellectualcrafters.plot.database.SQLManager; import com.intellectualcrafters.plot.database.SQLite; 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 com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.TaskManager; import com.plotsquared.general.commands.CommandDeclaration; -import java.io.File; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Map.Entry; -import java.util.concurrent.ConcurrentHashMap; - @CommandDeclaration( command = "database", aliases = { "convert" }, @@ -25,7 +26,7 @@ category = CommandCategory.DEBUG, permission = "plots.database", description = "Convert/Backup Storage", requiredType = RequiredType.CONSOLE, -usage = "/plots database [world] " +usage = "/plots database [area] " ) public class Database extends SubCommand { @@ -58,15 +59,16 @@ public class Database extends SubCommand { @Override public boolean onCommand(final PlotPlayer player, String[] args) { if (args.length < 1) { - MainUtil.sendMessage(player, "/plot database [world] "); + MainUtil.sendMessage(player, "/plot database [area] "); return false; } ArrayList plots; - if (PS.get().isPlotWorld(args[0])) { - plots = PS.get().sortPlotsByTemp(PS.get().getPlotsInWorld(args[0])); + PlotArea area = PS.get().getPlotAreaByString(args[0]); + if (area != null) { + plots = PS.get().sortPlotsByTemp(area.getPlots()); args = Arrays.copyOfRange(args, 1, args.length); } else { - plots = PS.get().sortPlotsByTemp(PS.get().getPlotsRaw()); + plots = PS.get().sortPlotsByTemp(PS.get().getPlots()); } if (args.length < 1) { MainUtil.sendMessage(player, "/plot database [world] "); @@ -90,18 +92,30 @@ public class Database extends SubCommand { MainUtil.sendMessage(player, "&6Starting..."); implementation = new SQLite(file.getPath()); final SQLManager manager = new SQLManager(implementation, (args.length == 3) ? args[2] : "", true); - final ConcurrentHashMap> map = manager.getPlots(); + final HashMap> map = manager.getPlots(); plots = new ArrayList(); - for (final Entry> entry : map.entrySet()) { - for (final Entry entry2 : entry.getValue().entrySet()) { - final Plot plot = entry2.getValue(); - if (PS.get().getPlot(plot.world, plot.getId()) != null) { - MainUtil.sendMessage(player, "Skipping duplicate plot: " + plot + " | id=" + plot.temp); - continue; + for (final Entry> entry : map.entrySet()) { + String areaname = entry.getKey(); + PlotArea pa = PS.get().getPlotAreaByString(areaname); + if (pa != null) { + for (final Entry entry2 : entry.getValue().entrySet()) { + final Plot plot = entry2.getValue(); + if (pa.getOwnedPlotAbs(plot.getId()) != null) { + MainUtil.sendMessage(player, "Skipping duplicate plot: " + plot + " | id=" + plot.temp); + continue; + } + PS.get().updatePlot(plot); + plots.add(entry2.getValue()); } - PS.get().updatePlot(plot); - plots.add(entry2.getValue()); } + else { + HashMap plotmap = PS.get().plots_tmp.get(areaname); + if (plotmap == null) { + plotmap = new HashMap<>(); + PS.get().plots_tmp.put(areaname, plotmap); + } + plotmap.putAll(entry.getValue()); + } } DBFunc.createPlotsAndData(plots, new Runnable() { @Override diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Debug.java b/src/main/java/com/intellectualcrafters/plot/commands/Debug.java index a5e8bb592..9bbd637ee 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Debug.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Debug.java @@ -22,7 +22,9 @@ package com.intellectualcrafters.plot.commands; import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.C; +import com.intellectualcrafters.plot.object.PlotArea; import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.util.MainUtil; import com.plotsquared.general.commands.CommandDeclaration; @@ -49,11 +51,14 @@ public class Debug extends SubCommand { } { final StringBuilder worlds = new StringBuilder(""); - for (final String world : PS.get().getPlotWorlds()) { - worlds.append(world).append(" "); - } + PS.get().foreachPlotArea(new RunnableVal() { + @Override + public void run(PlotArea value) { + worlds.append(value.toString()).append(" "); + } + }); information.append(header); - information.append(getSection(section, "PlotWorld")); + information.append(getSection(section, "PlotArea")); information.append(getLine(line, "Plot Worlds", worlds)); information.append(getLine(line, "Owned Plots", PS.get().getPlots().size())); information.append(getSection(section, "Messages")); diff --git a/src/main/java/com/intellectualcrafters/plot/commands/DebugClaimTest.java b/src/main/java/com/intellectualcrafters/plot/commands/DebugClaimTest.java index abd4cfcee..c6000204d 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/DebugClaimTest.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/DebugClaimTest.java @@ -30,16 +30,16 @@ import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.object.ChunkLoc; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotArea; import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotManager; import com.intellectualcrafters.plot.object.PlotPlayer; -import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.object.StringWrapper; -import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.EventUtil; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.UUIDHandler; +import com.intellectualcrafters.plot.util.WorldUtil; import com.plotsquared.general.commands.CommandDeclaration; @CommandDeclaration( @@ -57,11 +57,11 @@ public class DebugClaimTest extends SubCommand { public static boolean claimPlot(final PlotPlayer player, final Plot plot, final boolean teleport, final String schematic) { final boolean result = EventUtil.manager.callClaim(player, plot, false); if (result) { - MainUtil.createPlot(player.getUUID(), plot); - MainUtil.setSign(player.getName(), plot); + plot.create(player.getUUID(), true); + plot.setSign(player.getName()); MainUtil.sendMessage(player, C.CLAIMED); if (teleport) { - MainUtil.teleportPlayer(player, player.getLocation(), plot); + plot.teleportPlayer(player); } } return !result; @@ -75,9 +75,10 @@ public class DebugClaimTest extends SubCommand { null, "If you accidentally delete your database, this command will attempt to restore all plots based on the data from the plot signs. \n\n&cMissing world arg /plot debugclaimtest {world} {PlotId min} {PlotId max}"); } - final String world = args[0]; - if (!BlockManager.manager.isWorld(world) || !PS.get().isPlotWorld(world)) { - return !MainUtil.sendMessage(plr, "&cInvalid plot world!"); + PlotArea area = PS.get().getPlotAreaByString(args[0]); + if (area == null || !WorldUtil.IMP.isWorld(area.worldname)) { + C.NOT_VALID_PLOT_WORLD.send(plr, args[0]); + return false; } PlotId min, max; try { @@ -91,22 +92,21 @@ public class DebugClaimTest extends SubCommand { } MainUtil.sendMessage(plr, "&3Sign Block&8->&3PlotSquared&8: &7Beginning sign to plot conversion. This may take a while..."); MainUtil.sendMessage(plr, "&3Sign Block&8->&3PlotSquared&8: Found an excess of 250,000 chunks. Limiting search radius... (~3.8 min)"); - final PlotManager manager = PS.get().getPlotManager(world); - final PlotWorld plotworld = PS.get().getPlotWorld(world); + final PlotManager manager = area.getPlotManager(); final ArrayList plots = new ArrayList<>(); for (final PlotId id : MainUtil.getPlotSelectionIds(min, max)) { - final Plot plot = MainUtil.getPlotAbs(world, id); - if (PS.get().getPlot(world, plot.getId()) != null) { + final Plot plot = area.getPlotAbs(id); + if (plot.hasOwner()) { MainUtil.sendMessage(plr, " - &cDB Already contains: " + plot.getId()); continue; } - final Location loc = manager.getSignLoc(plotworld, plot); + final Location loc = manager.getSignLoc(area, plot); final ChunkLoc chunk = new ChunkLoc(loc.getX() >> 4, loc.getZ() >> 4); - final boolean result = ChunkManager.manager.loadChunk(world, chunk, false); + final boolean result = ChunkManager.manager.loadChunk(area.worldname, chunk, false); if (!result) { continue; } - final String[] lines = BlockManager.manager.getSign(loc); + final String[] lines = WorldUtil.IMP.getSign(loc); if (lines != null) { String line = lines[2]; if ((line != null) && (line.length() > 2)) { diff --git a/src/main/java/com/intellectualcrafters/plot/commands/DebugExec.java b/src/main/java/com/intellectualcrafters/plot/commands/DebugExec.java index 9ec6a73a7..9df88ebb5 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/DebugExec.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/DebugExec.java @@ -20,40 +20,6 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// package com.intellectualcrafters.plot.commands; -import com.google.common.io.Files; -import com.intellectualcrafters.plot.PS; -import com.intellectualcrafters.plot.config.C; -import com.intellectualcrafters.plot.config.Settings; -import com.intellectualcrafters.plot.database.DBFunc; -import com.intellectualcrafters.plot.flag.FlagManager; -import com.intellectualcrafters.plot.generator.HybridUtils; -import com.intellectualcrafters.plot.object.ChunkLoc; -import com.intellectualcrafters.plot.object.ConsolePlayer; -import com.intellectualcrafters.plot.object.Location; -import com.intellectualcrafters.plot.object.OfflinePlotPlayer; -import com.intellectualcrafters.plot.object.Plot; -import com.intellectualcrafters.plot.object.PlotAnalysis; -import com.intellectualcrafters.plot.object.PlotBlock; -import com.intellectualcrafters.plot.object.PlotId; -import com.intellectualcrafters.plot.object.PlotPlayer; -import com.intellectualcrafters.plot.object.RunnableVal; -import com.intellectualcrafters.plot.util.AbstractTitle; -import com.intellectualcrafters.plot.util.BlockManager; -import com.intellectualcrafters.plot.util.ChunkManager; -import com.intellectualcrafters.plot.util.EconHandler; -import com.intellectualcrafters.plot.util.EventUtil; -import com.intellectualcrafters.plot.util.ExpireManager; -import com.intellectualcrafters.plot.util.MainUtil; -import com.intellectualcrafters.plot.util.MathMan; -import com.intellectualcrafters.plot.util.SchematicHandler; -import com.intellectualcrafters.plot.util.SetupUtils; -import com.intellectualcrafters.plot.util.StringMan; -import com.intellectualcrafters.plot.util.TaskManager; -import com.intellectualcrafters.plot.util.UUIDHandler; -import com.plotsquared.bukkit.util.BukkitHybridUtils; -import com.plotsquared.general.commands.Command; -import com.plotsquared.general.commands.CommandDeclaration; - import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; @@ -74,6 +40,41 @@ import javax.script.ScriptEngineManager; import javax.script.ScriptException; import javax.script.SimpleScriptContext; +import com.google.common.io.Files; +import com.intellectualcrafters.plot.PS; +import com.intellectualcrafters.plot.config.C; +import com.intellectualcrafters.plot.config.Settings; +import com.intellectualcrafters.plot.database.DBFunc; +import com.intellectualcrafters.plot.flag.FlagManager; +import com.intellectualcrafters.plot.generator.HybridUtils; +import com.intellectualcrafters.plot.object.ChunkLoc; +import com.intellectualcrafters.plot.object.ConsolePlayer; +import com.intellectualcrafters.plot.object.Location; +import com.intellectualcrafters.plot.object.OfflinePlotPlayer; +import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotAnalysis; +import com.intellectualcrafters.plot.object.PlotArea; +import com.intellectualcrafters.plot.object.PlotBlock; +import com.intellectualcrafters.plot.object.PlotId; +import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.object.RunnableVal; +import com.intellectualcrafters.plot.util.AbstractTitle; +import com.intellectualcrafters.plot.util.ChunkManager; +import com.intellectualcrafters.plot.util.EconHandler; +import com.intellectualcrafters.plot.util.EventUtil; +import com.intellectualcrafters.plot.util.ExpireManager; +import com.intellectualcrafters.plot.util.MainUtil; +import com.intellectualcrafters.plot.util.MathMan; +import com.intellectualcrafters.plot.util.SchematicHandler; +import com.intellectualcrafters.plot.util.SetupUtils; +import com.intellectualcrafters.plot.util.StringMan; +import com.intellectualcrafters.plot.util.TaskManager; +import com.intellectualcrafters.plot.util.UUIDHandler; +import com.intellectualcrafters.plot.util.WorldUtil; +import com.plotsquared.bukkit.util.BukkitHybridUtils; +import com.plotsquared.general.commands.Command; +import com.plotsquared.general.commands.CommandDeclaration; + @CommandDeclaration(command = "debugexec", permission = "plots.admin", description = "Mutli-purpose debug command", aliases = { "exec" }, category = CommandCategory.DEBUG) public class DebugExec extends SubCommand { @@ -135,7 +136,7 @@ public class DebugExec extends SubCommand { scope.put("ConsolePlayer", ConsolePlayer.getConsole()); scope.put("SchematicHandler", SchematicHandler.manager); scope.put("ChunkManager", ChunkManager.manager); - scope.put("BlockManager", BlockManager.manager); + scope.put("BlockManager", WorldUtil.IMP); scope.put("SetupUtils", SetupUtils.manager); scope.put("EventUtil", EventUtil.manager); scope.put("EconHandler", EconHandler.manager); @@ -160,7 +161,7 @@ public class DebugExec extends SubCommand { boolean async = false; switch (arg) { case "analyze": { - final Plot plot = MainUtil.getPlotAbs(player.getLocation()); + final Plot plot = player.getCurrentPlot(); if (plot == null) { MainUtil.sendMessage(player, C.NOT_IN_PLOT); return false; @@ -175,7 +176,7 @@ public class DebugExec extends SubCommand { MainUtil.sendMessage(player, "$1Starting task..."); HybridUtils.manager.analyzePlot(plot, new RunnableVal() { @Override - public void run() { + public void run(PlotAnalysis value) { MainUtil.sendMessage(player, "$1Done: $2use $3/plot debugexec analyze$2 for more information"); } }); @@ -231,14 +232,15 @@ public class DebugExec extends SubCommand { return false; } boolean result; - if (!PS.get().isPlotWorld(args[1])) { + PlotArea area = PS.get().getPlotAreaByString(args[1]); + if (area == null) { MainUtil.sendMessage(player, C.NOT_VALID_PLOT_WORLD, args[1]); return false; } if (HybridUtils.regions != null) { - result = ((BukkitHybridUtils) (HybridUtils.manager)).scheduleRoadUpdate(args[1], HybridUtils.regions, 0); + result = ((BukkitHybridUtils) (HybridUtils.manager)).scheduleRoadUpdate(area, HybridUtils.regions, 0); } else { - result = HybridUtils.manager.scheduleRoadUpdate(args[1], 0); + result = HybridUtils.manager.scheduleRoadUpdate(area, 0); } if (!result) { MainUtil.sendMessage(player, "&cCannot schedule mass schematic update! (Is one already in progress?)"); @@ -265,12 +267,13 @@ public class DebugExec extends SubCommand { } case "update-expired": { if (args.length > 1) { - final String world = args[1]; - if (!BlockManager.manager.isWorld(world)) { - return MainUtil.sendMessage(player, "Invalid world: " + args[1]); + PlotArea area = PS.get().getPlotAreaByString(args[1]); + if (area == null || !WorldUtil.IMP.isWorld(area.worldname)) { + C.NOT_VALID_PLOT_WORLD.send(player, args[1]); + return false; } MainUtil.sendMessage(player, "Updating expired plot list"); - ExpireManager.updateExpired(args[1]); + ExpireManager.updateExpired(area); return true; } return MainUtil.sendMessage(player, "Use /plot debugexec update-expired "); @@ -278,7 +281,7 @@ public class DebugExec extends SubCommand { case "show-expired": { if (args.length > 1) { final String world = args[1]; - if (!BlockManager.manager.isWorld(world)) { + if (!WorldUtil.IMP.isWorld(world)) { return MainUtil.sendMessage(player, "Invalid world: " + args[1]); } if (!ExpireManager.expiredPlots.containsKey(args[1])) { @@ -286,7 +289,8 @@ public class DebugExec extends SubCommand { } MainUtil.sendMessage(player, "Expired plots (" + ExpireManager.expiredPlots.get(args[1]).size() + "):"); for (final Plot plot : ExpireManager.expiredPlots.get(args[1])) { - MainUtil.sendMessage(player, " - " + plot.world + ";" + plot.getId().x + ";" + plot.getId().y + ";" + UUIDHandler.getName(plot.owner) + " : " + ExpireManager.dates.get(plot.owner)); + MainUtil.sendMessage(player, + " - " + plot.area + ";" + plot.getId().x + ";" + plot.getId().y + ";" + UUIDHandler.getName(plot.owner) + " : " + ExpireManager.dates.get(plot.owner)); } return true; } @@ -320,7 +324,7 @@ public class DebugExec extends SubCommand { return MainUtil.sendMessage(player, "&7 - Run after plot expiry has run"); } final String world = args[1]; - if (!BlockManager.manager.isWorld(world) || !PS.get().isPlotWorld(args[1])) { + if (!WorldUtil.IMP.isWorld(world) || !PS.get().hasPlotArea(args[1])) { return MainUtil.sendMessage(player, "Invalid world: " + args[1]); } final ArrayList empty = new ArrayList<>(); diff --git a/src/main/java/com/intellectualcrafters/plot/commands/DebugFixFlags.java b/src/main/java/com/intellectualcrafters/plot/commands/DebugFixFlags.java index c991bd28d..c90d59307 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/DebugFixFlags.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/DebugFixFlags.java @@ -30,9 +30,10 @@ import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotArea; import com.intellectualcrafters.plot.object.PlotPlayer; -import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.MainUtil; +import com.intellectualcrafters.plot.util.WorldUtil; import com.plotsquared.general.commands.Argument; import com.plotsquared.general.commands.CommandDeclaration; @@ -51,13 +52,13 @@ public class DebugFixFlags extends SubCommand { @Override public boolean onCommand(final PlotPlayer plr, final String[] args) { - final String world = args[0]; - if (!BlockManager.manager.isWorld(world) || !PS.get().isPlotWorld(world)) { + PlotArea area = PS.get().getPlotAreaByString(args[0]); + if (area == null || !WorldUtil.IMP.isWorld(area.worldname)) { MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_WORLD, args[0]); return false; } MainUtil.sendMessage(plr, "&8--- &6Starting task &8 ---"); - for (final Plot plot : PS.get().getPlotsInWorld(world)) { + for (final Plot plot : area.getPlots()) { final HashMap flags = plot.getFlags(); final Iterator> i = flags.entrySet().iterator(); boolean changed = false; diff --git a/src/main/java/com/intellectualcrafters/plot/commands/DebugPaste.java b/src/main/java/com/intellectualcrafters/plot/commands/DebugPaste.java index 8a53c09b0..6741b3498 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/DebugPaste.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/DebugPaste.java @@ -3,16 +3,14 @@ package com.intellectualcrafters.plot.commands; import java.io.File; import java.io.IOException; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.plugin.Plugin; - import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.C; +import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.HastebinUtility; +import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.TaskManager; -import com.plotsquared.bukkit.BukkitMain; +import com.intellectualcrafters.plot.util.UUIDHandler; import com.plotsquared.general.commands.CommandDeclaration; @CommandDeclaration( @@ -33,9 +31,9 @@ public class DebugPaste extends SubCommand { final String settingsYML = HastebinUtility.upload(PS.get().configFile); String latestLOG; try { - latestLOG = HastebinUtility.upload(new File(BukkitMain.THIS.getDirectory(), "../../logs/latest.log")); + latestLOG = HastebinUtility.upload(new File(PS.get().IMP.getDirectory(), "../../logs/latest.log")); } catch (final Exception e) { - plr.sendMessage(ChatColor.RED + "latest.log is too big to be pasted, will ignore"); + MainUtil.sendMessage(plr, "&clatest.log is too big to be pasted, will ignore"); latestLOG = "too big :("; } final StringBuilder b = new StringBuilder(); @@ -43,12 +41,16 @@ public class DebugPaste extends SubCommand { b.append("links.settings_yml: '").append(settingsYML).append("'\n"); b.append("links.latest_log: '").append(latestLOG).append("'\n"); b.append("\n# YAAAS! Now let us move on to the server info\n"); - b.append("version.server: '").append(Bukkit.getServer().getVersion()).append("'\n"); - b.append("version.bukkit: '").append(Bukkit.getBukkitVersion()).append("'\n"); - b.append("online_mode: ").append(Bukkit.getServer().getOnlineMode()).append("\n"); + b.append("version.server: '").append(PS.get().IMP.getServerVersion()).append("'\n"); + b.append("online_mode: ").append(UUIDHandler.getUUIDWrapper() + ";" + !Settings.OFFLINE_MODE).append("\n"); b.append("plugins:"); - for (final Plugin p : Bukkit.getPluginManager().getPlugins()) { - b.append("\n ").append(p.getName()).append(":\n ").append("version: '").append(p.getDescription().getVersion()).append("'").append("\n enabled: ").append(p.isEnabled()); + for (String id : PS.get().IMP.getPluginIds()) { + String[] split = id.split(":"); + String[] split2 = split[0].split(";"); + String enabled = split.length == 2 ? split[1] : "unknown"; + String name = split2[0]; + String version = split2.length == 2 ? split2[1] : "unknown"; + b.append("\n ").append(name).append(":\n ").append("version: '").append(version).append("'").append("\n enabled: ").append(enabled); } b.append("\n\n# YAY! Now, let's see what we can find in your JVM\n"); final Runtime runtime = Runtime.getRuntime(); diff --git a/src/main/java/com/intellectualcrafters/plot/commands/DebugRoadRegen.java b/src/main/java/com/intellectualcrafters/plot/commands/DebugRoadRegen.java index 1bafdb35e..843c56f97 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/DebugRoadRegen.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/DebugRoadRegen.java @@ -20,7 +20,6 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// package com.intellectualcrafters.plot.commands; -import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.generator.HybridPlotManager; import com.intellectualcrafters.plot.generator.HybridPlotWorld; @@ -28,8 +27,8 @@ import com.intellectualcrafters.plot.generator.HybridUtils; import com.intellectualcrafters.plot.object.ChunkLoc; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotArea; import com.intellectualcrafters.plot.object.PlotPlayer; -import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MathMan; import com.plotsquared.general.commands.CommandDeclaration; @@ -46,8 +45,7 @@ public class DebugRoadRegen extends SubCommand { @Override public boolean onCommand(final PlotPlayer player, final String... args) { final Location loc = player.getLocation(); - final String world = loc.getWorld(); - final PlotWorld plotworld = loc.getPlotWorld(); + final PlotArea plotworld = loc.getPlotArea(); if (!(plotworld instanceof HybridPlotWorld)) { return sendMessage(player, C.NOT_IN_PLOT_WORLD); } @@ -65,11 +63,11 @@ public class DebugRoadRegen extends SubCommand { } } } - final boolean result = HybridUtils.manager.regenerateRoad(world, chunk, extend); + final boolean result = HybridUtils.manager.regenerateRoad(plotworld, chunk, extend); MainUtil.sendMessage(player, "&6Regenerating chunk: " + chunk.x + "," + chunk.z + "\n&6 - Result: " + (result ? "&aSuccess" : "&cFailed")); MainUtil.sendMessage(player, "&cTo regenerate all roads: /plot regenallroads"); } else { - final HybridPlotManager manager = (HybridPlotManager) PS.get().getPlotManager(world); + final HybridPlotManager manager = (HybridPlotManager) plotworld.getPlotManager(); manager.createRoadEast(plotworld, plot); manager.createRoadSouth(plotworld, plot); manager.createRoadSouthEast(plotworld, plot); diff --git a/src/main/java/com/intellectualcrafters/plot/commands/DebugUUID.java b/src/main/java/com/intellectualcrafters/plot/commands/DebugUUID.java index edc2ebcd2..d5117fa30 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/DebugUUID.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/DebugUUID.java @@ -32,8 +32,6 @@ import java.util.List; import java.util.Map.Entry; import java.util.UUID; -import org.bukkit.Bukkit; - import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.database.AbstractDB; @@ -46,6 +44,7 @@ import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.StringMan; import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.UUIDHandler; +import com.intellectualcrafters.plot.util.WorldUtil; import com.intellectualcrafters.plot.uuid.UUIDWrapper; import com.plotsquared.bukkit.uuid.DefaultUUIDWrapper; import com.plotsquared.bukkit.uuid.LowerOfflineUUIDWrapper; @@ -125,7 +124,7 @@ public class DebugUUID extends SubCommand { MainUtil.sendMessage(player, "&7 - Collecting playerdata"); final HashSet worlds = new HashSet<>(); - worlds.add(Bukkit.getWorlds().get(0).getName()); + worlds.add(WorldUtil.IMP.getMainWorld()); worlds.add("world"); final HashSet uuids = new HashSet<>(); final HashSet names = new HashSet<>(); @@ -259,7 +258,7 @@ public class DebugUUID extends SubCommand { MainUtil.sendMessage(player, "&7 - Updating plot objects"); - for (final Plot plot : PS.get().getPlotsRaw()) { + for (final Plot plot : PS.get().getPlots()) { final UUID value = uCMap.get(plot.owner); if (value != null) { plot.owner = value; diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Delete.java b/src/main/java/com/intellectualcrafters/plot/commands/Delete.java index 40ec7f296..a4f894e21 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Delete.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Delete.java @@ -20,12 +20,14 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// package com.intellectualcrafters.plot.commands; +import java.util.HashSet; + import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotArea; import com.intellectualcrafters.plot.object.PlotPlayer; -import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.util.CmdConfirm; import com.intellectualcrafters.plot.util.EconHandler; import com.intellectualcrafters.plot.util.MainUtil; @@ -33,8 +35,6 @@ import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.TaskManager; import com.plotsquared.general.commands.CommandDeclaration; -import java.util.HashSet; - @CommandDeclaration( command = "delete", permission = "plots.delete", @@ -49,7 +49,7 @@ public class Delete extends SubCommand { public boolean onCommand(final PlotPlayer plr, final String[] args) { final Location loc = plr.getLocation(); - final Plot plot = MainUtil.getPlotAbs(loc); + final Plot plot = loc.getPlotAbs(); if (plot == null) { return !sendMessage(plr, C.NOT_IN_PLOT); } @@ -59,8 +59,8 @@ public class Delete extends SubCommand { if (!plot.isOwner(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.delete")) { return !sendMessage(plr, C.NO_PLOT_PERMS); } - final PlotWorld plotworld = plot.getWorld(); - final HashSet plots = MainUtil.getConnectedPlots(plot); + final PlotArea plotworld = plot.getArea(); + final HashSet plots = plot.getConnectedPlots(); final Runnable run = new Runnable() { @Override public void run() { diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Deny.java b/src/main/java/com/intellectualcrafters/plot/commands/Deny.java index 9cc208d6b..7c8d992f0 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Deny.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Deny.java @@ -27,11 +27,11 @@ import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotPlayer; -import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.EventUtil; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.UUIDHandler; +import com.intellectualcrafters.plot.util.WorldUtil; import com.plotsquared.bukkit.uuid.SQLUUIDHandler; import com.plotsquared.general.commands.Argument; import com.plotsquared.general.commands.CommandDeclaration; @@ -47,7 +47,7 @@ public class Deny extends SubCommand { public boolean onCommand(final PlotPlayer plr, final String[] args) { final Location loc = plr.getLocation(); - final Plot plot = MainUtil.getPlotAbs(loc); + final Plot plot = loc.getPlotAbs(); if (plot == null) { return !sendMessage(plr, C.NOT_IN_PLOT); } @@ -104,10 +104,10 @@ public class Deny extends SubCommand { if (!plot.equals(pp.getCurrentPlot())) { return; } - if (pp.hasPermission("plots.admin.command.deny")) { + if (pp.hasPermission("plots.admin.entry.denied")) { return; } - pp.teleport(BlockManager.manager.getSpawn(pp.getLocation().getWorld())); + pp.teleport(WorldUtil.IMP.getSpawn(pp.getLocation().getWorld())); MainUtil.sendMessage(pp, C.YOU_GOT_DENIED); } } diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Done.java b/src/main/java/com/intellectualcrafters/plot/commands/Done.java index fe805a2cc..81e261d21 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Done.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Done.java @@ -40,7 +40,7 @@ public class Done extends SubCommand { @Override public boolean onCommand(final PlotPlayer plr, final String[] args) { final Location loc = plr.getLocation(); - final Plot plot = MainUtil.getPlotAbs(loc); + final Plot plot = loc.getPlotAbs(); if ((plot == null) || !plot.hasOwner()) { return !sendMessage(plr, C.NOT_IN_PLOT); } @@ -60,7 +60,7 @@ public class Done extends SubCommand { MainUtil.sendMessage(plr, C.GENERATING_LINK); HybridUtils.manager.analyzePlot(plot, new RunnableVal() { @Override - public void run() { + public void run(PlotAnalysis value) { plot.removeRunning(); if ((value == null) || (value.getComplexity() >= Settings.CLEAR_THRESHOLD)) { final Flag flag = new Flag(FlagManager.getFlag("done"), (System.currentTimeMillis() / 1000)); diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Download.java b/src/main/java/com/intellectualcrafters/plot/commands/Download.java index 22f7baa2f..afe501197 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Download.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Download.java @@ -27,10 +27,10 @@ public class Download extends SubCommand { return false; } final String world = plr.getLocation().getWorld(); - if (!PS.get().isPlotWorld(world)) { + if (!PS.get().hasPlotArea(world)) { return !sendMessage(plr, C.NOT_IN_PLOT_WORLD); } - final Plot plot = MainUtil.getPlotAbs(plr.getLocation()); + final Plot plot = plr.getCurrentPlot(); if (plot == null) { return !sendMessage(plr, C.NOT_IN_PLOT); } @@ -48,9 +48,9 @@ public class Download extends SubCommand { } plot.addRunning(); MainUtil.sendMessage(plr, C.GENERATING_LINK); - SchematicHandler.manager.getCompoundTag(plot.world, plot.getId(), new RunnableVal() { + SchematicHandler.manager.getCompoundTag(plot, new RunnableVal() { @Override - public void run() { + public void run(final CompoundTag value) { TaskManager.runTaskAsync(new Runnable() { @Override public void run() { diff --git a/src/main/java/com/intellectualcrafters/plot/commands/FlagCmd.java b/src/main/java/com/intellectualcrafters/plot/commands/FlagCmd.java index 9bc503dac..d966146e8 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/FlagCmd.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/FlagCmd.java @@ -68,7 +68,7 @@ public class FlagCmd extends SubCommand { return false; } final Location loc = player.getLocation(); - final Plot plot = MainUtil.getPlotAbs(loc); + final Plot plot = loc.getPlotAbs(); if (plot == null) { MainUtil.sendMessage(player, C.NOT_IN_PLOT); return false; diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Inbox.java b/src/main/java/com/intellectualcrafters/plot/commands/Inbox.java index 567215e44..361a7e0c9 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Inbox.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Inbox.java @@ -83,18 +83,18 @@ public class Inbox extends SubCommand { @Override public boolean onCommand(final PlotPlayer player, final String[] args) { - final Plot plot = MainUtil.getPlotAbs(player.getLocation()); + final Plot plot = player.getCurrentPlot(); if (args.length == 0) { sendMessage(player, C.COMMAND_SYNTAX, "/plot inbox [inbox] [delete |clear|page]"); for (final CommentInbox inbox : CommentManager.inboxes.values()) { if (inbox.canRead(plot, player)) { - if (!inbox.getComments(plot, new RunnableVal() { + if (!inbox.getComments(plot, new RunnableVal>() { @Override - public void run() { + public void run(List value) { if (value != null) { int total = 0; int unread = 0; - for (final PlotComment comment : (ArrayList) value) { + for (final PlotComment comment : value) { total++; if (comment.timestamp > CommentManager.getTimestamp(player, inbox.toString())) { unread++; @@ -149,10 +149,10 @@ public class Inbox extends SubCommand { return false; } - if (!inbox.getComments(plot, new RunnableVal() { + if (!inbox.getComments(plot, new RunnableVal>() { @Override - public void run() { - final List comments = (List) value; + public void run(List value) { + final List comments = value; if (index > comments.size()) { sendMessage(player, C.NOT_VALID_INBOX_INDEX, index + ""); return; @@ -196,10 +196,10 @@ public class Inbox extends SubCommand { sendMessage(player, C.NO_PERM_INBOX); return false; } - if (!inbox.getComments(plot, new RunnableVal() { + if (!inbox.getComments(plot, new RunnableVal>() { @Override - public void run() { - final List comments = (List) value; + public void run(List value) { + final List comments = value; displayComments(player, comments, page); } })) { diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Info.java b/src/main/java/com/intellectualcrafters/plot/commands/Info.java index 82601620c..f9360cc8d 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Info.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Info.java @@ -37,12 +37,10 @@ public class Info extends SubCommand { @Override public boolean onCommand(final PlotPlayer player, String[] args) { - String arg = null; Plot plot; + String arg; if (args.length > 0) { - arg = args[0] + ""; - } - if (arg != null) { + arg = args[0]; switch (arg) { case "trusted": case "alias": @@ -66,11 +64,12 @@ public class Info extends SubCommand { } break; } + if (plot == null) { + plot = player.getCurrentPlot(); + } } else { - plot = MainUtil.getPlotFromString(player, null, false); - } - if ((plot == null) && (arg != null)) { - plot = MainUtil.getPlotFromString(player, null, false); + arg = null; + plot = player.getCurrentPlot(); } if (plot == null) { MainUtil.sendMessage(player, C.NOT_IN_PLOT); @@ -138,7 +137,7 @@ public class Info extends SubCommand { } MainUtil.format(info, plot, player, full, new RunnableVal() { @Override - public void run() { + public void run(String value) { MainUtil.sendMessage(player, C.PLOT_INFO_HEADER.s() + '\n' + value + '\n' + C.PLOT_INFO_FOOTER.s(), false); } }); diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Kick.java b/src/main/java/com/intellectualcrafters/plot/commands/Kick.java index daf5c0e17..49eac2261 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Kick.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Kick.java @@ -24,10 +24,10 @@ import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotPlayer; -import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.UUIDHandler; +import com.intellectualcrafters.plot.util.WorldUtil; import com.plotsquared.general.commands.CommandDeclaration; @CommandDeclaration(command = "kick", aliases = { "k" }, description = "Kick a player from your plot", permission = "plots.kick", category = CommandCategory.ACTIONS, requiredType = RequiredType.NONE) @@ -36,7 +36,7 @@ public class Kick extends SubCommand { @Override public boolean onCommand(final PlotPlayer plr, final String[] args) { final Location loc = plr.getLocation(); - final Plot plot = MainUtil.getPlotAbs(loc); + final Plot plot = loc.getPlot(); if (plot == null) { return !sendMessage(plr, C.NOT_IN_PLOT); } @@ -54,15 +54,15 @@ public class Kick extends SubCommand { return false; } final Location otherLoc = player.getLocation(); - if (!plr.getLocation().getWorld().equals(otherLoc.getWorld()) || !plot.equals(MainUtil.getPlotAbs(otherLoc))) { + if (!plr.getLocation().getWorld().equals(otherLoc.getWorld()) || !plot.equals(otherLoc.getPlot())) { MainUtil.sendMessage(plr, C.INVALID_PLAYER, args[0]); return false; } - if (player.hasPermission("plots.admin.command.kick")) { + if (player.hasPermission("plots.admin.entry.denied")) { C.CANNOT_KICK_PLAYER.send(plr, player.getName()); return false; } - player.teleport(BlockManager.manager.getSpawn(loc.getWorld())); + player.teleport(WorldUtil.IMP.getSpawn(loc.getWorld())); return true; } } diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Load.java b/src/main/java/com/intellectualcrafters/plot/commands/Load.java index b74cac53b..2034d263e 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Load.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Load.java @@ -36,10 +36,10 @@ public class Load extends SubCommand { return false; } final String world = plr.getLocation().getWorld(); - if (!PS.get().isPlotWorld(world)) { + if (!PS.get().hasPlotArea(world)) { return !sendMessage(plr, C.NOT_IN_PLOT_WORLD); } - final Plot plot = MainUtil.getPlotAbs(plr.getLocation()); + final Plot plot = plr.getCurrentPlot(); if (plot == null) { return !sendMessage(plr, C.NOT_IN_PLOT); } @@ -93,7 +93,7 @@ public class Load extends SubCommand { } SchematicHandler.manager.paste(schematic, plot, 0, 0, new RunnableVal() { @Override - public void run() { + public void run(Boolean value) { plot.removeRunning(); if (value) { sendMessage(plr, C.SCHEMATIC_PASTE_SUCCESS); diff --git a/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java b/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java index 124cde014..fce95e9b8 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java @@ -20,11 +20,19 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// package com.intellectualcrafters.plot.commands; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; + import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.object.ConsolePlayer; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotArea; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MathMan; @@ -37,13 +45,6 @@ import com.plotsquared.general.commands.Command; import com.plotsquared.general.commands.CommandHandlingOutput; import com.plotsquared.general.commands.CommandManager; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; - /** * PlotSquared command class * @@ -83,7 +84,6 @@ public class MainCommand extends CommandManager { createCommand(new Auto()); createCommand(new Visit()); createCommand(new Home()); - createCommand(new TP()); createCommand(new Set()); createCommand(new Toggle()); createCommand(new Clear()); @@ -273,12 +273,12 @@ public class MainCommand extends CommandManager { } default: { if (args.length >= 2) { - String world = player.getLocation().getWorld(); - Plot newPlot = Plot.fromString(world, args[0]); + PlotArea area = player.getApplicablePlotArea(); + Plot newPlot = Plot.fromString(area, args[0]); if (newPlot == null) { break; } - if (!ConsolePlayer.isConsole(player) && (!newPlot.world.equals(world) || newPlot.isDenied(player.getUUID())) && !Permissions.hasPermission(player, C.PERMISSION_ADMIN)) { + if (!ConsolePlayer.isConsole(player) && (!newPlot.area.equals(area) || newPlot.isDenied(player.getUUID())) && !Permissions.hasPermission(player, C.PERMISSION_ADMIN)) { break; } // Save meta diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Merge.java b/src/main/java/com/intellectualcrafters/plot/commands/Merge.java index 33e37e358..a4069390c 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Merge.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Merge.java @@ -20,12 +20,15 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// package com.intellectualcrafters.plot.commands; +import java.util.HashSet; +import java.util.UUID; + import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotArea; import com.intellectualcrafters.plot.object.PlotPlayer; -import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.util.CmdConfirm; import com.intellectualcrafters.plot.util.EconHandler; import com.intellectualcrafters.plot.util.MainUtil; @@ -34,9 +37,6 @@ import com.intellectualcrafters.plot.util.StringMan; import com.intellectualcrafters.plot.util.UUIDHandler; import com.plotsquared.general.commands.CommandDeclaration; -import java.util.HashSet; -import java.util.UUID; - @CommandDeclaration( command = "merge", aliases = { "m" }, @@ -74,7 +74,7 @@ public class Merge extends SubCommand { @Override public boolean onCommand(final PlotPlayer plr, final String[] args) { final Location loc = plr.getLocationFull(); - final Plot plot = MainUtil.getPlotAbs(loc); + final Plot plot = loc.getPlotAbs(); if (plot == null) { return !sendMessage(plr, C.NOT_IN_PLOT); } @@ -92,7 +92,7 @@ public class Merge extends SubCommand { uuid = plot.owner; } } - final PlotWorld plotworld = plot.getWorld(); + final PlotArea plotworld = plot.getArea(); if ((EconHandler.manager != null) && plotworld.USE_ECONOMY && plotworld.MERGE_PRICE > 0d && EconHandler.manager.getMoney(plr) < plotworld.MERGE_PRICE) { sendMessage(plr, C.CANNOT_AFFORD_MERGE, plotworld.MERGE_PRICE + ""); return false; @@ -125,7 +125,7 @@ public class Merge extends SubCommand { if (args.length == 2) { terrain = args[1].equalsIgnoreCase("true"); } - if (MainUtil.autoMerge(plot, -1, maxSize - size, uuid, terrain)) { + if (plot.autoMerge(-1, maxSize, uuid, terrain)) { if ((EconHandler.manager != null) && plotworld.USE_ECONOMY && plotworld.MERGE_PRICE > 0d) { EconHandler.manager.withdrawMoney(plr, plotworld.MERGE_PRICE); sendMessage(plr, C.REMOVED_BALANCE, plotworld.MERGE_PRICE + ""); @@ -155,7 +155,7 @@ public class Merge extends SubCommand { } else { terrain = Settings.MERGE_REMOVES_ROADS; } - if (MainUtil.autoMerge(plot, direction, maxSize - size, uuid, terrain)) { + if (plot.autoMerge(direction, maxSize - size, uuid, terrain)) { if ((EconHandler.manager != null) && plotworld.USE_ECONOMY && plotworld.MERGE_PRICE > 0d) { EconHandler.manager.withdrawMoney(plr, plotworld.MERGE_PRICE); sendMessage(plr, C.REMOVED_BALANCE, plotworld.MERGE_PRICE + ""); @@ -163,7 +163,7 @@ public class Merge extends SubCommand { MainUtil.sendMessage(plr, C.SUCCESS_MERGE); return true; } - Plot adjacent = MainUtil.getPlotAbs(plot.world, MainUtil.getPlotIdRelative(plot.getId(), direction)); + Plot adjacent = plot.getRelative(direction); if (adjacent == null || !adjacent.hasOwner() || adjacent.getMerged((direction + 2) % 4) || adjacent.isOwner(uuid)) { MainUtil.sendMessage(plr, C.NO_AVAILABLE_AUTOMERGE); return false; @@ -185,7 +185,7 @@ public class Merge extends SubCommand { @Override public void run() { MainUtil.sendMessage(accepter, C.MERGE_ACCEPTED); - MainUtil.autoMerge(plot, dir, maxSize - size, owner, terrain); + plot.autoMerge(dir, maxSize - size, owner, terrain); final PlotPlayer pp = UUIDHandler.getPlayer(plr.getUUID()); if (pp == null) { sendMessage(accepter, C.MERGE_NOT_VALID); diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Middle.java b/src/main/java/com/intellectualcrafters/plot/commands/Middle.java index 5c17eda5f..472d57793 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Middle.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Middle.java @@ -4,8 +4,6 @@ import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotPlayer; -import com.intellectualcrafters.plot.object.RegionWrapper; -import com.intellectualcrafters.plot.util.MainUtil; import com.plotsquared.general.commands.CommandDeclaration; /** @@ -26,7 +24,7 @@ public class Middle extends SubCommand { @Override public boolean onCommand(PlotPlayer player, String[] arguments) { final Location location = player.getLocation(); - final Plot plot = MainUtil.getPlotAbs(location); + final Plot plot = location.getPlot(); if (plot == null) { return sendMessage(player, C.NOT_IN_PLOT); } @@ -36,13 +34,7 @@ public class Middle extends SubCommand { if (!player.hasPermission("plots.middle")) { return sendMessage(player, C.NO_PERMISSION, "plots.middle"); } - - RegionWrapper largestRegion = MainUtil.getLargestRegion(plot); - final int x = ((largestRegion.maxX - largestRegion.minX) / 2) + largestRegion.minX; - final int z = ((largestRegion.maxZ - largestRegion.minZ) / 2) + largestRegion.minZ; - final int y = MainUtil.getHeighestBlock(plot.getWorld().worldname, x, z) + 1; - - player.teleport(new Location(plot.getWorld().worldname, x, y, z)); + player.teleport(plot.getCenter()); return true; } } diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Move.java b/src/main/java/com/intellectualcrafters/plot/commands/Move.java index cd622470b..aff5aad98 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Move.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Move.java @@ -41,7 +41,7 @@ public class Move extends SubCommand { @Override public boolean onCommand(final PlotPlayer plr, final String[] args) { final Location loc = plr.getLocation(); - final Plot plot1 = MainUtil.getPlotAbs(loc); + final Plot plot1 = loc.getPlotAbs(); if (plot1 == null) { return !MainUtil.sendMessage(plr, C.NOT_IN_PLOT); } @@ -62,11 +62,11 @@ public class Move extends SubCommand { MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot copy "); return false; } - if (!plot1.getWorld().isCompatible(plot2.getWorld())) { + if (!plot1.area.isCompatible(plot2.area)) { C.PLOTWORLD_INCOMPATIBLE.send(plr); return false; } - if (MainUtil.move(plot1, plot2, new Runnable() { + if (plot1.move(plot2, new Runnable() { @Override public void run() { MainUtil.sendMessage(plr, C.MOVE_SUCCESS); diff --git a/src/main/java/com/intellectualcrafters/plot/commands/MusicSubcommand.java b/src/main/java/com/intellectualcrafters/plot/commands/MusicSubcommand.java index 95f72784d..a57309ca0 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/MusicSubcommand.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/MusicSubcommand.java @@ -29,8 +29,8 @@ import com.intellectualcrafters.plot.object.PlotBlock; import com.intellectualcrafters.plot.object.PlotInventory; import com.intellectualcrafters.plot.object.PlotItemStack; import com.intellectualcrafters.plot.object.PlotPlayer; -import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.MainUtil; +import com.intellectualcrafters.plot.util.WorldUtil; import com.plotsquared.general.commands.CommandDeclaration; @CommandDeclaration(command = "music", permission = "plots.music", description = "Player music in a plot", usage = "/plot music", category = CommandCategory.ACTIONS, requiredType = RequiredType.NONE) @@ -39,7 +39,7 @@ public class MusicSubcommand extends SubCommand { @Override public boolean onCommand(final PlotPlayer player, final String[] args) { final Location loc = player.getLocation(); - final Plot plot = MainUtil.getPlotAbs(loc); + final Plot plot = loc.getPlotAbs(); if (plot == null) { return !sendMessage(player, C.NOT_IN_PLOT); } @@ -65,7 +65,7 @@ public class MusicSubcommand extends SubCommand { }; int index = 0; for (int i = 2256; i < 2268; i++) { - final String name = "&r&6" + BlockManager.manager.getClosestMatchingName(new PlotBlock((short) i, (byte) 0)); + final String name = "&r&6" + WorldUtil.IMP.getClosestMatchingName(new PlotBlock((short) i, (byte) 0)); final String[] lore = { "&r&aClick to play!" }; final PlotItemStack item = new PlotItemStack(i, (byte) 0, 1, name, lore); inv.setItem(index, item); diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Owner.java b/src/main/java/com/intellectualcrafters/plot/commands/Owner.java index 7f4e41461..489d1ef85 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Owner.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Owner.java @@ -44,7 +44,7 @@ public class Owner extends SetCommand { @Override public boolean set(PlotPlayer plr, Plot plot, String value) { - HashSet plots = MainUtil.getConnectedPlots(plot); + HashSet plots = plot.getConnectedPlots(); UUID uuid = null; String name = null; if (value.length() == 36) { @@ -72,18 +72,18 @@ public class Owner extends SetCommand { return false; } final int size = plots.size(); - final int currentPlots = (Settings.GLOBAL_LIMIT ? MainUtil.getPlayerPlotCount(other) : MainUtil.getPlayerPlotCount(plot.world, other)) + size; - if (currentPlots > MainUtil.getAllowedPlots(other)) { + final int currentPlots = (Settings.GLOBAL_LIMIT ? other.getPlotCount() : other.getPlotCount(plot.area.worldname)) + size; + if (currentPlots > other.getAllowedPlots()) { sendMessage(plr, C.CANT_TRANSFER_MORE_PLOTS); return false; } } plot.setOwner(uuid); - MainUtil.setSign(name, plot); + plot.setSign(name); MainUtil.sendMessage(plr, C.SET_OWNER); if (other != null) { - MainUtil.sendMessage(other, C.NOW_OWNER, plot.world + ";" + plot.getId()); + MainUtil.sendMessage(other, C.NOW_OWNER, plot.area + ";" + plot.getId()); } return true; } diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Purge.java b/src/main/java/com/intellectualcrafters/plot/commands/Purge.java index 5e69f017c..bb69a00c4 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Purge.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Purge.java @@ -20,8 +20,9 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// package com.intellectualcrafters.plot.commands; -import java.util.Collection; +import java.util.HashMap; import java.util.HashSet; +import java.util.Map.Entry; import java.util.Set; import java.util.UUID; @@ -29,136 +30,157 @@ import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.database.DBFunc; 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 com.intellectualcrafters.plot.util.MainUtil; +import com.intellectualcrafters.plot.util.CmdConfirm; +import com.intellectualcrafters.plot.util.StringMan; import com.intellectualcrafters.plot.util.UUIDHandler; import com.plotsquared.general.commands.CommandDeclaration; -@CommandDeclaration(command = "purge", permission = "plots.admin", description = "Purge all plots for a world", category = CommandCategory.ACTIONS, requiredType = RequiredType.CONSOLE) +@CommandDeclaration( +usage = "/plot purge world: area: id: owner: shared: unknown:[true|false]", +command = "purge", +permission = "plots.admin", +description = "Purge all plots for a world", +category = CommandCategory.ACTIONS, +requiredType = RequiredType.CONSOLE) public class Purge extends SubCommand { - - public PlotId getId(final String id) { - try { - final String[] split = id.split(";"); - return new PlotId(Integer.parseInt(split[0]), Integer.parseInt(split[1])); - } catch (final Exception e) { - return null; - } - } - @Override public boolean onCommand(final PlotPlayer plr, final String[] args) { - if (args.length == 1) { - final String arg = args[0].toLowerCase(); - final PlotId id = getId(arg); - if (id != null) { - MainUtil.sendMessage(plr, "/plot purxe x;z &l"); - return false; - } - final UUID uuid = UUIDHandler.getUUID(args[0], null); - if (uuid != null) { - MainUtil.sendMessage(plr, "/plot purge " + args[0] + " &l"); - return false; - } - if (arg.equals("player")) { - MainUtil.sendMessage(plr, "/plot purge &l "); - return false; - } - if (arg.equals("unowned")) { - MainUtil.sendMessage(plr, "/plot purge unowned &l"); - return false; - } - if (arg.equals("unknown")) { - MainUtil.sendMessage(plr, "/plot purge unknown &l"); - return false; - } - if (arg.equals("all")) { - MainUtil.sendMessage(plr, "/plot purge all &l"); - return false; - } - MainUtil.sendMessage(plr, C.PURGE_SYNTAX); + if (args.length == 0) { return false; } - if (args.length != 2) { - MainUtil.sendMessage(plr, C.PURGE_SYNTAX); - return false; - } - final String worldname = args[1]; - if (!PS.get().isPlotWorld(worldname)) { - C.NOT_VALID_PLOT_WORLD.send(plr); - return false; - } - final String arg = args[0].toLowerCase(); - final PlotId id = getId(arg); - if (id != null) { - final HashSet ids = new HashSet(); - final int DBid = DBFunc.getId(MainUtil.getPlotAbs(worldname, id)); - if (DBid != Integer.MAX_VALUE) { - ids.add(DBid); + + String world = null; + PlotArea area = null; + PlotId id = null; + UUID owner = null; + UUID added = null; + boolean unknown = false; + for (String arg : args) { + String[] split = arg.split(":"); + if (split.length != 2) { + C.COMMAND_SYNTAX.send(plr, getUsage()); + return false; } - DBFunc.purgeIds(worldname, ids); - return finishPurge(DBid == Integer.MAX_VALUE ? 1 : 0); - } - if (arg.equals("all")) { - final Set ids = PS.get().getPlots(worldname).keySet(); - final int length = ids.size(); - if (length == 0) { - return MainUtil.sendMessage(plr, "&cNo plots found"); + switch (split[0].toLowerCase()) { + case "world": + case "w": { + world = split[1]; + break; + } + case "area": + case "a": { + area = PS.get().getPlotAreaByString(split[1]); + if (area == null) { + C.NOT_VALID_PLOT_WORLD.send(plr, split[1]); + return false; + } + break; + } + case "plotid": + case "id": { + id = PlotId.fromString(split[1]); + if (id == null) { + C.NOT_VALID_PLOT_ID.send(plr, split[1]); + return false; + } + break; + } + case "owner": + case "o": { + owner = UUIDHandler.getUUID(split[1], null); + if (owner == null) { + C.INVALID_PLAYER.send(plr, split[1]); + return false; + } + break; + } + case "shared": + case "s": { + added = UUIDHandler.getUUID(split[1], null); + if (added == null) { + C.INVALID_PLAYER.send(plr, split[1]); + return false; + } + break; + } + case "unknown": + case "?": + case "u": { + unknown = Boolean.parseBoolean(split[1]); + break; + } } - DBFunc.purge(worldname, ids); - return finishPurge(length); } - if (arg.equals("unknown")) { - final Collection plots = PS.get().getPlotsInWorld(worldname); - final Set ids = new HashSet<>(); - for (final Plot plot : plots) { - if (plot.owner != null) { - final String name = UUIDHandler.getName(plot.owner); - if (name == null) { - ids.add(plot.getId()); + final HashSet toDelete = new HashSet<>(); + Set basePlots = PS.get().getBasePlots(); + for (Plot plot : PS.get().getBasePlots()) { + if (world != null && !plot.area.worldname.equalsIgnoreCase(world)) { + continue; + } + if (area != null && !plot.area.equals(area)) { + continue; + } + if (id != null && !plot.id.equals(id)) { + continue; + } + if (owner != null && !plot.isOwner(owner)) { + continue; + } + if (added != null && !plot.isAdded(added)) { + continue; + } + if (unknown && UUIDHandler.getName(plot.owner) != null) { + continue; + } + for (Plot current : plot.getConnectedPlots()) { + final int DBid = DBFunc.getId(current); + if (DBid != Integer.MAX_VALUE) { + toDelete.add(DBid); + } + } + } + if (PS.get().plots_tmp != null) { + for (Entry> entry : PS.get().plots_tmp.entrySet()) { + String worldname = entry.getKey(); + if (world != null && !world.equalsIgnoreCase(worldname)) { + continue; + } + for (Entry entry2 : entry.getValue().entrySet()) { + Plot plot = entry2.getValue(); + if (id != null && !plot.id.equals(id)) { + continue; + } + if (owner != null && !plot.isOwner(owner)) { + continue; + } + if (added != null && !plot.isAdded(added)) { + continue; + } + if (unknown && UUIDHandler.getName(plot.owner) != null) { + continue; + } + final int DBid = DBFunc.getId(plot); + if (DBid != Integer.MAX_VALUE) { + toDelete.add(DBid); } } } - final int length = ids.size(); - if (length == 0) { - return MainUtil.sendMessage(plr, "&cNo plots found"); - } - DBFunc.purge(worldname, ids); - return finishPurge(length); } - if (arg.equals("unowned")) { - final Collection plots = PS.get().getPlotsInWorld(worldname); - final Set ids = new HashSet<>(); - for (final Plot plot : plots) { - if (plot.owner == null) { - ids.add(plot.getId()); - } - } - final int length = ids.size(); - if (length == 0) { - return MainUtil.sendMessage(plr, "&cNo plots found"); - } - DBFunc.purge(worldname, ids); - return finishPurge(length); + if (toDelete.size() == 0) { + C.FOUND_NO_PLOTS.send(plr); + return false; } - final UUID uuid = UUIDHandler.getUUID(args[0], null); - if (uuid != null) { - final Set plots = PS.get().getPlots(worldname, uuid); - final Set ids = new HashSet<>(); - for (final Plot plot : plots) { - ids.add(plot.getId()); + String cmd = "/plot purge " + StringMan.join(args, " ") + " (" + toDelete.size() + " plots)"; + CmdConfirm.addPending(plr, cmd, new Runnable() { + @Override + public void run() { + DBFunc.purgeIds(toDelete); + C.PURGE_SUCCESS.send(plr, toDelete.size() + ""); } - final int length = ids.size(); - DBFunc.purge(worldname, ids); - return finishPurge(length); - } - MainUtil.sendMessage(plr, C.PURGE_SYNTAX); - return false; - } - - private boolean finishPurge(final int amount) { - MainUtil.sendMessage(null, C.PURGE_SUCCESS, amount + ""); - return false; + }); + return true; } } diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Rate.java b/src/main/java/com/intellectualcrafters/plot/commands/Rate.java index 13a73593c..b542570c4 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Rate.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Rate.java @@ -33,7 +33,6 @@ import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.database.DBFunc; -import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotInventory; import com.intellectualcrafters.plot.object.PlotItemStack; @@ -89,7 +88,7 @@ public class Rate extends SubCommand { && p.isBasePlot() && ((p.getSettings().ratings == null) || !p.getSettings().ratings.containsKey(uuid)) && !p.isAdded(uuid)) { - MainUtil.teleportPlayer(player, player.getLocation(), p); + p.teleportPlayer(player); MainUtil.sendMessage(player, C.RATE_THIS); return true; } @@ -98,8 +97,7 @@ public class Rate extends SubCommand { return false; } } - final Location loc = player.getLocation(); - final Plot plot = MainUtil.getPlot(loc); + final Plot plot = player.getCurrentPlot(); if (plot == null) { return !sendMessage(player, C.NOT_IN_PLOT); } diff --git a/src/main/java/com/intellectualcrafters/plot/commands/RegenAllRoads.java b/src/main/java/com/intellectualcrafters/plot/commands/RegenAllRoads.java index 0b70fe7b3..980d962d6 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/RegenAllRoads.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/RegenAllRoads.java @@ -27,10 +27,12 @@ import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.generator.HybridPlotManager; import com.intellectualcrafters.plot.generator.HybridUtils; import com.intellectualcrafters.plot.object.ChunkLoc; +import com.intellectualcrafters.plot.object.PlotArea; import com.intellectualcrafters.plot.object.PlotManager; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.MainUtil; +import com.intellectualcrafters.plot.util.WorldUtil; import com.plotsquared.general.commands.CommandDeclaration; @CommandDeclaration( @@ -58,8 +60,13 @@ public class RegenAllRoads extends SubCommand { MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot regenallroads [height]"); return false; } + PlotArea area = PS.get().getPlotAreaByString(args[0]); + if (area == null || WorldUtil.IMP.isWorld(area.worldname)) { + C.NOT_VALID_PLOT_WORLD.send(plr, args[0]); + return false; + } final String name = args[0]; - final PlotManager manager = PS.get().getPlotManager(name); + final PlotManager manager = area.getPlotManager(); if ((manager == null) || !(manager instanceof HybridPlotManager)) { MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_WORLD); return false; @@ -69,7 +76,7 @@ public class RegenAllRoads extends SubCommand { MainUtil.sendMessage(plr, "&7 - To set a schematic, stand in a plot and use &c/plot createroadschematic"); MainUtil.sendMessage(plr, "&6Potential chunks to update: &7" + (chunks.size() * 1024)); MainUtil.sendMessage(plr, "&6Estimated time: &7" + (chunks.size()) + " seconds"); - final boolean result = HybridUtils.manager.scheduleRoadUpdate(name, height); + final boolean result = HybridUtils.manager.scheduleRoadUpdate(area, height); if (!result) { MainUtil.sendMessage(plr, "&cCannot schedule mass schematic update! (Is one already in progress?)"); return false; diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Reload.java b/src/main/java/com/intellectualcrafters/plot/commands/Reload.java index e63c870fb..e3e351a76 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Reload.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Reload.java @@ -20,11 +20,16 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// package com.intellectualcrafters.plot.commands; +import java.util.Objects; + import com.intellectualcrafters.configuration.ConfigurationSection; +import com.intellectualcrafters.configuration.MemorySection; +import com.intellectualcrafters.configuration.file.YamlConfiguration; import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.C; +import com.intellectualcrafters.plot.object.PlotArea; import com.intellectualcrafters.plot.object.PlotPlayer; -import com.intellectualcrafters.plot.object.PlotWorld; +import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.util.MainUtil; import com.plotsquared.general.commands.CommandDeclaration; @@ -40,12 +45,52 @@ public class Reload extends SubCommand { PS.get().config.load(PS.get().configFile); PS.get().setupConfig(); C.load(PS.get().translationFile); - for (final String pw : PS.get().getPlotWorlds()) { - final PlotWorld plotworld = PS.get().getPlotWorld(pw); - final ConfigurationSection section = PS.get().config.getConfigurationSection("worlds." + pw); - plotworld.saveConfiguration(section); - plotworld.loadDefaultConfiguration(section); - } + PS.get().foreachPlotArea(new RunnableVal() { + @Override + public void run(PlotArea area) { + final ConfigurationSection worldSection = PS.get().config.getConfigurationSection("worlds." + area.worldname); + if (area.TYPE != 2 || !worldSection.contains("areas")) { + area.saveConfiguration(worldSection); + area.loadDefaultConfiguration(worldSection); + } else { + ConfigurationSection areaSection = worldSection.getConfigurationSection("areas." + area.id + "-" + area.getMin() + "-" + area.getMax()); + YamlConfiguration clone = new YamlConfiguration(); + for (String key : areaSection.getKeys(true)) { + if (areaSection.get(key) instanceof MemorySection) { + continue; + } + if (!clone.contains(key)) { + clone.set(key, areaSection.get(key)); + } + } + for (String key : worldSection.getKeys(true)) { + if (worldSection.get(key) instanceof MemorySection) { + continue; + } + if (!key.startsWith("areas") && !clone.contains(key)) { + clone.set(key, worldSection.get(key)); + } + } + area.saveConfiguration(clone); + // netSections is the combination of + for (String key : clone.getKeys(true)) { + if (clone.get(key) instanceof MemorySection) { + continue; + } + if (!worldSection.contains(key)) { + worldSection.set(key, clone.get(key)); + } else { + Object value = worldSection.get(key); + if (Objects.equals(value, clone.get(key))) { + areaSection.set(key, clone.get(key)); + } + } + } + area.loadDefaultConfiguration(clone); + } + } + }); + PS.get().config.save(PS.get().configFile); MainUtil.sendMessage(plr, C.RELOADED_CONFIGS); } catch (final Exception e) { e.printStackTrace(); diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Remove.java b/src/main/java/com/intellectualcrafters/plot/commands/Remove.java index d74296187..c2b86bbd5 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Remove.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Remove.java @@ -56,7 +56,7 @@ public class Remove extends SubCommand { return true; } final Location loc = plr.getLocation(); - final Plot plot = MainUtil.getPlotAbs(loc); + final Plot plot = loc.getPlotAbs(); if (plot == null) { return !sendMessage(plr, C.NOT_IN_PLOT); } diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Save.java b/src/main/java/com/intellectualcrafters/plot/commands/Save.java index c77845bb0..c8fee6e19 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Save.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Save.java @@ -30,10 +30,10 @@ public class Save extends SubCommand { return false; } final String world = plr.getLocation().getWorld(); - if (!PS.get().isPlotWorld(world)) { + if (!PS.get().hasPlotArea(world)) { return !sendMessage(plr, C.NOT_IN_PLOT_WORLD); } - final Plot plot = MainUtil.getPlotAbs(plr.getLocation()); + final Plot plot = plr.getCurrentPlot(); if (plot == null) { return !sendMessage(plr, C.NOT_IN_PLOT); } @@ -50,18 +50,18 @@ public class Save extends SubCommand { return false; } plot.addRunning(); - SchematicHandler.manager.getCompoundTag(plot.world, plot.getId(), new RunnableVal() { + SchematicHandler.manager.getCompoundTag(plot, new RunnableVal() { @Override - public void run() { + public void run(final CompoundTag value) { TaskManager.runTaskAsync(new Runnable() { @Override public void run() { final String time = (System.currentTimeMillis() / 1000) + ""; final String name = PS.get().IMP.getServerName().replaceAll("[^A-Za-z0-9]", ""); - Location[] corners = MainUtil.getCorners(plot); + Location[] corners = plot.getCorners(); final int size = (corners[1].getX() - corners[0].getX()) + 1; final PlotId id = plot.getId(); - final String world = plot.world.replaceAll("[^A-Za-z0-9]", ""); + final String world = plot.area.toString().replaceAll(";", "-").replaceAll("[^A-Za-z0-9]", ""); final String file = time + "_" + world + "_" + id.x + "_" + id.y + "_" + size + "_" + name; final UUID uuid = plr.getUUID(); diff --git a/src/main/java/com/intellectualcrafters/plot/commands/SchematicCmd.java b/src/main/java/com/intellectualcrafters/plot/commands/SchematicCmd.java index 69bc68650..797a9a9aa 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/SchematicCmd.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/SchematicCmd.java @@ -31,6 +31,7 @@ import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.object.ConsolePlayer; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotArea; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.util.MainUtil; @@ -71,7 +72,7 @@ public class SchematicCmd extends SubCommand { break; } final Location loc = plr.getLocation(); - final Plot plot = MainUtil.getPlotAbs(loc); + final Plot plot = loc.getPlotAbs(); if (plot == null) { return !sendMessage(plr, C.NOT_IN_PLOT); } @@ -115,7 +116,7 @@ public class SchematicCmd extends SubCommand { } SchematicHandler.manager.paste(schematic, plot, 0, 0, new RunnableVal() { @Override - public void run() { + public void run(Boolean value) { running = false; if (value) { sendMessage(plr, C.SCHEMATIC_PASTE_SUCCESS); @@ -167,12 +168,17 @@ public class SchematicCmd extends SubCommand { return false; } if (args.length != 2) { - MainUtil.sendMessage(plr, "&cNeed world arg. Use &7/plots sch exportall "); + MainUtil.sendMessage(plr, "&cNeed world arg. Use &7/plots sch exportall "); return false; } - final Collection plots = PS.get().getPlotsInWorld(args[1]); + PlotArea area = PS.get().getPlotAreaByString(args[1]); + if (area == null) { + C.NOT_VALID_PLOT_WORLD.send(plr, args[1]); + return false; + } + final Collection plots = area.getPlots(); if ((plots.size() == 0)) { - MainUtil.sendMessage(plr, "&cInvalid world. Use &7/plots sch exportall "); + MainUtil.sendMessage(plr, "&cInvalid world. Use &7/plots sch exportall "); return false; } final boolean result = SchematicHandler.manager.exportAll(plots, null, null, new Runnable() { @@ -202,7 +208,7 @@ public class SchematicCmd extends SubCommand { } final Plot p2; final Location loc = plr.getLocation(); - final Plot plot = MainUtil.getPlotAbs(loc); + final Plot plot = loc.getPlotAbs(); if (plot == null) { return !sendMessage(plr, C.NOT_IN_PLOT); } diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Set.java b/src/main/java/com/intellectualcrafters/plot/commands/Set.java index 0ab84e231..0d2a8abc4 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Set.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Set.java @@ -20,28 +20,28 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// package com.intellectualcrafters.plot.commands; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; + import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.Configuration; import com.intellectualcrafters.plot.flag.AbstractFlag; import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotArea; import com.intellectualcrafters.plot.object.PlotBlock; import com.intellectualcrafters.plot.object.PlotManager; import com.intellectualcrafters.plot.object.PlotPlayer; -import com.intellectualcrafters.plot.object.PlotWorld; -import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; -import com.intellectualcrafters.plot.util.SetBlockQueue; +import com.intellectualcrafters.plot.util.SetQueue; import com.intellectualcrafters.plot.util.StringComparison; import com.intellectualcrafters.plot.util.StringMan; +import com.intellectualcrafters.plot.util.WorldUtil; import com.plotsquared.general.commands.Command; import com.plotsquared.general.commands.CommandDeclaration; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; - @CommandDeclaration( command = "set", description = "Set a plot value", @@ -66,7 +66,7 @@ public class Set extends SubCommand { @Override public boolean set(PlotPlayer plr, final Plot plot, String value) { - final PlotWorld plotworld = plr.getLocation().getPlotWorld(); + final PlotArea plotworld = plr.getLocation().getPlotArea(); final PlotManager manager = plr.getLocation().getPlotManager(); final String[] components = manager.getPlotComponents(plotworld, plot.getId()); final boolean allowUnsafe = DebugAllowUnsafe.unsafeAllowed.contains(plr.getUUID()); @@ -98,22 +98,22 @@ public class Set extends SubCommand { } else { name = split[i]; } - final StringComparison.ComparisonResult match = BlockManager.manager.getClosestBlock(name); + final StringComparison.ComparisonResult match = WorldUtil.IMP.getClosestBlock(name); if (match != null) { - name = BlockManager.manager.getClosestMatchingName(match.best); + name = WorldUtil.IMP.getClosestMatchingName(match.best); if (name != null) { MainUtil.sendMessage(plr, C.DID_YOU_MEAN, name.toLowerCase()); } } return false; - } else if (!allowUnsafe && !BlockManager.manager.isBlockSolid(block)) { + } else if (!allowUnsafe && !WorldUtil.IMP.isBlockSolid(block)) { MainUtil.sendMessage(plr, C.NOT_ALLOWED_BLOCK, block.toString()); return false; } } if (!allowUnsafe) { for (final PlotBlock block : blocks) { - if (!BlockManager.manager.isBlockSolid(block)) { + if (!WorldUtil.IMP.isBlockSolid(block)) { MainUtil.sendMessage(plr, C.NOT_ALLOWED_BLOCK, block.toString()); return false; } @@ -128,11 +128,11 @@ public class Set extends SubCommand { return false; } plot.addRunning(); - for (Plot current : MainUtil.getConnectedPlots(plot)) { + for (Plot current : plot.getConnectedPlots()) { manager.setComponent(plotworld, current.getId(), component, blocks); } MainUtil.sendMessage(plr, C.GENERATING_COMPONENT); - SetBlockQueue.addNotify(new Runnable() { + SetQueue.IMP.addTask(new Runnable() { @Override public void run() { plot.removeRunning(); @@ -151,7 +151,7 @@ public class Set extends SubCommand { newValues.addAll(Arrays.asList("biome", "alias", "home", "flag")); Plot plot = plr.getCurrentPlot(); if (plot != null) { - newValues.addAll(Arrays.asList(plot.getManager().getPlotComponents(plot.getWorld(), plot.getId()))); + newValues.addAll(Arrays.asList(plot.getManager().getPlotComponents(plot.getArea(), plot.getId()))); } MainUtil.sendMessage(plr, C.SUBCOMMAND_SET_OPTIONS_HEADER.s() + StringMan.join(newValues, C.BLOCK_LIST_SEPARATER.formatted())); return false; @@ -173,7 +173,7 @@ public class Set extends SubCommand { return false; } // components - HashSet components = new HashSet<>(Arrays.asList(plot.getManager().getPlotComponents(plot.getWorld(), plot.getId()))); + HashSet components = new HashSet<>(Arrays.asList(plot.getManager().getPlotComponents(plot.getArea(), plot.getId()))); if (components.contains(args[0].toLowerCase())) { return component.onCommand(plr, Arrays.copyOfRange(args, 0, args.length)); } diff --git a/src/main/java/com/intellectualcrafters/plot/commands/SetCommand.java b/src/main/java/com/intellectualcrafters/plot/commands/SetCommand.java index 7315fca7c..da57b123e 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/SetCommand.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/SetCommand.java @@ -13,7 +13,7 @@ public abstract class SetCommand extends SubCommand { @Override public boolean onCommand(PlotPlayer plr, String[] args) { final Location loc = plr.getLocation(); - final Plot plot = MainUtil.getPlotAbs(loc); + final Plot plot = loc.getPlotAbs(); if (plot == null) { return !sendMessage(plr, C.NOT_IN_PLOT); } diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Setup.java b/src/main/java/com/intellectualcrafters/plot/commands/Setup.java index 23aa01ab4..f396c7d94 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Setup.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Setup.java @@ -20,24 +20,25 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// package com.intellectualcrafters.plot.commands; -import com.intellectualcrafters.plot.PS; -import com.intellectualcrafters.plot.config.C; -import com.intellectualcrafters.plot.config.ConfigurationNode; -import com.intellectualcrafters.plot.config.Settings; -import com.intellectualcrafters.plot.generator.PlotGenerator; -import com.intellectualcrafters.plot.object.PlotPlayer; -import com.intellectualcrafters.plot.object.SetupObject; -import com.intellectualcrafters.plot.util.BlockManager; -import com.intellectualcrafters.plot.util.MainUtil; -import com.intellectualcrafters.plot.util.SetupUtils; -import com.intellectualcrafters.plot.util.StringMan; -import com.plotsquared.general.commands.CommandDeclaration; - import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Map.Entry; +import com.intellectualcrafters.plot.PS; +import com.intellectualcrafters.plot.config.C; +import com.intellectualcrafters.plot.config.ConfigurationNode; +import com.intellectualcrafters.plot.generator.GeneratorWrapper; +import com.intellectualcrafters.plot.object.PlotArea; +import com.intellectualcrafters.plot.object.PlotId; +import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.object.SetupObject; +import com.intellectualcrafters.plot.util.MainUtil; +import com.intellectualcrafters.plot.util.SetupUtils; +import com.intellectualcrafters.plot.util.StringMan; +import com.intellectualcrafters.plot.util.WorldUtil; +import com.plotsquared.general.commands.CommandDeclaration; + @CommandDeclaration( command = "setup", permission = "plots.admin.command.setup", @@ -50,7 +51,7 @@ public class Setup extends SubCommand { public void displayGenerators(final PlotPlayer plr) { final StringBuilder message = new StringBuilder(); message.append("&6What generator do you want?"); - for (final Entry> entry : SetupUtils.generators.entrySet()) { + for (final Entry> entry : SetupUtils.generators.entrySet()) { if (entry.getKey().equals("PlotSquared")) { message.append("\n&8 - &2").append(entry.getKey()).append(" (Default Generator)"); } else if (entry.getValue().isFull()) { @@ -65,10 +66,10 @@ public class Setup extends SubCommand { @Override public boolean onCommand(final PlotPlayer plr, final String[] args) { // going through setup - final String name = plr.getName(); - if (!SetupUtils.setupMap.containsKey(name)) { - final SetupObject object = new SetupObject(); - SetupUtils.setupMap.put(name, object); + SetupObject object = (SetupObject) plr.getMeta("setup"); + if (object == null) { + object = new SetupObject(); + plr.setMeta("setup", object); SetupUtils.manager.updateGenerators(); sendMessage(plr, C.SETUP_INIT); displayGenerators(plr); @@ -76,12 +77,11 @@ public class Setup extends SubCommand { } if (args.length == 1) { if (args[0].equalsIgnoreCase("cancel")) { - SetupUtils.setupMap.remove(name); + plr.deleteMeta("setup"); MainUtil.sendMessage(plr, "&aCancelled setup"); return false; } if (args[0].equalsIgnoreCase("back")) { - final SetupObject object = SetupUtils.setupMap.get(name); if (object.setup_index > 0) { object.setup_index--; final ConfigurationNode node = object.step[object.setup_index]; @@ -92,7 +92,6 @@ public class Setup extends SubCommand { } } } - final SetupObject object = SetupUtils.setupMap.get(name); final int index = object.current; switch (index) { case 0: { // choose generator @@ -104,7 +103,7 @@ public class Setup extends SubCommand { } object.setupGenerator = args[0]; object.current++; - final String partial = Settings.ENABLE_CLUSTERS ? "\n&8 - &7PARTIAL&8 - &7Vanilla with clusters of plots" : ""; + final String partial = "\n&8 - &7PARTIAL&8 - &7Vanilla with clusters of plots"; MainUtil.sendMessage(plr, "&6What world type do you want?" + "\n&8 - &2DEFAULT&8 - &7Standard plot generation" + "\n&8 - &7AUGMENTED&8 - &7Plot generation with terrain" + partial); break; } @@ -117,9 +116,7 @@ public class Setup extends SubCommand { types.add("default"); } types.add("augmented"); - if (Settings.ENABLE_CLUSTERS) { - types.add("partial"); - } + types.add("partial"); if ((args.length != 1) || !types.contains(args[0].toLowerCase())) { MainUtil.sendMessage(plr, "&cYou must choose a world type!"); for (final String type : types) { @@ -133,16 +130,16 @@ public class Setup extends SubCommand { return false; } object.type = allTypes.indexOf(args[0].toLowerCase()); - final PlotGenerator gen = SetupUtils.generators.get(object.setupGenerator); + final GeneratorWrapper gen = SetupUtils.generators.get(object.setupGenerator); if (object.type == 0) { - object.current++; + object.current = 7; if (object.step == null) { object.plotManager = object.setupGenerator; - object.step = SetupUtils.generators.get(object.plotManager).getNewPlotWorld(null).getSettingNodes(); - SetupUtils.generators.get(object.plotManager).processSetup(object); + object.step = SetupUtils.generators.get(object.plotManager).getPlotGenerator().getNewPlotArea("CheckingPlotSquaredGenerator", null, null, null).getSettingNodes(); + SetupUtils.generators.get(object.plotManager).getPlotGenerator().processSetup(object); } if (object.step.length == 0) { - object.current = 4; + object.current = 7; MainUtil.sendMessage(plr, "&6What do you want your world to be called?"); object.setup_index = 0; return true; @@ -153,24 +150,75 @@ public class Setup extends SubCommand { if (gen.isFull()) { object.plotManager = object.setupGenerator; object.setupGenerator = null; - object.step = SetupUtils.generators.get(object.plotManager).getNewPlotWorld(null).getSettingNodes(); - SetupUtils.generators.get(object.plotManager).processSetup(object); + object.step = SetupUtils.generators.get(object.plotManager).getPlotGenerator().getNewPlotArea("CheckingPlotSquaredGenerator", null, null, null).getSettingNodes(); + SetupUtils.generators.get(object.plotManager).getPlotGenerator().processSetup(object); } else { object.plotManager = "PlotSquared"; MainUtil.sendMessage(plr, "&c[WARNING] The specified generator does not identify as BukkitPlotGenerator"); MainUtil.sendMessage(plr, "&7 - You may need to manually configure the other plugin"); - object.step = SetupUtils.generators.get(object.plotManager).getNewPlotWorld(null).getSettingNodes(); + object.step = SetupUtils.generators.get(object.plotManager).getPlotGenerator().getNewPlotArea("CheckingPlotSquaredGenerator", null, null, null).getSettingNodes(); + } + if (object.type == 2) { + MainUtil.sendMessage(plr, "What would you like this area called?"); + object.current++; + } else { + MainUtil.sendMessage(plr, "&6What terrain would you like in plots?" + + "\n&8 - &2NONE&8 - &7No terrain at all" + + "\n&8 - &7ORE&8 - &7Just some ore veins and trees" + + "\n&8 - &7ROAD&8 - &7Terrain separated by roads" + + "\n&8 - &7ALL&8 - &7Entirely vanilla generation"); + object.current = 5; } - MainUtil.sendMessage(plr, "&6What terrain would you like in plots?" - + "\n&8 - &2NONE&8 - &7No terrain at all" - + "\n&8 - &7ORE&8 - &7Just some ore veins and trees" - + "\n&8 - &7ROAD&8 - &7Terrain separated by roads" - + "\n&8 - &7ALL&8 - &7Entirely vanilla generation"); } - object.current++; break; } - case 2: { // Choose terrain + case 2: { // area id + if (!StringMan.isAlphanumericUnd(args[0])) { + MainUtil.sendMessage(plr, "&cThe area id must be alphanumerical!"); + return false; + } + for (PlotArea area : PS.get().getPlotAreas()) { + if (area.id != null && area.id.equalsIgnoreCase(args[0])) { + MainUtil.sendMessage(plr, "&cYou must choose an area id that is not in use!"); + return false; + } + } + object.id = args[0]; + object.current++; + MainUtil.sendMessage(plr, "&6What should be the minimum Plot Id?"); + break; + } + case 3: { // min + object.min = PlotId.fromString(args[0]); + if (object.min == null) { + MainUtil.sendMessage(plr, "&cYou must choose a valid minimum PlotId!"); + return false; + } + object.current++; + MainUtil.sendMessage(plr, "&6What should be the maximum Plot Id?"); + break; + } + case 4: { + // max + PlotId id = PlotId.fromString(args[0]); + if (id == null) { + MainUtil.sendMessage(plr, "&cYou must choose a valid maximum PlotId!"); + return false; + } + if (id.x <= object.min.x || id.y <= object.min.y) { + MainUtil.sendMessage(plr, "&cThe max PlotId must be greater than the minimum!"); + return false; + } + object.max = id; + object.current++; + MainUtil.sendMessage(plr, "&6What terrain would you like in plots?" + + "\n&8 - &2NONE&8 - &7No terrain at all" + + "\n&8 - &7ORE&8 - &7Just some ore veins and trees" + + "\n&8 - &7ROAD&8 - &7Terrain separated by roads" + + "\n&8 - &7ALL&8 - &7Entirely vanilla generation"); + break; + } + case 5: { // Choose terrain final List terrain = Arrays.asList("none", "ore", "road", "all"); if ((args.length != 1) || !terrain.contains(args[0].toLowerCase())) { MainUtil.sendMessage(plr, "&cYou must choose the terrain!" @@ -183,13 +231,13 @@ public class Setup extends SubCommand { object.terrain = terrain.indexOf(args[0].toLowerCase()); object.current++; if (object.step == null) { - object.step = SetupUtils.generators.get(object.plotManager).getNewPlotWorld(null).getSettingNodes(); + object.step = SetupUtils.generators.get(object.plotManager).getPlotGenerator().getNewPlotArea("CheckingPlotSquaredGenerator", null, null, null).getSettingNodes(); } final ConfigurationNode step = object.step[object.setup_index]; sendMessage(plr, C.SETUP_STEP, object.setup_index + 1 + "", step.getDescription(), step.getType().getType(), step.getDefaultValue() + ""); break; } - case 3: { // world setup + case 6: { // world setup if (object.setup_index == object.step.length) { MainUtil.sendMessage(plr, "&6What do you want your world to be called?"); object.setup_index = 0; @@ -219,13 +267,13 @@ public class Setup extends SubCommand { return false; } } - case 4: { + case 7: { if (args.length != 1) { MainUtil.sendMessage(plr, "&cYou need to choose a world name!"); return false; } - if (BlockManager.manager.isWorld(args[0])) { - if (PS.get().isPlotWorld(args[0])) { + if (WorldUtil.IMP.isWorld(args[0])) { + if (PS.get().hasPlotArea(args[0])) { MainUtil.sendMessage(plr, "&cThat world name is already taken!"); return false; } @@ -233,7 +281,7 @@ public class Setup extends SubCommand { "&cThe world you specified already exists. After restarting, new terrain will use PlotSquared, however you may need to reset the world for it to generate correctly!"); } object.world = args[0]; - SetupUtils.setupMap.remove(name); + plr.deleteMeta("setup"); final String world; if (object.setupManager == null) { world = SetupUtils.manager.setupWorld(object); @@ -241,13 +289,12 @@ public class Setup extends SubCommand { world = object.setupManager.setupWorld(object); } try { - plr.teleport(BlockManager.manager.getSpawn(world)); + plr.teleport(WorldUtil.IMP.getSpawn(world)); } catch (final Exception e) { plr.sendMessage("&cAn error occurred. See console for more information"); e.printStackTrace(); } sendMessage(plr, C.SETUP_FINISHED, object.world); - SetupUtils.setupMap.remove(name); } } return false; diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Swap.java b/src/main/java/com/intellectualcrafters/plot/commands/Swap.java index 473697f4f..da7b254f3 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Swap.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Swap.java @@ -34,7 +34,7 @@ public class Swap extends SubCommand { @Override public boolean onCommand(final PlotPlayer plr, final String[] args) { final Location loc = plr.getLocation(); - final Plot plot1 = MainUtil.getPlotAbs(loc); + final Plot plot1 = loc.getPlotAbs(); if (plot1 == null) { return !MainUtil.sendMessage(plr, C.NOT_IN_PLOT); } @@ -55,11 +55,11 @@ public class Swap extends SubCommand { MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot copy "); return false; } - if (!plot1.getWorld().isCompatible(plot2.getWorld())) { + if (!plot1.area.isCompatible(plot2.area)) { C.PLOTWORLD_INCOMPATIBLE.send(plr); return false; } - if (MainUtil.move(plot1, plot2, new Runnable() { + if (plot1.move(plot2, new Runnable() { @Override public void run() { MainUtil.sendMessage(plr, C.SWAP_SUCCESS); diff --git a/src/main/java/com/intellectualcrafters/plot/commands/TP.java b/src/main/java/com/intellectualcrafters/plot/commands/TP.java deleted file mode 100644 index bd35c6e4e..000000000 --- a/src/main/java/com/intellectualcrafters/plot/commands/TP.java +++ /dev/null @@ -1,99 +0,0 @@ -//////////////////////////////////////////////////////////////////////////////////////////////////// -// PlotSquared - A plot manager and world generator for the Bukkit API / -// Copyright (c) 2014 IntellectualSites/IntellectualCrafters / -// / -// This program is free software; you can redistribute it and/or modify / -// it under the terms of the GNU General Public License as published by / -// the Free Software Foundation; either version 3 of the License, or / -// (at your option) any later version. / -// / -// This program is distributed in the hope that it will be useful, / -// but WITHOUT ANY WARRANTY; without even the implied warranty of / -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the / -// GNU General Public License for more details. / -// / -// You should have received a copy of the GNU General Public License / -// along with this program; if not, write to the Free Software Foundation, / -// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA / -// / -// You can contact us via: support@intellectualsites.com / -//////////////////////////////////////////////////////////////////////////////////////////////////// -package com.intellectualcrafters.plot.commands; - -import com.intellectualcrafters.plot.PS; -import com.intellectualcrafters.plot.config.C; -import com.intellectualcrafters.plot.object.Location; -import com.intellectualcrafters.plot.object.Plot; -import com.intellectualcrafters.plot.object.PlotId; -import com.intellectualcrafters.plot.object.PlotPlayer; -import com.intellectualcrafters.plot.util.BlockManager; -import com.intellectualcrafters.plot.util.MainUtil; -import com.intellectualcrafters.plot.util.MathMan; -import com.intellectualcrafters.plot.util.UUIDHandler; -import com.plotsquared.general.commands.Argument; -import com.plotsquared.general.commands.CommandDeclaration; - -@CommandDeclaration(command = "tp", description = "Teleport to a plot", permission = "plots.tp", usage = "/plot tp ", requiredType = RequiredType.NONE, category = CommandCategory.TELEPORT) -public class TP extends SubCommand { - - public TP() { - requiredArguments = new Argument[] { Argument.String }; - } - - @Override - public boolean onCommand(final PlotPlayer plr, final String[] args) { - final String id = args[0]; - PlotId plotid; - final Location loc = plr.getLocation(); - final String pworld = loc.getWorld(); - String world = pworld; - if (args.length == 2) { - if (BlockManager.manager.isWorld(args[1])) { - world = args[1]; - } - } - if (!PS.get().isPlotWorld(world)) { - MainUtil.sendMessage(plr, C.NOT_IN_PLOT_WORLD); - return false; - } - Plot temp; - if ((temp = isAlias(world, id)) != null) { - MainUtil.teleportPlayer(plr, plr.getLocation(), temp); - return true; - } - try { - plotid = new PlotId(Integer.parseInt(id.split(";")[0]), Integer.parseInt(id.split(";")[1])); - MainUtil.teleportPlayer(plr, plr.getLocation(), MainUtil.getPlotAbs(world, plotid)); - return true; - } catch (final Exception e) { - MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID); - } - return false; - } - - private Plot isAlias(final String world, String a) { - int index = 0; - if (a.contains(";")) { - final String[] split = a.split(";"); - if ((split[1].length() > 0) && MathMan.isInteger(split[1])) { - index = Integer.parseInt(split[1]); - } - a = split[0]; - } - final PlotPlayer player = UUIDHandler.getPlayer(a); - if (player != null) { - final java.util.Set plotMainPlots = PS.get().getPlots(world, player); - final Plot[] plots = plotMainPlots.toArray(new Plot[plotMainPlots.size()]); - if (plots.length > index) { - return plots[index]; - } - return null; - } - for (final Plot p : PS.get().getPlotsInWorld(world)) { - if ((p.getAlias().length() > 0) && p.getAlias().equalsIgnoreCase(a)) { - return p; - } - } - return null; - } -} diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Target.java b/src/main/java/com/intellectualcrafters/plot/commands/Target.java index e614a7622..1ee250ae1 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Target.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Target.java @@ -24,7 +24,6 @@ import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; -import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.StringMan; @@ -32,7 +31,7 @@ import com.plotsquared.general.commands.CommandDeclaration; @CommandDeclaration( command = "target", -usage = "/plot target ", +usage = "/plot target <|nearest>", description = "Target a plot with your compass", permission = "plots.target", requiredType = RequiredType.NONE, @@ -42,30 +41,28 @@ public class Target extends SubCommand { @Override public boolean onCommand(final PlotPlayer plr, final String[] args) { final Location ploc = plr.getLocation(); - if (!PS.get().isPlotWorld(ploc.getWorld())) { + if (!PS.get().hasPlotArea(ploc.getWorld())) { MainUtil.sendMessage(plr, C.NOT_IN_PLOT_WORLD); return false; } - PlotId id = PlotId.fromString(args[0]); - if (id == null) { - if (StringMan.isEqualIgnoreCaseToAny(args[0], "near", "nearest")) { - Plot closest = null; - int distance = Integer.MAX_VALUE; - for (final Plot plot : PS.get().getPlotsInWorld(ploc.getWorld())) { - final double current = plot.getBottomAbs().getEuclideanDistanceSquared(ploc); - if (current < distance) { - distance = (int) current; - closest = plot; - } + Plot target = null; + if (StringMan.isEqualIgnoreCaseToAny(args[0], "near", "nearest")) { + int distance = Integer.MAX_VALUE; + for (final Plot plot : PS.get().getPlots(ploc.getWorld())) { + final double current = plot.getCenter().getEuclideanDistanceSquared(ploc); + if (current < distance) { + distance = (int) current; + target = plot; } - id = closest.getId(); - } else { - MainUtil.sendMessage(plr, C.NOT_VALID_PLOT_ID); + } + if (target == null) { + C.FOUND_NO_PLOTS.send(plr); return false; } + } else if ((target = MainUtil.getPlotFromString(plr, args[0], true)) == null) { + return false; } - final Location loc = MainUtil.getPlotHome(ploc.getWorld(), id); - plr.setCompassTarget(loc); + plr.setCompassTarget(target.getCenter()); MainUtil.sendMessage(plr, C.COMPASS_TARGET); return true; } diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Template.java b/src/main/java/com/intellectualcrafters/plot/commands/Template.java index aa546787e..de3a87f8e 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Template.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Template.java @@ -35,15 +35,15 @@ import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.ConfigurationNode; import com.intellectualcrafters.plot.object.FileBytes; +import com.intellectualcrafters.plot.object.PlotArea; import com.intellectualcrafters.plot.object.PlotManager; import com.intellectualcrafters.plot.object.PlotPlayer; -import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.object.SetupObject; -import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.MainUtil; -import com.intellectualcrafters.plot.util.SetBlockQueue; +import com.intellectualcrafters.plot.util.SetQueue; import com.intellectualcrafters.plot.util.SetupUtils; import com.intellectualcrafters.plot.util.TaskManager; +import com.intellectualcrafters.plot.util.WorldUtil; import com.plotsquared.general.commands.CommandDeclaration; @CommandDeclaration( @@ -89,7 +89,7 @@ public class Template extends SubCommand { } } - public static byte[] getBytes(final PlotWorld plotworld) { + public static byte[] getBytes(final PlotArea plotworld) { final ConfigurationSection section = PS.get().config.getConfigurationSection("worlds." + plotworld.worldname); final YamlConfiguration config = new YamlConfiguration(); final String generator = SetupUtils.manager.getGenerator(plotworld); @@ -139,7 +139,7 @@ public class Template extends SubCommand { MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot template import