:D Tab completion

This commit is contained in:
Sauilitired 2014-11-01 16:13:44 +01:00
parent fd81546bab
commit 5b62523003
3 changed files with 77 additions and 45 deletions

View File

@ -137,7 +137,8 @@ public enum C {
/* /*
* Commands * 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."), NO_COMMANDS("&cI'm sorry, but you're not permitted to use any subcommands."),
SUBCOMMAND_SET_OPTIONS_HEADER("&cPossible Values: "), SUBCOMMAND_SET_OPTIONS_HEADER("&cPossible Values: "),
/* /*

View File

@ -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<String>() { getCommand("plots").setAliases(new ArrayList<String>() {
{ {
add("p"); add("p");
@ -679,7 +680,7 @@ public class PlotMain extends JavaPlugin {
add("plot"); add("plot");
} }
}); });
getCommand("plots").setTabCompleter(command);
getServer().getPluginManager().registerEvents(new PlayerEvents(), this); getServer().getPluginManager().registerEvents(new PlayerEvents(), this);
PlotPlusListener.startRunnable(this); PlotPlusListener.startRunnable(this);
getServer().getPluginManager().registerEvents(new PlotPlusListener(), this); getServer().getPluginManager().registerEvents(new PlotPlusListener(), this);
@ -958,36 +959,37 @@ public class PlotMain extends JavaPlugin {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public static void killAllEntities() { public static void killAllEntities() {
Bukkit.getScheduler().scheduleSyncRepeatingTask(getMain(), new Runnable() { Bukkit.getScheduler().scheduleSyncRepeatingTask(getMain(), new Runnable() {
Location location; Location location;
long ticked = 0l; long ticked = 0l;
long error = 0l; long error = 0l;
{
sendConsoleSenderMessage(C.PREFIX.s() + "KillAllEntities started.");
}
@Override {
public void run() { sendConsoleSenderMessage(C.PREFIX.s() + "KillAllEntities started.");
if (this.ticked > 36000l) { }
this.ticked = 0l;
sendConsoleSenderMessage(C.PREFIX.s() + "KillAllEntities has been running for 60 minutes. Errors: " @Override
+ this.error); public void run() {
this.error = 0l; if (this.ticked > 36000l) {
} this.ticked = 0l;
for (String w : getPlotWorlds()) { sendConsoleSenderMessage(C.PREFIX.s() + "KillAllEntities has been running for 60 minutes. Errors: "
getWorldSettings(w); + this.error);
World world = Bukkit.getServer().getWorld(w); this.error = 0l;
try { }
if (world.getLoadedChunks().length < 1) { for (String w : getPlotWorlds()) {
continue; getWorldSettings(w);
} World world = Bukkit.getServer().getWorld(w);
for (Chunk chunk : world.getLoadedChunks()) { try {
Entity[] entities = chunk.getEntities(); if (world.getLoadedChunks().length < 1) {
for (int i = entities.length - 1; i >= 0; i--) { continue;
Entity entity = entities[i]; }
if ((entity instanceof Player) || PlayerEvents.isInPlot(entity.getLocation())) { for (Chunk chunk : world.getLoadedChunks()) {
continue; Entity[] entities = chunk.getEntities();
} for (int i = entities.length - 1; i >= 0; i--) {
entity.remove(); Entity entity = entities[i];
if ((entity instanceof Player) || PlayerEvents.isInPlot(entity.getLocation())) {
continue;
}
entity.remove();
// boolean tamed = false; // boolean tamed = false;
// if (Settings.MOB_PATHFINDING) { // if (Settings.MOB_PATHFINDING) {
// if (entity instanceof Tameable) { // if (entity instanceof Tameable) {
@ -1046,18 +1048,16 @@ public class PlotMain extends JavaPlugin {
// } // }
// entity.teleport(this.location.subtract(this.location.getDirection().normalize().multiply(2))); // entity.teleport(this.location.subtract(this.location.getDirection().normalize().multiply(2)));
// } // }
} }
} }
} } catch (Throwable e) {
catch (Throwable e) { ++this.error;
++this.error; } finally {
} ++this.ticked;
finally { }
++this.ticked; }
} }
} }, 2L, 2L);
}
}, 2L, 2L);
} }
/** /**

View File

@ -11,21 +11,24 @@ package com.intellectualcrafters.plot.commands;
import com.intellectualcrafters.plot.C; import com.intellectualcrafters.plot.C;
import com.intellectualcrafters.plot.PlayerFunctions; import com.intellectualcrafters.plot.PlayerFunctions;
import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.PlotMain;
import com.intellectualcrafters.plot.StringComparsion;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List;
/** /**
* PlotMain command class * PlotMain command class
* *
* @author Citymonstret * @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(), 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(), 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); 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; return false;
} }
@ -145,4 +154,26 @@ public class MainCommand implements CommandExecutor {
return ChatColor.translateAlternateColorCodes('&', s); return ChatColor.translateAlternateColorCodes('&', s);
} }
@Override
public List<String> onTabComplete(CommandSender commandSender, Command command, String s, String[] strings) {
if(!(commandSender instanceof Player)) return null;
Player player = (Player) commandSender;
ArrayList<SubCommand> 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;
}
} }