From 26249d00a3f1801c51b1e509be2ef3a17816b8f3 Mon Sep 17 00:00:00 2001 From: boy0001 Date: Thu, 25 Sep 2014 11:54:57 +1000 Subject: [PATCH] Java can be a pain sometimes... - Fixed weird bug with plot clear (I basically just swapped the plot.clear() method and DBFunc.delete(plot) as referencing the plot directly afterwards added it back to the HashMap) --- .../plot/PlayerFunctions.java | 1 - .../intellectualcrafters/plot/PlotHelper.java | 2 +- .../intellectualcrafters/plot/PlotMain.java | 14 +++--- .../plot/commands/Clear.java | 4 +- .../plot/database/DBFunc.java | 50 +++++++++---------- 5 files changed, 35 insertions(+), 36 deletions(-) diff --git a/PlotSquared/src/com/intellectualcrafters/plot/PlayerFunctions.java b/PlotSquared/src/com/intellectualcrafters/plot/PlayerFunctions.java index 39383282a..a8f97f867 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/PlayerFunctions.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/PlayerFunctions.java @@ -136,7 +136,6 @@ public class PlayerFunctions { return null; } HashMap plots = PlotMain.getPlots(world); - if (plots != null) { if (plots.containsKey(id)) { return plots.get(id); diff --git a/PlotSquared/src/com/intellectualcrafters/plot/PlotHelper.java b/PlotSquared/src/com/intellectualcrafters/plot/PlotHelper.java index 253fa679c..8eee93e04 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/PlotHelper.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/PlotHelper.java @@ -458,8 +458,8 @@ public class PlotHelper { } public static void clear(final Player requester, final Plot plot) { - final PlotWorld plotworld = PlotMain.getWorldSettings(Bukkit.getWorld(plot.world)); final long start = System.nanoTime(); + final PlotWorld plotworld = PlotMain.getWorldSettings(Bukkit.getWorld(plot.world)); PlotHelper.setBiome(requester.getWorld(), plot, Biome.FOREST); PlotHelper.removeSign(requester, plot); PlayerFunctions.sendMessage(requester, C.CLEARING_PLOT); diff --git a/PlotSquared/src/com/intellectualcrafters/plot/PlotMain.java b/PlotSquared/src/com/intellectualcrafters/plot/PlotMain.java index cfb9013d9..57f28c831 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/PlotMain.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/PlotMain.java @@ -269,12 +269,14 @@ public class PlotMain extends JavaPlugin { return (plots.get(world.getName()).values().toArray(new Plot[0])); } - public static boolean removePlot(String world, PlotId id) { - PlotDeleteEvent event = new PlotDeleteEvent(world, id); - Bukkit.getServer().getPluginManager().callEvent(event); - if (event.isCancelled()) { - event.setCancelled(true); - return false; + public static boolean removePlot(String world, PlotId id, boolean callEvent) { + if (callEvent) { + PlotDeleteEvent event = new PlotDeleteEvent(world, id); + Bukkit.getServer().getPluginManager().callEvent(event); + if (event.isCancelled()) { + event.setCancelled(true); + return false; + } } plots.get(world).remove(id); return true; diff --git a/PlotSquared/src/com/intellectualcrafters/plot/commands/Clear.java b/PlotSquared/src/com/intellectualcrafters/plot/commands/Clear.java index 4c8fe32a4..5c9b232d0 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/commands/Clear.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/commands/Clear.java @@ -32,10 +32,10 @@ public class Clear extends SubCommand { return true; } Plot plot = PlayerFunctions.getCurrentPlot(plr); - boolean result = PlotMain.removePlot(plr.getWorld().getName(), plot.id); + boolean result = PlotMain.removePlot(plr.getWorld().getName(), plot.id, true); if (result) { - DBFunc.delete(plr.getWorld().getName(), plot); plot.clear(plr); + DBFunc.delete(plr.getWorld().getName(), plot); } else { PlayerFunctions.sendMessage(plr, "Plot clearing has been denied."); } diff --git a/PlotSquared/src/com/intellectualcrafters/plot/database/DBFunc.java b/PlotSquared/src/com/intellectualcrafters/plot/database/DBFunc.java index 5a4d50198..9216983cb 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/database/DBFunc.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/database/DBFunc.java @@ -149,33 +149,31 @@ public class DBFunc { * @param plot */ public static void delete(final String world, final Plot plot) { - boolean result = PlotMain.removePlot(world, plot.id); - if (result) { - runTask(new Runnable() { - @Override - public void run() { - PreparedStatement stmt = null; - int id = getId(world, plot.id); - try { - stmt = connection.prepareStatement("DELETE FROM `plot_settings` WHERE `plot_plot_id` = ?"); - stmt.setInt(1, id); - stmt.executeUpdate(); - stmt.close(); - stmt = connection.prepareStatement("DELETE FROM `plot_helpers` WHERE `plot_plot_id` = ?"); - stmt.setInt(1, id); - stmt.executeUpdate(); - stmt.close(); - stmt = connection.prepareStatement("DELETE FROM `plot` WHERE `id` = ?"); - stmt.setInt(1, id); - stmt.executeUpdate(); - stmt.close(); - } catch (SQLException e) { - e.printStackTrace(); - Logger.add(LogLevel.DANGER, "Failed to delete plot " + plot.id); - } + boolean result = PlotMain.removePlot(world, plot.id, false); + runTask(new Runnable() { + @Override + public void run() { + PreparedStatement stmt = null; + int id = getId(world, plot.id); + try { + stmt = connection.prepareStatement("DELETE FROM `plot_settings` WHERE `plot_plot_id` = ?"); + stmt.setInt(1, id); + stmt.executeUpdate(); + stmt.close(); + stmt = connection.prepareStatement("DELETE FROM `plot_helpers` WHERE `plot_plot_id` = ?"); + stmt.setInt(1, id); + stmt.executeUpdate(); + stmt.close(); + stmt = connection.prepareStatement("DELETE FROM `plot` WHERE `id` = ?"); + stmt.setInt(1, id); + stmt.executeUpdate(); + stmt.close(); + } catch (SQLException e) { + e.printStackTrace(); + Logger.add(LogLevel.DANGER, "Failed to delete plot " + plot.id); } - }); - } + } + }); } /**