mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 21:26:45 +01:00
finished plot command confirmation (clear, delete, unlink)
This commit is contained in:
parent
972a3325e4
commit
37e638acad
@ -708,6 +708,12 @@ public class PlotSquared {
|
||||
final Map<String, Object> options = new HashMap<>();
|
||||
options.put("teleport.delay", 0);
|
||||
options.put("auto_update", false);
|
||||
|
||||
options.put("confirmation.clear", Settings.CONFIRM_CLEAR);
|
||||
options.put("confirmation.delete", Settings.CONFIRM_DELETE);
|
||||
options.put("confirmation.unlink", Settings.CONFIRM_UNLINK);
|
||||
|
||||
|
||||
options.put("clusters.enabled", Settings.ENABLE_CLUSTERS);
|
||||
options.put("plotme-alias", Settings.USE_PLOTME_ALIAS);
|
||||
options.put("plotme-convert.enabled", Settings.CONVERT_PLOTME);
|
||||
@ -738,6 +744,11 @@ public class PlotSquared {
|
||||
if (Settings.DEBUG) {
|
||||
log(C.PREFIX.s() + "&6Debug Mode Enabled (Default). Edit the config to turn this off.");
|
||||
}
|
||||
|
||||
Settings.CONFIRM_CLEAR = config.getBoolean("confirmation.clear");
|
||||
Settings.CONFIRM_DELETE = config.getBoolean("confirmation.delete");
|
||||
Settings.CONFIRM_UNLINK = config.getBoolean("confirmation.unlink");
|
||||
|
||||
Settings.TELEPORT_DELAY = config.getInt("teleport.delay");
|
||||
Settings.CONSOLE_COLOR = config.getBoolean("console.color");
|
||||
Settings.TELEPORT_ON_LOGIN = config.getBoolean("teleport.on_login");
|
||||
|
@ -24,12 +24,15 @@ import java.util.Set;
|
||||
|
||||
import com.intellectualcrafters.plot.PlotSquared;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.CmdConfirm;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||
|
||||
public class Clear extends SubCommand {
|
||||
@ -56,9 +59,20 @@ public class Clear extends SubCommand {
|
||||
if (plot == null) {
|
||||
PlotSquared.log("Could not find plot " + args[0] + " in world " + world);
|
||||
} else {
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MainUtil.clear(world, plot, true, null);
|
||||
PlotSquared.log("Plot " + plot.getId().toString() + " cleared.");
|
||||
}
|
||||
};
|
||||
if (Settings.CONFIRM_CLEAR) {
|
||||
CmdConfirm.addPending(plr, "/plot clear " + id, runnable);
|
||||
}
|
||||
else {
|
||||
TaskManager.runTask(runnable);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -100,6 +114,13 @@ public class Clear extends SubCommand {
|
||||
return sendMessage(plr, C.NO_PLOT_PERMS);
|
||||
}
|
||||
assert plot != null;
|
||||
if (MainUtil.runners.containsKey(plot)) {
|
||||
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
|
||||
return false;
|
||||
}
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final long start = System.currentTimeMillis();
|
||||
final boolean result = MainUtil.clearAsPlayer(plot, false, new Runnable() {
|
||||
@Override
|
||||
@ -110,8 +131,14 @@ public class Clear extends SubCommand {
|
||||
if (!result) {
|
||||
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
|
||||
}
|
||||
// sign
|
||||
// wall
|
||||
return result;
|
||||
}
|
||||
};
|
||||
if (Settings.CONFIRM_CLEAR) {
|
||||
CmdConfirm.addPending(plr, "/plot clear " + plot.id, runnable);
|
||||
}
|
||||
else {
|
||||
TaskManager.runTask(runnable);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -74,6 +74,7 @@ public enum Command {
|
||||
BAN("ban", "block"),
|
||||
UNBAN("unban", "unblock"),
|
||||
DATABASE("database", "convert"),
|
||||
CONFIRM("confirm"),
|
||||
TP("tp", "tp");
|
||||
/**
|
||||
* Command
|
||||
|
@ -34,6 +34,7 @@ import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
import com.intellectualcrafters.plot.util.CmdConfirm;
|
||||
import com.intellectualcrafters.plot.util.EconHandler;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||
|
||||
/**
|
||||
@ -47,12 +48,17 @@ public class Confirm extends SubCommand {
|
||||
@Override
|
||||
public boolean execute(final PlotPlayer plr, final String... args) {
|
||||
String name = plr.getName();
|
||||
CmdInstance command = CmdConfirm.pending.get(name);
|
||||
if (cmd == null) {
|
||||
// Tell user no pending commands
|
||||
CmdInstance command = CmdConfirm.getPending(plr);
|
||||
if (command == null) {
|
||||
MainUtil.sendMessage(plr, C.FAILED_CONFIRM);
|
||||
return false;
|
||||
}
|
||||
// TODO check command timestamp;
|
||||
return command.command.execute(plr, command.args);
|
||||
CmdConfirm.removePending(plr);
|
||||
if (System.currentTimeMillis() - command.timestamp > 10000) {
|
||||
MainUtil.sendMessage(plr, C.FAILED_CONFIRM);
|
||||
return false;
|
||||
}
|
||||
TaskManager.runTask(command.command);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -22,14 +22,17 @@ package com.intellectualcrafters.plot.commands;
|
||||
|
||||
import com.intellectualcrafters.plot.PlotSquared;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
import com.intellectualcrafters.plot.util.CmdConfirm;
|
||||
import com.intellectualcrafters.plot.util.EconHandler;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||
|
||||
public class Delete extends SubCommand {
|
||||
@ -52,6 +55,13 @@ public class Delete extends SubCommand {
|
||||
}
|
||||
assert plot != null;
|
||||
final PlotWorld pWorld = PlotSquared.getPlotWorld(plot.world);
|
||||
if (MainUtil.runners.containsKey(plot)) {
|
||||
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
|
||||
return false;
|
||||
}
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if ((PlotSquared.economy != null) && pWorld.USE_ECONOMY && (plot != null) && plot.hasOwner() && plot.getOwner().equals(UUIDHandler.getUUID(plr))) {
|
||||
final double c = pWorld.SELL_PRICE;
|
||||
if (c > 0d) {
|
||||
@ -59,25 +69,25 @@ public class Delete extends SubCommand {
|
||||
sendMessage(plr, C.ADDED_BALANCE, c + "");
|
||||
}
|
||||
}
|
||||
if (MainUtil.runners.containsKey(plot)) {
|
||||
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
|
||||
return false;
|
||||
}
|
||||
final boolean result = PlotSquared.removePlot(loc.getWorld(), plot.id, true);
|
||||
PlotSquared.removePlot(loc.getWorld(), plot.id, true);
|
||||
final long start = System.currentTimeMillis();
|
||||
if (result) {
|
||||
final boolean result2 = MainUtil.clearAsPlayer(plot, true, new Runnable() {
|
||||
final boolean result = MainUtil.clearAsPlayer(plot, true, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MainUtil.sendMessage(plr, C.CLEARING_DONE, "" + (System.currentTimeMillis() - start));
|
||||
}
|
||||
});
|
||||
if (!result2) {
|
||||
if (!result) {
|
||||
MainUtil.sendMessage(plr, C.WAIT_FOR_TIMER);
|
||||
}
|
||||
DBFunc.delete(loc.getWorld(), plot);
|
||||
} else {
|
||||
MainUtil.sendMessage(plr, "Plot deletion has been denied.");
|
||||
}
|
||||
};
|
||||
if (Settings.CONFIRM_DELETE) {
|
||||
CmdConfirm.addPending(plr, "/plot delete " + plot.id, runnable);
|
||||
}
|
||||
else {
|
||||
TaskManager.runTask(runnable);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ public class MainCommand {
|
||||
/**
|
||||
* Main Permission Node
|
||||
*/
|
||||
private final static SubCommand[] _subCommands = new SubCommand[] { new Template(), new Setup(), new DebugSaveTest(), new DebugLoadTest(), new CreateRoadSchematic(), new RegenAllRoads(), new DebugClear(), new Claim(), new Auto(), new Home(), new Visit(), new TP(), new Set(), new Clear(), new Delete(), new SetOwner(), new Denied(), new Helpers(), new Trusted(), new Info(), new list(), new Help(), new Debug(), new SchematicCmd(), new plugin(), new Inventory(), new Purge(), new Reload(), new Merge(), new Unlink(), new Kick(), new Rate(), new DebugClaimTest(), new Inbox(), new Comment(), new Database(), new Unclaim(), new Swap(), new MusicSubcommand(), new DebugRoadRegen(), new Trim(), new DebugExec(), new FlagCmd(), new Target(), new DebugFixFlags(), new Move(), new Condense() };
|
||||
private final static SubCommand[] _subCommands = new SubCommand[] { new Template(), new Setup(), new DebugSaveTest(), new DebugLoadTest(), new CreateRoadSchematic(), new RegenAllRoads(), new DebugClear(), new Claim(), new Auto(), new Home(), new Visit(), new TP(), new Set(), new Clear(), new Delete(), new SetOwner(), new Denied(), new Helpers(), new Trusted(), new Info(), new list(), new Help(), new Debug(), new SchematicCmd(), new plugin(), new Inventory(), new Purge(), new Reload(), new Merge(), new Unlink(), new Kick(), new Rate(), new DebugClaimTest(), new Inbox(), new Comment(), new Database(), new Unclaim(), new Swap(), new MusicSubcommand(), new DebugRoadRegen(), new Trim(), new DebugExec(), new FlagCmd(), new Target(), new DebugFixFlags(), new Move(), new Condense(), new Confirm() };
|
||||
public final static ArrayList<SubCommand> subCommands = new ArrayList<SubCommand>() {
|
||||
{
|
||||
addAll(Arrays.asList(_subCommands));
|
||||
|
@ -70,10 +70,12 @@ public class Set extends SubCommand {
|
||||
sendMessage(plr, C.PLOT_NOT_CLAIMED);
|
||||
return false;
|
||||
}
|
||||
if (!plot.isAdded(plr.getUUID()) && !Permissions.hasPermission(plr, "plots.admin.command.set")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PLOT_PERMS);
|
||||
if (!plot.isAdded(plr.getUUID())) {
|
||||
if (!Permissions.hasPermission(plr, "plots.set.other")) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.set.other");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (args.length < 1) {
|
||||
PlotManager manager = PlotSquared.getPlotManager(loc.getWorld());
|
||||
ArrayList<String> newValues = new ArrayList<String>();
|
||||
@ -111,7 +113,7 @@ public class Set extends SubCommand {
|
||||
return false;
|
||||
}
|
||||
if (!Permissions.hasPermission(plr, "plots.set.flag." + args[1].toLowerCase())) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION);
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.set.flag." + args[1].toLowerCase());
|
||||
return false;
|
||||
}
|
||||
if (args.length == 2) {
|
||||
@ -225,6 +227,9 @@ public class Set extends SubCommand {
|
||||
final String[] components = manager.getPlotComponents(plotworld, plot.id);
|
||||
for (final String component : components) {
|
||||
if (component.equalsIgnoreCase(args[0])) {
|
||||
if (!Permissions.hasPermission(plr, "plots.set." + component)) {
|
||||
MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.set." + component);
|
||||
}
|
||||
PlotBlock[] blocks;
|
||||
try {
|
||||
blocks = (PlotBlock[]) Configuration.BLOCKLIST.parseString(args[1]);
|
||||
|
@ -24,6 +24,7 @@ import java.util.ArrayList;
|
||||
|
||||
import com.intellectualcrafters.plot.PlotSquared;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.config.Settings;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
@ -31,9 +32,11 @@ import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.PlotManager;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
import com.intellectualcrafters.plot.util.CmdConfirm;
|
||||
import com.intellectualcrafters.plot.util.EventUtil;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualcrafters.plot.util.TaskManager;
|
||||
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
||||
|
||||
/**
|
||||
@ -59,12 +62,24 @@ public class Unlink extends SubCommand {
|
||||
if (MainUtil.getTopPlot(plot).equals(MainUtil.getBottomPlot(plot))) {
|
||||
return sendMessage(plr, C.UNLINK_IMPOSSIBLE);
|
||||
}
|
||||
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!unlinkPlot(plot)) {
|
||||
MainUtil.sendMessage(plr, "&cUnlink has been cancelled");
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
MainUtil.update(plr.getLocation());
|
||||
MainUtil.sendMessage(plr, "&6Plots unlinked successfully!");
|
||||
MainUtil.sendMessage(plr, C.UNLINK_SUCCESS);
|
||||
}
|
||||
};
|
||||
if (Settings.CONFIRM_UNLINK) {
|
||||
CmdConfirm.addPending(plr, "/plot unlink " + plot.id, runnable);
|
||||
}
|
||||
else {
|
||||
TaskManager.runTask(runnable);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -35,6 +35,11 @@ import com.intellectualsites.translation.bukkit.BukkitTranslation;
|
||||
* @author Citymonstret
|
||||
*/
|
||||
public enum C {
|
||||
/*
|
||||
* Confirm
|
||||
*/
|
||||
FAILED_CONFIRM("$2You have no pending actions to confirm!"),
|
||||
REQUIRES_CONFIRM("$2Are you sure you wish to execute: $1%s$2?\n$2If you are sure: $1/plot confirm"),
|
||||
/*
|
||||
* Move
|
||||
*/
|
||||
@ -208,6 +213,7 @@ public enum C {
|
||||
NO_PERM_MERGE("$2You are not the owner of the plot: $1%plot%"),
|
||||
UNLINK_REQUIRED("$2An unlink is required to do this."),
|
||||
UNLINK_IMPOSSIBLE("$2You can only unlink a mega-plot"),
|
||||
UNLINK_SUCCESS("$2Successfully unlinked plots."),
|
||||
NO_MERGE_TO_MEGA("$2Mega plots cannot be merged into. Please merge from the desired mega plot."),
|
||||
/*
|
||||
* Commands
|
||||
|
@ -136,6 +136,12 @@ public class Settings {
|
||||
* Use offline mode storage
|
||||
*/
|
||||
public static boolean OFFLINE_MODE = false;
|
||||
/**
|
||||
* Command confirmation
|
||||
*/
|
||||
public static boolean CONFIRM_CLEAR = true;
|
||||
public static boolean CONFIRM_DELETE = true;
|
||||
public static boolean CONFIRM_UNLINK = true;
|
||||
|
||||
/**
|
||||
* Database settings
|
||||
|
@ -79,6 +79,7 @@ import com.intellectualcrafters.plot.object.PlotManager;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||
import com.intellectualcrafters.plot.object.StringWrapper;
|
||||
import com.intellectualcrafters.plot.util.CmdConfirm;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualcrafters.plot.util.SetupUtils;
|
||||
@ -812,6 +813,7 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
|
||||
if (SetupUtils.setupMap.containsKey(name)) {
|
||||
SetupUtils.setupMap.remove(name);
|
||||
}
|
||||
CmdConfirm.removePending(name);
|
||||
BukkitUtil.removePlayer(name);
|
||||
if (Settings.DELETE_PLOTS_ON_BAN && event.getPlayer().isBanned()) {
|
||||
final Collection<Plot> plots = PlotSquared.getPlots(name).values();
|
||||
|
@ -1,15 +1,12 @@
|
||||
package com.intellectualcrafters.plot.object;
|
||||
|
||||
import com.intellectualcrafters.plot.commands.SubCommand;
|
||||
|
||||
public class CmdInstance {
|
||||
public final SubCommand command;
|
||||
public final String[] args;
|
||||
public final Runnable command;
|
||||
public final long timestamp;
|
||||
|
||||
public CmdInstance(SubCommand command, String[] args) {
|
||||
public CmdInstance(Runnable command) {
|
||||
this.command = command;
|
||||
this.args = args;
|
||||
this.timestamp = System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
|
@ -3,8 +3,43 @@ package com.intellectualcrafters.plot.util;
|
||||
import java.util.HashMap;
|
||||
|
||||
import com.intellectualcrafters.plot.commands.SubCommand;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
import com.intellectualcrafters.plot.object.CmdInstance;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
|
||||
public class CmdConfirm {
|
||||
public static HashMap<String, CmdInstance> pending = new HashMap<>();
|
||||
private static HashMap<String, CmdInstance> pending = new HashMap<>();
|
||||
|
||||
public static CmdInstance getPending(PlotPlayer player) {
|
||||
if (player == null) {
|
||||
return pending.get("__CONSOLE__");
|
||||
}
|
||||
return pending.get(player.getName());
|
||||
}
|
||||
|
||||
public static void removePending(PlotPlayer player) {
|
||||
if (player == null) {
|
||||
pending.remove("__CONSOLE__");
|
||||
}
|
||||
else {
|
||||
pending.remove(player.getName());
|
||||
}
|
||||
}
|
||||
|
||||
public static void removePending(String name) {
|
||||
pending.remove(name);
|
||||
}
|
||||
|
||||
public static void addPending(PlotPlayer player, String commandStr, Runnable runnable) {
|
||||
MainUtil.sendMessage(player, C.REQUIRES_CONFIRM, commandStr);
|
||||
CmdInstance cmd = new CmdInstance(runnable);
|
||||
String name;
|
||||
if (player == null) {
|
||||
name = "__CONSOLE__";
|
||||
}
|
||||
else {
|
||||
name = player.getName();
|
||||
}
|
||||
pending.put(name, cmd);
|
||||
}
|
||||
}
|
||||
|
@ -591,6 +591,7 @@ public class MainUtil {
|
||||
final int bottomZ = getPlotBottomLoc(world, plot.id).getZ() + 1;
|
||||
final int topZ = getPlotTopLoc(world, plot.id).getZ();
|
||||
BukkitUtil.setBiome(world, bottomX, bottomZ, topX, topZ, biome);
|
||||
update(getPlotHome(world, plot));
|
||||
}
|
||||
|
||||
public static int getHeighestBlock(final String world, final int x, final int z) {
|
||||
|
Loading…
Reference in New Issue
Block a user