2016-02-23 05:11:28 +01:00
|
|
|
package com.intellectualcrafters.plot.commands;
|
|
|
|
|
2016-03-24 10:57:59 +01:00
|
|
|
import com.intellectualcrafters.plot.PS;
|
2016-02-23 05:11:28 +01:00
|
|
|
import com.intellectualcrafters.plot.config.C;
|
|
|
|
import com.intellectualcrafters.plot.object.ConsolePlayer;
|
2016-06-19 16:52:05 +02:00
|
|
|
import com.intellectualcrafters.plot.object.Expression;
|
2016-02-23 05:11:28 +01:00
|
|
|
import com.intellectualcrafters.plot.object.Location;
|
|
|
|
import com.intellectualcrafters.plot.object.Plot;
|
|
|
|
import com.intellectualcrafters.plot.object.PlotArea;
|
|
|
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
2016-03-24 10:57:59 +01:00
|
|
|
import com.intellectualcrafters.plot.object.RunnableVal2;
|
|
|
|
import com.intellectualcrafters.plot.object.RunnableVal3;
|
|
|
|
import com.intellectualcrafters.plot.util.CmdConfirm;
|
|
|
|
import com.intellectualcrafters.plot.util.EconHandler;
|
2016-02-23 05:11:28 +01:00
|
|
|
import com.intellectualcrafters.plot.util.Permissions;
|
|
|
|
import com.plotsquared.general.commands.Command;
|
2016-03-24 10:57:59 +01:00
|
|
|
import com.plotsquared.general.commands.CommandDeclaration;
|
2016-04-02 01:14:46 +02:00
|
|
|
|
2016-02-23 05:11:28 +01:00
|
|
|
import java.util.Arrays;
|
|
|
|
|
|
|
|
/**
|
2016-03-23 02:41:37 +01:00
|
|
|
* PlotSquared command class.
|
2016-02-23 05:11:28 +01:00
|
|
|
*/
|
2016-03-24 10:57:59 +01:00
|
|
|
@CommandDeclaration(
|
|
|
|
command = "plot",
|
|
|
|
aliases = {"plots", "p", "plotsquared", "plot2", "p2", "ps", "2", "plotme", "plotz", "ap"})
|
|
|
|
public class MainCommand extends Command {
|
|
|
|
|
2016-02-23 05:11:28 +01:00
|
|
|
private static MainCommand instance;
|
2016-03-26 06:44:38 +01:00
|
|
|
public Help help;
|
|
|
|
public Toggle toggle;
|
2016-03-13 19:09:48 +01:00
|
|
|
|
2016-02-23 05:11:28 +01:00
|
|
|
private MainCommand() {
|
2016-03-24 10:57:59 +01:00
|
|
|
super(null, true);
|
2016-02-23 05:11:28 +01:00
|
|
|
instance = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static MainCommand getInstance() {
|
|
|
|
if (instance == null) {
|
|
|
|
instance = new MainCommand();
|
2016-03-24 10:57:59 +01:00
|
|
|
new Buy();
|
|
|
|
new Save();
|
|
|
|
new Load();
|
|
|
|
new Confirm();
|
|
|
|
new Template();
|
|
|
|
new Download();
|
|
|
|
new Update();
|
|
|
|
new Template();
|
|
|
|
new Setup();
|
|
|
|
new Area();
|
|
|
|
new DebugSaveTest();
|
|
|
|
new DebugLoadTest();
|
|
|
|
new CreateRoadSchematic();
|
|
|
|
new DebugAllowUnsafe();
|
|
|
|
new RegenAllRoads();
|
|
|
|
new Claim();
|
|
|
|
new Auto();
|
|
|
|
new Visit();
|
|
|
|
new Set();
|
|
|
|
new Clear();
|
|
|
|
new Delete();
|
|
|
|
new Trust();
|
|
|
|
new Add();
|
|
|
|
new Deny();
|
|
|
|
new Remove();
|
|
|
|
new Info();
|
2016-09-25 10:06:20 +02:00
|
|
|
new Near();
|
2016-03-24 10:57:59 +01:00
|
|
|
new ListCmd();
|
|
|
|
new Debug();
|
|
|
|
new SchematicCmd();
|
|
|
|
new PluginCmd();
|
|
|
|
new Purge();
|
|
|
|
new Reload();
|
2016-03-29 19:34:48 +02:00
|
|
|
new Relight();
|
2016-03-24 10:57:59 +01:00
|
|
|
new Merge();
|
|
|
|
new DebugPaste();
|
|
|
|
new Unlink();
|
|
|
|
new Kick();
|
|
|
|
new Rate();
|
|
|
|
new DebugClaimTest();
|
|
|
|
new Inbox();
|
|
|
|
new Comment();
|
|
|
|
new Database();
|
|
|
|
new Swap();
|
|
|
|
new Music();
|
|
|
|
new DebugRoadRegen();
|
|
|
|
new Trust();
|
|
|
|
new DebugExec();
|
|
|
|
new FlagCmd();
|
|
|
|
new Target();
|
|
|
|
new DebugFixFlags();
|
|
|
|
new Move();
|
|
|
|
new Condense();
|
|
|
|
new Condense();
|
|
|
|
new Copy();
|
|
|
|
new Chat();
|
|
|
|
new Trim();
|
|
|
|
new Done();
|
|
|
|
new Continue();
|
|
|
|
new BO3();
|
|
|
|
new Middle();
|
|
|
|
new Grant();
|
2016-03-26 06:44:38 +01:00
|
|
|
// Set commands
|
2016-03-24 10:57:59 +01:00
|
|
|
new Owner();
|
|
|
|
new Desc();
|
|
|
|
new Biome();
|
|
|
|
new Alias();
|
|
|
|
new SetHome();
|
|
|
|
new Cluster();
|
2016-03-26 06:44:38 +01:00
|
|
|
// Referenced commands
|
|
|
|
instance.toggle = new Toggle();
|
|
|
|
instance.help = new Help(instance);
|
2016-02-23 05:11:28 +01:00
|
|
|
}
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
2016-03-24 10:57:59 +01:00
|
|
|
public static boolean onCommand(final PlotPlayer player, String... args) {
|
|
|
|
if (args.length >= 1 && args[0].contains(":")) {
|
|
|
|
String[] split2 = args[0].split(":");
|
|
|
|
if (split2.length == 2) {
|
|
|
|
// Ref: c:v, this will push value to the last spot in the array
|
|
|
|
// ex. /p h:2 SomeUsername
|
|
|
|
// > /p h SomeUsername 2
|
|
|
|
String[] tmp = new String[args.length + 1];
|
|
|
|
tmp[0] = split2[0];
|
|
|
|
tmp[args.length] = split2[1];
|
2016-03-28 14:04:08 +02:00
|
|
|
if (args.length >= 2) {
|
2016-03-24 10:57:59 +01:00
|
|
|
System.arraycopy(args, 1, tmp, 1, args.length - 1);
|
|
|
|
}
|
|
|
|
args = tmp;
|
2016-02-23 05:11:28 +01:00
|
|
|
}
|
|
|
|
}
|
2016-05-21 21:29:19 +02:00
|
|
|
try {
|
|
|
|
getInstance().execute(player, args, new RunnableVal3<Command, Runnable, Runnable>() {
|
|
|
|
@Override
|
|
|
|
public void run(final Command cmd, final Runnable success, final Runnable failure) {
|
|
|
|
if (cmd.hasConfirmation(player)) {
|
|
|
|
CmdConfirm.addPending(player, cmd.getUsage(), new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
if (EconHandler.manager != null) {
|
|
|
|
PlotArea area = player.getApplicablePlotArea();
|
|
|
|
if (area != null) {
|
2016-06-21 05:32:28 +02:00
|
|
|
Expression<Double> priceEval = area.PRICES.get(cmd.getFullId());
|
2016-07-17 04:51:49 +02:00
|
|
|
Double price = priceEval != null ? priceEval.evaluate(0d) : 0d;
|
2016-05-21 21:29:19 +02:00
|
|
|
if (price != null && EconHandler.manager.getMoney(player) < price) {
|
|
|
|
if (failure != null) {
|
|
|
|
failure.run();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2016-03-24 10:57:59 +01:00
|
|
|
}
|
|
|
|
}
|
2016-05-21 21:29:19 +02:00
|
|
|
if (success != null) {
|
|
|
|
success.run();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (EconHandler.manager != null) {
|
|
|
|
PlotArea area = player.getApplicablePlotArea();
|
|
|
|
if (area != null) {
|
2016-06-19 16:52:05 +02:00
|
|
|
Expression<Double> priceEval = area.PRICES.get(cmd.getFullId());
|
2016-07-17 04:51:49 +02:00
|
|
|
Double price = priceEval != null ? priceEval.evaluate(0d) : 0d;
|
2016-06-19 16:52:05 +02:00
|
|
|
if (price != 0d && EconHandler.manager.getMoney(player) < price) {
|
2016-05-21 21:29:19 +02:00
|
|
|
if (failure != null) {
|
|
|
|
failure.run();
|
|
|
|
}
|
|
|
|
return;
|
2016-03-24 10:57:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-05-21 21:29:19 +02:00
|
|
|
if (success != null) {
|
|
|
|
success.run();
|
|
|
|
}
|
2016-02-23 05:11:28 +01:00
|
|
|
}
|
2016-05-21 21:29:19 +02:00
|
|
|
}, new RunnableVal2<Command, CommandResult>() {
|
|
|
|
@Override
|
|
|
|
public void run(Command cmd, CommandResult result) {
|
|
|
|
// Post command stuff!?
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} catch (CommandException e) {
|
|
|
|
e.perform(player);
|
|
|
|
}
|
2016-03-24 10:57:59 +01:00
|
|
|
// Always true
|
|
|
|
return true;
|
2016-02-23 05:11:28 +01:00
|
|
|
}
|
2016-03-22 18:53:17 +01:00
|
|
|
|
2016-04-02 01:14:46 +02:00
|
|
|
@Deprecated
|
|
|
|
/**
|
|
|
|
* @Deprecated legacy
|
|
|
|
*/
|
|
|
|
public void addCommand(SubCommand command) {
|
|
|
|
PS.debug("Command registration is now done during instantiation");
|
|
|
|
}
|
|
|
|
|
2016-03-24 10:57:59 +01:00
|
|
|
@Override
|
2016-10-14 06:14:08 +02:00
|
|
|
public void execute(final PlotPlayer player, String[] args, RunnableVal3<Command, Runnable, Runnable> confirm, RunnableVal2<Command, CommandResult> whenDone) {
|
2016-02-23 05:11:28 +01:00
|
|
|
// Clear perm caching //
|
|
|
|
player.deleteMeta("perm");
|
2016-03-24 10:57:59 +01:00
|
|
|
// Optional command scope //
|
2016-02-23 05:11:28 +01:00
|
|
|
Location loc = null;
|
|
|
|
Plot plot = null;
|
|
|
|
boolean tp = false;
|
2016-03-24 10:57:59 +01:00
|
|
|
if (args.length >= 2) {
|
|
|
|
PlotArea area = player.getApplicablePlotArea();
|
|
|
|
Plot newPlot = Plot.fromString(area, args[0]);
|
2016-05-21 21:29:19 +02:00
|
|
|
if (newPlot != null && (player instanceof ConsolePlayer || newPlot.getArea().equals(area) || Permissions.hasPermission(player, C.PERMISSION_ADMIN)) && !newPlot.isDenied(player.getUUID())) {
|
2016-06-20 19:02:41 +02:00
|
|
|
Location newLoc = newPlot.getCenter();
|
|
|
|
if (player.canTeleport(newLoc)) {
|
|
|
|
// Save meta
|
|
|
|
loc = player.getMeta("location");
|
|
|
|
plot = player.getMeta("lastplot");
|
|
|
|
tp = true;
|
|
|
|
// Set loc
|
|
|
|
player.setMeta("location", newLoc);
|
|
|
|
player.setMeta("lastplot", newPlot);
|
|
|
|
} else {
|
|
|
|
C.BORDER.send(player);
|
|
|
|
}
|
2016-03-24 10:57:59 +01:00
|
|
|
// Trim command
|
|
|
|
args = Arrays.copyOfRange(args, 1, args.length);
|
2016-02-23 05:11:28 +01:00
|
|
|
}
|
2016-12-09 22:58:32 +01:00
|
|
|
if (args.length >= 2 && !args[0].isEmpty() && args[0].charAt(0) == '-') {
|
2016-10-14 06:14:08 +02:00
|
|
|
switch (args[0].substring(1)) {
|
|
|
|
case "f":
|
|
|
|
confirm = new RunnableVal3<Command, Runnable, Runnable>() {
|
|
|
|
@Override
|
2016-12-09 22:58:32 +01:00
|
|
|
public void run(Command cmd, Runnable success, Runnable failure) {
|
2016-10-14 06:14:08 +02:00
|
|
|
if (EconHandler.manager != null) {
|
|
|
|
PlotArea area = player.getApplicablePlotArea();
|
|
|
|
if (area != null) {
|
|
|
|
Expression<Double> priceEval = area.PRICES.get(cmd.getFullId());
|
|
|
|
Double price = priceEval != null ? priceEval.evaluate(0d) : 0d;
|
|
|
|
if (price != 0d && EconHandler.manager.getMoney(player) < price) {
|
|
|
|
if (failure != null) {
|
|
|
|
failure.run();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (success != null) {
|
|
|
|
success.run();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
args = Arrays.copyOfRange(args, 1, args.length);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
C.INVALID_COMMAND_FLAG.send(player);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2016-02-23 05:11:28 +01:00
|
|
|
}
|
2016-06-28 11:55:51 +02:00
|
|
|
try {
|
|
|
|
super.execute(player, args, confirm, whenDone);
|
2016-06-29 13:22:55 +02:00
|
|
|
} catch (CommandException e) {
|
|
|
|
throw e;
|
2016-06-28 11:55:51 +02:00
|
|
|
} catch (Throwable e) {
|
|
|
|
e.printStackTrace();
|
2016-06-29 13:22:55 +02:00
|
|
|
String message = e.getLocalizedMessage();
|
|
|
|
if (message != null) {
|
|
|
|
C.ERROR.send(player, message);
|
|
|
|
} else {
|
|
|
|
C.ERROR.send(player);
|
|
|
|
}
|
2016-06-28 11:55:51 +02:00
|
|
|
}
|
2016-03-24 10:57:59 +01:00
|
|
|
// Reset command scope //
|
2016-05-21 21:29:19 +02:00
|
|
|
if (tp && !(player instanceof ConsolePlayer)) {
|
2016-02-23 05:11:28 +01:00
|
|
|
if (loc == null) {
|
|
|
|
player.deleteMeta("location");
|
|
|
|
} else {
|
|
|
|
player.setMeta("location", loc);
|
|
|
|
}
|
|
|
|
if (plot == null) {
|
|
|
|
player.deleteMeta("lastplot");
|
|
|
|
} else {
|
|
|
|
player.setMeta("lastplot", plot);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-03-22 18:53:17 +01:00
|
|
|
|
2016-02-23 05:11:28 +01:00
|
|
|
@Override
|
2016-03-26 17:34:55 +01:00
|
|
|
public boolean canExecute(PlotPlayer player, boolean message) {
|
2016-03-24 10:57:59 +01:00
|
|
|
return true;
|
2016-02-23 05:11:28 +01:00
|
|
|
}
|
|
|
|
}
|