plot condensing/purge and command confirmation bypass

This commit is contained in:
boy0001 2015-03-08 12:11:02 +11:00
parent 37e638acad
commit debbb50e1d
7 changed files with 32 additions and 17 deletions

View File

@ -66,7 +66,7 @@ public class Clear extends SubCommand {
PlotSquared.log("Plot " + plot.getId().toString() + " cleared."); PlotSquared.log("Plot " + plot.getId().toString() + " cleared.");
} }
}; };
if (Settings.CONFIRM_CLEAR) { if (Settings.CONFIRM_CLEAR && !(Permissions.hasPermission(plr, "plots.confirm.bypass"))) {
CmdConfirm.addPending(plr, "/plot clear " + id, runnable); CmdConfirm.addPending(plr, "/plot clear " + id, runnable);
} }
else { else {
@ -133,7 +133,7 @@ public class Clear extends SubCommand {
} }
} }
}; };
if (Settings.CONFIRM_CLEAR) { if (Settings.CONFIRM_CLEAR && !(Permissions.hasPermission(plr, "plots.confirm.bypass"))) {
CmdConfirm.addPending(plr, "/plot clear " + plot.id, runnable); CmdConfirm.addPending(plr, "/plot clear " + plot.id, runnable);
} }
else { else {

View File

@ -94,7 +94,7 @@ public class Condense extends SubCommand {
} }
start = Auto.getNextPlot(start, 1); start = Auto.getNextPlot(start, 1);
} }
MainUtil.move(worldname, to_move.get(0), free.get(0), new Runnable() { MainUtil.move(worldname, to_move.get(0), free.get(0), new Runnable() {
@Override @Override
public void run() { public void run() {
if (!TASK) { if (!TASK) {

View File

@ -83,7 +83,7 @@ public class Delete extends SubCommand {
DBFunc.delete(loc.getWorld(), plot); DBFunc.delete(loc.getWorld(), plot);
} }
}; };
if (Settings.CONFIRM_DELETE) { if (Settings.CONFIRM_DELETE && !(Permissions.hasPermission(plr, "plots.confirm.bypass"))) {
CmdConfirm.addPending(plr, "/plot delete " + plot.id, runnable); CmdConfirm.addPending(plr, "/plot delete " + plot.id, runnable);
} }
else { else {

View File

@ -114,16 +114,18 @@ public class Purge extends SubCommand {
for (final Plot plot : plots) { for (final Plot plot : plots) {
ids.add(plot.id); ids.add(plot.id);
} }
int length = ids.size();
DBFunc.purge(worldname, ids); DBFunc.purge(worldname, ids);
return finishPurge(ids.size()); return finishPurge(length);
} }
if (arg.equals("all")) { if (arg.equals("all")) {
final Set<PlotId> ids = PlotSquared.getPlots(worldname).keySet(); final Set<PlotId> ids = PlotSquared.getPlots(worldname).keySet();
if (ids.size() == 0) { int length = ids.size();
if (length == 0) {
return MainUtil.sendMessage(null, "&cNo plots found"); return MainUtil.sendMessage(null, "&cNo plots found");
} }
DBFunc.purge(worldname, ids); DBFunc.purge(worldname, ids);
return finishPurge(ids.size()); return finishPurge(length);
} }
if (arg.equals("unknown")) { if (arg.equals("unknown")) {
final Collection<Plot> plots = PlotSquared.getPlots(worldname).values(); final Collection<Plot> plots = PlotSquared.getPlots(worldname).values();
@ -136,11 +138,12 @@ public class Purge extends SubCommand {
} }
} }
} }
if (ids.size() == 0) { int length = ids.size();
if (length == 0) {
return MainUtil.sendMessage(null, "&cNo plots found"); return MainUtil.sendMessage(null, "&cNo plots found");
} }
DBFunc.purge(worldname, ids); DBFunc.purge(worldname, ids);
return finishPurge(ids.size()); return finishPurge(length);
} }
if (arg.equals("unowned")) { if (arg.equals("unowned")) {
final Collection<Plot> plots = PlotSquared.getPlots(worldname).values(); final Collection<Plot> plots = PlotSquared.getPlots(worldname).values();
@ -150,11 +153,12 @@ public class Purge extends SubCommand {
ids.add(plot.id); ids.add(plot.id);
} }
} }
if (ids.size() == 0) { int length = ids.size();
if (length == 0) {
return MainUtil.sendMessage(null, "&cNo plots found"); return MainUtil.sendMessage(null, "&cNo plots found");
} }
DBFunc.purge(worldname, ids); DBFunc.purge(worldname, ids);
return finishPurge(ids.size()); return finishPurge(length);
} }
MainUtil.sendMessage(plr, C.PURGE_SYNTAX); MainUtil.sendMessage(plr, C.PURGE_SYNTAX);
return false; return false;

View File

@ -74,7 +74,7 @@ public class Unlink extends SubCommand {
MainUtil.sendMessage(plr, C.UNLINK_SUCCESS); MainUtil.sendMessage(plr, C.UNLINK_SUCCESS);
} }
}; };
if (Settings.CONFIRM_UNLINK) { if (Settings.CONFIRM_UNLINK && !(Permissions.hasPermission(plr, "plots.confirm.bypass"))) {
CmdConfirm.addPending(plr, "/plot unlink " + plot.id, runnable); CmdConfirm.addPending(plr, "/plot unlink " + plot.id, runnable);
} }
else { else {

View File

@ -29,6 +29,7 @@ import java.sql.Statement;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -866,6 +867,12 @@ public class SQLManager implements AbstractDB {
if (uniqueIds.size() > 0) { if (uniqueIds.size() > 0) {
try { try {
String stmt_prefix = ""; String stmt_prefix = "";
final StringBuilder idstr2 = new StringBuilder("");
for (final Integer id : uniqueIds) {
idstr2.append(stmt_prefix + id);
stmt_prefix = " OR `id` = ";
}
stmt_prefix = "";
final StringBuilder idstr = new StringBuilder(""); final StringBuilder idstr = new StringBuilder("");
for (final Integer id : uniqueIds) { for (final Integer id : uniqueIds) {
idstr.append(stmt_prefix + id); idstr.append(stmt_prefix + id);
@ -883,8 +890,7 @@ public class SQLManager implements AbstractDB {
stmt = SQLManager.this.connection.prepareStatement("DELETE FROM `" + this.prefix + "plot_trusted` WHERE `plot_plot_id` = " + idstr + ""); stmt = SQLManager.this.connection.prepareStatement("DELETE FROM `" + this.prefix + "plot_trusted` WHERE `plot_plot_id` = " + idstr + "");
stmt.executeUpdate(); stmt.executeUpdate();
stmt.close(); stmt.close();
stmt = SQLManager.this.connection.prepareStatement("DELETE FROM `" + this.prefix + "plot` WHERE `world` = ?"); stmt = SQLManager.this.connection.prepareStatement("DELETE FROM `" + this.prefix + "plot` WHERE `id` = " + idstr2 + "");
stmt.setString(1, world);
stmt.executeUpdate(); stmt.executeUpdate();
stmt.close(); stmt.close();
} catch (final SQLException e) { } catch (final SQLException e) {
@ -898,9 +904,6 @@ public class SQLManager implements AbstractDB {
@Override @Override
public void purge(final String world, final Set<PlotId> plots) { public void purge(final String world, final Set<PlotId> plots) {
for (final PlotId id : plots) {
PlotSquared.removePlot(world, new PlotId(id.x, id.y), true);
}
PreparedStatement stmt; PreparedStatement stmt;
try { try {
stmt = SQLManager.this.connection.prepareStatement("SELECT `id`, `plot_id_x`, `plot_id_z` FROM `" + this.prefix + "plot` WHERE `world` = ?"); stmt = SQLManager.this.connection.prepareStatement("SELECT `id`, `plot_id_x`, `plot_id_z` FROM `" + this.prefix + "plot` WHERE `world` = ?");
@ -917,6 +920,12 @@ public class SQLManager implements AbstractDB {
purgeIds(world, ids); purgeIds(world, ids);
stmt.close(); stmt.close();
r.close(); r.close();
for (Iterator<PlotId> iter = plots.iterator(); iter.hasNext();) {
PlotId plotId = iter.next();
iter.remove();
PlotId id = new PlotId(plotId.x, plotId.y);
PlotSquared.removePlot(world, new PlotId(id.x, id.y), true);
}
} catch (final SQLException e) { } catch (final SQLException e) {
e.printStackTrace(); e.printStackTrace();
PlotSquared.log("&c[ERROR] " + "FAILED TO PURGE WORLD '" + world + "'!"); PlotSquared.log("&c[ERROR] " + "FAILED TO PURGE WORLD '" + world + "'!");

View File

@ -825,12 +825,14 @@ public class MainUtil {
final Location top = MainUtil.getPlotTopLoc(world, current); final Location top = MainUtil.getPlotTopLoc(world, current);
final Plot currentPlot = MainUtil.getPlot(world, current); final Plot currentPlot = MainUtil.getPlot(world, current);
if (currentPlot.owner == null) { if (currentPlot.owner == null) {
TaskManager.runTaskLater(whenDone, 1);
return false; return false;
} }
final Plot pos1 = getBottomPlot(currentPlot); final Plot pos1 = getBottomPlot(currentPlot);
final Plot pos2 = getTopPlot(currentPlot); final Plot pos2 = getTopPlot(currentPlot);
final PlotId size = MainUtil.getSize(world, currentPlot); final PlotId size = MainUtil.getSize(world, currentPlot);
if (!MainUtil.isUnowned(world, newPlot, new PlotId((newPlot.x + size.x) - 1, (newPlot.y + size.y) - 1))) { if (!MainUtil.isUnowned(world, newPlot, new PlotId((newPlot.x + size.x) - 1, (newPlot.y + size.y) - 1))) {
TaskManager.runTaskLater(whenDone, 1);
return false; return false;
} }
final int offset_x = newPlot.x - pos1.id.x; final int offset_x = newPlot.x - pos1.id.x;