mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-12-26 17:18:43 +01:00
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:
parent
04167997ad
commit
26249d00a3
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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.");
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user