Merge remote-tracking branch 'origin/master'

This commit is contained in:
Sauilitired 2014-10-19 10:46:12 +02:00
commit fde2e84d1a
5 changed files with 130 additions and 19 deletions

View File

@ -136,7 +136,7 @@ public enum C {
/* /*
* purge * purge
*/ */
PURGE_SYNTAX("&c/plots purge {world}"), PURGE_SYNTAX("&c/plots purge {world|world;x,z}"),
PURGE_SUCCESS("All plots for the specified world have now been purged."), PURGE_SUCCESS("All plots for the specified world have now been purged."),
/* /*
* No {plot} * No {plot}

View File

@ -283,6 +283,13 @@ public class PlotMain extends JavaPlugin {
return new HashSet<Plot>(myplots); return new HashSet<Plot>(myplots);
} }
public static HashMap<PlotId, Plot> getPlots(String world) {
if (plots.containsKey(world)) {
return plots.get(world);
}
return new HashMap<PlotId, Plot>();
}
/** /**
* @param world * @param world
* @return * @return
@ -309,12 +316,20 @@ public class PlotMain extends JavaPlugin {
} }
/** /**
* @param world * @param world
* @return * @return
*/ */
public static boolean isPlotWorld(World world) { public static boolean isPlotWorld(World world) {
return (worlds.containsKey(world.getName())); return (worlds.containsKey(world.getName()));
} }
/**
* @param world
* @return
*/
public static boolean isPlotWorld(String world) {
return (worlds.containsKey(world));
}
/** /**
* @param world * @param world

View File

@ -82,7 +82,6 @@ public class Claim extends SubCommand {
return false; return false;
} }
return true; return true;
} }
public static boolean claimPlot(Player player, Plot plot, boolean teleport) { public static boolean claimPlot(Player player, Plot plot, boolean teleport) {

View File

@ -12,6 +12,7 @@ import org.bukkit.entity.Player;
import com.intellectualcrafters.plot.C; import com.intellectualcrafters.plot.C;
import com.intellectualcrafters.plot.PlayerFunctions; import com.intellectualcrafters.plot.PlayerFunctions;
import com.intellectualcrafters.plot.PlotId;
import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.PlotMain;
import com.intellectualcrafters.plot.PlotWorld; import com.intellectualcrafters.plot.PlotWorld;
import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.database.DBFunc;
@ -27,22 +28,52 @@ public class Purge extends SubCommand {
@Override @Override
public boolean execute(Player plr, String... args) { public boolean execute(Player plr, String... args) {
if (args.length!=1) { if (args.length!=2) {
if (args.length==1) {
try {
String[] split = args[0].split(";");
String world = split[0];
PlotId id = new PlotId(Integer.parseInt(split[1]), Integer.parseInt(split[2]));
System.out.print("VALID ID");
if (plr!=null) {
PlayerFunctions.sendMessage(plr, (C.NOT_CONSOLE));
return false;
}
if (!PlotMain.isPlotWorld(world)) {
PlayerFunctions.sendMessage(plr, C.NOT_VALID_PLOT_WORLD);
return false;
}
PlotMain.getPlots(world).remove(id);
DBFunc.purge(world, id);
}
catch (Exception e) {
PlayerFunctions.sendMessage(plr, C.NOT_VALID_PLOT_ID);
}
}
PlayerFunctions.sendMessage(plr, C.PURGE_SYNTAX); PlayerFunctions.sendMessage(plr, C.PURGE_SYNTAX);
return false; return false;
} }
PlotWorld plotworld = PlotMain.getWorldSettings(args[0]); if (args[1].equals("-o")) {
if (plotworld == null) { PlotWorld plotworld = PlotMain.getWorldSettings(args[0]);
PlayerFunctions.sendMessage(plr, C.NOT_VALID_PLOT_WORLD); if (plotworld == null) {
return false; PlayerFunctions.sendMessage(plr, C.NOT_VALID_PLOT_WORLD);
return false;
}
if (plr!=null) {
PlayerFunctions.sendMessage(plr, (C.NOT_CONSOLE));
return false;
}
DBFunc.purge(args[0]);
PlayerFunctions.sendMessage(plr, (C.PURGE_SUCCESS));
return true;
} }
if (plr!=null) { else {
PlayerFunctions.sendMessage(plr, (C.NOT_CONSOLE)); PlayerFunctions.sendMessage(plr, "This is a dangerous command, if you are sure, use /plot purge {world} -o");
return false; return false;
} }
DBFunc.purge(args[0]);
PlayerFunctions.sendMessage(plr, (C.PURGE_SUCCESS));
return true;
} }
} }

View File

@ -589,6 +589,72 @@ public class DBFunc {
PlotMain.getMain().getServer().getScheduler().runTaskAsynchronously(PlotMain.getMain(), r); PlotMain.getMain().getServer().getScheduler().runTaskAsynchronously(PlotMain.getMain(), r);
} }
public static void purge(final String world, final PlotId id) {
runTask(new Runnable() {
@Override
public void run() {
ArrayList<Integer> ids = new ArrayList<Integer>();
// Fetching a list of plot IDs for a world
try {
PreparedStatement stmt = connection.prepareStatement("SELECT `id` FROM `plot` WHERE `world` = ? AND `plot_id_x` = ? AND `plot_id_z` = ?");
stmt.setString(1, world);
stmt.setInt(2, id.x);
stmt.setInt(3, id.y);
ResultSet result = stmt.executeQuery();
while (result.next()) {
int id = result.getInt("id");
ids.add(id);
}
}
catch (SQLException e) {
e.printStackTrace();
Logger.add(LogLevel.WARNING, "FAILED TO PURGE WORLD '"+world+"'!");
return;
}
if (ids.size() > 0) {
try {
String prefix = "";
StringBuilder idstr = new StringBuilder("");
for (Integer id:ids) {
idstr.append(prefix + id);
prefix = " OR `plot_plot_id` = ";
}
PreparedStatement stmt = connection.prepareStatement("DELETE FROM `plot_helpers` WHERE `plot_plot_id` = "+idstr+"");
stmt.executeUpdate();
stmt.close();
stmt = connection.prepareStatement("DELETE FROM `plot_denied` WHERE `plot_plot_id` = "+idstr+"");
stmt.executeUpdate();
stmt.close();
stmt = connection.prepareStatement("DELETE FROM `plot_settings` WHERE `plot_plot_id` = "+idstr+"");
stmt.executeUpdate();
stmt.close();
stmt = connection.prepareStatement("DELETE FROM `plot_trusted` WHERE `plot_plot_id` = "+idstr+"");
stmt.executeUpdate();
stmt.close();
stmt = connection.prepareStatement("DELETE FROM `plot` WHERE `world` = ?");
stmt.setString(1, world);
stmt.executeUpdate();
stmt.close();
}
catch (SQLException e) {
e.printStackTrace();
Logger.add(LogLevel.DANGER, "FAILED TO PURGE PLOT FROM DB '"+world+"' , '"+id+"' !");
return;
}
}
Logger.add(LogLevel.GENERAL, "SUCCESSFULLY PURGED PLOT FROM DB '"+world+"' , '"+id+"'!");
}
});
}
public static void purge(final String world) { public static void purge(final String world) {
runTask(new Runnable() { runTask(new Runnable() {
@Override @Override