From b45eaf1c90beaf36aa36c6340c4f049e098ea487 Mon Sep 17 00:00:00 2001 From: boy0001 Date: Sat, 2 May 2015 23:58:52 +1000 Subject: [PATCH] 2.10, WE blacklist, plot border, string comparison - --- PlotSquared/pom.xml | 2 +- .../plot/PlotSquared.java | 2 ++ .../plot/config/Settings.java | 4 +++ .../plot/generator/ClassicPlotManager.java | 6 ++-- .../plot/listeners/worldedit/WEListener.java | 15 ++------- .../plot/util/StringComparison.java | 31 +++++++++---------- 6 files changed, 26 insertions(+), 34 deletions(-) diff --git a/PlotSquared/pom.xml b/PlotSquared/pom.xml index fbba2eb39..ff14f40fa 100644 --- a/PlotSquared/pom.xml +++ b/PlotSquared/pom.xml @@ -8,7 +8,7 @@ UTF-8 PlotSquared - 2.10 + 2.10.1 PlotSquared jar diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotSquared.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotSquared.java index b7a6bb37e..31bd88321 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotSquared.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotSquared.java @@ -866,6 +866,7 @@ public class PlotSquared { options.put("worldedit.require-selection-in-mask", Settings.REQUIRE_SELECTION); options.put("worldedit.max-volume", Settings.WE_MAX_VOLUME); options.put("worldedit.max-iterations", Settings.WE_MAX_ITERATIONS); + options.put("worldedit.blacklist", Arrays.asList("cs", ".s", "restore", "snapshot", "delchunks", "listchunks")); // Chunk processor options.put("chunk-processor.enabled", Settings.CHUNK_PROCESSOR); @@ -941,6 +942,7 @@ public class PlotSquared { Settings.REQUIRE_SELECTION = config.getBoolean("worldedit.require-selection-in-mask"); Settings.WE_MAX_VOLUME = config.getLong("worldedit.max-volume"); Settings.WE_MAX_ITERATIONS = config.getLong("worldedit.max-iterations"); + Settings.WE_BLACKLIST = config.getStringList("worldedit.blacklist"); // Chunk processor Settings.CHUNK_PROCESSOR = config.getBoolean("chunk-processor.enabled"); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/Settings.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/Settings.java index 079ff51ea..ca5ac5ec6 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/Settings.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/Settings.java @@ -20,6 +20,9 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// package com.intellectualcrafters.plot.config; +import java.util.ArrayList; +import java.util.List; + /** * Updater and DB settings * @@ -68,6 +71,7 @@ public class Settings { public static boolean REQUIRE_SELECTION = true; public static long WE_MAX_VOLUME = 500000; public static long WE_MAX_ITERATIONS = 1000; + public static List WE_BLACKLIST = new ArrayList<>(); /** * Default kill road mobs: true */ diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/ClassicPlotManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/ClassicPlotManager.java index 4b09eb12b..d7def6823 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/ClassicPlotManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/ClassicPlotManager.java @@ -277,7 +277,7 @@ public abstract class ClassicPlotManager extends SquarePlotManager { final PlotBlock block = ((ClassicPlotWorld) plotworld).CLAIMED_WALL_BLOCK; final PlotBlock unclaim = ((ClassicPlotWorld) plotworld).WALL_BLOCK; for (final PlotId id : plotIds) { - if (!block.equals(unclaim)) { + if (block.id != 0 || !block.equals(unclaim)) { setWall(plotworld, id, new PlotBlock[] { block }); } } @@ -298,7 +298,7 @@ public abstract class ClassicPlotManager extends SquarePlotManager { public boolean claimPlot(final PlotWorld plotworld, final Plot plot) { final PlotBlock unclaim = ((ClassicPlotWorld) plotworld).WALL_BLOCK; final PlotBlock claim = ((ClassicPlotWorld) plotworld).CLAIMED_WALL_BLOCK; - if (!claim.equals(unclaim)) { + if (claim.id != 0 || !claim.equals(unclaim)) { setWall(plotworld, plot.id, new PlotBlock[] { claim }); } return true; @@ -308,7 +308,7 @@ public abstract class ClassicPlotManager extends SquarePlotManager { public boolean unclaimPlot(final PlotWorld plotworld, final Plot plot) { final PlotBlock unclaim = ((ClassicPlotWorld) plotworld).WALL_BLOCK; final PlotBlock claim = ((ClassicPlotWorld) plotworld).CLAIMED_WALL_BLOCK; - if (!claim.equals(unclaim)) { + if (unclaim.id != 0 || !claim.equals(unclaim)) { setWall(plotworld, plot.id, new PlotBlock[] { unclaim }); } MainUtil.removeSign(plot); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/worldedit/WEListener.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/worldedit/WEListener.java index b63d429a1..8a9d94661 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/worldedit/WEListener.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/worldedit/WEListener.java @@ -36,12 +36,9 @@ public class WEListener implements Listener { public final HashSet region = new HashSet<>(Arrays.asList("move", "set", "replace", "overlay", "walls", "outline", "deform", "hollow", "smooth", "naturalize", "paste", "count", "distr", "regen", "copy", "cut", "green", "setbiome")); public final HashSet regionExtend = new HashSet<>(Arrays.asList("stack")); public final HashSet unregioned = new HashSet<>(Arrays.asList("paste", "redo", "undo", "rotate", "flip", "generate", "schematic", "schem")); - public final HashSet unsafe1 = new HashSet<>(Arrays.asList("cs", ".s", "restore", "snapshot", "delchunks", "listchunks", "sel poly")); - public final HashSet unsafe2 = new HashSet<>(Arrays.asList("sel poly", "worldedit reload")); + public final HashSet unsafe1 = new HashSet<>(Arrays.asList("cs", ".s", "restore", "snapshot", "delchunks", "listchunks")); public final HashSet restricted = new HashSet<>(Arrays.asList("up")); -// public final HashSet allowSingleSlash = new HashSet<>(Arrays.asList("sel", ".s", "cs", "restore", "brush", "fixwater", "fixlava", "up", "worldedit", "mask", "gmask", "snapshot", "schem", "schematic", "remove", "fill", "pumpkins", "forestgen", "removenear", "ex", "butcher", "size", "snow")); - public boolean checkCommand(List list, String cmd) { for (String identifier : list) { if (("/" + identifier).equals(cmd) || ("//" + identifier).equals(cmd) || ("/worldedit:/" + identifier).equals(cmd) || ("/worldedit:" + identifier).equals(cmd)) { @@ -226,20 +223,12 @@ public class WEListener implements Listener { } return true; } - if (unsafe2.contains(reduced)) { - MainUtil.sendMessage(pp, C.WORLDEDIT_UNSAFE); - e.setCancelled(true); - if (Permissions.hasPermission(pp, "plots.worldedit.bypass")) { - MainUtil.sendMessage(pp, C.WORLDEDIT_BYPASS); - } - return true; - } if (regionExtend.contains(reduced)) { return checkSelection(p, pp, getInt(split[1]), maxVolume, e); } } String reduced = reduceCmd(split[0], single); - if (unsafe1.contains(reduced)) { + if (Settings.WE_BLACKLIST.contains(reduced)) { MainUtil.sendMessage(pp, C.WORLDEDIT_UNSAFE); e.setCancelled(true); if (Permissions.hasPermission(pp, "plots.worldedit.bypass")) { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/StringComparison.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/StringComparison.java index 19c68820f..7c4f71842 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/StringComparison.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/StringComparison.java @@ -23,6 +23,9 @@ package com.intellectualcrafters.plot.util; import java.util.ArrayList; import java.util.Collections; +import org.apache.commons.lang.StringUtils; +import org.bukkit.util.StringUtil; + /** * String comparison library * @@ -39,7 +42,7 @@ public class StringComparison { * * Can be checked for low match (< .25 or something) */ - private double match = 0; + private double match = Integer.MAX_VALUE; /** * The actual object */ @@ -51,12 +54,13 @@ public class StringComparison { * @param input Input Base Value * @param objects Objects to compare */ - public StringComparison(final String input, final Object[] objects) { - double c; + public StringComparison(String input, final Object[] objects) { + int c; this.bestMatch = objects[0].toString(); this.bestMatchObject = objects[0]; + input = input.toLowerCase(); for (final Object o : objects) { - if ((c = compare(input, o.toString())) > this.match) { + if ((c = compare(input, o.toString().toLowerCase())) < this.match) { this.match = c; this.bestMatch = o.toString(); this.bestMatchObject = o; @@ -72,20 +76,13 @@ public class StringComparison { * * @return match */ - public static double compare(final String s1, final String s2) { - final ArrayList p1 = wLetterPair(s1.toUpperCase()), p2 = wLetterPair(s2.toUpperCase()); - int intersection = 0; - final int union = p1.size() + p2.size(); - for (final Object aP1 : p1) { - for (final Object aP2 : p2) { - if (aP1.equals(aP2)) { - intersection++; - p2.remove(aP2); - break; - } - } + public static int compare(final String s1, final String s2) { + int distance = StringUtils.getLevenshteinDistance(s1, s2); + if (s2.contains(s1) || s2.contains(s1)) { + distance -= 4; } - return (2.0 * intersection) / union; +// distance += Math.abs(s1.length() - s2.length()); + return distance; } /**