Fixes #768 (Plot clearing with given plot id)
This commit is contained in:
Jesse Boyd
2015-12-03 02:42:50 +11:00
parent 82ccca8f63
commit f102b2b448
8 changed files with 221 additions and 127 deletions

View File

@ -22,20 +22,17 @@ package com.intellectualcrafters.plot.commands;
import java.util.Set;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.flag.FlagManager;
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.SetBlockQueue;
import com.intellectualcrafters.plot.util.TaskManager;
import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(command = "clear", description = "Clear a plot", permission = "plots.clear", category = CommandCategory.ACTIONS, usage = "/plot clear [id]")
@ -45,34 +42,34 @@ public class Clear extends SubCommand {
public boolean onCommand(final PlotPlayer plr, final String... args) {
final Location loc = plr.getLocation();
final Plot plot;
if (args.length == 2) {
final PlotId id = PlotId.fromString(args[0]);
if (id == null) {
if (args[1].equalsIgnoreCase("mine")) {
final Set<Plot> plots = PS.get().getPlots(plr);
if (plots.size() == 0) {
MainUtil.sendMessage(plr, C.NO_PLOTS);
return false;
}
if (args.length == 1) {
if (args[0].equalsIgnoreCase("mine")) {
Set<Plot> plots = plr.getPlots();
if (plots.size() > 0) {
plot = plots.iterator().next();
} else {
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot clear [X;Z|mine]");
MainUtil.sendMessage(plr, C.NO_PLOTS);
return false;
}
} else {
plot = MainUtil.getPlotAbs(loc.getWorld(), id);
plot = MainUtil.getPlotFromString(plr, args[0], true);
}
if (plot == null) {
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot clear [X;Z|mine]");
return false;
}
} else if (args.length == 0) {
plot = MainUtil.getPlotAbs(loc);
if (plot == null) {
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot clear [X;Z|mine]");
C.NOT_IN_PLOT.send(plr);
return false;
}
} else {
plot = MainUtil.getPlotAbs(loc);
}
if (plot == null) {
MainUtil.sendMessage(plr, C.COMMAND_SYNTAX, "/plot clear [X;Z|mine]");
return sendMessage(plr, C.NOT_IN_PLOT);
return false;
}
// if (!MainUtil.getTopPlot(plot).equals(MainUtil.getBottomPlot(plot))) {
// return sendMessage(plr, C.UNLINK_REQUIRED);
// }
if (((plot == null) || !plot.hasOwner() || !plot.isOwner(plr.getUUID())) && !Permissions.hasPermission(plr, "plots.admin.command.clear")) {
if ((!plot.hasOwner() || !plot.isOwner(plr.getUUID())) && !Permissions.hasPermission(plr, "plots.admin.command.clear")) {
return sendMessage(plr, C.NO_PLOT_PERMS);
}
if (plot.getRunning() != 0) {

View File

@ -26,7 +26,6 @@ import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions;
import com.plotsquared.general.commands.Argument;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
@ -39,10 +38,6 @@ usage = "/plot copy <X;Z>",
requiredType = RequiredType.NONE)
public class Copy extends SubCommand {
public Copy() {
requiredArguments = new Argument[] { Argument.PlotID };
}
@Override
public boolean onCommand(final PlotPlayer plr, final String[] args) {
final Location loc = plr.getLocation();

View File

@ -26,12 +26,11 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.object.ConsolePlayer;
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.MainUtil;
import com.intellectualcrafters.plot.util.MathMan;
@ -205,65 +204,84 @@ public class MainCommand extends CommandManager<PlotPlayer> {
new HelpMenu(player).setCategory(catEnum).getCommands().generateMaxPages().generatePage(page, label).render();
}
public static boolean onCommand(final PlotPlayer player, final String cmd, String... args) {
// Clear perm caching //
player.deleteMeta("perm");
////////////////////////
int help_index = -1;
String category = null;
if (args.length == 0) {
help_index = 0;
} else if (StringMan.isEqualIgnoreCaseToAny(args[0], "he", "help", "?")) {
help_index = 0;
switch (args.length) {
case 3: {
category = args[1];
if (MathMan.isInteger(args[2])) {
try {
help_index = Integer.parseInt(args[2]);
} catch (final NumberFormatException e) {
help_index = 1;
}
}
break;
}
case 2: {
if (MathMan.isInteger(args[1])) {
category = null;
try {
help_index = Integer.parseInt(args[1]);
} catch (final NumberFormatException e) {
help_index = 1;
}
} else {
help_index = 1;
category = args[1];
String category = null;
Location loc = null;
switch (args.length) {
case 0: {
help_index = 0;
break;
}
case 1: {
if (MathMan.isInteger(args[0])) {
try {
help_index = Integer.parseInt(args[args.length - 1]);
} catch (final NumberFormatException e) {}
break;
}
}
} else if ((args.length == 1) && MathMan.isInteger(args[args.length - 1])) {
try {
help_index = Integer.parseInt(args[args.length - 1]);
} catch (final NumberFormatException e) {}
} else if (ConsolePlayer.isConsole(player) && (args.length >= 2)) {
final String[] split = args[0].split(";");
String world;
PlotId id;
if (split.length == 2) {
world = player.getLocation().getWorld();
id = PlotId.fromString(split[0] + ";" + split[1]);
} else if (split.length == 3) {
world = split[0];
id = PlotId.fromString(split[1] + ";" + split[2]);
} else {
id = null;
world = null;
}
if ((id != null) && PS.get().isPlotWorld(world)) {
final Plot plot = MainUtil.getPlotAbs(world, id);
if (plot != null) {
player.teleport(plot.getBottomAbs());
}
default: {
switch (args[0].toLowerCase()) {
case "he":
case "help":
case "?": {
switch (args.length) {
case 1: {
help_index = 0;
break;
}
case 2: {
if (MathMan.isInteger(args[1])) {
category = null;
try {
help_index = Integer.parseInt(args[1]);
} catch (final NumberFormatException e) {
help_index = 1;
}
} else {
help_index = 1;
category = args[1];
}
break;
}
case 3: {
category = args[1];
if (MathMan.isInteger(args[2])) {
try {
help_index = Integer.parseInt(args[2]);
} catch (final NumberFormatException e) {
help_index = 1;
}
}
break;
}
default: {
C.COMMAND_SYNTAX.send(player, "/" + cmd + "? [#|<term>|category [#]]");
return true;
}
}
break;
}
default: {
if (args.length >= 2) {
String world = player.getLocation().getWorld();
Plot plot = Plot.fromString(world, args[0]);
if (plot == null) {
break;
}
if (!ConsolePlayer.isConsole(player) && (!plot.world.equals(world) || plot.isDenied(player.getUUID())) && !Permissions.hasPermission(player, C.PERMISSION_ADMIN)) {
break;
}
loc = (Location) player.getMeta("location");
player.setMeta("location", plot.getBottomAbs());
args = Arrays.copyOfRange(args, 1, args.length);
}
}
}
}
}
}
if (help_index != -1) {
@ -274,6 +292,9 @@ public class MainCommand extends CommandManager<PlotPlayer> {
args[0] = args[0].replaceFirst(":", " ");
}
String fullCmd = StringMan.join(args, " ");
getInstance().handle(player, cmd + " " + fullCmd);
if (loc != null) {
player.setMeta("location", loc);
}
return true;
}
@ -320,9 +341,6 @@ public class MainCommand extends CommandManager<PlotPlayer> {
}
@Override
public int handle(final PlotPlayer plr, final String input) {
// Clear perm caching //
plr.deleteMeta("perm");
public int handle(final PlotPlayer plr, final String input) {
final String[] parts = input.split(" ");
String[] args;

View File

@ -26,7 +26,6 @@ import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions;
import com.plotsquared.general.commands.Argument;
import com.plotsquared.general.commands.CommandDeclaration;
@CommandDeclaration(
@ -39,10 +38,6 @@ category = CommandCategory.ACTIONS,
requiredType = RequiredType.NONE)
public class Move extends SubCommand {
public Move() {
requiredArguments = new Argument[] { Argument.PlotID };
}
@Override
public boolean onCommand(final PlotPlayer plr, final String[] args) {
final Location loc = plr.getLocation();