Update scripts and code to work nicely with each other.

Fixes #2208
This commit is contained in:
dordsor21 2019-01-12 19:56:11 +00:00
parent f62777bc1a
commit d81d3c72e4
10 changed files with 113 additions and 20 deletions

View File

@ -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<Plot> sortPlots(Collection<Plot> plots) {
return sortPlots(plots, SortType.DISTANCE_FROM_ORIGIN, null);
}
/**
* Sort a collection of plots by world (with a priority world), then
* by hashcode.

View File

@ -164,11 +164,8 @@ import java.util.*;
"$1<threshold> $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();

View File

@ -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);

View File

@ -0,0 +1,18 @@
/*
This will increase a player's allowed plots by the provided value
/plot debugexec runasync addperm <player> <amount>
*/
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);
}

View File

@ -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);
}

View File

@ -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 <removeroads>");
MainUtil.sendMessage(PlotPlayer, "$1<removeroads> is true or false if you want to remove roads when auto merging");
MainUtil.class.static.sendMessage(PlotPlayer, "$1<removeroads> is true or false if you want to remove roads when auto merging");
}

View File

@ -0,0 +1,33 @@
/*
* Script to find the furthest plot from origin in a world:
* - /plot debugexec runasync furthest.js <plotworld>
*/
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 <plotworld>");
}

View File

@ -0,0 +1,2 @@
// This command is registered from the start.js file which is run during startup
PlotPlayer.sendMessage("Hello World!");

View File

@ -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);
}

View File

@ -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");
}