This commit is contained in:
Jesse Boyd 2015-09-30 16:11:44 +10:00
parent 3bd4895676
commit 9d77b422df
8 changed files with 103 additions and 51 deletions

View File

@ -8,7 +8,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> </properties>
<artifactId>PlotSquared</artifactId> <artifactId>PlotSquared</artifactId>
<version>3.2.6</version> <version>3.2.7</version>
<name>PlotSquared</name> <name>PlotSquared</name>
<packaging>jar</packaging> <packaging>jar</packaging>
<build> <build>

View File

@ -58,7 +58,7 @@ public class Database extends SubCommand {
@Override @Override
public boolean onCommand(final PlotPlayer player, String[] args) { public boolean onCommand(final PlotPlayer player, String[] args) {
if (args.length < 1) { if (args.length < 1) {
MainUtil.sendMessage(player, "/plot database [world] <sqlite|mysql>"); MainUtil.sendMessage(player, "/plot database [world] <sqlite|mysql|import>");
return false; return false;
} }
ArrayList<Plot> plots; ArrayList<Plot> plots;
@ -82,8 +82,13 @@ public class Database extends SubCommand {
MainUtil.sendMessage(player, "/plot database import [sqlite file] [prefix]"); MainUtil.sendMessage(player, "/plot database import [sqlite file] [prefix]");
return false; 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..."); 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 SQLManager manager = new SQLManager(implementation, (args.length == 3) ? args[2] : "", true);
final ConcurrentHashMap<String, ConcurrentHashMap<PlotId, Plot>> map = manager.getPlots(); final ConcurrentHashMap<String, ConcurrentHashMap<PlotId, Plot>> map = manager.getPlots();
plots = new ArrayList<Plot>(); plots = new ArrayList<Plot>();

View File

@ -197,14 +197,12 @@ public class FlagCmd extends SubCommand {
MainUtil.sendMessage(player, C.NOT_VALID_FLAG); MainUtil.sendMessage(player, C.NOT_VALID_FLAG);
return false; return false;
} }
if (!Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase())) {
for (final String entry : args[2].split(",")) { for (final String entry : args[2].split(",")) {
if (!Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase() + "." + entry)) { if (!Permissions.hasPermission(player, "plots.set.flag." + args[1].toLowerCase() + "." + entry)) {
MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag." + args[1].toLowerCase() + "." + entry); MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.set.flag." + args[1].toLowerCase() + "." + entry);
return false; return false;
} }
} }
}
final String value = StringMan.join(Arrays.copyOfRange(args, 2, args.length), " "); final String value = StringMan.join(Arrays.copyOfRange(args, 2, args.length), " ");
final Object parsed = af.parseValueRaw(value); final Object parsed = af.parseValueRaw(value);
if (parsed == null) { if (parsed == null) {

View File

@ -316,6 +316,42 @@ public class MainCommand extends CommandManager<PlotPlayer> {
return true; return true;
} }
public int getMatch(String[] args, Command<PlotPlayer> cmd) {
int count = 0;
String perm = cmd.getPermission();
HashSet<String> desc = new HashSet<String>();
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 @Override
public int handle(final PlotPlayer plr, final String input) { public int handle(final PlotPlayer plr, final String input) {
final String[] parts = input.split(" "); final String[] parts = input.split(" ");
@ -346,46 +382,16 @@ public class MainCommand extends CommandManager<PlotPlayer> {
for (final String arg : args) { for (final String arg : args) {
setargs.add(arg.toLowerCase()); setargs.add(arg.toLowerCase());
} }
setargs.add(label.toLowerCase()); setargs.add(label);
final String[] allargs = setargs.toArray(new String[setargs.size()]); final String[] allargs = setargs.toArray(new String[setargs.size()]);
int best = 0; int best = 0;
for (final Command<PlotPlayer> current : cmds) { for (final Command<PlotPlayer> current : cmds) {
if (current.getUsage() != null) { int match = getMatch(allargs, current);
int count = 0; if (match > best) {
for (final String word : new HashSet<String>(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<String>(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; cmd = current;
} }
} }
} System.out.print(StringMan.getString(allargs) + " | " + cmd + " | " + best);
if (cmd == null) { if (cmd == null) {
cmd = new StringComparison<>(label, getCommandAndAliases(null, plr)).getMatchObject(); cmd = new StringComparison<>(label, getCommandAndAliases(null, plr)).getMatchObject();
} }

View File

@ -26,7 +26,7 @@ import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.LinkedHashSet; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
@ -299,6 +299,26 @@ public class MainUtil {
}, 1); }, 1);
} }
public static <T> void objectTask(Collection<T> objects, final RunnableVal<T> task, final Runnable whenDone) {
final Iterator<T> 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<Plot> run) { public static void plotTask(Plot plot, RunnableVal<Plot> run) {
if (!plot.isMerged()) { if (!plot.isMerged()) {
run.value = plot; run.value = plot;
@ -723,7 +743,7 @@ public class MainUtil {
} }
public static void update(final Plot plot) { public static void update(final Plot plot) {
TaskManager.runTaskAsync(new Runnable() { TaskManager.runTask(new Runnable() {
@Override @Override
public void run() { public void run() {
final HashSet<ChunkLoc> chunks = new HashSet<>(); final HashSet<ChunkLoc> chunks = new HashSet<>();
@ -2098,6 +2118,7 @@ public class MainUtil {
/** /**
* @deprecated raw access is deprecated * @deprecated raw access is deprecated
*/ */
@Deprecated
public static HashSet<Plot> connected_cache; public static HashSet<Plot> connected_cache;
public static HashSet<RegionWrapper> regions_cache; public static HashSet<RegionWrapper> regions_cache;

View File

@ -6,6 +6,7 @@ import java.util.Collection;
import java.util.Comparator; import java.util.Comparator;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set;
public class StringMan { public class StringMan {
public static String replaceFromMap(final String string, final Map<String, String> replacements) { public static String replaceFromMap(final String string, final Map<String, String> replacements) {
@ -29,6 +30,16 @@ public class StringMan {
return sb.toString(); return sb.toString();
} }
public static int intersection(Set<String> options, String[] toCheck) {
int count = 0;
for (String check : toCheck) {
if (options.contains(check)) {
count++;
}
}
return count;
}
public static String getString(final Object obj) { public static String getString(final Object obj) {
if (obj == null) { if (obj == null) {
return "null"; return "null";

View File

@ -7,7 +7,9 @@ import org.bukkit.Chunk;
import org.bukkit.World; import org.bukkit.World;
import com.intellectualcrafters.plot.object.ChunkLoc; import com.intellectualcrafters.plot.object.ChunkLoc;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.util.BlockUpdateUtil; import com.intellectualcrafters.plot.util.BlockUpdateUtil;
import com.intellectualcrafters.plot.util.MainUtil;
public abstract class BukkitSetBlockManager extends BlockUpdateUtil { public abstract class BukkitSetBlockManager extends BlockUpdateUtil {
public static BukkitSetBlockManager setBlockManager = null; public static BukkitSetBlockManager setBlockManager = null;
@ -18,11 +20,20 @@ public abstract class BukkitSetBlockManager extends BlockUpdateUtil {
@Override @Override
public void update(final String worldname, final Collection<ChunkLoc> chunkLocs) { public void update(final String worldname, final Collection<ChunkLoc> chunkLocs) {
final ArrayList<Chunk> chunks = new ArrayList<>();
final World world = BukkitUtil.getWorld(worldname); final World world = BukkitUtil.getWorld(worldname);
final ArrayList<Chunk> chunks = new ArrayList<Chunk>(); MainUtil.objectTask(chunkLocs, new RunnableVal<ChunkLoc>() {
for (final ChunkLoc loc : chunkLocs) {
chunks.add(world.getChunkAt(loc.x, loc.z)); @Override
public void run() {
chunks.add(world.getChunkAt(value.x, value.z));
} }
}, new Runnable() {
@Override
public void run() {
setBlockManager.update(chunks); setBlockManager.update(chunks);
} }
});
}
} }

Binary file not shown.