From 0ff50aed1110eae59b4dec854e2f5ebe71d697dc Mon Sep 17 00:00:00 2001 From: Sauilitired Date: Thu, 6 Nov 2014 09:37:46 +0100 Subject: [PATCH] Experimenting with String comparison, and help methods --- .../com/intellectualcrafters/plot/Plot.java | 9 ++++ .../plot/StringComparsion.java | 5 ++ .../plot/commands/MainCommand.java | 48 +++++-------------- 3 files changed, 25 insertions(+), 37 deletions(-) diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/Plot.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/Plot.java index 6fbcea5bb..3004da105 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/Plot.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/Plot.java @@ -277,6 +277,15 @@ public class Plot implements Cloneable { PlotHelper.clear(plr, this); } + /** + * Get the plot hashcode + * + * @return integer. You can easily make this a character array
+ * xI = c[0] + * x = c[1 -> xI...] + * yI = c[xI ... + 1] + * y = c[xI ... + 2 -> yI ...] + */ @Override public int hashCode() { final int diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/StringComparsion.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/StringComparsion.java index e5aefa907..7caa0360b 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/StringComparsion.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/StringComparsion.java @@ -11,6 +11,7 @@ import java.util.Collections; public class StringComparsion { private String bestMatch; + private Object bestMatchObject; private double match; public StringComparsion(final String input, final Object[] objects) { @@ -19,10 +20,14 @@ public class StringComparsion { if ((c = compare(input, o.toString())) > this.match) { this.match = c; this.bestMatch = o.toString(); + this.bestMatchObject = o; } } } + public Object getMatchObject() { + return this.bestMatchObject; + } public String getBestMatch() { return this.bestMatch; } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java index ef8e08892..2c6f673fa 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java @@ -8,10 +8,10 @@ package com.intellectualcrafters.plot.commands; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - +import com.intellectualcrafters.plot.C; +import com.intellectualcrafters.plot.PlayerFunctions; +import com.intellectualcrafters.plot.PlotMain; +import com.intellectualcrafters.plot.StringComparsion; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; @@ -20,10 +20,9 @@ import org.bukkit.command.TabCompleter; import org.bukkit.entity.Player; import org.bukkit.util.ChatPaginator; -import com.intellectualcrafters.plot.C; -import com.intellectualcrafters.plot.PlayerFunctions; -import com.intellectualcrafters.plot.PlotMain; -import com.intellectualcrafters.plot.StringComparsion; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; /** * PlotMain command class @@ -139,7 +138,10 @@ public class MainCommand implements CommandExecutor, TabCompleter { commands[x] = subCommands.get(x).cmd; } - PlayerFunctions.sendMessage(player, C.DID_YOU_MEAN, new StringComparsion(args[0], commands).getBestMatch()); + /* Let's try to get a proper usage string */ + SubCommand command = (SubCommand) new StringComparsion(args[0], commands).getMatchObject(); + PlayerFunctions.sendMessage(player, C.DID_YOU_MEAN, command.usage.contains("plot") ? command.usage : "/plot " + command.usage); + //PlayerFunctions.sendMessage(player, C.DID_YOU_MEAN, new StringComparsion(args[0], commands).getBestMatch()); } return false; } @@ -154,34 +156,6 @@ public class MainCommand implements CommandExecutor, TabCompleter { return cmds; } - /* - * // Current page - * int page = 0; - * //is a page specified? else use 0 - * if(args.length > 1) { - * try { - * page = Integer.parseInt(args[1]); - * } catch(Exception e) { - * page = 0; - * } - * } - * //Get the total pages - * int totalPages = ((int) Math.ceil(12 * (PlotMain.getPlotsSorted().size()) - * / 100)); - * if(page > totalPages) - * page = totalPages; - * //Only display 12! - * int max = (page * 12) + 12; - * if(max > PlotMain.getPlotsSorted().size()) - * max = PlotMain.getPlotsSorted().size(); - * StringBuilder string = new StringBuilder(); - * string.append(C.PLOT_LIST_HEADER_PAGED.s().replaceAll("%cur", page + 1 + - * "").replaceAll("%max", totalPages + 1 + "").replaceAll("%word%", "all") + - * "\n"); - * Plot p; - * //This might work xD - * for (int x = (page * 12); x < max; x++) { - */ public static ArrayList helpMenu(final Player player, final SubCommand.CommandCategory category, int page) { final List commands = getCommands(category, player); // final int totalPages = ((int) Math.ceil(12 * (commands.size()) /