From c76536b8b07afe6d3ce0f602fabb9c0fe9e8acbf Mon Sep 17 00:00:00 2001 From: boy0001 Date: Fri, 3 Apr 2015 13:42:49 +1100 Subject: [PATCH] Fixed home plot sorting --- .../intellectualcrafters/jnbt/ListTag.java | 2 -- .../plot/PlotSquared.java | 22 ++++++++++++++++--- .../plot/commands/BukkitCommand.java | 2 +- .../plot/commands/Home.java | 2 +- .../plot/commands/MainCommand.java | 2 +- .../plot/commands/Visit.java | 2 +- .../plot/generator/BukkitHybridUtils.java | 3 ++- .../plot/generator/HybridUtils.java | 2 +- 8 files changed, 26 insertions(+), 11 deletions(-) diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/ListTag.java b/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/ListTag.java index 614a86af4..5a0cd5faf 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/ListTag.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/jnbt/ListTag.java @@ -6,7 +6,6 @@ import java.util.Collections; import java.util.List; import java.util.NoSuchElementException; -import javax.annotation.Nullable; /** * The {@code TAG_List} tag. @@ -74,7 +73,6 @@ public final class ListTag extends Tag { * * @return the tag or null */ - @Nullable public Tag getIfExists(final int index) { try { return this.value.get(index); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotSquared.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotSquared.java index f2ad55392..c720ba90b 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotSquared.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotSquared.java @@ -181,9 +181,11 @@ public class PlotSquared { } } } - for (Entry> entry : PlotSquared.plots.entrySet()) { - if (!entry.getKey().equals(priorityWorld)) { - for (Plot plot : entry.getValue().values()) { + ArrayList worlds = new ArrayList<>(PlotSquared.plots.keySet()); + Collections.sort(worlds); + for (String world : worlds) { + if (!world.equals(priorityWorld)) { + for (Plot plot : PlotSquared.plots.get(world).values()) { if (plots.contains(plot)) { newPlots.add(plot); } @@ -192,6 +194,20 @@ public class PlotSquared { } return newPlots; } + + public static ArrayList sortPlotsByWorld(Collection plots) { + ArrayList newPlots = new ArrayList<>(); + ArrayList worlds = new ArrayList<>(PlotSquared.plots.keySet()); + Collections.sort(worlds); + for (String world : worlds) { + for (Plot plot : PlotSquared.plots.get(world).values()) { + if (plots.contains(plot)) { + newPlots.add(plot); + } + } + } + return newPlots; + } public static Set getPlots(final String world, final String player) { final UUID uuid = UUIDHandler.getUUID(player); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/BukkitCommand.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/BukkitCommand.java index 0e05fefe0..f9e375390 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/BukkitCommand.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/BukkitCommand.java @@ -51,7 +51,7 @@ public class BukkitCommand implements CommandExecutor, TabCompleter { if (cmd.permission.hasPermission(player)) { if (cmd.cmd.startsWith(arg)) { tabOptions.add(cmd.cmd); - } else if (cmd.alias.get(0).startsWith(arg)) { + } else if (cmd.alias.size() > 0 && cmd.alias.get(0).startsWith(arg)) { tabOptions.add(cmd.alias.get(0)); } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Home.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Home.java index 3daef2e5f..b1e1953b9 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Home.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Home.java @@ -47,7 +47,7 @@ public class Home extends SubCommand { @Override public boolean execute(final PlotPlayer plr, String... args) { - final ArrayList plots = PlotSquared.sortPlots(PlotSquared.getPlots(plr), plr.getLocation().getWorld()); + final ArrayList plots = PlotSquared.sortPlotsByWorld(PlotSquared.getPlots(plr)); if (plots.size() == 1) { MainUtil.teleportPlayer(plr, plr.getLocation(), plots.get(0)); return true; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java index 9b8b18724..a35372d32 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java @@ -40,7 +40,7 @@ public class MainCommand { /** * Main Permission Node */ - private final static SubCommand[] _subCommands = new SubCommand[] { new Template(), new Setup(), new DebugSaveTest(), new DebugLoadTest(), new CreateRoadSchematic(), new RegenAllRoads(), new DebugClear(), new Claim(), new Auto(), new Home(), new Visit(), new TP(), new Set(), new Clear(), new Delete(), new SetOwner(), new Denied(), new Helpers(), new Trusted(), new Info(), new list(), new Help(), new Debug(), new SchematicCmd(), new plugin(), new Inventory(), new Purge(), new Reload(), new Merge(), new Unlink(), new Kick(), new Rate(), new DebugClaimTest(), new Inbox(), new Comment(), new Database(), new Unclaim(), new Swap(), new MusicSubcommand(), new DebugRoadRegen(), new Trim(), new DebugExec(), new FlagCmd(), new Target(), new DebugFixFlags(), new Move(), new Condense(), new Confirm(), new Copy() }; + private final static SubCommand[] _subCommands = new SubCommand[] { new Template(), new Setup(), new DebugSaveTest(), new DebugLoadTest(), new CreateRoadSchematic(), new RegenAllRoads(), new DebugClear(), new Claim(), new Auto(), new Home(), new Visit(), new TP(), new Set(), new Clear(), new Delete(), new SetOwner(), new Denied(), new Helpers(), new Trusted(), new Info(), new list(), new Help(), new Debug(), new SchematicCmd(), new plugin(), new Inventory(), new Purge(), new Reload(), new Merge(), new Unlink(), new Kick(), new Rate(), new DebugClaimTest(), new Inbox(), new Comment(), new Database(), new Unclaim(), new Swap(), new MusicSubcommand(), new DebugRoadRegen(), new Trim(), new DebugExec(), new FlagCmd(), new Target(), new DebugFixFlags(), new Move(), new Condense(), new Confirm(), new Copy(), new WE_Anywhere() }; public final static ArrayList subCommands = new ArrayList() { { addAll(Arrays.asList(_subCommands)); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Visit.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Visit.java index 1fe36383e..efeca0826 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Visit.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Visit.java @@ -55,7 +55,7 @@ public class Visit extends SubCommand { final UUID uuid = UUIDHandler.getUUID(username); List plots = null; if (uuid != null) { - plots = PlotSquared.sortPlots(getPlots(uuid), plr.getLocation().getWorld()); + plots = PlotSquared.sortPlotsByWorld(getPlots(uuid)); } if ((uuid == null) || plots.isEmpty()) { return sendMessage(plr, C.FOUND_NO_PLOTS); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/BukkitHybridUtils.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/BukkitHybridUtils.java index fa40e9da6..8ccb66eaa 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/BukkitHybridUtils.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/BukkitHybridUtils.java @@ -29,7 +29,7 @@ import com.intellectualcrafters.plot.util.bukkit.BukkitUtil; public class BukkitHybridUtils extends HybridUtils { - public void checkModified(final Plot plot, final int requiredChanges, final Runnable whenDone) { + public void checkModified(final Plot plot, final int requiredChanges, final Runnable whenDone, final Runnable ifFailed) { TaskManager.index.increment(); final Location bot = MainUtil.getPlotBottomLoc(plot.world, plot.id).add(1, 0, 1); @@ -72,6 +72,7 @@ public class BukkitHybridUtils extends HybridUtils { return; } if (chunks.size() == 0) { + TaskManager.runTaskLater(ifFailed, 1); Bukkit.getScheduler().cancelTask(TaskManager.tasks.get(currentIndex)); TaskManager.tasks.remove(currentIndex); return; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridUtils.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridUtils.java index b6dc94eb5..a561df522 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridUtils.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridUtils.java @@ -21,7 +21,7 @@ public abstract class HybridUtils { public static HybridUtils manager; - public abstract void checkModified(Plot plot, int requiredChanges, Runnable ifPassed); + public abstract void checkModified(Plot plot, int requiredChanges, Runnable ifPassed, Runnable ifFailed); public abstract int checkModified(final String world, final int x1, final int x2, final int y1, final int y2, final int z1, final int z2, final PlotBlock[] blocks);