mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 05:06:44 +01:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
fde2e84d1a
@ -136,7 +136,7 @@ public enum C {
|
||||
/*
|
||||
* 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."),
|
||||
/*
|
||||
* No {plot}
|
||||
|
@ -283,6 +283,13 @@ public class PlotMain extends JavaPlugin {
|
||||
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
|
||||
* @return
|
||||
@ -309,12 +316,20 @@ public class PlotMain extends JavaPlugin {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param world
|
||||
* @return
|
||||
*/
|
||||
public static boolean isPlotWorld(World world) {
|
||||
return (worlds.containsKey(world.getName()));
|
||||
}
|
||||
* @param world
|
||||
* @return
|
||||
*/
|
||||
public static boolean isPlotWorld(World world) {
|
||||
return (worlds.containsKey(world.getName()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param world
|
||||
* @return
|
||||
*/
|
||||
public static boolean isPlotWorld(String world) {
|
||||
return (worlds.containsKey(world));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param world
|
||||
|
@ -82,7 +82,6 @@ public class Claim extends SubCommand {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
public static boolean claimPlot(Player player, Plot plot, boolean teleport) {
|
||||
|
@ -12,6 +12,7 @@ import org.bukkit.entity.Player;
|
||||
|
||||
import com.intellectualcrafters.plot.C;
|
||||
import com.intellectualcrafters.plot.PlayerFunctions;
|
||||
import com.intellectualcrafters.plot.PlotId;
|
||||
import com.intellectualcrafters.plot.PlotMain;
|
||||
import com.intellectualcrafters.plot.PlotWorld;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
@ -27,22 +28,52 @@ public class Purge extends SubCommand {
|
||||
|
||||
@Override
|
||||
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);
|
||||
return false;
|
||||
}
|
||||
PlotWorld plotworld = PlotMain.getWorldSettings(args[0]);
|
||||
if (plotworld == null) {
|
||||
PlayerFunctions.sendMessage(plr, C.NOT_VALID_PLOT_WORLD);
|
||||
return false;
|
||||
if (args[1].equals("-o")) {
|
||||
PlotWorld plotworld = PlotMain.getWorldSettings(args[0]);
|
||||
if (plotworld == null) {
|
||||
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) {
|
||||
PlayerFunctions.sendMessage(plr, (C.NOT_CONSOLE));
|
||||
return false;
|
||||
else {
|
||||
PlayerFunctions.sendMessage(plr, "This is a dangerous command, if you are sure, use /plot purge {world} -o");
|
||||
return false;
|
||||
}
|
||||
DBFunc.purge(args[0]);
|
||||
PlayerFunctions.sendMessage(plr, (C.PURGE_SUCCESS));
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -589,6 +589,72 @@ public class DBFunc {
|
||||
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) {
|
||||
runTask(new Runnable() {
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user