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)
This commit is contained in:
boy0001 2014-09-25 11:54:57 +10:00
parent 04167997ad
commit 26249d00a3
5 changed files with 35 additions and 36 deletions

View File

@ -136,7 +136,6 @@ public class PlayerFunctions {
return null;
}
HashMap<PlotId, Plot> plots = PlotMain.getPlots(world);
if (plots != null) {
if (plots.containsKey(id)) {
return plots.get(id);

View File

@ -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);

View File

@ -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;

View File

@ -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.");
}

View File

@ -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);
}
});
}
}
});
}
/**