diff --git a/pom.xml b/pom.xml index 8500f56b6..c885acc1d 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ UTF-8 PlotSquared - 3.2.6 + 3.2.7 PlotSquared jar diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Database.java b/src/main/java/com/intellectualcrafters/plot/commands/Database.java index 72de12724..198c3d1e0 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Database.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Database.java @@ -58,7 +58,7 @@ public class Database extends SubCommand { @Override public boolean onCommand(final PlotPlayer player, String[] args) { if (args.length < 1) { - MainUtil.sendMessage(player, "/plot database [world] "); + MainUtil.sendMessage(player, "/plot database [world] "); return false; } ArrayList plots; @@ -82,8 +82,13 @@ public class Database extends SubCommand { MainUtil.sendMessage(player, "/plot database import [sqlite file] [prefix]"); return false; } + File file = new File(PS.get().IMP.getDirectory() + File.separator + args[1] + ".db"); + if (!file.exists()) { + MainUtil.sendMessage(player, "&6Database does not exist: " + file); + return false; + } MainUtil.sendMessage(player, "&6Starting..."); - implementation = new SQLite(PS.get().IMP.getDirectory() + File.separator + args[1] + ".db"); + implementation = new SQLite(file.getPath()); final SQLManager manager = new SQLManager(implementation, (args.length == 3) ? args[2] : "", true); final ConcurrentHashMap> map = manager.getPlots(); plots = new ArrayList(); diff --git a/src/main/java/com/intellectualcrafters/plot/commands/FlagCmd.java b/src/main/java/com/intellectualcrafters/plot/commands/FlagCmd.java index 0419bce94..d7270c371 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/FlagCmd.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/FlagCmd.java @@ -197,12 +197,10 @@ public class FlagCmd extends SubCommand { MainUtil.sendMessage(player, C.NOT_VALID_FLAG); return false; } - if (!Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase())) { - for (final String entry : args[2].split(",")) { - if (!Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase() + "." + entry)) { - MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag." + args[1].toLowerCase() + "." + entry); - return false; - } + for (final String entry : args[2].split(",")) { + if (!Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase() + "." + entry)) { + MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag." + args[1].toLowerCase() + "." + entry); + return false; } } final String value = StringMan.join(Arrays.copyOfRange(args, 2, args.length), " "); diff --git a/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java b/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java index 3c346b986..67d46058e 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java @@ -316,6 +316,42 @@ public class MainCommand extends CommandManager { return true; } + public int getMatch(String[] args, Command cmd) { + int count = 0; + String perm = cmd.getPermission(); + HashSet desc = new HashSet(); + for (String word : cmd.getDescription().split(" ")) { + desc.add(word); + } + for (String arg : args) { + if (perm.startsWith(arg)) { + count++; + } + if (desc.contains(arg)) { + count++; + } + } + String[] usage = cmd.getUsage().split(" "); + for (int i = 0; i < Math.min(4 , usage.length); i++) { + int require; + if (usage[i].startsWith("<")) { + require = 1; + } else { + require = 0; + } + String[] split = usage[i].split("\\|| |\\>|\\<|\\[|\\]|\\{|\\}|\\_|\\/"); + for (int j = 0; j < split.length; j++) { + for (String arg : args) { + if (StringMan.isEqualIgnoreCase(arg, split[j])) { + count += 5 - i + require; + } + } + } + } + count += StringMan.intersection(desc, args); + return count; + } + @Override public int handle(final PlotPlayer plr, final String input) { final String[] parts = input.split(" "); @@ -346,46 +382,16 @@ public class MainCommand extends CommandManager { for (final String arg : args) { setargs.add(arg.toLowerCase()); } - setargs.add(label.toLowerCase()); + setargs.add(label); final String[] allargs = setargs.toArray(new String[setargs.size()]); int best = 0; for (final Command current : cmds) { - if (current.getUsage() != null) { - int count = 0; - for (final String word : new HashSet(Arrays.asList((current.getUsage() + " " + current.getPermission() + " " + current.getCategory().name()).toLowerCase() - .replaceAll("\\||\\>|\\<|\\[|\\]|\\{|\\}|\\_|\\/", " ").trim().replaceAll("\\s+", " ").split(" ")))) { - for (int i = 0; i < allargs.length; i++) { - final String arg = allargs[i]; - if ((best - count - ((allargs.length - i) * 3)) >= 0) { - continue; - } - if (StringMan.isEqual(arg, word)) { - count += 3; - } else if ((word.length() > arg.length()) && word.contains(arg)) { - count += 2; - } - } - } - for (final String word : new HashSet(Arrays.asList((current.getDescription()).toLowerCase().replaceAll("\\||\\>|\\<|\\[|\\]|\\{|\\}|\\_|\\/", " ").trim() - .replaceAll("\\s+", " ").split(" ")))) { - for (int i = 0; i < allargs.length; i++) { - final String arg = allargs[i]; - if ((best - count - ((allargs.length - i) * 2)) >= 0) { - continue; - } - if (StringMan.isEqual(arg, word)) { - count += 2; - } else if ((word.length() > arg.length()) && word.contains(arg)) { - count++; - } - } - } - if (count > best) { - best = count; - cmd = current; - } + int match = getMatch(allargs, current); + if (match > best) { + cmd = current; } } + System.out.print(StringMan.getString(allargs) + " | " + cmd + " | " + best); if (cmd == null) { cmd = new StringComparison<>(label, getCommandAndAliases(null, plr)).getMatchObject(); } diff --git a/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java b/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java index 7f180d18d..fb3d35c6c 100644 --- a/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java +++ b/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java @@ -26,7 +26,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; -import java.util.LinkedHashSet; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -299,6 +299,26 @@ public class MainUtil { }, 1); } + public static void objectTask(Collection objects, final RunnableVal task, final Runnable whenDone) { + final Iterator iter = objects.iterator(); + TaskManager.runTask(new Runnable() { + @Override + public void run() { + long start = System.currentTimeMillis(); + boolean hasNext; + while ((hasNext = iter.hasNext()) && System.currentTimeMillis() - start < 5) { + task.value = iter.next(); + task.run(); + } + if (!hasNext) { + TaskManager.runTaskLater(whenDone, 1); + } else { + TaskManager.runTaskLater(this, 1); + } + } + }); + } + public static void plotTask(Plot plot, RunnableVal run) { if (!plot.isMerged()) { run.value = plot; @@ -723,7 +743,7 @@ public class MainUtil { } public static void update(final Plot plot) { - TaskManager.runTaskAsync(new Runnable() { + TaskManager.runTask(new Runnable() { @Override public void run() { final HashSet chunks = new HashSet<>(); @@ -2098,6 +2118,7 @@ public class MainUtil { /** * @deprecated raw access is deprecated */ + @Deprecated public static HashSet connected_cache; public static HashSet regions_cache; diff --git a/src/main/java/com/intellectualcrafters/plot/util/StringMan.java b/src/main/java/com/intellectualcrafters/plot/util/StringMan.java index 81ecd7f49..e25efae9c 100644 --- a/src/main/java/com/intellectualcrafters/plot/util/StringMan.java +++ b/src/main/java/com/intellectualcrafters/plot/util/StringMan.java @@ -6,6 +6,7 @@ import java.util.Collection; import java.util.Comparator; import java.util.Map; import java.util.Map.Entry; +import java.util.Set; public class StringMan { public static String replaceFromMap(final String string, final Map replacements) { @@ -29,6 +30,16 @@ public class StringMan { return sb.toString(); } + public static int intersection(Set options, String[] toCheck) { + int count = 0; + for (String check : toCheck) { + if (options.contains(check)) { + count++; + } + } + return count; + } + public static String getString(final Object obj) { if (obj == null) { return "null"; diff --git a/src/main/java/com/plotsquared/bukkit/util/BukkitSetBlockManager.java b/src/main/java/com/plotsquared/bukkit/util/BukkitSetBlockManager.java index 688d45e53..5fb7a7c95 100644 --- a/src/main/java/com/plotsquared/bukkit/util/BukkitSetBlockManager.java +++ b/src/main/java/com/plotsquared/bukkit/util/BukkitSetBlockManager.java @@ -7,7 +7,9 @@ import org.bukkit.Chunk; import org.bukkit.World; import com.intellectualcrafters.plot.object.ChunkLoc; +import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.util.BlockUpdateUtil; +import com.intellectualcrafters.plot.util.MainUtil; public abstract class BukkitSetBlockManager extends BlockUpdateUtil { public static BukkitSetBlockManager setBlockManager = null; @@ -18,11 +20,20 @@ public abstract class BukkitSetBlockManager extends BlockUpdateUtil { @Override public void update(final String worldname, final Collection chunkLocs) { + final ArrayList chunks = new ArrayList<>(); final World world = BukkitUtil.getWorld(worldname); - final ArrayList chunks = new ArrayList(); - for (final ChunkLoc loc : chunkLocs) { - chunks.add(world.getChunkAt(loc.x, loc.z)); - } - setBlockManager.update(chunks); + MainUtil.objectTask(chunkLocs, new RunnableVal() { + + @Override + public void run() { + chunks.add(world.getChunkAt(value.x, value.z)); + } + }, new Runnable() { + + @Override + public void run() { + setBlockManager.update(chunks); + } + }); } } diff --git a/target/PlotSquared-Bukkit.jar b/target/PlotSquared-Bukkit.jar index addb85dae..0a1832b72 100644 Binary files a/target/PlotSquared-Bukkit.jar and b/target/PlotSquared-Bukkit.jar differ