: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
*/
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: "),
/*

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>() {
{
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);
}
/**

View File

@ -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<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;
}
}