mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-06-25 10:14:42 +02:00
Random scripting stuff
This commit is contained in:
@ -7,6 +7,7 @@ import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.reflect.Array;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
@ -265,6 +266,7 @@ public class PS {
|
||||
}
|
||||
|
||||
// Copy files
|
||||
copyFile("automerge.js", "scripts");
|
||||
copyFile("town.template", "templates");
|
||||
copyFile("skyblock.template", "templates");
|
||||
copyFile("german.yml", "translations");
|
||||
@ -317,8 +319,8 @@ public class PS {
|
||||
* @param message Message to log
|
||||
* @see IPlotMain#log(String)
|
||||
*/
|
||||
public static void log(final String message) {
|
||||
get().IMP.log(message);
|
||||
public static void log(Object message) {
|
||||
get().IMP.log(StringMan.getString(message));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -40,6 +40,8 @@ import javax.script.ScriptEngineManager;
|
||||
import javax.script.ScriptException;
|
||||
import javax.script.SimpleScriptContext;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import com.google.common.io.Files;
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.config.C;
|
||||
@ -120,7 +122,6 @@ public class DebugExec extends SubCommand {
|
||||
scope.put("UUIDHandler", UUIDHandler.implementation);
|
||||
scope.put("DBFunc", DBFunc.dbManager);
|
||||
scope.put("HybridUtils", HybridUtils.manager);
|
||||
scope.put("HybridUtils", HybridUtils.manager);
|
||||
scope.put("IMP", PS.get().IMP);
|
||||
scope.put("MainCommand", MainCommand.getInstance());
|
||||
|
||||
@ -366,7 +367,7 @@ public class DebugExec extends SubCommand {
|
||||
}
|
||||
case "run": {
|
||||
try {
|
||||
script = StringMan.join(Files.readLines(new File(PS.get().IMP.getDirectory(), args[1]), StandardCharsets.UTF_8), "");
|
||||
script = StringMan.join(Files.readLines(new File(new File(PS.get().IMP.getDirectory() + File.separator + "scripts"), args[1]), StandardCharsets.UTF_8), System.getProperty("line.separator"));
|
||||
if (args.length > 2) {
|
||||
HashMap<String, String> replacements = new HashMap<>();
|
||||
for (int i = 2; i < args.length; i++) {
|
||||
@ -384,9 +385,13 @@ public class DebugExec extends SubCommand {
|
||||
script = StringMan.join(args, " ");
|
||||
}
|
||||
}
|
||||
if (!ConsolePlayer.isConsole(player)) {
|
||||
MainUtil.sendMessage(player, C.NOT_CONSOLE);
|
||||
return false;
|
||||
}
|
||||
init();
|
||||
scope.put("PlotPlayer", player);
|
||||
PS.log("> " + script);
|
||||
System.out.print("> " + script);
|
||||
try {
|
||||
if (async) {
|
||||
final String toExec = script;
|
||||
|
@ -476,9 +476,10 @@ public class Plot {
|
||||
/**
|
||||
* Auto merge the plot with any adjacent plots of the same owner
|
||||
* @see MainUtil#autoMerge(Plot, UUID) to specify the owner
|
||||
* @param removeRoads If to remove roads when merging
|
||||
*/
|
||||
public void autoMerge() {
|
||||
MainUtil.autoMerge(this, owner);
|
||||
public void autoMerge(boolean removeRoads) {
|
||||
MainUtil.autoMerge(this, owner, removeRoads);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -821,7 +821,7 @@ public class MainUtil {
|
||||
return string;
|
||||
}
|
||||
|
||||
public static void autoMerge(final Plot plot, final UUID uuid) {
|
||||
public static void autoMerge(final Plot plot, final UUID uuid, boolean removeRoads) {
|
||||
if (plot == null) {
|
||||
return;
|
||||
}
|
||||
@ -843,7 +843,7 @@ public class MainUtil {
|
||||
final PlotId top = getTopPlot(plot).id;
|
||||
plots = getPlotSelectionIds(new PlotId(bot.x, bot.y - 1), new PlotId(top.x, top.y));
|
||||
if (ownsPlots(plot.world, plots, uuid, 0)) {
|
||||
final boolean result = mergePlots(plot.world, plots, true);
|
||||
final boolean result = mergePlots(plot.world, plots, removeRoads);
|
||||
if (result) {
|
||||
merge = true;
|
||||
continue;
|
||||
@ -851,7 +851,7 @@ public class MainUtil {
|
||||
}
|
||||
plots = getPlotSelectionIds(new PlotId(bot.x, bot.y), new PlotId(top.x + 1, top.y));
|
||||
if (ownsPlots(plot.world, plots, uuid, 1)) {
|
||||
final boolean result = mergePlots(plot.world, plots, true);
|
||||
final boolean result = mergePlots(plot.world, plots, removeRoads);
|
||||
if (result) {
|
||||
merge = true;
|
||||
continue;
|
||||
@ -859,7 +859,7 @@ public class MainUtil {
|
||||
}
|
||||
plots = getPlotSelectionIds(new PlotId(bot.x, bot.y), new PlotId(top.x, top.y + 1));
|
||||
if (ownsPlots(plot.world, plots, uuid, 2)) {
|
||||
final boolean result = mergePlots(plot.world, plots, true);
|
||||
final boolean result = mergePlots(plot.world, plots, removeRoads);
|
||||
if (result) {
|
||||
merge = true;
|
||||
continue;
|
||||
@ -867,7 +867,7 @@ public class MainUtil {
|
||||
}
|
||||
plots = getPlotSelectionIds(new PlotId(bot.x - 1, bot.y), new PlotId(top.x, top.y));
|
||||
if (ownsPlots(plot.world, plots, uuid, 3)) {
|
||||
final boolean result = mergePlots(plot.world, plots, true);
|
||||
final boolean result = mergePlots(plot.world, plots, removeRoads);
|
||||
if (result) {
|
||||
merge = true;
|
||||
continue;
|
||||
@ -928,7 +928,7 @@ public class MainUtil {
|
||||
}
|
||||
final PlotWorld plotworld = PS.get().getPlotWorld(plot.world);
|
||||
if (plotworld.AUTO_MERGE) {
|
||||
autoMerge(p, uuid);
|
||||
autoMerge(p, uuid, true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
package com.intellectualcrafters.plot.util;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
@ -26,6 +28,37 @@ public class StringMan {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static String getString(Object obj) {
|
||||
if (obj == null) {
|
||||
return "null";
|
||||
}
|
||||
if (obj.getClass() == String.class) {
|
||||
return (String) obj;
|
||||
}
|
||||
if (obj.getClass().isArray()) {
|
||||
String result = "";
|
||||
String prefix = "";
|
||||
|
||||
for(int i=0; i<Array.getLength(obj); i++){
|
||||
result += prefix + getString(Array.get(obj, i));
|
||||
prefix = ",";
|
||||
}
|
||||
return "( " + result + " )";
|
||||
}
|
||||
else if (obj instanceof Collection<?>) {
|
||||
String result = "";
|
||||
String prefix = "";
|
||||
for (Object element : (List<?>) obj) {
|
||||
result += prefix + getString(element);
|
||||
prefix = ",";
|
||||
}
|
||||
return "[ " + result + " ]";
|
||||
}
|
||||
else {
|
||||
return obj.toString();
|
||||
}
|
||||
}
|
||||
|
||||
public static String replaceFirst(char c, String s) {
|
||||
if (s == null) {
|
||||
return "";
|
||||
|
Reference in New Issue
Block a user