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

@ -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] <sqlite|mysql>");
MainUtil.sendMessage(player, "/plot database [world] <sqlite|mysql|import>");
return false;
}
ArrayList<Plot> 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<String, ConcurrentHashMap<PlotId, Plot>> map = manager.getPlots();
plots = new ArrayList<Plot>();

View File

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

View File

@ -316,6 +316,42 @@ public class MainCommand extends CommandManager<PlotPlayer> {
getInstance().handle(player, builder.toString());
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
public int handle(final PlotPlayer plr, final String input) {
@ -346,46 +382,16 @@ public class MainCommand extends CommandManager<PlotPlayer> {
final HashSet<String> setargs = new HashSet<>(args.length + 1);
for (final String arg : args) {
setargs.add(arg.toLowerCase());
}
}
setargs.add(label);
final String[] allargs = setargs.toArray(new String[setargs.size()]);
int best = 0;
for (final Command<PlotPlayer> current : cmds) {
if (current.getUsage() != null) {
int count = 0;
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;
for (final Command<PlotPlayer> current : cmds) {
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();