From 8e240b52742af7da48c8a3a11fdcae03ab70cbca Mon Sep 17 00:00:00 2001 From: boy0001 Date: Tue, 4 Aug 2015 22:21:12 +1000 Subject: [PATCH] stuff --- .../com/intellectualcrafters/plot/PS.java | 121 ++++++++--- .../plot/commands/Auto.java | 2 +- .../plot/commands/DebugExec.java | 2 - .../plot/commands/Home.java | 3 +- .../plot/commands/Limit.java | 9 - .../plot/commands/Merge.java | 5 +- .../plot/commands/SchematicCmd.java | 4 +- .../plot/commands/Visit.java | 5 +- .../plot/commands/WE_Anywhere.java | 1 - .../plot/commands/list.java | 3 +- .../plot/database/AbstractDB.java | 9 +- .../plot/database/DBFunc.java | 53 ++--- .../plot/database/SQLManager.java | 54 ++++- .../plot/generator/HybridUtils.java | 1 - .../plot/object/Plot.java | 16 +- .../plot/util/ChunkManager.java | 2 +- .../plot/util/ClusterManager.java | 1 - .../plot/util/MainUtil.java | 51 +++-- .../plot/util/SetBlockQueue.java | 7 +- .../com/plotsquared/bukkit/BukkitMain.java | 189 +++++++++--------- .../bukkit/generator/AugmentedPopulator.java | 1 - .../bukkit/listeners/ChatListener.java | 4 - .../bukkit/util/BukkitChunkManager.java | 37 ++-- .../bukkit/util/BukkitCommand.java | 2 - .../bukkit/util/BukkitEconHandler.java | 2 - .../bukkit/util/BukkitHybridUtils.java | 1 - .../plotsquared/bukkit/util/SetBlockSlow.java | 2 - .../bukkit/util/WorldEditSchematic.java | 1 - .../plotsquared/sponge/SpongeHybridUtils.java | 2 - .../com/plotsquared/sponge/SpongeMain.java | 4 +- .../sponge/SpongeSchematicHandler.java | 1 - .../sponge/generator/AugmentedPopulator.java | 1 - .../sponge/generator/SpongePlotPopulator.java | 1 - .../sponge/generator/WorldModify.java | 1 - .../sponge/listener/MainListener.java | 1 - .../sponge/util/SpongeChunkManager.java | 12 +- src/main/resources/plugin.yml | 2 +- 37 files changed, 364 insertions(+), 249 deletions(-) diff --git a/src/main/java/com/intellectualcrafters/plot/PS.java b/src/main/java/com/intellectualcrafters/plot/PS.java index d4be138de..0398214d5 100644 --- a/src/main/java/com/intellectualcrafters/plot/PS.java +++ b/src/main/java/com/intellectualcrafters/plot/PS.java @@ -7,8 +7,6 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; -import java.lang.reflect.Array; -import java.net.URI; import java.net.URL; import java.net.URLConnection; import java.nio.file.Files; @@ -23,12 +21,12 @@ import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashMap; -import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Map.Entry; 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; @@ -115,7 +113,7 @@ public class PS { private int[] VERSION = null; private String LAST_VERSION; private boolean LOADING_WORLD = false; - private LinkedHashMap> plots; + private ConcurrentHashMap> plots; private Database database; private Connection connection; private Thread thread; @@ -354,7 +352,7 @@ public class PS { public void updatePlot(final Plot plot) { final String world = plot.world; if (!plots.containsKey(world)) { - plots.put(world, new HashMap()); + plots.put(world, new ConcurrentHashMap()); } plots.get(world).put(plot.id, plot); } @@ -386,7 +384,7 @@ public class PS { plotworlds.put(world, plotworld); plotmanagers.put(world, manager); if (!plots.containsKey(world)) { - plots.put(world, new HashMap()); + plots.put(world, new ConcurrentHashMap()); } } @@ -418,7 +416,8 @@ public class PS { * * @return HashMap containing the world name, and another map with the plot id and the plot object */ - public HashMap> getAllPlotsRaw() { + @Deprecated + public ConcurrentHashMap> getAllPlotsRaw() { return plots; } @@ -429,7 +428,7 @@ public class PS { */ public Set getPlots(PlotFilter... filters) { HashSet set = new HashSet<>(); - for (Entry> entry : plots.entrySet()) { + for (Entry> entry : plots.entrySet()) { for (PlotFilter filter : filters) { if (!filter.allowsWorld(entry.getKey())) { continue; @@ -455,7 +454,8 @@ public class PS { * @see #getAllPlotsRaw() to get the raw plot object * @param plots */ - public void setAllPlotsRaw(final LinkedHashMap> plots) { + @Deprecated + public void setAllPlotsRaw(final ConcurrentHashMap> plots) { this.plots = plots; } @@ -465,13 +465,19 @@ public class PS { * @return Set of Plot */ public Set getPlots() { - final ArrayList newplots = new ArrayList<>(); - for (final Entry> entry : plots.entrySet()) { + int size = 0; + for (Entry> entry : plots.entrySet()) { if (isPlotWorld(entry.getKey())) { - newplots.addAll(entry.getValue().values()); + size += entry.getValue().size(); } } - return new LinkedHashSet<>(newplots); + Set result = new HashSet<>(size); + for (Entry> entry : plots.entrySet()) { + if (isPlotWorld(entry.getKey())) { + result.addAll(entry.getValue().values()); + } + } + return result; } @@ -480,12 +486,17 @@ public class PS { * @return set of plot * @see #setAllPlotsRaw(LinkedHashMap) to set the raw plot object */ + @Deprecated public Set getPlotsRaw() { - final ArrayList newplots = new ArrayList<>(); - for (final Entry> entry : plots.entrySet()) { - newplots.addAll(entry.getValue().values()); + int size = 0; + for (Entry> entry : plots.entrySet()) { + size += entry.getValue().size(); } - return new LinkedHashSet<>(newplots); + Set result = new HashSet<>(size); + for (Entry> entry : plots.entrySet()) { + result.addAll(entry.getValue().values()); + } + return result; } @@ -493,17 +504,20 @@ public class PS { * Sort a collection of plots by the hashcode (assumes that all plots are in the same world) * @param plots * @return ArrayList of plot + * @deprecated use sortPlot */ @Deprecated public ArrayList sortPlots(Collection plots) { - return sortPlotsByWorld(plots); + return sortPlots(plots, SortType.DISTANCE_FROM_ORIGIN, null); } /** * Sort plots by hashcode * @param plots * @return + * @deprecated Unchecked, please use {@link #sortPlots(Collection, SortType, String)} which has additional checks before calling this */ + @Deprecated public ArrayList sortPlotsByHash(Collection plots) { int hardmax = 256000; int max = 0; @@ -545,6 +559,13 @@ public class PS { return result; } + /** + * Sort plots by creation timestamp + * @param input + * @deprecated Unchecked, use {@link #sortPlots(Collection, SortType, String)} instead which will call this after checks + * @return + */ + @Deprecated public static ArrayList sortPlotsByTimestamp(Collection input) { List list; if (input instanceof ArrayList) { @@ -720,6 +741,10 @@ public class PS { } } + /** + * @deprecated Unchecked, use {@link #sortPlots(Collection, SortType, String)} instead which will in turn call this + * @param input + */ public static void sortPlotsByHash(Plot[] input) { final int SIZE = 100; List[] bucket = new ArrayList[SIZE]; @@ -748,6 +773,12 @@ public class PS { } } + /** + * Sort plots by timestamp + * @param input + * @deprecated Unchecked, use {@link #sortPlots(Collection, SortType, String)} instead which will in turn call this + */ + @Deprecated public static void sortPlotsByTimestamp(Plot[] input) { final int SIZE = 100; List[] bucket = new ArrayList[SIZE]; @@ -776,25 +807,26 @@ public class PS { } } + public enum SortType { CREATION_DATE, DISTANCE_FROM_ORIGIN; } + /** * Sort a collection of plots by world (with a priority world), then by hashcode * @param plots - * @param priorityWorld - Use "world" or "gibberish" if you don't care - * @see #sortPlotsByWorld(Collection) to sort plots by world, then by hashcode - * @see #sortPlots(Collection) to sort plots just by hashcode + * @param type The sorting method to use for each world (timestamp, or hash) + * @param priorityWorld - Use null, "world" or "gibberish" if you want default world order * @return ArrayList of plot */ - public ArrayList sortPlots(Collection plots, final String priorityWorld) { + public ArrayList sortPlots(Collection plots, final SortType type, final String priorityWorld) { // group by world // sort each HashMap> map = new HashMap<>(); ArrayList worlds = new ArrayList(getPlotWorlds()); int totalSize = 0; - for (Entry> entry : this.plots.entrySet()) { + for (Entry> entry : this.plots.entrySet()) { totalSize += entry.getValue().size(); } if (plots.size() == totalSize) { - for (Entry> entry : this.plots.entrySet()) { + for (Entry> entry : this.plots.entrySet()) { map.put(entry.getKey(), entry.getValue().values()); } } @@ -826,7 +858,17 @@ public class PS { }); ArrayList toReturn = new ArrayList(plots.size()); for (String world : worlds) { - toReturn.addAll(sortPlotsByHash(map.get(world))); + switch (type) { + case CREATION_DATE: + toReturn.addAll(sortPlotsByTimestamp(map.get(world))); + break; + case DISTANCE_FROM_ORIGIN: + toReturn.addAll(sortPlotsByHash(map.get(world))); + break; + default: + break; + + } } return toReturn; } @@ -835,10 +877,10 @@ public class PS { /** * Sort a collection of plots by world, then by hashcode * @param plots - * @see #sortPlots(Collection, String) to sort with a specific priority world - * @see #sortPlots(Collection) to sort plots just by hashcode + * @deprecated Use #sortPlots(Collection, String) instead * @return ArrayList of plot */ + @Deprecated public ArrayList sortPlotsByWorld(Collection plots) { ArrayList newPlots = new ArrayList<>(); ArrayList worlds = new ArrayList<>(this.plots.keySet()); @@ -928,16 +970,25 @@ public class PS { } + private String lastWorld; + private Map lastMap; + /** * Get a map of the plots for a world * @param world * @return HashMap of PlotId to Plot */ - public HashMap getPlots(final String world) { - if (plots.containsKey(world)) { - return plots.get(world); + @Deprecated + public Map getPlots(final String world) { + if (world == lastWorld) { + return lastMap; } - return new HashMap<>(); + lastWorld = world; + if (plots.containsKey(world)) { + lastMap = plots.get(world); + return lastMap; + } + return new ConcurrentHashMap<>(); } @@ -984,7 +1035,7 @@ public class PS { if (callEvent) { EventUtil.manager.callDelete(world, id); } - HashMap allPlots = plots.get(world); + ConcurrentHashMap allPlots = plots.get(world); if (allPlots == null) { return false; } @@ -1377,6 +1428,10 @@ public class PS { */ public void disable() { try { + // Validate that all data in the db is correct + DBFunc.validatePlots(getPlotsRaw()); + + // Close the connection database.closeConnection(); UUIDHandler.handleShutdown(); } catch (NullPointerException | SQLException e) { @@ -1584,6 +1639,7 @@ public class PS { options.put("uuid.read-from-disk", Settings.UUID_FROM_DISK); // 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); @@ -1702,6 +1758,7 @@ 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 diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Auto.java b/src/main/java/com/intellectualcrafters/plot/commands/Auto.java index 03fa8438c..9bdeda809 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Auto.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Auto.java @@ -225,7 +225,7 @@ public class Auto extends SubCommand { Claim.claimPlot(plr, plot, teleport, true); } } - if (!MainUtil.mergePlots(worldname, MainUtil.getPlotSelectionIds(start, end), true)) { + if (!MainUtil.mergePlots(worldname, MainUtil.getPlotSelectionIds(start, end), true, true)) { return false; } br = true; diff --git a/src/main/java/com/intellectualcrafters/plot/commands/DebugExec.java b/src/main/java/com/intellectualcrafters/plot/commands/DebugExec.java index f3131ef7d..9ce4ecb9e 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/DebugExec.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/DebugExec.java @@ -40,8 +40,6 @@ import javax.script.ScriptEngineManager; import javax.script.ScriptException; import javax.script.SimpleScriptContext; -import org.bukkit.ChatColor; - import com.google.common.io.Files; import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.C; diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Home.java b/src/main/java/com/intellectualcrafters/plot/commands/Home.java index 82d6e7ca7..052187415 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Home.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Home.java @@ -23,6 +23,7 @@ package com.intellectualcrafters.plot.commands; import java.util.ArrayList; import com.intellectualcrafters.plot.PS; +import com.intellectualcrafters.plot.PS.SortType; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotPlayer; @@ -51,7 +52,7 @@ public class Home extends SubCommand { @Override public boolean onCommand(final PlotPlayer plr, String[] args) { - final ArrayList plots = PS.get().sortPlotsByWorld(PS.get().getPlots(plr)); + final ArrayList plots = PS.get().sortPlots(PS.get().getPlots(plr), SortType.CREATION_DATE, null); if (plots.size() == 1) { MainUtil.teleportPlayer(plr, plr.getLocation(), plots.get(0)); return true; diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Limit.java b/src/main/java/com/intellectualcrafters/plot/commands/Limit.java index fd8f129a6..583844575 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Limit.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Limit.java @@ -20,21 +20,12 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// package com.intellectualcrafters.plot.commands; -import java.io.BufferedReader; -import java.io.InputStreamReader; -import java.net.URL; -import java.net.URLConnection; -import java.util.ArrayList; import java.util.UUID; -import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.object.OfflinePlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer; -import com.intellectualcrafters.plot.util.EconHandler; 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.plotsquared.general.commands.Argument; import com.plotsquared.general.commands.CommandDeclaration; diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Merge.java b/src/main/java/com/intellectualcrafters/plot/commands/Merge.java index 5ab29e137..0501b1dff 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Merge.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Merge.java @@ -38,7 +38,6 @@ import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.StringMan; import com.intellectualcrafters.plot.util.UUIDHandler; -import com.plotsquared.general.commands.Argument; import com.plotsquared.general.commands.CommandDeclaration; @CommandDeclaration( @@ -212,7 +211,7 @@ public class Merge extends SubCommand { return; } MainUtil.sendMessage(plr, C.SUCCESS_MERGE); - MainUtil.mergePlots(world, plots, true); + MainUtil.mergePlots(world, plots, true, true); MainUtil.setSign(UUIDHandler.getName(plot.owner), plot); } MainUtil.sendMessage(accepter, C.MERGE_ACCEPTED); @@ -241,7 +240,7 @@ public class Merge extends SubCommand { return false; } MainUtil.sendMessage(plr, C.SUCCESS_MERGE); - MainUtil.mergePlots(world, plots, true); + MainUtil.mergePlots(world, plots, true, true); MainUtil.setSign(UUIDHandler.getName(plot.owner), plot); return true; } diff --git a/src/main/java/com/intellectualcrafters/plot/commands/SchematicCmd.java b/src/main/java/com/intellectualcrafters/plot/commands/SchematicCmd.java index a8e1aa946..b3fe98a03 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/SchematicCmd.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/SchematicCmd.java @@ -23,7 +23,7 @@ package com.intellectualcrafters.plot.commands; import java.net.URL; import java.util.ArrayList; import java.util.Collection; -import java.util.HashMap; +import java.util.Map; import java.util.UUID; import com.intellectualcrafters.plot.PS; @@ -181,7 +181,7 @@ public class SchematicCmd extends SubCommand { MainUtil.sendMessage(null, "&cNeed world arg. Use &7/plots sch exportall "); return false; } - final HashMap plotmap = PS.get().getPlots(args[1]); + final Map plotmap = PS.get().getPlots(args[1]); if ((plotmap == null) || (plotmap.size() == 0)) { MainUtil.sendMessage(plr, "&cInvalid world. Use &7/plots sch exportall "); return false; diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Visit.java b/src/main/java/com/intellectualcrafters/plot/commands/Visit.java index ca6e27893..2fac3e57f 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Visit.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Visit.java @@ -25,6 +25,7 @@ import java.util.List; import java.util.UUID; import com.intellectualcrafters.plot.PS; +import com.intellectualcrafters.plot.PS.SortType; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotPlayer; @@ -67,10 +68,10 @@ public class Visit extends SubCommand { UUID user = UUIDHandler.getCachedUUID(args[0], null); if (user != null ) { // do plots by username - plots = PS.get().sortPlots(PS.get().getPlots(user), null); + plots = PS.get().sortPlots(PS.get().getPlots(user), SortType.CREATION_DATE, null); } else if (PS.get().isPlotWorld(args[0])) { // do plots by world - plots = PS.get().sortPlots(PS.get().getPlots(args[0]).values(), null); + plots = PS.get().sortPlots(PS.get().getPlots(args[0]).values(), SortType.CREATION_DATE, null); } else { Plot plot = MainUtil.getPlotFromString(plr, args[0], true); diff --git a/src/main/java/com/intellectualcrafters/plot/commands/WE_Anywhere.java b/src/main/java/com/intellectualcrafters/plot/commands/WE_Anywhere.java index acbe7f239..48675275e 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/WE_Anywhere.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/WE_Anywhere.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.object.PlotPlayer; import com.intellectualcrafters.plot.util.MainUtil; diff --git a/src/main/java/com/intellectualcrafters/plot/commands/list.java b/src/main/java/com/intellectualcrafters/plot/commands/list.java index 27d22462c..125cf91d0 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/list.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/list.java @@ -30,6 +30,7 @@ import java.util.UUID; import org.bukkit.ChatColor; import com.intellectualcrafters.plot.PS; +import com.intellectualcrafters.plot.PS.SortType; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.flag.Flag; @@ -303,7 +304,7 @@ public class list extends SubCommand { public void displayPlots(PlotPlayer player, List plots, int pageSize, int page, String world, String[] args, boolean sort) { if (sort) { - plots = PS.get().sortPlots(plots, world); + plots = PS.get().sortPlots(plots, SortType.CREATION_DATE, world); } if (page < 0) { page = 0; diff --git a/src/main/java/com/intellectualcrafters/plot/database/AbstractDB.java b/src/main/java/com/intellectualcrafters/plot/database/AbstractDB.java index 41c71c73d..19196276f 100644 --- a/src/main/java/com/intellectualcrafters/plot/database/AbstractDB.java +++ b/src/main/java/com/intellectualcrafters/plot/database/AbstractDB.java @@ -25,9 +25,9 @@ import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; -import java.util.LinkedHashMap; import java.util.Set; import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.object.Plot; @@ -119,7 +119,12 @@ public interface AbstractDB { /** * @return A linked hashmap containing all plots */ - LinkedHashMap> getPlots(); + ConcurrentHashMap> getPlots(); + + /** + * + */ + void validateAllPlots(Set toValidate); /** * @return A hashmap containing all plot clusters diff --git a/src/main/java/com/intellectualcrafters/plot/database/DBFunc.java b/src/main/java/com/intellectualcrafters/plot/database/DBFunc.java index df7da0c27..934e19f12 100644 --- a/src/main/java/com/intellectualcrafters/plot/database/DBFunc.java +++ b/src/main/java/com/intellectualcrafters/plot/database/DBFunc.java @@ -27,9 +27,9 @@ import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; -import java.util.LinkedHashMap; import java.util.Set; import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.object.Plot; @@ -56,11 +56,16 @@ public class DBFunc { public static AbstractDB dbManager; public static void movePlot(final Plot originalPlot, final Plot newPlot) { - if (originalPlot.temp || newPlot.temp) { + if (originalPlot.temp != -1 || newPlot.temp != -1) { return; } dbManager.movePlot(originalPlot, newPlot); } + + public static void validatePlots(Set plots) { + dbManager.validateAllPlots(plots); + } + /** * Check if a resultset contains a column * @param rs @@ -90,7 +95,7 @@ public class DBFunc { * @param uuid New Owner */ public static void setOwner(final Plot plot, final UUID uuid) { - if (plot.temp) { + if (plot.temp != -1) { return; } dbManager.setOwner(plot, uuid); @@ -111,7 +116,7 @@ public class DBFunc { * @param plot Plot to create */ public static void createPlot(final Plot plot) { - if (plot.temp) { + if (plot.temp != -1) { return; } dbManager.createPlot(plot); @@ -123,7 +128,7 @@ public class DBFunc { * @param plot Plot to create */ public static void createPlotAndSettings(final Plot plot) { - if (plot.temp) { + if (plot.temp != -1) { return; } dbManager.createPlotAndSettings(plot); @@ -144,7 +149,7 @@ public class DBFunc { * @param plot Plot to delete */ public static void delete(final Plot plot) { - if (plot.temp) { + if (plot.temp != -1) { return; } dbManager.delete(plot); @@ -161,7 +166,7 @@ public class DBFunc { * @param plot Plot Object */ public static void createPlotSettings(final int id, final Plot plot) { - if (plot.temp) { + if (plot.temp != -1) { return; } dbManager.createPlotSettings(id, plot); @@ -192,19 +197,19 @@ public class DBFunc { /** * @return Plots */ - public static LinkedHashMap> getPlots() { + public static ConcurrentHashMap> getPlots() { return dbManager.getPlots(); } public static void setMerged(final Plot plot, final boolean[] merged) { - if (plot.temp) { + if (plot.temp != -1) { return; } dbManager.setMerged(plot, merged); } public static void setFlags(final Plot plot, final Collection flags) { - if (plot.temp) { + if (plot.temp != -1) { return; } dbManager.setFlags(plot, flags); @@ -219,7 +224,7 @@ public class DBFunc { * @param alias */ public static void setAlias(final Plot plot, final String alias) { - if (plot.temp) { + if (plot.temp != -1) { return; } dbManager.setAlias(plot, alias); @@ -238,7 +243,7 @@ public class DBFunc { * @param position */ public static void setPosition(final Plot plot, final String position) { - if (plot.temp) { + if (plot.temp != -1) { return; } dbManager.setPosition(plot, position); @@ -258,14 +263,14 @@ public class DBFunc { * @param comment */ public static void removeComment(final Plot plot, final PlotComment comment) { - if (plot != null && plot.temp) { + if (plot != null && plot.temp != -1) { return; } dbManager.removeComment(plot, comment); } public static void clearInbox(final Plot plot, final String inbox) { - if (plot != null && plot.temp) { + if (plot != null && plot.temp != -1) { return; } dbManager.clearInbox(plot, inbox); @@ -276,7 +281,7 @@ public class DBFunc { * @param comment */ public static void setComment(final Plot plot, final PlotComment comment) { - if (plot != null && plot.temp) { + if (plot != null && plot.temp != -1) { return; } dbManager.setComment(plot, comment); @@ -286,7 +291,7 @@ public class DBFunc { * @param plot */ public static void getComments(final Plot plot, final String inbox, RunnableVal whenDone) { - if (plot != null && plot.temp) { + if (plot != null && plot.temp != -1) { return; } dbManager.getComments(plot, inbox, whenDone); @@ -297,7 +302,7 @@ public class DBFunc { * @param uuid */ public static void removeTrusted(final Plot plot, final UUID uuid) { - if (plot.temp) { + if (plot.temp != -1) { return; } dbManager.removeTrusted(plot, uuid); @@ -332,7 +337,7 @@ public class DBFunc { * @param uuid */ public static void removeMember(final Plot plot, final UUID uuid) { - if (plot.temp) { + if (plot.temp != -1) { return; } dbManager.removeMember(plot, uuid); @@ -353,7 +358,7 @@ public class DBFunc { * @param uuid */ public static void setTrusted(final Plot plot, final UUID uuid) { - if (plot.temp) { + if (plot.temp != -1) { return; } dbManager.setTrusted(plot, uuid); @@ -369,7 +374,7 @@ public class DBFunc { * @param uuid */ public static void setMember(final Plot plot, final UUID uuid) { - if (plot.temp) { + if (plot.temp != -1) { return; } dbManager.setMember(plot, uuid); @@ -385,7 +390,7 @@ public class DBFunc { * @param uuid */ public static void removeDenied(final Plot plot, final UUID uuid) { - if (plot.temp) { + if (plot.temp != -1) { return; } dbManager.removeDenied(plot, uuid); @@ -397,21 +402,21 @@ public class DBFunc { * @param uuid */ public static void setDenied(final Plot plot, final UUID uuid) { - if (plot.temp) { + if (plot.temp != -1) { return; } dbManager.setDenied(plot, uuid); } public static HashMap getRatings(final Plot plot) { - if (plot.temp) { + if (plot.temp != -1) { return new HashMap<>(); } return dbManager.getRatings(plot); } public static void setRating(Plot plot, UUID rater, int value) { - if (plot.temp) { + if (plot.temp != -1) { return; } dbManager.setRating(plot, rater, value); diff --git a/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java b/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java index d0a3428c3..6f5536bcb 100644 --- a/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java +++ b/src/main/java/com/intellectualcrafters/plot/database/SQLManager.java @@ -36,6 +36,7 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Set; import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.Settings; @@ -909,8 +910,8 @@ public class SQLManager implements AbstractDB { * Load all plots, helpers, denied, trusted, and every setting from DB into a hashmap */ @Override - public LinkedHashMap> getPlots() { - final LinkedHashMap> newplots = new LinkedHashMap<>(); + public ConcurrentHashMap> getPlots() { + final ConcurrentHashMap> newplots = new ConcurrentHashMap(); final HashMap plots = new HashMap<>(); Statement stmt = null; try { @@ -959,7 +960,7 @@ public class SQLManager implements AbstractDB { else { time = timestamp.getTime(); } - p = new Plot(plot_id, user, new HashSet(), new HashSet(), new HashSet(), "", null, null, worldname, new boolean[]{false, false, false, false}, time); + p = new Plot(plot_id, user, new HashSet(), new HashSet(), new HashSet(), "", null, null, worldname, new boolean[]{false, false, false, false}, time, id); plots.put(id, p); } if (Settings.CACHE_RATINGS) { @@ -1051,7 +1052,7 @@ public class SQLManager implements AbstractDB { if (plot != null) { plots.remove(id); if (!newplots.containsKey(plot.world)) { - newplots.put(plot.world, new HashMap()); + newplots.put(plot.world, new ConcurrentHashMap()); } newplots.get(plot.world).put(plot.id, plot); final String alias = r.getString("alias"); @@ -2263,4 +2264,49 @@ public class SQLManager implements AbstractDB { this.settings = settings; } } + + @Override + public void validateAllPlots(Set toValidate) { +// ConcurrentHashMap> database = getPlots(); +// +// ArrayList toCreate = new ArrayList<>(); +// ArrayList toTrust1 = new ArrayList<>(); +// ArrayList toTrust2 = new ArrayList<>(); +// +// for (Plot plot : plots) { +// if (plot.temp) { +// continue; +// } +// ConcurrentHashMap worldplots = database.get(plot.world); +// if (worldplots == null) { +// toCreate.add(plot); +// continue; +// } +// Plot dataplot = worldplots.get(plot.id); +// if (dataplot == null) { +// toCreate.add(plot); +// continue; +// } +// // owner +// if (!plot.owner.equals(dataplot)) { +// toSet.add(plot); +// continue; +// } +// plot. +// // trusted +// if (!plot.getTrusted().equals(dataplot.trusted)) { +// toSet.add(plot); +// continue; +// } +// if (!plot.getMembers().equals(dataplot.members)) { +// toSet.add(plot); +// continue; +// } +// if (!plot.getDenied().equals(dataplot.denied)) { +// toSet.add(plot); +// continue; +// } +// ssettings = plot.getSettings(); +// } + } } diff --git a/src/main/java/com/intellectualcrafters/plot/generator/HybridUtils.java b/src/main/java/com/intellectualcrafters/plot/generator/HybridUtils.java index 9485714ce..4f7a3532f 100644 --- a/src/main/java/com/intellectualcrafters/plot/generator/HybridUtils.java +++ b/src/main/java/com/intellectualcrafters/plot/generator/HybridUtils.java @@ -19,7 +19,6 @@ import com.intellectualcrafters.plot.object.PlotLoc; import com.intellectualcrafters.plot.object.PlotManager; import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.object.RunnableVal; -import com.intellectualcrafters.plot.util.BlockManager; import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.SchematicHandler; diff --git a/src/main/java/com/intellectualcrafters/plot/object/Plot.java b/src/main/java/com/intellectualcrafters/plot/object/Plot.java index 2f5a71f5a..d9e45ccbd 100644 --- a/src/main/java/com/intellectualcrafters/plot/object/Plot.java +++ b/src/main/java/com/intellectualcrafters/plot/object/Plot.java @@ -27,8 +27,6 @@ import java.util.List; import java.util.Map.Entry; import java.util.UUID; -import javax.annotation.concurrent.ThreadSafe; - import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.Configuration; import com.intellectualcrafters.plot.database.DBFunc; @@ -103,9 +101,13 @@ public class Plot { */ public boolean countsTowardsMax = true; /** - * If this plot is temporary i.e. not stored in the DB + * Represents whatever the database manager needs it to:
+ * - A value of -1 usually indicates the plot will not be stored in the DB
+ * - A value of 0 usually indicates that the DB manager hasn't set a value
+ * @deprecated magical */ - public final boolean temp; + @Deprecated + public int temp; /** * Constructor for a new plot @@ -118,7 +120,6 @@ public class Plot { this.world = world; this.id = id; this.owner = owner; - this.temp = false; } /** @@ -129,7 +130,7 @@ public class Plot { * @param owner * @param temp */ - public Plot(String world, PlotId id, UUID owner, boolean temp) { + public Plot(String world, PlotId id, UUID owner, int temp) { this.world = world; this.id = id; this.owner = owner; @@ -145,7 +146,7 @@ public class Plot { * @param denied * @param merged */ - public Plot(final PlotId id, final UUID owner, final HashSet trusted, final HashSet members, final HashSet denied, final String alias, final BlockLoc position, final Collection flags, final String world, final boolean[] merged, final long timestamp) { + public Plot(final PlotId id, final UUID owner, final HashSet trusted, final HashSet members, final HashSet denied, final String alias, final BlockLoc position, final Collection flags, final String world, final boolean[] merged, final long timestamp, final int temp) { this.id = id; this.world = world; this.owner = owner; @@ -162,7 +163,6 @@ public class Plot { } } this.timestamp = timestamp; - this.temp = false; } /** diff --git a/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java b/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java index 4416c425d..125b3153e 100644 --- a/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java +++ b/src/main/java/com/intellectualcrafters/plot/util/ChunkManager.java @@ -126,7 +126,7 @@ public abstract class ChunkManager { */ public abstract boolean regenerateRegion(final Location pos1, final Location pos2, final Runnable whenDone); - public abstract void clearAllEntities(final Plot plot); + public abstract void clearAllEntities(final Location pos1, final Location pos2); public abstract void swap(String world, PlotId id, PlotId plotid); diff --git a/src/main/java/com/intellectualcrafters/plot/util/ClusterManager.java b/src/main/java/com/intellectualcrafters/plot/util/ClusterManager.java index 6dfc4906d..23ca04120 100644 --- a/src/main/java/com/intellectualcrafters/plot/util/ClusterManager.java +++ b/src/main/java/com/intellectualcrafters/plot/util/ClusterManager.java @@ -3,7 +3,6 @@ package com.intellectualcrafters.plot.util; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; -import java.util.Map.Entry; import java.util.Random; import org.bukkit.Bukkit; diff --git a/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java b/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java index c035d5cce..15f8eae5c 100644 --- a/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java +++ b/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java @@ -24,12 +24,12 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Map.Entry; import java.util.UUID; import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.C; -import com.intellectualcrafters.plot.config.Configuration; import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.object.BlockLoc; @@ -289,7 +289,7 @@ public class MainUtil { MainUtil.sendMessage(player, C.REMOVED_BALANCE, cost + ""); } } - return MainUtil.mergePlots(world, plotIds, true); + return MainUtil.mergePlots(world, plotIds, true, true); } public static boolean unlinkPlot(final Plot plot) { @@ -620,10 +620,13 @@ public class MainUtil { * * @return boolean (success) */ - public static boolean mergePlots(final String world, final ArrayList plotIds, final boolean removeRoads) { + public static boolean mergePlots(final String world, final ArrayList plotIds, final boolean removeRoads, final boolean updateDatabase) { if (plotIds.size() < 2) { return false; } + +// merged plots set db before finished merging + final PlotId pos1 = plotIds.get(0); final PlotId pos2 = plotIds.get(plotIds.size() - 1); final PlotManager manager = PS.get().getPlotManager(world); @@ -676,14 +679,16 @@ public class MainUtil { } } } - for (int x = pos1.x; x <= pos2.x; x++) { - for (int y = pos1.y; y <= pos2.y; y++) { - final PlotId id = new PlotId(x, y); - final Plot plot = PS.get().getPlots(world).get(id); - DBFunc.setMerged(plot, plot.getSettings().getMerged()); + manager.finishPlotMerge(plotworld, plotIds); + if (updateDatabase) { + for (int x = pos1.x; x <= pos2.x; x++) { + for (int y = pos1.y; y <= pos2.y; y++) { + final PlotId id = new PlotId(x, y); + final Plot plot = PS.get().getPlots(world).get(id); + DBFunc.setMerged(plot, plot.getSettings().getMerged()); + } } } - manager.finishPlotMerge(plotworld, plotIds); return true; } @@ -744,7 +749,7 @@ public class MainUtil { /** * Merges 2 plots Removes the road inbetween
- Assumes the first plot parameter is lower
- Assumes neither - * are a Mega-plot
- Assumes plots are directly next to each other
- Saves to DB + * are a Mega-plot
- Assumes plots are directly next to each other
- Does not save to DB * * @param world * @param lesserPlot @@ -840,6 +845,7 @@ public class MainUtil { ArrayList plots; boolean merge = true; int count = 0; + ArrayList toUpdate = new ArrayList<>(); while (merge) { if (count > 16) { break; @@ -849,38 +855,46 @@ public class MainUtil { final PlotId top = getTopPlot(plot).id; plots = getPlotSelectionIds(new PlotId(bot.x, bot.y - 1), new PlotId(top.x, top.y)); if (ownsPlots(plot.world, plots, uuid, 0)) { - final boolean result = mergePlots(plot.world, plots, removeRoads); + final boolean result = mergePlots(plot.world, plots, removeRoads, false); if (result) { + toUpdate.addAll(plots); merge = true; continue; } } plots = getPlotSelectionIds(new PlotId(bot.x, bot.y), new PlotId(top.x + 1, top.y)); if (ownsPlots(plot.world, plots, uuid, 1)) { - final boolean result = mergePlots(plot.world, plots, removeRoads); + final boolean result = mergePlots(plot.world, plots, removeRoads, false); if (result) { + toUpdate.addAll(plots); merge = true; continue; } } plots = getPlotSelectionIds(new PlotId(bot.x, bot.y), new PlotId(top.x, top.y + 1)); if (ownsPlots(plot.world, plots, uuid, 2)) { - final boolean result = mergePlots(plot.world, plots, removeRoads); + final boolean result = mergePlots(plot.world, plots, removeRoads, false); if (result) { + toUpdate.addAll(plots); merge = true; continue; } } plots = getPlotSelectionIds(new PlotId(bot.x - 1, bot.y), new PlotId(top.x, top.y)); if (ownsPlots(plot.world, plots, uuid, 3)) { - final boolean result = mergePlots(plot.world, plots, removeRoads); + final boolean result = mergePlots(plot.world, plots, removeRoads, false); if (result) { + toUpdate.addAll(plots); merge = true; continue; } } merge = false; } + for (PlotId id : toUpdate) { + Plot update = getPlot(plot.world, id); + DBFunc.setMerged(plot, plot.getSettings().getMerged()); + } } private static boolean ownsPlots(final String world, final ArrayList plots, final UUID uuid, final int dir) { @@ -944,7 +958,7 @@ public class MainUtil { */ public static Plot createPlotAbs(final UUID uuid, final Plot plot) { final String w = plot.world; - HashMap plots = PS.get().getPlots(plot.world); + Map plots = PS.get().getPlots(plot.world); Plot p = plots.get(plot.id); if (p != null) { return p; @@ -985,9 +999,12 @@ public class MainUtil { if (runners.containsKey(plot)) { return false; } - ChunkManager.manager.clearAllEntities(plot); + long start = System.currentTimeMillis(); + ChunkManager.manager.clearAllEntities(plot.getBottom().add(1, 0, 1), plot.getTop()); + if (isDelete) { + removeSign(plot); + } clear(plot, isDelete, whenDone); - removeSign(plot); return true; } diff --git a/src/main/java/com/intellectualcrafters/plot/util/SetBlockQueue.java b/src/main/java/com/intellectualcrafters/plot/util/SetBlockQueue.java index 2dd05208f..8ffcaf99e 100644 --- a/src/main/java/com/intellectualcrafters/plot/util/SetBlockQueue.java +++ b/src/main/java/com/intellectualcrafters/plot/util/SetBlockQueue.java @@ -67,6 +67,7 @@ public class SetBlockQueue { TaskManager.runTask(runnable); } } + lastInt = -1; lastBlock = null; runnables = null; blocks = new HashMap<>(); @@ -75,8 +76,8 @@ public class SetBlockQueue { return; } long newLast = System.currentTimeMillis(); - last = Math.max(newLast - 100, last); - while (blocks.size() > 0 && (System.currentTimeMillis() - last < 100 + allocate)) { + last = Math.max(newLast - 50, last); + while (blocks.size() > 0 && (System.currentTimeMillis() - last < 50 + allocate)) { if (locked) { return; } @@ -129,7 +130,7 @@ public class SetBlockQueue { } } } - }, 2); + }, 1); TaskManager.tasks.put(current, task); running = true; } diff --git a/src/main/java/com/plotsquared/bukkit/BukkitMain.java b/src/main/java/com/plotsquared/bukkit/BukkitMain.java index b05dd8b94..150c131d6 100644 --- a/src/main/java/com/plotsquared/bukkit/BukkitMain.java +++ b/src/main/java/com/plotsquared/bukkit/BukkitMain.java @@ -16,8 +16,6 @@ import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.Listener; import org.bukkit.generator.ChunkGenerator; -import org.bukkit.metadata.MetadataValue; -import org.bukkit.metadata.MetadataValueAdapter; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.java.JavaPlugin; @@ -200,98 +198,107 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { for (final PlotWorld pw : PS.get().getPlotWorldObjects()) { world = Bukkit.getWorld(pw.worldname); try { - for (Entity entity : world.getEntities()) { - switch (entity.getType()) { - case EGG: - case ENDER_CRYSTAL: - case COMPLEX_PART: - case ARMOR_STAND: - case FISHING_HOOK: - case ENDER_SIGNAL: - case EXPERIENCE_ORB: - case LEASH_HITCH: - case FIREWORK: - case WEATHER: - case LIGHTNING: - case WITHER_SKULL: - case UNKNOWN: - case ITEM_FRAME: - case PAINTING: - case PLAYER: { - // non moving / unremovable - continue; - } - case THROWN_EXP_BOTTLE: - case SPLASH_POTION: - case SNOWBALL: - case ENDER_PEARL: - case ARROW: { - // managed elsewhere | projectile - continue; - } - case MINECART: - case MINECART_CHEST: - case MINECART_COMMAND: - case MINECART_FURNACE: - case MINECART_HOPPER: - case MINECART_MOB_SPAWNER: - case MINECART_TNT: - case BOAT: { - // vehicle - continue; - } - case SMALL_FIREBALL: - case FIREBALL: - case DROPPED_ITEM: { - // dropped item - continue; - } - case PRIMED_TNT: - case FALLING_BLOCK: { - // managed elsewhere - continue; - } - case BAT: - case BLAZE: - case CAVE_SPIDER: - case CHICKEN: - case COW: - case CREEPER: - case ENDERMAN: - case ENDERMITE: - case ENDER_DRAGON: - case GHAST: - case GIANT: - case GUARDIAN: - case HORSE: - case IRON_GOLEM: - case MAGMA_CUBE: - case MUSHROOM_COW: - case OCELOT: - case PIG: - case PIG_ZOMBIE: - case RABBIT: - case SHEEP: - case SILVERFISH: - case SKELETON: - case SLIME: - case SNOWMAN: - case SPIDER: - case SQUID: - case VILLAGER: - case WITCH: - case WITHER: - case WOLF: - case ZOMBIE: - default: { - Location loc = entity.getLocation(); - if (MainUtil.isPlotRoad(BukkitUtil.getLocation(loc))) { - entity.remove(); + for (Entity entity : world.getEntities()) { + switch (entity.getType()) { + case EGG: + case ENDER_CRYSTAL: + case COMPLEX_PART: + case ARMOR_STAND: + case FISHING_HOOK: + case ENDER_SIGNAL: + case EXPERIENCE_ORB: + case LEASH_HITCH: + case FIREWORK: + case WEATHER: + case LIGHTNING: + case WITHER_SKULL: + case UNKNOWN: + case ITEM_FRAME: + case PAINTING: + case PLAYER: { + // non moving / unremovable + continue; + } + case THROWN_EXP_BOTTLE: + case SPLASH_POTION: + case SNOWBALL: + case ENDER_PEARL: + case ARROW: { + // managed elsewhere | projectile + continue; + } + case MINECART: + case MINECART_CHEST: + case MINECART_COMMAND: + case MINECART_FURNACE: + case MINECART_HOPPER: + case MINECART_MOB_SPAWNER: + case MINECART_TNT: + case BOAT: { + if (!Settings.KILL_ROAD_VEHICLES) { + continue; + } + Location loc = entity.getLocation(); + if (MainUtil.isPlotRoad(BukkitUtil.getLocation(loc))) { + entity.remove(); + } + break; + } + case SMALL_FIREBALL: + case FIREBALL: + case DROPPED_ITEM: { + // dropped item + continue; + } + case PRIMED_TNT: + case FALLING_BLOCK: { + // managed elsewhere + continue; + } + case BAT: + case BLAZE: + case CAVE_SPIDER: + case CHICKEN: + case COW: + case CREEPER: + case ENDERMAN: + case ENDERMITE: + case ENDER_DRAGON: + case GHAST: + case GIANT: + case GUARDIAN: + case HORSE: + case IRON_GOLEM: + case MAGMA_CUBE: + case MUSHROOM_COW: + case OCELOT: + case PIG: + case PIG_ZOMBIE: + case RABBIT: + case SHEEP: + case SILVERFISH: + case SKELETON: + case SLIME: + case SNOWMAN: + case SPIDER: + case SQUID: + case VILLAGER: + case WITCH: + case WITHER: + case WOLF: + case ZOMBIE: + default: { + if (!Settings.KILL_ROAD_MOBS) { + continue; + } + Location loc = entity.getLocation(); + if (MainUtil.isPlotRoad(BukkitUtil.getLocation(loc))) { + entity.remove(); + } + break; } - break; } } - } } catch (final Throwable e) { ++this.error; } finally { diff --git a/src/main/java/com/plotsquared/bukkit/generator/AugmentedPopulator.java b/src/main/java/com/plotsquared/bukkit/generator/AugmentedPopulator.java index 0835d9997..af2719717 100644 --- a/src/main/java/com/plotsquared/bukkit/generator/AugmentedPopulator.java +++ b/src/main/java/com/plotsquared/bukkit/generator/AugmentedPopulator.java @@ -19,7 +19,6 @@ import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotLoc; import com.intellectualcrafters.plot.object.PlotManager; import com.intellectualcrafters.plot.object.PlotWorld; -import com.intellectualcrafters.plot.object.RegionWrapper; import com.intellectualcrafters.plot.util.ChunkManager; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.TaskManager; diff --git a/src/main/java/com/plotsquared/bukkit/listeners/ChatListener.java b/src/main/java/com/plotsquared/bukkit/listeners/ChatListener.java index 3b210f7ab..e4a249b38 100644 --- a/src/main/java/com/plotsquared/bukkit/listeners/ChatListener.java +++ b/src/main/java/com/plotsquared/bukkit/listeners/ChatListener.java @@ -1,9 +1,5 @@ package com.plotsquared.bukkit.listeners; -import java.util.Set; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; diff --git a/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java b/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java index b61c6cd9c..310e2e916 100644 --- a/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java +++ b/src/main/java/com/plotsquared/bukkit/util/BukkitChunkManager.java @@ -7,7 +7,6 @@ import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Random; -import java.util.concurrent.atomic.AtomicInteger; import org.bukkit.Bukkit; import org.bukkit.Chunk; @@ -44,7 +43,6 @@ import org.bukkit.entity.Vehicle; import org.bukkit.generator.BlockPopulator; import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; -import org.bukkit.plugin.Plugin; import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.object.BlockLoc; @@ -63,7 +61,6 @@ import com.intellectualcrafters.plot.util.ClusterManager; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.SetBlockQueue.ChunkWrapper; import com.intellectualcrafters.plot.util.TaskManager; -import com.plotsquared.bukkit.BukkitMain; import com.plotsquared.bukkit.generator.AugmentedPopulator; import com.plotsquared.bukkit.object.entity.EntityWrapper; @@ -907,19 +904,28 @@ public class BukkitChunkManager extends ChunkManager { } @Override - public void clearAllEntities(final Plot plot) { - final List entities = BukkitUtil.getEntities(plot.world); + public void clearAllEntities(final Location pos1, final Location pos2) { + final String world = pos1.getWorld(); + final List entities = BukkitUtil.getEntities(world); + final int bx = pos1.getX(); + final int bz = pos1.getZ(); + final int tx = pos2.getX(); + final int tz = pos2.getZ(); for (final Entity entity : entities) { - final PlotId id = MainUtil.getPlotId(BukkitUtil.getLocation(entity)); - if (plot.id.equals(id)) { - if (entity instanceof Player) { - final Player player = (Player) entity; - final PlotPlayer pp = BukkitUtil.getPlayer(player); + if (entity instanceof Player) { + final Player player = (Player) entity; + final PlotPlayer pp = BukkitUtil.getPlayer(player); + Plot plot = pp.getCurrentPlot(); + if (plot != null) { final Location plotHome = MainUtil.getDefaultHome(plot); if (pp.getLocation().getY() <= plotHome.getY()) { pp.teleport(plotHome); } - } else { + } + } + else { + org.bukkit.Location loc = entity.getLocation(); + if (loc.getX() >= bx && loc.getX() <= tx && loc.getZ() >= bz && loc.getZ() <= tz) { entity.remove(); } } @@ -997,8 +1003,13 @@ public class BukkitChunkManager extends ChunkManager { final Location top2 = MainUtil.getPlotTopLoc(worldname, pos2); swap(worldname, bot1, top1, bot2, top2); - clearAllEntities(MainUtil.getPlot(worldname, pos1)); - clearAllEntities(MainUtil.getPlot(worldname, pos2)); + Plot plot1 = MainUtil.getPlot(worldname, pos1); + Plot plot2 = MainUtil.getPlot(worldname, pos2); + + // TODO clear all entities + + clearAllEntities(plot1.getBottom().add(1, 0, 1), plot1.getTop()); + clearAllEntities(plot2.getBottom().add(1, 0, 1), plot2.getTop()); } @Override diff --git a/src/main/java/com/plotsquared/bukkit/util/BukkitCommand.java b/src/main/java/com/plotsquared/bukkit/util/BukkitCommand.java index 1ab214022..d04f5d680 100644 --- a/src/main/java/com/plotsquared/bukkit/util/BukkitCommand.java +++ b/src/main/java/com/plotsquared/bukkit/util/BukkitCommand.java @@ -11,10 +11,8 @@ import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; import org.bukkit.entity.Player; -import com.intellectualcrafters.plot.commands.Cluster; import com.intellectualcrafters.plot.commands.DebugUUID; import com.intellectualcrafters.plot.commands.MainCommand; -import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.object.ConsolePlayer; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.StringComparison; diff --git a/src/main/java/com/plotsquared/bukkit/util/BukkitEconHandler.java b/src/main/java/com/plotsquared/bukkit/util/BukkitEconHandler.java index 95ac37774..3e7f2f0cd 100644 --- a/src/main/java/com/plotsquared/bukkit/util/BukkitEconHandler.java +++ b/src/main/java/com/plotsquared/bukkit/util/BukkitEconHandler.java @@ -7,12 +7,10 @@ import org.bukkit.Bukkit; import org.bukkit.World; import org.bukkit.plugin.RegisteredServiceProvider; -import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.object.OfflinePlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.util.EconHandler; import com.plotsquared.bukkit.object.BukkitOfflinePlayer; -import com.plotsquared.bukkit.object.BukkitPlayer; public class BukkitEconHandler extends EconHandler { diff --git a/src/main/java/com/plotsquared/bukkit/util/BukkitHybridUtils.java b/src/main/java/com/plotsquared/bukkit/util/BukkitHybridUtils.java index 7f3980b46..348cd0faa 100644 --- a/src/main/java/com/plotsquared/bukkit/util/BukkitHybridUtils.java +++ b/src/main/java/com/plotsquared/bukkit/util/BukkitHybridUtils.java @@ -6,7 +6,6 @@ import java.util.List; import java.util.Random; import org.bukkit.Bukkit; -import org.bukkit.Chunk; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Biome; diff --git a/src/main/java/com/plotsquared/bukkit/util/SetBlockSlow.java b/src/main/java/com/plotsquared/bukkit/util/SetBlockSlow.java index a66014697..9cae4dfd7 100644 --- a/src/main/java/com/plotsquared/bukkit/util/SetBlockSlow.java +++ b/src/main/java/com/plotsquared/bukkit/util/SetBlockSlow.java @@ -6,8 +6,6 @@ import org.bukkit.Chunk; import org.bukkit.World; import org.bukkit.block.Block; -import com.intellectualcrafters.plot.util.MainUtil; - public class SetBlockSlow extends BukkitSetBlockManager { @Override public void set(final World world, final int x, final int y, final int z, final int id, final byte data) { diff --git a/src/main/java/com/plotsquared/bukkit/util/WorldEditSchematic.java b/src/main/java/com/plotsquared/bukkit/util/WorldEditSchematic.java index 7f635d3ae..976d90cfd 100644 --- a/src/main/java/com/plotsquared/bukkit/util/WorldEditSchematic.java +++ b/src/main/java/com/plotsquared/bukkit/util/WorldEditSchematic.java @@ -4,7 +4,6 @@ import java.io.File; import org.bukkit.Bukkit; -import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.util.MainUtil; diff --git a/src/main/java/com/plotsquared/sponge/SpongeHybridUtils.java b/src/main/java/com/plotsquared/sponge/SpongeHybridUtils.java index 758744087..531629495 100644 --- a/src/main/java/com/plotsquared/sponge/SpongeHybridUtils.java +++ b/src/main/java/com/plotsquared/sponge/SpongeHybridUtils.java @@ -1,6 +1,5 @@ package com.plotsquared.sponge; -import org.bukkit.block.Block; import org.spongepowered.api.block.BlockState; import org.spongepowered.api.block.BlockTypes; import org.spongepowered.api.world.World; @@ -11,7 +10,6 @@ import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotAnalysis; import com.intellectualcrafters.plot.object.PlotBlock; import com.intellectualcrafters.plot.object.RunnableVal; -import com.plotsquared.bukkit.util.BukkitUtil; import com.plotsquared.sponge.util.SpongeUtil; public class SpongeHybridUtils extends HybridUtils { diff --git a/src/main/java/com/plotsquared/sponge/SpongeMain.java b/src/main/java/com/plotsquared/sponge/SpongeMain.java index 11acee96f..63bbbbdd2 100644 --- a/src/main/java/com/plotsquared/sponge/SpongeMain.java +++ b/src/main/java/com/plotsquared/sponge/SpongeMain.java @@ -17,14 +17,12 @@ import java.util.concurrent.ConcurrentHashMap; import org.slf4j.Logger; import org.spongepowered.api.CatalogType; import org.spongepowered.api.Game; -import org.spongepowered.api.Platform; import org.spongepowered.api.Server; import org.spongepowered.api.block.BlockState; import org.spongepowered.api.block.BlockType; import org.spongepowered.api.block.BlockTypes; import org.spongepowered.api.data.manipulator.block.StoneData; import org.spongepowered.api.entity.player.Player; -import org.spongepowered.api.entity.player.gamemode.GameModes; import org.spongepowered.api.event.Subscribe; import org.spongepowered.api.event.entity.player.PlayerChatEvent; import org.spongepowered.api.event.state.PreInitializationEvent; @@ -521,7 +519,7 @@ public class SpongeMain implements IPlotMain, PluginContainer { @Override public void registerCommands() { - getGame().getCommandDispatcher().register(plugin, new SpongeCommand(), "plots", "p", "plot", "ps", "plotsquared", "p2"); + getGame().getCommandDispatcher().register(plugin, new SpongeCommand(), "plots", "p", "plot", "ps", "plotsquared", "p2", "2"); } @Override diff --git a/src/main/java/com/plotsquared/sponge/SpongeSchematicHandler.java b/src/main/java/com/plotsquared/sponge/SpongeSchematicHandler.java index af4b93b99..dbac4dc4a 100644 --- a/src/main/java/com/plotsquared/sponge/SpongeSchematicHandler.java +++ b/src/main/java/com/plotsquared/sponge/SpongeSchematicHandler.java @@ -14,7 +14,6 @@ import com.intellectualcrafters.jnbt.ListTag; import com.intellectualcrafters.jnbt.ShortTag; import com.intellectualcrafters.jnbt.StringTag; import com.intellectualcrafters.jnbt.Tag; -import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.object.ChunkLoc; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.PlotBlock; diff --git a/src/main/java/com/plotsquared/sponge/generator/AugmentedPopulator.java b/src/main/java/com/plotsquared/sponge/generator/AugmentedPopulator.java index 54262460e..4ea3fe1f6 100644 --- a/src/main/java/com/plotsquared/sponge/generator/AugmentedPopulator.java +++ b/src/main/java/com/plotsquared/sponge/generator/AugmentedPopulator.java @@ -16,7 +16,6 @@ import org.spongepowered.api.world.gen.Populator; import org.spongepowered.api.world.gen.WorldGenerator; import com.flowpowered.math.vector.Vector3i; -import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.PlotBlock; import com.intellectualcrafters.plot.object.PlotCluster; diff --git a/src/main/java/com/plotsquared/sponge/generator/SpongePlotPopulator.java b/src/main/java/com/plotsquared/sponge/generator/SpongePlotPopulator.java index ae17e052f..5a96248e0 100644 --- a/src/main/java/com/plotsquared/sponge/generator/SpongePlotPopulator.java +++ b/src/main/java/com/plotsquared/sponge/generator/SpongePlotPopulator.java @@ -7,7 +7,6 @@ import org.spongepowered.api.world.extent.MutableBlockVolume; import org.spongepowered.api.world.gen.GeneratorPopulator; import com.flowpowered.math.vector.Vector3i; -import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.object.PseudoRandom; import com.intellectualcrafters.plot.object.RegionWrapper; import com.intellectualcrafters.plot.util.ChunkManager; diff --git a/src/main/java/com/plotsquared/sponge/generator/WorldModify.java b/src/main/java/com/plotsquared/sponge/generator/WorldModify.java index dd8b863e1..c5e458a63 100644 --- a/src/main/java/com/plotsquared/sponge/generator/WorldModify.java +++ b/src/main/java/com/plotsquared/sponge/generator/WorldModify.java @@ -5,7 +5,6 @@ import org.spongepowered.api.world.WorldCreationSettings; import org.spongepowered.api.world.gen.WorldGenerator; import org.spongepowered.api.world.gen.WorldGeneratorModifier; -import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.object.PlotCluster; import com.intellectualcrafters.plot.object.PlotWorld; import com.intellectualcrafters.plot.util.ClusterManager; diff --git a/src/main/java/com/plotsquared/sponge/listener/MainListener.java b/src/main/java/com/plotsquared/sponge/listener/MainListener.java index c63205677..3110d95af 100644 --- a/src/main/java/com/plotsquared/sponge/listener/MainListener.java +++ b/src/main/java/com/plotsquared/sponge/listener/MainListener.java @@ -20,7 +20,6 @@ import java.util.UUID; import org.spongepowered.api.block.BlockState; import org.spongepowered.api.entity.Entity; -import org.spongepowered.api.entity.EntityType; import org.spongepowered.api.entity.EntityTypes; import org.spongepowered.api.entity.player.Player; import org.spongepowered.api.event.Subscribe; diff --git a/src/main/java/com/plotsquared/sponge/util/SpongeChunkManager.java b/src/main/java/com/plotsquared/sponge/util/SpongeChunkManager.java index 6f66f4f08..3fc78acc5 100644 --- a/src/main/java/com/plotsquared/sponge/util/SpongeChunkManager.java +++ b/src/main/java/com/plotsquared/sponge/util/SpongeChunkManager.java @@ -102,12 +102,6 @@ public class SpongeChunkManager extends ChunkManager { return false; } - @Override - public void clearAllEntities(Plot plot) { - // TODO Auto-generated method stub - - } - @Override public void swap(String world, PlotId id, PlotId plotid) { // TODO Auto-generated method stub @@ -119,5 +113,11 @@ public class SpongeChunkManager extends ChunkManager { // TODO Auto-generated method stub } + + @Override + public void clearAllEntities(Location pos1, Location pos2) { + // TODO Auto-generated method stub + + } } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 0840e7d21..f1ccf40da 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -11,7 +11,7 @@ database: false commands: plots: description: PlotSquared PlotSquared command. - aliases: [p,plot,ps,plotsquared,p2] + aliases: [p,plot,ps,plotsquared,p2,2] permission: plots.use permission-message: "You are lacking the permission node 'plots.use'" permissions: