diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/C.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/C.java index 0800998f3..5dcc54eaf 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/C.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/C.java @@ -137,7 +137,8 @@ public enum C { /* * Commands */ - NOT_VALID_SUBCOMMAND("&cThat is not a valid subcommand."), + NOT_VALID_SUBCOMMAND("&cThat is not a valid subcommand"), + DID_YOU_MEAN("&cDid you mean: &6%s"), NO_COMMANDS("&cI'm sorry, but you're not permitted to use any subcommands."), SUBCOMMAND_SET_OPTIONS_HEADER("&cPossible Values: "), /* diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java index 65a7885ee..02bbbb5dd 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java @@ -670,7 +670,8 @@ public class PlotMain extends JavaPlugin { } } - getCommand("plots").setExecutor(new MainCommand()); + MainCommand command = new MainCommand(); + getCommand("plots").setExecutor(command); getCommand("plots").setAliases(new ArrayList() { { add("p"); @@ -679,7 +680,7 @@ public class PlotMain extends JavaPlugin { add("plot"); } }); - + getCommand("plots").setTabCompleter(command); getServer().getPluginManager().registerEvents(new PlayerEvents(), this); PlotPlusListener.startRunnable(this); getServer().getPluginManager().registerEvents(new PlotPlusListener(), this); @@ -958,36 +959,37 @@ public class PlotMain extends JavaPlugin { @SuppressWarnings("deprecation") public static void killAllEntities() { Bukkit.getScheduler().scheduleSyncRepeatingTask(getMain(), new Runnable() { - Location location; - long ticked = 0l; - long error = 0l; - { - sendConsoleSenderMessage(C.PREFIX.s() + "KillAllEntities started."); - } + Location location; + long ticked = 0l; + long error = 0l; - @Override - public void run() { - if (this.ticked > 36000l) { - this.ticked = 0l; - sendConsoleSenderMessage(C.PREFIX.s() + "KillAllEntities has been running for 60 minutes. Errors: " - + this.error); - this.error = 0l; - } - for (String w : getPlotWorlds()) { - getWorldSettings(w); - World world = Bukkit.getServer().getWorld(w); - try { - if (world.getLoadedChunks().length < 1) { - continue; - } - for (Chunk chunk : world.getLoadedChunks()) { - Entity[] entities = chunk.getEntities(); - for (int i = entities.length - 1; i >= 0; i--) { - Entity entity = entities[i]; - if ((entity instanceof Player) || PlayerEvents.isInPlot(entity.getLocation())) { - continue; - } - entity.remove(); + { + sendConsoleSenderMessage(C.PREFIX.s() + "KillAllEntities started."); + } + + @Override + public void run() { + if (this.ticked > 36000l) { + this.ticked = 0l; + sendConsoleSenderMessage(C.PREFIX.s() + "KillAllEntities has been running for 60 minutes. Errors: " + + this.error); + this.error = 0l; + } + for (String w : getPlotWorlds()) { + getWorldSettings(w); + World world = Bukkit.getServer().getWorld(w); + try { + if (world.getLoadedChunks().length < 1) { + continue; + } + for (Chunk chunk : world.getLoadedChunks()) { + Entity[] entities = chunk.getEntities(); + for (int i = entities.length - 1; i >= 0; i--) { + Entity entity = entities[i]; + if ((entity instanceof Player) || PlayerEvents.isInPlot(entity.getLocation())) { + continue; + } + entity.remove(); // boolean tamed = false; // if (Settings.MOB_PATHFINDING) { // if (entity instanceof Tameable) { @@ -1046,18 +1048,16 @@ public class PlotMain extends JavaPlugin { // } // entity.teleport(this.location.subtract(this.location.getDirection().normalize().multiply(2))); // } - } - } - } - catch (Throwable e) { - ++this.error; - } - finally { - ++this.ticked; - } - } - } - }, 2L, 2L); + } + } + } catch (Throwable e) { + ++this.error; + } finally { + ++this.ticked; + } + } + } + }, 2L, 2L); } /** 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 2011be25a..3e54e5f15 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java @@ -11,21 +11,24 @@ package com.intellectualcrafters.plot.commands; 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; import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; import org.bukkit.entity.Player; import java.util.ArrayList; import java.util.Arrays; +import java.util.List; /** * PlotMain command class * * @author Citymonstret */ -public class MainCommand implements CommandExecutor { +public class MainCommand implements CommandExecutor, TabCompleter { private static SubCommand[] _subCommands = new SubCommand[] { new Claim(), new Paste(), new Copy(), new Clipboard(), new Auto(), new Home(), new Visit(), new TP(), new Set(), new Clear(), new Delete(), new SetOwner(), new Denied(), new Helpers(), new Trusted(), @@ -114,6 +117,12 @@ public class MainCommand implements CommandExecutor { } } PlayerFunctions.sendMessage(player, C.NOT_VALID_SUBCOMMAND); + + String[] commands = new String[subCommands.size()]; + for(int x = 0; x < subCommands.size(); x++) + commands[x] = subCommands.get(x).cmd; + + PlayerFunctions.sendMessage(player, C.DID_YOU_MEAN, new StringComparsion(args[0], commands).getBestMatch()); } return false; } @@ -145,4 +154,26 @@ public class MainCommand implements CommandExecutor { return ChatColor.translateAlternateColorCodes('&', s); } + @Override + public List onTabComplete(CommandSender commandSender, Command command, String s, String[] strings) { + if(!(commandSender instanceof Player)) return null; + Player player = (Player) commandSender; + ArrayList subo = subCommands; + while(true) { + String sub = new StringComparsion(strings[0], subo.toArray()).getBestMatch(); + if(subo.isEmpty()) + break; + for (SubCommand subCommand : subo) { + if (subCommand.cmd.equals(sub)) { + if(subCommand.permission.hasPermission(player)) + return Arrays.asList(sub); + else { + subo.remove(subCommand); + break; + } + } + } + } + return null; + } }