diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotSquared.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotSquared.java index 301a05efa..06af1a84b 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotSquared.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotSquared.java @@ -269,7 +269,13 @@ import java.util.zip.ZipInputStream; } // Copy files + copyFile("addplots.js", Settings.Paths.SCRIPTS); + copyFile("addsigns.js", Settings.Paths.SCRIPTS); copyFile("automerge.js", Settings.Paths.SCRIPTS); + copyFile("furthest.js", Settings.Paths.SCRIPTS); + copyFile("mycommand.js", Settings.Paths.SCRIPTS); + copyFile("setbiomes.js", Settings.Paths.SCRIPTS); + copyFile("start.js", Settings.Paths.SCRIPTS); copyFile("town.template", Settings.Paths.TEMPLATES); copyFile("skyblock.template", Settings.Paths.TEMPLATES); copyFile("bridge.template", Settings.Paths.TEMPLATES); @@ -756,6 +762,10 @@ import java.util.zip.ZipInputStream; return list; } + public ArrayList sortPlots(Collection plots) { + return sortPlots(plots, SortType.DISTANCE_FROM_ORIGIN, null); + } + /** * Sort a collection of plots by world (with a priority world), then * by hashcode. diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugExec.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugExec.java index d68220814..dfcda68ae 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugExec.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/DebugExec.java @@ -164,11 +164,8 @@ import java.util.*; "$1 $2= $1The percentage of plots you want to clear as a number between 0 - 100"); return false; } - PlotAnalysis.calcOptimalModifiers(new Runnable() { - @Override public void run() { - MainUtil.sendMessage(player, "$1Thank you for calibrating plot expiry"); - } - }, threshold); + PlotAnalysis.calcOptimalModifiers( + () -> MainUtil.sendMessage(player, "$1Thank you for calibrating plot expiry"), threshold); return true; case "stop-expire": if (ExpireManager.IMP == null || !ExpireManager.IMP.cancelTask()) { @@ -404,18 +401,16 @@ import java.util.*; try { if (async) { final String toExec = script; - TaskManager.runTaskAsync(new Runnable() { - @Override public void run() { - long start = System.currentTimeMillis(); - Object result = null; - try { - result = DebugExec.this.engine.eval(toExec, DebugExec.this.scope); - } catch (ScriptException e) { - e.printStackTrace(); - } - PlotSquared.log( - "> " + (System.currentTimeMillis() - start) + "ms -> " + result); + TaskManager.runTaskAsync(() -> { + long start = System.currentTimeMillis(); + Object result = null; + try { + result = DebugExec.this.engine.eval(toExec, DebugExec.this.scope); + } catch (ScriptException e) { + e.printStackTrace(); } + PlotSquared.log( + "> " + (System.currentTimeMillis() - start) + "ms -> " + result); }); } else { long start = System.currentTimeMillis(); diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java index 5ed2b6636..c57299bd8 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java @@ -958,6 +958,10 @@ public class Plot { TaskManager.runTask(() -> Plot.this.setSign(name)); return; } + if(name == null) { + PlotSquared.log("Attempted to add null name to sign at plot: " + getId()); + return; + } PlotManager manager = this.area.getPlotManager(); if (this.area.ALLOW_SIGNS) { Location loc = manager.getSignLoc(this.area, this); diff --git a/Core/src/main/resources/addplots.js b/Core/src/main/resources/addplots.js new file mode 100644 index 000000000..6f12712b4 --- /dev/null +++ b/Core/src/main/resources/addplots.js @@ -0,0 +1,18 @@ +/* +This will increase a player's allowed plots by the provided value +/plot debugexec runasync addperm +*/ +var uuid = UUIDHandler.getUUID('%s0', null); +if (uuid === null) { + C_INVALID_PLAYER.send(PlotPlayer, '%s0'); +} +else if (!MathMan.class.static.isInteger('%s1')) { + C_NOT_VALID_NUMBER.send(PlotPlayer, '(0, ' + Settings.MAX_PLOTS + ')'); +} +else { + var amount = parseInt('%s1'); + var pp = IMP.wrapPlayer(UUIDHandler.getUUIDWrapper().getOfflinePlayer(uuid).player); + var allowed = pp.getAllowedPlots(); + MainUtil.class.static.sendMessage(PlotPlayer, '$4Setting permission: plots.plot.' + (allowed + amount) + ' for %s0'); + IMP.getEconomyHandler().setPermission("", pp.getName(), 'plots.plot.' + (allowed + amount), true); +} diff --git a/Core/src/main/resources/addsigns.js b/Core/src/main/resources/addsigns.js new file mode 100644 index 000000000..7f0996ca1 --- /dev/null +++ b/Core/src/main/resources/addsigns.js @@ -0,0 +1,12 @@ +/* +This script will fix all signs in the world. +*/ +var plots = PS.sortPlots(PS.getPlots()); +for (var i = 0; i < plots.size(); i++) { + var plot = plots.get(i); + if (!plot.isMerged() || !plot.getMerged(0)) { + plot.setSign(); + PS.class.static.log('&cSetting sign for: ' + plot); + } + java.lang.Thread.sleep(10); +} diff --git a/Core/src/main/resources/automerge.js b/Core/src/main/resources/automerge.js index 91ce1040c..b8326e842 100644 --- a/Core/src/main/resources/automerge.js +++ b/Core/src/main/resources/automerge.js @@ -5,7 +5,7 @@ Need to script something quick with PlotSquared? This is an example script that will auto merge all plots The following utility classes are usable: - - PS + - PlotSquared - TaskManager - TitleManager - ConsolePlayer @@ -33,16 +33,16 @@ PS.class.static.log("Attempting to auto merge " + plots.size() + " plots"); if ("%s0" === "true") { for (var i = 0; i < plots.size(); i++) { var plot = plots.get(i); - plot.autoMerge(false); + plot.autoMerge(-1, 250000, plot.owner, true); } } else if ("%s0" === "false") { for (var i = 0; i < plots.size(); i++) { var plot = plots.get(i); - plot.autoMerge(false); + plot.autoMerge(-1, 250000, plot.owner, false); } } else { C_COMMAND_SYNTAX.send(PlotPlayer, "/plot debugexec automerge.js "); - MainUtil.sendMessage(PlotPlayer, "$1 is true or false if you want to remove roads when auto merging"); + MainUtil.class.static.sendMessage(PlotPlayer, "$1 is true or false if you want to remove roads when auto merging"); } diff --git a/Core/src/main/resources/furthest.js b/Core/src/main/resources/furthest.js new file mode 100644 index 000000000..b0f973088 --- /dev/null +++ b/Core/src/main/resources/furthest.js @@ -0,0 +1,33 @@ +/* +* Script to find the furthest plot from origin in a world: +* - /plot debugexec runasync furthest.js +*/ + +if (PS.hasPlotArea("%s0")) { + var plots = PS.getAllPlotsRaw().get("%s0").values().toArray(); + var max = 0; + var maxplot; + for (var i in plots) { + var plot = plots[i]; + if (plot.x > max) { + max = plot.x; + maxplot = plot; + } + if (plot.y > max) { + max = plot.y; + maxplot = plot; + } + if (-plot.x > max) { + max = -plot.x; + maxplot = plot; + } + if (-plot.y > max) { + max = -plot.y; + maxplot = plot; + } + } + PS.class.static.log(plot); +} +else { + PlotPlayer.sendMessage("Usage: /plot debugexec runasync furthest.js "); +} diff --git a/Core/src/main/resources/mycommand.js b/Core/src/main/resources/mycommand.js new file mode 100644 index 000000000..e5a3f27c3 --- /dev/null +++ b/Core/src/main/resources/mycommand.js @@ -0,0 +1,2 @@ +// This command is registered from the start.js file which is run during startup +PlotPlayer.sendMessage("Hello World!"); \ No newline at end of file diff --git a/Core/src/main/resources/setbiomes.js b/Core/src/main/resources/setbiomes.js new file mode 100644 index 000000000..b3d1dd4ff --- /dev/null +++ b/Core/src/main/resources/setbiomes.js @@ -0,0 +1,12 @@ +/* +This script will reset all biomes in claimed plots +*/ +var plots = PS.sortPlots(PS.getPlots()); +for (var i = 0; i < plots.size(); i++) { + var plot = plots.get(i); + if (!plot.isMerged() || !plot.getMerged(0)) { + plot.setBiome("%s0", null); + PS.class.static.log('&cSetting biome for: ' + plot); + } + java.lang.Thread.sleep(1000); +} diff --git a/Core/src/main/resources/start.js b/Core/src/main/resources/start.js new file mode 100644 index 000000000..f58be7459 --- /dev/null +++ b/Core/src/main/resources/start.js @@ -0,0 +1,7 @@ +// Add your commands to this list +var commands = ["mycommand"]; + +// Command registration: +for (var i in commands) { + MainCommand.class.static.onCommand(PlotPlayer, "plot", "debugexec", "addcmd", commands[i] + ".js"); +} \ No newline at end of file