2020-04-16 04:52:39 +02:00
|
|
|
/*
|
|
|
|
* _____ _ _ _____ _
|
|
|
|
* | __ \| | | | / ____| | |
|
|
|
|
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
|
|
|
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
|
|
|
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
|
|
|
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
|
|
|
* | |
|
|
|
|
* |_|
|
|
|
|
* PlotSquared plot management system for Minecraft
|
|
|
|
* Copyright (C) 2020 IntellectualSites
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2020-04-15 21:26:54 +02:00
|
|
|
package com.plotsquared.core.command;
|
2016-02-23 05:11:28 +01:00
|
|
|
|
2020-07-11 17:19:19 +02:00
|
|
|
import com.google.inject.Injector;
|
2020-07-10 17:32:07 +02:00
|
|
|
import com.plotsquared.core.PlotSquared;
|
2020-04-16 06:14:33 +02:00
|
|
|
import com.plotsquared.core.configuration.Captions;
|
|
|
|
import com.plotsquared.core.configuration.Settings;
|
2020-07-10 19:25:05 +02:00
|
|
|
import com.plotsquared.core.configuration.file.YamlConfiguration;
|
2020-07-10 18:17:44 +02:00
|
|
|
import com.plotsquared.core.listener.PlotListener;
|
2020-04-15 21:26:54 +02:00
|
|
|
import com.plotsquared.core.location.Location;
|
2020-04-30 12:33:59 +02:00
|
|
|
import com.plotsquared.core.player.ConsolePlayer;
|
|
|
|
import com.plotsquared.core.player.PlotPlayer;
|
2020-04-15 21:26:54 +02:00
|
|
|
import com.plotsquared.core.plot.Plot;
|
|
|
|
import com.plotsquared.core.plot.PlotArea;
|
2020-07-10 17:32:07 +02:00
|
|
|
import com.plotsquared.core.plot.world.PlotAreaManager;
|
2020-04-15 21:26:54 +02:00
|
|
|
import com.plotsquared.core.util.EconHandler;
|
2020-07-10 18:17:44 +02:00
|
|
|
import com.plotsquared.core.util.EventDispatcher;
|
2020-04-30 12:33:59 +02:00
|
|
|
import com.plotsquared.core.util.Expression;
|
2020-04-15 21:26:54 +02:00
|
|
|
import com.plotsquared.core.util.Permissions;
|
2020-04-30 12:33:59 +02:00
|
|
|
import com.plotsquared.core.util.task.RunnableVal2;
|
|
|
|
import com.plotsquared.core.util.task.RunnableVal3;
|
2020-07-10 19:25:05 +02:00
|
|
|
import com.sk89q.worldedit.WorldEdit;
|
2016-04-02 01:14:46 +02:00
|
|
|
|
2020-07-10 19:25:05 +02:00
|
|
|
import java.io.File;
|
2016-02-23 05:11:28 +01:00
|
|
|
import java.util.Arrays;
|
2020-07-11 17:19:19 +02:00
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.List;
|
2019-01-21 09:20:33 +01:00
|
|
|
import java.util.concurrent.CompletableFuture;
|
2016-02-23 05:11:28 +01:00
|
|
|
|
|
|
|
/**
|
2016-03-23 02:41:37 +01:00
|
|
|
* PlotSquared command class.
|
2016-02-23 05:11:28 +01:00
|
|
|
*/
|
2018-12-26 18:21:06 +01:00
|
|
|
@CommandDeclaration(command = "plot",
|
|
|
|
aliases = {"plots", "p", "plotsquared", "plot2", "p2", "ps", "2", "plotme", "plotz", "ap"})
|
|
|
|
public class MainCommand extends Command {
|
2018-08-10 17:01:10 +02:00
|
|
|
|
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();
|
2020-07-10 18:17:44 +02:00
|
|
|
|
2020-07-12 07:38:57 +02:00
|
|
|
final Injector injector = PlotSquared.platform().getInjector();
|
2020-07-11 17:19:19 +02:00
|
|
|
final List<Class<? extends Command>> commands = new LinkedList<>();
|
|
|
|
commands.add(Caps.class);
|
|
|
|
commands.add(Buy.class);
|
|
|
|
commands.add(Save.class);
|
|
|
|
commands.add(Load.class);
|
|
|
|
commands.add(Confirm.class);
|
|
|
|
commands.add(Template.class);
|
|
|
|
commands.add(Download.class);
|
|
|
|
commands.add(Setup.class);
|
|
|
|
commands.add(Area.class);
|
|
|
|
commands.add(DebugSaveTest.class);
|
|
|
|
commands.add(DebugLoadTest.class);
|
|
|
|
commands.add(CreateRoadSchematic.class);
|
|
|
|
commands.add(DebugAllowUnsafe.class);
|
|
|
|
commands.add(RegenAllRoads.class);
|
|
|
|
commands.add(Claim.class);
|
|
|
|
commands.add(Auto.class);
|
|
|
|
commands.add(HomeCommand.class);
|
|
|
|
commands.add(Visit.class);
|
|
|
|
commands.add(Set.class);
|
|
|
|
commands.add(Clear.class);
|
|
|
|
commands.add(Delete.class);
|
|
|
|
commands.add(Trust.class);
|
|
|
|
commands.add(Add.class);
|
|
|
|
commands.add(Leave.class);
|
|
|
|
commands.add(Deny.class);
|
|
|
|
commands.add(Remove.class);
|
|
|
|
commands.add(Info.class);
|
|
|
|
commands.add(Near.class);
|
|
|
|
commands.add(ListCmd.class);
|
|
|
|
commands.add(Debug.class);
|
|
|
|
commands.add(SchematicCmd.class);
|
|
|
|
commands.add(PluginCmd.class);
|
|
|
|
commands.add(Purge.class);
|
|
|
|
commands.add(Reload.class);
|
|
|
|
commands.add(Relight.class);
|
|
|
|
commands.add(Merge.class);
|
|
|
|
commands.add(DebugPaste.class);
|
|
|
|
commands.add(Unlink.class);
|
|
|
|
commands.add(Kick.class);
|
|
|
|
commands.add(Inbox.class);
|
|
|
|
commands.add(Comment.class);
|
|
|
|
commands.add(DatabaseCommand.class);
|
|
|
|
commands.add(Swap.class);
|
|
|
|
commands.add(Music.class);
|
|
|
|
commands.add(DebugRoadRegen.class);
|
|
|
|
commands.add(DebugExec.class);
|
|
|
|
commands.add(FlagCommand.class);
|
|
|
|
commands.add(Target.class);
|
|
|
|
commands.add(Move.class);
|
|
|
|
commands.add(Condense.class);
|
|
|
|
commands.add(Copy.class);
|
|
|
|
commands.add(Chat.class);
|
|
|
|
commands.add(Trim.class);
|
|
|
|
commands.add(Done.class);
|
|
|
|
commands.add(Continue.class);
|
|
|
|
commands.add(Middle.class);
|
|
|
|
commands.add(Grant.class);
|
|
|
|
commands.add(Owner.class);
|
|
|
|
commands.add(Desc.class);
|
|
|
|
commands.add(Biome.class);
|
|
|
|
commands.add(Alias.class);
|
|
|
|
commands.add(SetHome.class);
|
|
|
|
commands.add(Cluster.class);
|
|
|
|
commands.add(DebugImportWorlds.class);
|
|
|
|
commands.add(Backup.class);
|
2019-04-01 17:39:28 +02:00
|
|
|
|
|
|
|
if (Settings.Ratings.USE_LIKES) {
|
2020-07-11 17:19:19 +02:00
|
|
|
commands.add(Like.class);
|
|
|
|
commands.add(Dislike.class);
|
2019-04-01 17:39:28 +02:00
|
|
|
} else {
|
2020-07-11 17:19:19 +02:00
|
|
|
commands.add(Rate.class);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (final Class<? extends Command> command : commands) {
|
|
|
|
injector.getInstance(command);
|
2019-04-01 17:39:28 +02:00
|
|
|
}
|
|
|
|
|
2016-03-26 06:44:38 +01:00
|
|
|
// Referenced commands
|
2020-07-11 17:19:19 +02:00
|
|
|
instance.toggle = injector.getInstance(Toggle.class);
|
|
|
|
instance.help = injector.getInstance(Help.class);
|
2016-02-23 05:11:28 +01:00
|
|
|
}
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
2020-07-10 17:32:07 +02:00
|
|
|
public static boolean onCommand(final PlotPlayer<?> player, String... args) {
|
2016-03-24 10:57:59 +01:00
|
|
|
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)) {
|
2019-03-06 18:47:38 +01:00
|
|
|
CmdConfirm.addPending(player, cmd.getUsage(), () -> {
|
2020-06-24 15:26:06 +02:00
|
|
|
if (EconHandler.getEconHandler() != null) {
|
2019-03-06 18:47:38 +01:00
|
|
|
PlotArea area = player.getApplicablePlotArea();
|
|
|
|
if (area != null) {
|
2020-04-30 12:33:59 +02:00
|
|
|
Expression<Double> priceEval =
|
|
|
|
area.getPrices().get(cmd.getFullId());
|
2019-03-06 18:47:38 +01:00
|
|
|
Double price = priceEval != null ? priceEval.evaluate(0d) : 0d;
|
|
|
|
if (price != null
|
2020-06-24 15:26:06 +02:00
|
|
|
&& EconHandler.getEconHandler().getMoney(player) < price) {
|
2019-03-06 18:47:38 +01:00
|
|
|
if (failure != null) {
|
|
|
|
failure.run();
|
2016-05-21 21:29:19 +02:00
|
|
|
}
|
2019-03-06 18:47:38 +01:00
|
|
|
return;
|
2016-03-24 10:57:59 +01:00
|
|
|
}
|
|
|
|
}
|
2019-03-06 18:47:38 +01:00
|
|
|
}
|
|
|
|
if (success != null) {
|
|
|
|
success.run();
|
2016-05-21 21:29:19 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
2020-06-24 15:26:06 +02:00
|
|
|
if (EconHandler.getEconHandler() != null) {
|
2016-05-21 21:29:19 +02:00
|
|
|
PlotArea area = player.getApplicablePlotArea();
|
|
|
|
if (area != null) {
|
2020-04-02 14:34:38 +02:00
|
|
|
Expression<Double> priceEval = area.getPrices().get(cmd.getFullId());
|
2016-07-17 04:51:49 +02:00
|
|
|
Double price = priceEval != null ? priceEval.evaluate(0d) : 0d;
|
2020-06-24 15:26:06 +02:00
|
|
|
if (price != 0d && EconHandler.getEconHandler().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>() {
|
2018-08-10 17:01:10 +02:00
|
|
|
@Override public void run(Command cmd, CommandResult result) {
|
2016-05-21 21:29:19 +02:00
|
|
|
// Post command stuff!?
|
|
|
|
}
|
2019-01-21 09:20:33 +01:00
|
|
|
}).thenAccept(result -> {
|
|
|
|
// TODO: Something with the command result
|
2016-05-21 21:29:19 +02:00
|
|
|
});
|
|
|
|
} 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
|
|
|
|
2020-04-30 12:33:59 +02:00
|
|
|
@Override
|
2020-05-27 14:08:48 +02:00
|
|
|
public CompletableFuture<Boolean> execute(final PlotPlayer<?> player, String[] args,
|
2018-08-10 17:01:10 +02:00
|
|
|
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 //
|
2019-09-08 20:02:45 +02:00
|
|
|
Location location = null;
|
2016-02-23 05:11:28 +01:00
|
|
|
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]);
|
2018-08-10 17:01:10 +02:00
|
|
|
if (newPlot != null && (player instanceof ConsolePlayer || newPlot.getArea()
|
2020-02-24 18:42:02 +01:00
|
|
|
.equals(area) || Permissions.hasPermission(player, Captions.PERMISSION_ADMIN)
|
|
|
|
|| Permissions.hasPermission(player, Captions.PERMISSION_ADMIN_SUDO_AREA))
|
2019-04-24 00:48:22 +02:00
|
|
|
&& !newPlot.isDenied(player.getUUID())) {
|
2020-04-07 20:19:39 +02:00
|
|
|
Location newLoc = newPlot.getCenterSynchronous();
|
2016-06-20 19:02:41 +02:00
|
|
|
if (player.canTeleport(newLoc)) {
|
|
|
|
// Save meta
|
2019-09-08 20:02:45 +02:00
|
|
|
location = player.getMeta(PlotPlayer.META_LOCATION);
|
2018-11-14 23:51:56 +01:00
|
|
|
plot = player.getMeta(PlotPlayer.META_LAST_PLOT);
|
2016-06-20 19:02:41 +02:00
|
|
|
tp = true;
|
|
|
|
// Set loc
|
2018-11-14 23:51:56 +01:00
|
|
|
player.setMeta(PlotPlayer.META_LOCATION, newLoc);
|
|
|
|
player.setMeta(PlotPlayer.META_LAST_PLOT, newPlot);
|
2016-06-20 19:02:41 +02:00
|
|
|
} else {
|
2019-02-22 17:51:06 +01:00
|
|
|
Captions.BORDER.send(player);
|
2016-06-20 19:02:41 +02:00
|
|
|
}
|
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) == '-') {
|
2019-01-21 09:20:33 +01:00
|
|
|
if ("f".equals(args[0].substring(1))) {
|
|
|
|
confirm = new RunnableVal3<Command, Runnable, Runnable>() {
|
|
|
|
@Override public void run(Command cmd, Runnable success, Runnable failure) {
|
2020-06-24 15:26:06 +02:00
|
|
|
if (EconHandler.getEconHandler() != null) {
|
2019-01-21 09:20:33 +01:00
|
|
|
PlotArea area = player.getApplicablePlotArea();
|
|
|
|
if (area != null) {
|
2020-04-30 12:33:59 +02:00
|
|
|
Expression<Double> priceEval =
|
|
|
|
area.getPrices().get(cmd.getFullId());
|
2019-01-21 09:20:33 +01:00
|
|
|
Double price = priceEval != null ? priceEval.evaluate(0d) : 0d;
|
|
|
|
if (price != 0d
|
2020-06-24 15:26:06 +02:00
|
|
|
&& EconHandler.getEconHandler().getMoney(player) < price) {
|
2019-01-21 09:20:33 +01:00
|
|
|
if (failure != null) {
|
|
|
|
failure.run();
|
2016-10-14 06:14:08 +02:00
|
|
|
}
|
2019-01-21 09:20:33 +01:00
|
|
|
return;
|
2016-10-14 06:14:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-01-21 09:20:33 +01:00
|
|
|
if (success != null) {
|
|
|
|
success.run();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
args = Arrays.copyOfRange(args, 1, args.length);
|
|
|
|
} else {
|
|
|
|
Captions.INVALID_COMMAND_FLAG.send(player);
|
|
|
|
return CompletableFuture.completedFuture(false);
|
2016-10-14 06:14:08 +02:00
|
|
|
}
|
|
|
|
}
|
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) {
|
2019-02-22 17:51:06 +01:00
|
|
|
Captions.ERROR.send(player, message);
|
2016-06-29 13:22:55 +02:00
|
|
|
} else {
|
2019-02-22 17:51:06 +01:00
|
|
|
Captions.ERROR.send(player);
|
2016-06-29 13:22:55 +02:00
|
|
|
}
|
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)) {
|
2019-09-08 20:02:45 +02:00
|
|
|
if (location == null) {
|
2018-11-14 23:51:56 +01:00
|
|
|
player.deleteMeta(PlotPlayer.META_LOCATION);
|
2016-02-23 05:11:28 +01:00
|
|
|
} else {
|
2019-09-08 20:02:45 +02:00
|
|
|
player.setMeta(PlotPlayer.META_LOCATION, location);
|
2016-02-23 05:11:28 +01:00
|
|
|
}
|
|
|
|
if (plot == null) {
|
2018-11-14 23:51:56 +01:00
|
|
|
player.deleteMeta(PlotPlayer.META_LAST_PLOT);
|
2016-02-23 05:11:28 +01:00
|
|
|
} else {
|
2018-11-14 23:51:56 +01:00
|
|
|
player.setMeta(PlotPlayer.META_LAST_PLOT, plot);
|
2016-02-23 05:11:28 +01:00
|
|
|
}
|
|
|
|
}
|
2019-01-21 09:20:33 +01:00
|
|
|
return CompletableFuture.completedFuture(true);
|
2016-02-23 05:11:28 +01:00
|
|
|
}
|
2016-03-22 18:53:17 +01:00
|
|
|
|
2020-02-20 16:03:17 +01:00
|
|
|
@Override 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
|
|
|
}
|
|
|
|
}
|