PlotSquared/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugExec.java

476 lines
23 KiB
Java
Raw Normal View History

package com.github.intellectualsites.plotsquared.plot.commands;
2015-01-24 01:00:57 +01:00
2019-11-04 20:55:55 +01:00
import com.github.intellectualsites.plotsquared.plot.util.block.BlockUtil;
import com.github.intellectualsites.plotsquared.commands.Command;
import com.github.intellectualsites.plotsquared.commands.CommandDeclaration;
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
import com.github.intellectualsites.plotsquared.plot.config.Captions;
import com.github.intellectualsites.plotsquared.plot.config.Settings;
import com.github.intellectualsites.plotsquared.plot.database.DBFunc;
import com.github.intellectualsites.plotsquared.plot.flag.Flag;
import com.github.intellectualsites.plotsquared.plot.flag.FlagManager;
import com.github.intellectualsites.plotsquared.plot.generator.HybridUtils;
import com.github.intellectualsites.plotsquared.plot.listener.WEManager;
2019-11-04 18:44:23 +01:00
import com.github.intellectualsites.plotsquared.plot.object.ConsolePlayer;
import com.github.intellectualsites.plotsquared.plot.object.Location;
import com.github.intellectualsites.plotsquared.plot.object.OfflinePlotPlayer;
import com.github.intellectualsites.plotsquared.plot.object.Plot;
import com.github.intellectualsites.plotsquared.plot.object.PlotArea;
2019-11-04 20:55:55 +01:00
import com.sk89q.worldedit.world.block.BlockState;
2019-11-04 18:44:23 +01:00
import com.github.intellectualsites.plotsquared.plot.object.PlotId;
import com.github.intellectualsites.plotsquared.plot.object.PlotMessage;
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
import com.github.intellectualsites.plotsquared.plot.object.RunnableVal;
import com.github.intellectualsites.plotsquared.plot.object.RunnableVal2;
import com.github.intellectualsites.plotsquared.plot.object.RunnableVal3;
import com.github.intellectualsites.plotsquared.plot.util.ChunkManager;
import com.github.intellectualsites.plotsquared.plot.util.EconHandler;
import com.github.intellectualsites.plotsquared.plot.util.EventUtil;
import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
import com.github.intellectualsites.plotsquared.plot.util.MathMan;
import com.github.intellectualsites.plotsquared.plot.util.SchematicHandler;
import com.github.intellectualsites.plotsquared.plot.util.SetupUtils;
import com.github.intellectualsites.plotsquared.plot.util.StringMan;
import com.github.intellectualsites.plotsquared.plot.util.TaskManager;
import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler;
import com.github.intellectualsites.plotsquared.plot.util.WorldUtil;
import com.github.intellectualsites.plotsquared.plot.util.block.GlobalBlockQueue;
import com.github.intellectualsites.plotsquared.plot.util.expiry.ExpireManager;
import com.github.intellectualsites.plotsquared.plot.util.expiry.PlotAnalysis;
import com.google.common.io.Files;
2018-08-10 17:01:10 +02:00
import javax.script.Bindings;
import javax.script.ScriptContext;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import javax.script.SimpleScriptContext;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.sql.Timestamp;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@CommandDeclaration(command = "debugexec", permission = "plots.admin",
description = "Mutli-purpose debug command", aliases = {"exec", "$"},
category = CommandCategory.DEBUG) public class DebugExec extends SubCommand {
private ScriptEngine engine;
private Bindings scope;
2016-03-22 18:53:17 +01:00
2015-09-13 06:04:31 +02:00
public DebugExec() {
init();
/*
2015-09-13 06:04:31 +02:00
try {
if (PlotSquared.get() != null) {
File file = new File(PlotSquared.get().IMP.getDirectory(),
2018-08-10 17:01:10 +02:00
Settings.Paths.SCRIPTS + File.separator + "start.js");
if (file.exists()) {
init();
2018-08-10 17:01:10 +02:00
String script = StringMan.join(Files.readLines(new File(new File(
Merge branch 'master' into breaking # Conflicts: # Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/events/PlotRateEvent.java # Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEventUtil.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotSquared.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Add.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Auto.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Delete.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Kick.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Load.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Music.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Owner.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Rate.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Reload.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/SchematicCmd.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Trust.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/GameModeFlag.java # Core/src/main/java/com/intellectualcrafters/plot/commands/Clear.java # Core/src/main/java/com/intellectualcrafters/plot/commands/PluginCmd.java # Core/src/main/java/com/intellectualcrafters/plot/commands/Relight.java # Core/src/main/java/com/intellectualcrafters/plot/commands/SetHome.java # Core/src/main/java/com/intellectualcrafters/plot/config/C.java # Core/src/main/java/com/intellectualcrafters/plot/config/Configuration.java # Core/src/main/java/com/intellectualcrafters/plot/config/Settings.java # Core/src/test/java/com/github/intellectualsites/plotsquared/plot/util/EventUtilTest.java # Nukkit/src/main/java/com/plotsquared/nukkit/util/NukkitEventUtil.java # README.md # Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/events/PlotRateEvent.java # Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/util/SpongeSchematicHandler.java # Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/util/block/SpongeLocalQueue.java # Sponge/src/main/java/com/plotsquared/sponge/util/SpongeEventUtil.java
2018-11-14 15:44:07 +01:00
PlotSquared.get().IMP.getDirectory() + File.separator
+ Settings.Paths.SCRIPTS), "start.js"), StandardCharsets.UTF_8),
System.getProperty("line.separator"));
2016-03-23 02:41:37 +01:00
this.scope.put("THIS", this);
this.scope.put("PlotPlayer", ConsolePlayer.getConsole());
this.engine.eval(script, this.scope);
}
}
2018-12-27 17:29:35 +01:00
} catch (IOException | ScriptException ignored) {
ignored.printStackTrace();
2016-06-18 08:29:51 +02:00
}
*/
}
2016-03-22 18:53:17 +01:00
2015-09-13 06:04:31 +02:00
public ScriptEngine getEngine() {
2016-06-24 07:41:27 +02:00
if (this.engine == null) {
init();
}
2016-03-23 02:41:37 +01:00
return this.engine;
2015-08-14 00:52:31 +02:00
}
2016-03-22 18:53:17 +01:00
2015-09-13 06:04:31 +02:00
public Bindings getScope() {
2016-03-23 02:41:37 +01:00
return this.scope;
2015-08-14 00:52:31 +02:00
}
2016-03-22 18:53:17 +01:00
2015-09-13 06:04:31 +02:00
public void init() {
2016-03-23 02:41:37 +01:00
if (this.engine != null) {
2015-09-13 06:04:31 +02:00
return;
}
//create script engine manager
ScriptEngineManager scriptEngineManager = new ScriptEngineManager();
//create nashorn engine
this.engine = scriptEngineManager.getEngineByName("nashorn");
try {
engine.eval("print('PlotSquared Scripting Test');");
} catch (ScriptException e) {
e.printStackTrace();
}
2016-03-23 02:41:37 +01:00
if (this.engine == null) {
this.engine = new ScriptEngineManager(null).getEngineByName("JavaScript");
}
2016-03-23 02:41:37 +01:00
ScriptContext context = new SimpleScriptContext();
this.scope = context.getBindings(ScriptContext.ENGINE_SCOPE);
2016-03-22 18:53:17 +01:00
// stuff
2016-03-23 02:41:37 +01:00
this.scope.put("MainUtil", new MainUtil());
this.scope.put("Settings", new Settings());
this.scope.put("StringMan", new StringMan());
this.scope.put("MathMan", new MathMan());
this.scope.put("FlagManager", new FlagManager());
2016-03-22 18:53:17 +01:00
// Classes
2016-03-23 02:41:37 +01:00
this.scope.put("Location", Location.class);
2019-11-04 20:55:55 +01:00
this.scope.put("BlockState", BlockState.class);
2016-03-23 02:41:37 +01:00
this.scope.put("Plot", Plot.class);
this.scope.put("PlotId", PlotId.class);
this.scope.put("Runnable", Runnable.class);
this.scope.put("RunnableVal", RunnableVal.class);
2016-03-22 18:53:17 +01:00
// Instances
this.scope.put("PS", PlotSquared.get());
2016-06-13 06:47:50 +02:00
this.scope.put("GlobalBlockQueue", GlobalBlockQueue.IMP);
2016-03-23 02:41:37 +01:00
this.scope.put("ExpireManager", ExpireManager.IMP);
if (PlotSquared.get().worldedit != null) {
2016-03-23 02:41:37 +01:00
this.scope.put("WEManager", new WEManager());
}
2016-06-13 06:47:50 +02:00
this.scope.put("TaskManager", TaskManager.IMP);
2016-03-23 02:41:37 +01:00
this.scope.put("ConsolePlayer", ConsolePlayer.getConsole());
this.scope.put("SchematicHandler", SchematicHandler.manager);
this.scope.put("ChunkManager", ChunkManager.manager);
this.scope.put("BlockManager", WorldUtil.IMP);
this.scope.put("SetupUtils", SetupUtils.manager);
this.scope.put("EventUtil", EventUtil.manager);
this.scope.put("EconHandler", EconHandler.manager);
this.scope.put("UUIDHandler", UUIDHandler.implementation);
this.scope.put("DBFunc", DBFunc.dbManager);
this.scope.put("HybridUtils", HybridUtils.manager);
this.scope.put("IMP", PlotSquared.get().IMP);
2016-03-23 02:41:37 +01:00
this.scope.put("MainCommand", MainCommand.getInstance());
2016-03-22 18:53:17 +01:00
// enums
for (Enum<?> value : Captions.values()) {
2016-03-23 02:41:37 +01:00
this.scope.put("C_" + value.name(), value);
}
}
2016-03-22 18:53:17 +01:00
2018-08-10 17:01:10 +02:00
@Override public boolean onCommand(final PlotPlayer player, String[] args) {
List<String> allowed_params = Arrays
.asList("analyze", "calibrate-analysis", "remove-flag", "stop-expire", "start-expire",
"seen", "list-scripts", "start-rgar", "stop-rgar", "help", "addcmd", "runasync",
"run", "allcmd", "all");
2015-09-13 06:04:31 +02:00
if (args.length > 0) {
2016-03-23 02:41:37 +01:00
String arg = args[0].toLowerCase();
String script;
boolean async = false;
2015-09-13 06:04:31 +02:00
switch (arg) {
case "analyze": {
2016-03-23 02:41:37 +01:00
Plot plot = player.getCurrentPlot();
2015-09-13 06:04:31 +02:00
if (plot == null) {
MainUtil.sendMessage(player, Captions.NOT_IN_PLOT);
return false;
}
PlotAnalysis analysis = plot.getComplexity(null);
2015-09-13 06:04:31 +02:00
if (analysis != null) {
MainUtil.sendMessage(player, "Changes/column: " + analysis.changes / 1.0);
return true;
}
MainUtil.sendMessage(player, "$1Starting task...");
2015-09-13 06:04:31 +02:00
HybridUtils.manager.analyzePlot(plot, new RunnableVal<PlotAnalysis>() {
2018-08-10 17:01:10 +02:00
@Override public void run(PlotAnalysis value) {
MainUtil.sendMessage(player,
"$1Done: $2Use $3/plot debugexec analyze$2 for more information");
}
});
2015-06-26 11:46:06 +02:00
return true;
}
case "calibrate-analysis":
2015-09-13 06:04:31 +02:00
if (args.length != 2) {
MainUtil.sendMessage(player, Captions.COMMAND_SYNTAX,
2018-08-10 17:01:10 +02:00
"/plot debugexec analyze <threshold>");
2016-03-23 02:41:37 +01:00
MainUtil.sendMessage(player,
2018-08-10 17:01:10 +02:00
"$1<threshold> $2= $1The percentage of plots you want to clear (100 clears 100% of plots so no point calibrating "
+ "it)");
return false;
}
double threshold;
2015-09-13 06:04:31 +02:00
try {
threshold = Integer.parseInt(args[1]) / 100d;
2016-05-12 23:09:35 +02:00
} catch (NumberFormatException ignored) {
MainUtil.sendMessage(player, "$2Invalid threshold: " + args[1]);
2018-08-10 17:01:10 +02:00
MainUtil.sendMessage(player,
"$1<threshold> $2= $1The percentage of plots you want to clear as a number between 0 - 100");
return false;
}
2019-02-04 14:59:11 +01:00
PlotAnalysis.calcOptimalModifiers(() -> MainUtil
.sendMessage(player, "$1Thank you for calibrating plot expiry"), threshold);
return true;
case "stop-expire":
if (ExpireManager.IMP == null || !ExpireManager.IMP.cancelTask()) {
return MainUtil.sendMessage(player, "Task already halted");
2015-02-20 07:34:19 +01:00
}
return MainUtil.sendMessage(player, "Cancelled task.");
case "remove-flag":
2015-09-13 06:04:31 +02:00
if (args.length != 2) {
MainUtil.sendMessage(player, Captions.COMMAND_SYNTAX,
2018-08-10 17:01:10 +02:00
"/plot debugexec remove-flag <flag>");
return false;
}
2016-03-23 02:41:37 +01:00
String flag = args[1];
for (Plot plot : PlotSquared.get().getBasePlots()) {
2016-04-19 22:59:10 +02:00
Flag<?> flag1 = FlagManager.getFlag(flag);
if (plot.getFlag(flag1).isPresent()) {
2016-04-26 16:14:22 +02:00
plot.removeFlag(flag1);
2015-06-24 22:33:43 +02:00
}
}
2015-09-11 12:09:22 +02:00
return MainUtil.sendMessage(player, "Cleared flag: " + flag);
2015-09-13 06:04:31 +02:00
case "start-rgar": {
if (args.length != 2) {
2018-08-10 17:01:10 +02:00
MainUtil.sendMessage(player,
"&cInvalid syntax: /plot debugexec start-rgar <world>");
return false;
}
PlotArea area = PlotSquared.get().getPlotAreaByString(args[1]);
2016-02-10 19:59:51 +01:00
if (area == null) {
MainUtil.sendMessage(player, Captions.NOT_VALID_PLOT_WORLD, args[1]);
return false;
}
boolean result;
2015-09-13 06:04:31 +02:00
if (HybridUtils.regions != null) {
2018-08-10 17:01:10 +02:00
result =
HybridUtils.manager.scheduleRoadUpdate(area, HybridUtils.regions, 0);
2015-09-13 06:04:31 +02:00
} else {
2016-02-10 19:59:51 +01:00
result = HybridUtils.manager.scheduleRoadUpdate(area, 0);
}
2015-09-13 06:04:31 +02:00
if (!result) {
2018-08-10 17:01:10 +02:00
MainUtil.sendMessage(player,
"&cCannot schedule mass schematic update! (Is one already in progress?)");
return false;
}
return true;
}
case "stop-rgar":
2015-09-13 06:04:31 +02:00
if (!HybridUtils.UPDATE) {
2016-03-22 18:53:17 +01:00
MainUtil.sendMessage(player, "&cTask not running!");
return false;
}
2015-08-02 13:56:18 +02:00
HybridUtils.UPDATE = false;
2016-03-22 18:53:17 +01:00
MainUtil.sendMessage(player, "&cCancelling task... (Please wait)");
return true;
case "start-expire":
if (ExpireManager.IMP == null) {
ExpireManager.IMP = new ExpireManager();
2015-02-20 07:34:19 +01:00
}
if (ExpireManager.IMP.runAutomatedTask()) {
return MainUtil.sendMessage(player, "Started plot expiry task");
} else {
return MainUtil.sendMessage(player, "Plot expiry task already started");
2015-02-20 07:34:19 +01:00
}
case "seen":
2015-09-13 06:04:31 +02:00
if (args.length != 2) {
return MainUtil.sendMessage(player, "Use /plot debugexec seen <player>");
}
2016-03-23 02:41:37 +01:00
UUID uuid = UUIDHandler.getUUID(args[1], null);
2015-09-13 06:04:31 +02:00
if (uuid == null) {
2016-03-22 18:53:17 +01:00
return MainUtil.sendMessage(player, "Player not found: " + args[1]);
2015-09-13 06:04:31 +02:00
}
2016-03-23 02:41:37 +01:00
OfflinePlotPlayer op = UUIDHandler.getUUIDWrapper().getOfflinePlayer(uuid);
if (op == null || op.getLastPlayed() == 0) {
2018-08-10 17:01:10 +02:00
return MainUtil
.sendMessage(player, "Player hasn't connected before: " + args[1]);
2015-09-13 06:04:31 +02:00
}
2016-03-23 02:41:37 +01:00
Timestamp stamp = new Timestamp(op.getLastPlayed());
Date date = new Date(stamp.getTime());
MainUtil.sendMessage(player, "PLAYER: " + args[1]);
MainUtil.sendMessage(player, "UUID: " + uuid);
MainUtil.sendMessage(player, "Object: " + date.toGMTString());
MainUtil.sendMessage(player, "GMT: " + date.toGMTString());
MainUtil.sendMessage(player, "Local: " + date.toLocaleString());
2015-02-20 07:34:19 +01:00
return true;
case "h":
case "he":
case "?":
case "help":
2018-08-10 17:01:10 +02:00
MainUtil.sendMessage(player,
"Possible sub commands: /plot debugexec <" + StringMan
.join(allowed_params, "|") + ">");
return false;
case "addcmd":
2015-09-13 06:04:31 +02:00
try {
2018-08-10 17:01:10 +02:00
final String cmd = StringMan.join(Files.readLines(MainUtil.getFile(new File(
Merge branch 'master' into breaking # Conflicts: # Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/events/PlotRateEvent.java # Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEventUtil.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotSquared.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Add.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Auto.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Delete.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Kick.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Load.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Music.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Owner.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Rate.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Reload.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/SchematicCmd.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Trust.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/GameModeFlag.java # Core/src/main/java/com/intellectualcrafters/plot/commands/Clear.java # Core/src/main/java/com/intellectualcrafters/plot/commands/PluginCmd.java # Core/src/main/java/com/intellectualcrafters/plot/commands/Relight.java # Core/src/main/java/com/intellectualcrafters/plot/commands/SetHome.java # Core/src/main/java/com/intellectualcrafters/plot/config/C.java # Core/src/main/java/com/intellectualcrafters/plot/config/Configuration.java # Core/src/main/java/com/intellectualcrafters/plot/config/Settings.java # Core/src/test/java/com/github/intellectualsites/plotsquared/plot/util/EventUtilTest.java # Nukkit/src/main/java/com/plotsquared/nukkit/util/NukkitEventUtil.java # README.md # Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/events/PlotRateEvent.java # Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/util/SpongeSchematicHandler.java # Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/util/block/SpongeLocalQueue.java # Sponge/src/main/java/com/plotsquared/sponge/util/SpongeEventUtil.java
2018-11-14 15:44:07 +01:00
PlotSquared.get().IMP.getDirectory() + File.separator
+ Settings.Paths.SCRIPTS), args[1]), StandardCharsets.UTF_8),
2018-08-10 17:01:10 +02:00
System.getProperty("line.separator"));
new Command(MainCommand.getInstance(), true, args[1].split("\\.")[0], null,
RequiredType.NONE, CommandCategory.DEBUG) {
@Override public CompletableFuture<Boolean> execute(PlotPlayer player, String[] args,
2018-08-10 17:01:10 +02:00
RunnableVal3<Command, Runnable, Runnable> confirm,
RunnableVal2<Command, CommandResult> whenDone) {
2015-09-13 06:04:31 +02:00
try {
DebugExec.this.scope.put("PlotPlayer", player);
2016-03-23 02:41:37 +01:00
DebugExec.this.scope.put("args", args);
DebugExec.this.engine.eval(cmd, DebugExec.this.scope);
} catch (ScriptException e) {
2015-09-11 12:09:22 +02:00
e.printStackTrace();
MainUtil.sendMessage(player, Captions.COMMAND_WENT_WRONG);
2015-09-11 12:09:22 +02:00
}
return CompletableFuture.completedFuture(true);
}
2015-09-11 12:09:22 +02:00
};
return true;
} catch (IOException e) {
e.printStackTrace();
MainUtil.sendMessage(player, Captions.COMMAND_SYNTAX,
"/plot debugexec addcmd <file>");
return false;
}
case "runasync":
async = true;
case "run":
2015-09-13 06:04:31 +02:00
try {
2018-08-10 17:01:10 +02:00
script = StringMan.join(Files.readLines(MainUtil.getFile(new File(
Merge branch 'master' into breaking # Conflicts: # Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/events/PlotRateEvent.java # Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEventUtil.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotSquared.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Add.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Auto.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Delete.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Kick.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Load.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Music.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Owner.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Rate.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Reload.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/SchematicCmd.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Trust.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/GameModeFlag.java # Core/src/main/java/com/intellectualcrafters/plot/commands/Clear.java # Core/src/main/java/com/intellectualcrafters/plot/commands/PluginCmd.java # Core/src/main/java/com/intellectualcrafters/plot/commands/Relight.java # Core/src/main/java/com/intellectualcrafters/plot/commands/SetHome.java # Core/src/main/java/com/intellectualcrafters/plot/config/C.java # Core/src/main/java/com/intellectualcrafters/plot/config/Configuration.java # Core/src/main/java/com/intellectualcrafters/plot/config/Settings.java # Core/src/test/java/com/github/intellectualsites/plotsquared/plot/util/EventUtilTest.java # Nukkit/src/main/java/com/plotsquared/nukkit/util/NukkitEventUtil.java # README.md # Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/events/PlotRateEvent.java # Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/util/SpongeSchematicHandler.java # Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/util/block/SpongeLocalQueue.java # Sponge/src/main/java/com/plotsquared/sponge/util/SpongeEventUtil.java
2018-11-14 15:44:07 +01:00
PlotSquared.get().IMP.getDirectory() + File.separator
+ Settings.Paths.SCRIPTS), args[1]), StandardCharsets.UTF_8),
2018-08-10 17:01:10 +02:00
System.getProperty("line.separator"));
2015-09-13 06:04:31 +02:00
if (args.length > 2) {
2016-03-23 02:41:37 +01:00
HashMap<String, String> replacements = new HashMap<>();
2015-09-13 06:04:31 +02:00
for (int i = 2; i < args.length; i++) {
2015-09-11 12:09:22 +02:00
replacements.put("%s" + (i - 2), args[i]);
}
script = StringMan.replaceFromMap(script, replacements);
}
2016-03-23 02:41:37 +01:00
} catch (IOException e) {
e.printStackTrace();
return false;
}
break;
case "list-scripts":
Merge branch 'master' into breaking # Conflicts: # Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/events/PlotRateEvent.java # Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEventUtil.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotSquared.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Add.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Auto.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Delete.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Kick.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Load.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Music.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Owner.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Rate.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Reload.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/SchematicCmd.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Trust.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/GameModeFlag.java # Core/src/main/java/com/intellectualcrafters/plot/commands/Clear.java # Core/src/main/java/com/intellectualcrafters/plot/commands/PluginCmd.java # Core/src/main/java/com/intellectualcrafters/plot/commands/Relight.java # Core/src/main/java/com/intellectualcrafters/plot/commands/SetHome.java # Core/src/main/java/com/intellectualcrafters/plot/config/C.java # Core/src/main/java/com/intellectualcrafters/plot/config/Configuration.java # Core/src/main/java/com/intellectualcrafters/plot/config/Settings.java # Core/src/test/java/com/github/intellectualsites/plotsquared/plot/util/EventUtilTest.java # Nukkit/src/main/java/com/plotsquared/nukkit/util/NukkitEventUtil.java # README.md # Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/events/PlotRateEvent.java # Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/util/SpongeSchematicHandler.java # Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/util/block/SpongeLocalQueue.java # Sponge/src/main/java/com/plotsquared/sponge/util/SpongeEventUtil.java
2018-11-14 15:44:07 +01:00
String path = PlotSquared.get().IMP.getDirectory() + File.separator
+ Settings.Paths.SCRIPTS;
File folder = new File(path);
File[] filesArray = folder.listFiles();
int page;
switch (args.length) {
case 1:
page = 0;
break;
case 2:
if (MathMan.isInteger(args[1])) {
page = Integer.parseInt(args[1]) - 1;
break;
}
default:
Captions.COMMAND_SYNTAX
.send(player, "/plot debugexec list-scripts [#]");
return false;
}
List<File> allFiles = Arrays.asList(filesArray);
2018-08-10 17:01:10 +02:00
paginate(player, allFiles, 8, page,
new RunnableVal3<Integer, File, PlotMessage>() {
2018-08-10 17:01:10 +02:00
@Override public void run(Integer i, File file, PlotMessage message) {
String name = file.getName();
message.text("[").color("$3").text(String.valueOf(i)).color("$1")
.text("]").color("$3").text(' ' + name).color("$1");
}
}, "/plot debugexec list-scripts", "List of scripts");
return true;
case "allcmd":
2015-12-04 10:00:30 +01:00
if (args.length < 3) {
Captions.COMMAND_SYNTAX
2018-08-10 17:01:10 +02:00
.send(player, "/plot debugexec allcmd <condition> <command>");
2015-12-04 10:00:30 +01:00
return false;
}
long start = System.currentTimeMillis();
Command cmd = MainCommand.getInstance().getCommand(args[3]);
2015-12-04 10:00:30 +01:00
String[] params = Arrays.copyOfRange(args, 4, args.length);
if ("true".equals(args[1])) {
2019-09-08 20:02:45 +02:00
Location location = player.getMeta(PlotPlayer.META_LOCATION);
Plot plot = player.getMeta(PlotPlayer.META_LAST_PLOT);
for (Plot current : PlotSquared.get().getBasePlots()) {
player.setMeta(PlotPlayer.META_LOCATION, current.getBottomAbs());
player.setMeta(PlotPlayer.META_LAST_PLOT, current);
cmd.execute(player, params, null, null);
2015-12-04 10:00:30 +01:00
}
2019-09-08 20:02:45 +02:00
if (location == null) {
player.deleteMeta(PlotPlayer.META_LOCATION);
2015-12-04 10:00:30 +01:00
} else {
2019-09-08 20:02:45 +02:00
player.setMeta(PlotPlayer.META_LOCATION, location);
2015-12-04 10:00:30 +01:00
}
if (plot == null) {
player.deleteMeta(PlotPlayer.META_LAST_PLOT);
2015-12-04 10:00:30 +01:00
} else {
player.setMeta(PlotPlayer.META_LAST_PLOT, plot);
2015-12-04 10:00:30 +01:00
}
player.sendMessage("&c> " + (System.currentTimeMillis() - start));
return true;
}
init();
2016-03-23 02:41:37 +01:00
this.scope.put("_2", params);
this.scope.put("_3", cmd);
2018-08-10 17:01:10 +02:00
script =
"_1=PS.getBasePlots().iterator();while(_1.hasNext()){plot=_1.next();if("
+ args[1]
2016-03-23 02:41:37 +01:00
+ "){PlotPlayer.setMeta(\"location\",plot.getBottomAbs());PlotPlayer.setMeta(\"lastplot\",plot);_3.onCommand"
+ "(PlotPlayer,_2)}}";
2015-12-04 10:00:30 +01:00
break;
case "all":
2015-12-04 10:00:30 +01:00
if (args.length < 3) {
Captions.COMMAND_SYNTAX
.send(player, "/plot debugexec all <condition> <code>");
2015-12-04 10:00:30 +01:00
return false;
}
2018-08-10 17:01:10 +02:00
script =
"_1=PS.getBasePlots().iterator();while(_1.hasNext()){plot=_1.next();if("
+ args[1] + "){" + StringMan
.join(Arrays.copyOfRange(args, 2, args.length), " ") + "}}";
2015-12-04 10:00:30 +01:00
break;
default:
script = StringMan.join(args, " ");
}
if (!(player instanceof ConsolePlayer)) {
MainUtil.sendMessage(player, Captions.NOT_CONSOLE);
2015-08-01 20:01:41 +02:00
return false;
}
init();
2016-03-23 02:41:37 +01:00
this.scope.put("PlotPlayer", player);
PlotSquared.debug("> " + script);
2015-09-13 06:04:31 +02:00
try {
if (async) {
final String toExec = script;
TaskManager.runTaskAsync(() -> {
long start = System.currentTimeMillis();
Object result = null;
try {
result = DebugExec.this.engine.eval(toExec, DebugExec.this.scope);
} catch (ScriptException e) {
e.printStackTrace();
}
2019-02-04 14:59:11 +01:00
PlotSquared
.log("> " + (System.currentTimeMillis() - start) + "ms -> " + result);
});
2015-09-13 06:04:31 +02:00
} else {
2016-03-23 02:41:37 +01:00
long start = System.currentTimeMillis();
Object result = this.engine.eval(script, this.scope);
Merge branch 'master' into breaking # Conflicts: # Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/events/PlotRateEvent.java # Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEventUtil.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotSquared.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Add.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Auto.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Delete.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Kick.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Load.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Music.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Owner.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Rate.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Reload.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/SchematicCmd.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Trust.java # Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/GameModeFlag.java # Core/src/main/java/com/intellectualcrafters/plot/commands/Clear.java # Core/src/main/java/com/intellectualcrafters/plot/commands/PluginCmd.java # Core/src/main/java/com/intellectualcrafters/plot/commands/Relight.java # Core/src/main/java/com/intellectualcrafters/plot/commands/SetHome.java # Core/src/main/java/com/intellectualcrafters/plot/config/C.java # Core/src/main/java/com/intellectualcrafters/plot/config/Configuration.java # Core/src/main/java/com/intellectualcrafters/plot/config/Settings.java # Core/src/test/java/com/github/intellectualsites/plotsquared/plot/util/EventUtilTest.java # Nukkit/src/main/java/com/plotsquared/nukkit/util/NukkitEventUtil.java # README.md # Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/events/PlotRateEvent.java # Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/util/SpongeSchematicHandler.java # Sponge/src/main/java/com/github/intellectualsites/plotsquared/sponge/util/block/SpongeLocalQueue.java # Sponge/src/main/java/com/plotsquared/sponge/util/SpongeEventUtil.java
2018-11-14 15:44:07 +01:00
PlotSquared
.log("> " + (System.currentTimeMillis() - start) + "ms -> " + result);
}
return true;
2016-03-23 02:41:37 +01:00
} catch (ScriptException e) {
e.printStackTrace();
return false;
2015-02-20 07:34:19 +01:00
}
2015-01-24 01:00:57 +01:00
}
return false;
2015-01-24 01:00:57 +01:00
}
}