More work on tab completion, see details.. #77

Completed:
- Jail check
- jail clear
- jail createcell
- jail deletecell
- Jail list
- jail listcells
- jail mute
This commit is contained in:
graywolf336 2015-06-01 21:14:01 -05:00
parent 73715c3d68
commit 019deea43a
35 changed files with 407 additions and 12 deletions

View File

@ -204,11 +204,15 @@ public class JailMain extends JavaPlugin {
getServer().getConsoleSender().sendMessage(Lang.PLUGINNOTLOADED.get());
}else {
debug("Tab Complete Args (" + args.length + ") for '" + commandLabel + "': " + Util.getStringFromArray(", ", args));
if(commandLabel.equalsIgnoreCase("jail") || commandLabel.equalsIgnoreCase("j")) {
return jh.parseTabComplete(jm, sender, args);
}else {
//cmdHand.handleCommand(jm, sender, command.getName().toLowerCase(), args);
//unjail,etc
try {
if(commandLabel.equalsIgnoreCase("jail") || commandLabel.equalsIgnoreCase("j")) {
return jh.parseTabComplete(jm, sender, args);
}else {
//cmdHand.handleCommand(jm, sender, command.getName().toLowerCase(), args);
//unjail,etc
}
}catch(Exception e) {
return Collections.emptyList();
}
}

View File

@ -1,8 +1,11 @@
package com.graywolf336.jail;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.UUID;
import org.bukkit.Location;
@ -80,6 +83,18 @@ public class JailManager {
return toReturn;
}
/** Returns a List of the jail names. */
public List<String> getJailNamesAsList() {
List<String> results = new ArrayList<String>();
for(Jail j : this.jails.values())
results.add(j.getName());
Collections.sort(results);
return results;
}
/**
* Adds a jail to the collection of them.

View File

@ -1,5 +1,7 @@
package com.graywolf336.jail.command;
import java.util.List;
import org.bukkit.command.CommandSender;
import com.graywolf336.jail.JailManager;
@ -9,7 +11,7 @@ import com.graywolf336.jail.JailManager;
*
* @author graywolf336
* @since 3.0.0
* @version 1.0.0
* @version 1.1.0
*/
public interface Command {
/**
@ -28,4 +30,6 @@ public interface Command {
* @return True if the method handled it in any way, false if we should send the usage message.
*/
public boolean execute(JailManager jm, CommandSender sender, String... args) throws Exception;
public List<String> provideTabCompletions(JailManager jm, CommandSender sender, String... args) throws Exception;
}

View File

@ -8,6 +8,7 @@ import java.util.Map.Entry;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.util.StringUtil;
import com.graywolf336.jail.JailMain;
import com.graywolf336.jail.JailManager;
@ -49,9 +50,10 @@ public class JailHandler {
plugin.debug("Loaded " + commands.size() + " sub-commands of /jail.");
}
public List<String> parseTabComplete(JailManager jm, CommandSender sender, String[] args) {
if(args[0].equalsIgnoreCase("")) {
public List<String> parseTabComplete(JailManager jm, CommandSender sender, String[] args) throws Exception {
if(args[0].equalsIgnoreCase("") || args.length == 1) {
List<String> results = new ArrayList<String>();
String arg0 = args[0].toLowerCase();
boolean hasJailPermission = false;
for(Command c : commands.values()) {
@ -65,7 +67,10 @@ public class JailHandler {
//Skip if the command requires a player and the sender isn't a player
if(i.needsPlayer() && !(sender instanceof Player)) continue;
if(sender.hasPermission(i.permission())) {
//If the sender has permission to the command
//and the first argument (sub command) is empty OR
//the first argument matches the command or starts with the string
if(sender.hasPermission(i.permission()) && (arg0.equalsIgnoreCase("") || (arg0.toLowerCase().matches(i.pattern()) || i.pattern().startsWith(arg0)))) {
results.add(i.pattern().split("\\|")[0]);
}
}
@ -74,11 +79,34 @@ public class JailHandler {
Collections.sort(results);
//Don't send out all the players if they don't have jail permission
if(hasJailPermission)
for(Player p : jm.getPlugin().getServer().getOnlinePlayers())
results.add(p.getName());
if(hasJailPermission) {
for(Player p : jm.getPlugin().getServer().getOnlinePlayers()) {
if(arg0.equalsIgnoreCase("") || StringUtil.startsWithIgnoreCase(p.getName(), arg0))
results.add(p.getName());
}
}
return results;
}else {
String arg0 = args[0].toLowerCase();
for(Command c : commands.values()) {
CommandInfo i = c.getClass().getAnnotation(CommandInfo.class);
//Skip if the command requires a player and the sender isn't a player
if(i.needsPlayer() && !(sender instanceof Player)) continue;
//If the sender doesn't have permission, we won't send them further
if(!sender.hasPermission(i.permission())) continue;
//Sender provided too many arguments which means there
//is nothing to tab complete
if(i.maxArgs() != -1 && i.maxArgs() < args.length - 1) continue;
if(arg0.toLowerCase().matches(i.pattern())) {
return c.provideTabCompletions(jm, sender, args);
}
}
}
return Collections.emptyList();

View File

@ -1,5 +1,8 @@
package com.graywolf336.jail.command.commands;
import java.util.Collections;
import java.util.List;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -38,4 +41,9 @@ public class HandCuffCommand implements Command {
return true;
}
public List<String> provideTabCompletions(JailManager jm, CommandSender sender, String... args) throws Exception {
//TODO implement
return Collections.emptyList();
}
}

View File

@ -1,5 +1,8 @@
package com.graywolf336.jail.command.commands;
import java.util.Collections;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
@ -21,4 +24,9 @@ public class ToggleJailDebugCommand implements Command {
sender.sendMessage("Jail debugging is now: " + (debug ? ChatColor.GREEN + "enabled" : ChatColor.RED + "disabled"));
return true;
}
public List<String> provideTabCompletions(JailManager jm, CommandSender sender, String... args) throws Exception {
//No tab completion required for toggling debug command
return Collections.emptyList();
}
}

View File

@ -1,5 +1,8 @@
package com.graywolf336.jail.command.commands;
import java.util.Collections;
import java.util.List;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -32,4 +35,9 @@ public class UnHandCuffCommand implements Command {
return true;
}
public List<String> provideTabCompletions(JailManager jm, CommandSender sender, String... args) throws Exception {
//TODO implement
return Collections.emptyList();
}
}

View File

@ -1,5 +1,8 @@
package com.graywolf336.jail.command.commands;
import java.util.Collections;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -60,4 +63,9 @@ public class UnJailCommand implements Command {
return true;
}
public List<String> provideTabCompletions(JailManager jm, CommandSender sender, String... args) throws Exception {
//TODO implement
return Collections.emptyList();
}
}

View File

@ -1,5 +1,8 @@
package com.graywolf336.jail.command.commands;
import java.util.Collections;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
@ -34,4 +37,9 @@ public class UnJailForceCommand implements Command {
return true;
}
public List<String> provideTabCompletions(JailManager jm, CommandSender sender, String... args) throws Exception {
//TODO implement
return Collections.emptyList();
}
}

View File

@ -1,7 +1,12 @@
package com.graywolf336.jail.command.subcommands;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.util.StringUtil;
import com.graywolf336.jail.JailManager;
import com.graywolf336.jail.beans.Prisoner;
@ -36,4 +41,19 @@ public class JailCheckCommand implements Command{
return true;
}
public List<String> provideTabCompletions(JailManager jm, CommandSender sender, String... args) throws Exception {
List<String> results = new ArrayList<String>();
for(Prisoner p : jm.getAllPrisoners().values()) {
if(args.length == 2 && StringUtil.startsWithIgnoreCase(p.getLastKnownName(), args[1].toLowerCase())) {
results.add(p.getLastKnownName());
}else {
results.add(p.getLastKnownName());
}
}
Collections.sort(results);
return results;
}
}

View File

@ -1,9 +1,15 @@
package com.graywolf336.jail.command.subcommands;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.bukkit.command.CommandSender;
import org.bukkit.util.StringUtil;
import com.graywolf336.jail.JailManager;
import com.graywolf336.jail.beans.ConfirmPlayer;
import com.graywolf336.jail.beans.Jail;
import com.graywolf336.jail.command.Command;
import com.graywolf336.jail.command.CommandInfo;
import com.graywolf336.jail.enums.Confirmation;
@ -38,4 +44,21 @@ public class JailClearCommand implements Command {
return true;
}
public List<String> provideTabCompletions(JailManager jm, CommandSender sender, String... args) throws Exception {
List<String> results = new ArrayList<String>();
for(Jail j : jm.getJails()) {
if((args.length == 2 && StringUtil.startsWithIgnoreCase(j.getName(), args[1]))
|| (args.length == 3 && StringUtil.startsWithIgnoreCase(j.getName(), args[2]))) {
results.add(j.getName());
}else {
results.add(j.getName());
}
}
Collections.sort(results);
return results;
}
}

View File

@ -1,6 +1,7 @@
package com.graywolf336.jail.command.subcommands;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
@ -245,4 +246,9 @@ public class JailCommand implements Command {
return true;
}
public List<String> provideTabCompletions(JailManager jm, CommandSender sender, String... args) throws Exception {
//TODO implement (this'll take a while)
return Collections.emptyList();
}
}

View File

@ -1,5 +1,8 @@
package com.graywolf336.jail.command.subcommands;
import java.util.Collections;
import java.util.List;
import org.bukkit.command.CommandSender;
import com.graywolf336.jail.JailManager;
@ -88,4 +91,8 @@ public class JailConfirmCommand implements Command{
return true;
}
public List<String> provideTabCompletions(JailManager jm, CommandSender sender, String... args) throws Exception {
//confirming doesn't require any tab completing
return Collections.emptyList();
}
}

View File

@ -1,8 +1,13 @@
package com.graywolf336.jail.command.subcommands;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.util.StringUtil;
import com.graywolf336.jail.JailManager;
import com.graywolf336.jail.beans.Jail;
@ -63,4 +68,22 @@ public class JailCreateCellCommand implements Command {
return true;
}
public List<String> provideTabCompletions(JailManager jm, CommandSender sender, String... args) throws Exception {
//We shouldn't provide when they want a cell name
if(args.length >= 3) return Collections.emptyList();
List<String> results = new ArrayList<String>();
for(Jail j : jm.getJails()) {
if(args.length == 2 && StringUtil.startsWithIgnoreCase(j.getName(), args[1])) {
results.add(j.getName());
}else {
results.add(j.getName());
}
}
Collections.sort(results);
return results;
}
}

View File

@ -1,5 +1,8 @@
package com.graywolf336.jail.command.subcommands;
import java.util.Collections;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -45,4 +48,9 @@ public class JailCreateCommand implements Command {
return true;
}
public List<String> provideTabCompletions(JailManager jm, CommandSender sender, String... args) throws Exception {
//Creating a jail shouldn't provide tab completion
return Collections.emptyList();
}
}

View File

@ -1,9 +1,16 @@
package com.graywolf336.jail.command.subcommands;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.bukkit.command.CommandSender;
import org.bukkit.util.StringUtil;
import com.graywolf336.jail.JailManager;
import com.graywolf336.jail.beans.Cell;
import com.graywolf336.jail.beans.ConfirmPlayer;
import com.graywolf336.jail.beans.Jail;
import com.graywolf336.jail.command.Command;
import com.graywolf336.jail.command.CommandInfo;
import com.graywolf336.jail.enums.Confirmation;
@ -28,4 +35,32 @@ public class JailDeleteCellCommand implements Command {
return true;
}
public List<String> provideTabCompletions(JailManager jm, CommandSender sender, String... args) throws Exception {
List<String> results = new ArrayList<String>();
switch(args.length) {
case 1:
results.addAll(jm.getJailNamesAsList());
break;
case 2:
for(Jail j : jm.getJails())
if(StringUtil.startsWithIgnoreCase(j.getName(), args[1]))
results.add(j.getName());
break;
case 3:
if(jm.isValidJail(args[1])) {
Jail j = jm.getJail(args[1]);
for(Cell c : j.getCells())
if(StringUtil.startsWithIgnoreCase(c.getName(), args[2]))
results.add(c.getName());
}
break;
}
Collections.sort(results);
return results;
}
}

View File

@ -1,5 +1,8 @@
package com.graywolf336.jail.command.subcommands;
import java.util.Collections;
import java.util.List;
import org.bukkit.command.CommandSender;
import com.graywolf336.jail.JailManager;
@ -28,4 +31,9 @@ public class JailDeleteCellsCommand implements Command {
return true;
}
public List<String> provideTabCompletions(JailManager jm, CommandSender sender, String... args) throws Exception {
//TODO implement
return Collections.emptyList();
}
}

View File

@ -1,5 +1,8 @@
package com.graywolf336.jail.command.subcommands;
import java.util.Collections;
import java.util.List;
import org.bukkit.command.CommandSender;
import com.graywolf336.jail.JailManager;
@ -28,4 +31,9 @@ public class JailDeleteCommand implements Command {
return true;
}
public List<String> provideTabCompletions(JailManager jm, CommandSender sender, String... args) throws Exception {
//TODO implement
return Collections.emptyList();
}
}

View File

@ -1,5 +1,8 @@
package com.graywolf336.jail.command.subcommands;
import java.util.Collections;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
@ -21,4 +24,9 @@ public class JailHelpCommand implements Command {
sender.sendMessage(ChatColor.GREEN + "https://github.com/graywolf336/Jail/wiki/Commands");
return true;
}
public List<String> provideTabCompletions(JailManager jm, CommandSender sender, String... args) throws Exception {
//TODO implement
return Collections.emptyList();
}
}

View File

@ -1,7 +1,12 @@
package com.graywolf336.jail.command.subcommands;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.util.StringUtil;
import com.graywolf336.jail.JailManager;
import com.graywolf336.jail.beans.Cell;
@ -51,4 +56,20 @@ public class JailListCellsCommand implements Command {
sender.sendMessage(ChatColor.AQUA + "-------------------------");
return true;
}
public List<String> provideTabCompletions(JailManager jm, CommandSender sender, String... args) throws Exception {
List<String> results = new ArrayList<String>();
for(Jail j : jm.getJails()) {
if(args.length == 2 && StringUtil.startsWithIgnoreCase(j.getName(), args[1])) {
results.add(j.getName());
}else {
results.add(j.getName());
}
}
Collections.sort(results);
return results;
}
}

View File

@ -1,9 +1,13 @@
package com.graywolf336.jail.command.subcommands;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.util.StringUtil;
import com.graywolf336.jail.JailManager;
import com.graywolf336.jail.beans.Jail;
@ -61,4 +65,20 @@ public class JailListCommand implements Command {
sender.sendMessage(ChatColor.AQUA + "-------------------------");
return true;
}
public List<String> provideTabCompletions(JailManager jm, CommandSender sender, String... args) throws Exception {
List<String> results = new ArrayList<String>();
for(Jail j : jm.getJails()) {
if(args.length == 2 && StringUtil.startsWithIgnoreCase(j.getName(), args[1])) {
results.add(j.getName());
}else {
results.add(j.getName());
}
}
Collections.sort(results);
return results;
}
}

View File

@ -1,6 +1,12 @@
package com.graywolf336.jail.command.subcommands;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.util.StringUtil;
import com.graywolf336.jail.JailManager;
import com.graywolf336.jail.command.Command;
@ -35,4 +41,19 @@ public class JailMuteCommand implements Command {
return true;
}
public List<String> provideTabCompletions(JailManager jm, CommandSender sender, String... args) throws Exception {
switch(args.length) {
case 2:
List<String> results = new ArrayList<String>();
for(Player p : jm.getPlugin().getServer().getOnlinePlayers())
if(StringUtil.startsWithIgnoreCase(p.getName(), args[1].toLowerCase()))
results.add(p.getName());
Collections.sort(results);
return results;
default:
return Collections.emptyList();
}
}
}

View File

@ -1,5 +1,7 @@
package com.graywolf336.jail.command.subcommands;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.bukkit.ChatColor;
@ -206,4 +208,9 @@ public class JailPayCommand implements Command {
return true;
}
public List<String> provideTabCompletions(JailManager jm, CommandSender sender, String... args) throws Exception {
//TODO implement
return Collections.emptyList();
}
}

View File

@ -1,5 +1,6 @@
package com.graywolf336.jail.command.subcommands;
import java.util.Collections;
import java.util.List;
import org.bukkit.command.CommandSender;
@ -42,4 +43,9 @@ public class JailRecordCommand implements Command {
return true;
}
public List<String> provideTabCompletions(JailManager jm, CommandSender sender, String... args) throws Exception {
//TODO implement
return Collections.emptyList();
}
}

View File

@ -1,5 +1,8 @@
package com.graywolf336.jail.command.subcommands;
import java.util.Collections;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
@ -28,4 +31,9 @@ public class JailReloadCommand implements Command {
return true;
}
public List<String> provideTabCompletions(JailManager jm, CommandSender sender, String... args) throws Exception {
//Reloading the plugin doesn't require tab completions
return Collections.emptyList();
}
}

View File

@ -1,5 +1,8 @@
package com.graywolf336.jail.command.subcommands;
import java.util.Collections;
import java.util.List;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -35,4 +38,8 @@ public class JailStatusCommand implements Command{
return true;
}
public List<String> provideTabCompletions(JailManager jm, CommandSender sender, String... args) throws Exception {
//Checking your jail status doesn't require tab completion
return Collections.emptyList();
}
}

View File

@ -1,5 +1,8 @@
package com.graywolf336.jail.command.subcommands;
import java.util.Collections;
import java.util.List;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -33,4 +36,9 @@ public class JailStickCommand implements Command {
return true;
}
public List<String> provideTabCompletions(JailManager jm, CommandSender sender, String... args) throws Exception {
//Nothing to tab complete on jail stick
return Collections.emptyList();
}
}

View File

@ -1,5 +1,8 @@
package com.graywolf336.jail.command.subcommands;
import java.util.Collections;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
@ -37,4 +40,9 @@ public class JailStopCommand implements Command {
return true;
}
public List<String> provideTabCompletions(JailManager jm, CommandSender sender, String... args) throws Exception {
//no tab completion required for stop command
return Collections.emptyList();
}
}

View File

@ -1,5 +1,8 @@
package com.graywolf336.jail.command.subcommands;
import java.util.Collections;
import java.util.List;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -51,4 +54,9 @@ public class JailTeleInCommand implements Command {
return true;
}
public List<String> provideTabCompletions(JailManager jm, CommandSender sender, String... args) throws Exception {
//TODO implement
return Collections.emptyList();
}
}

View File

@ -1,5 +1,8 @@
package com.graywolf336.jail.command.subcommands;
import java.util.Collections;
import java.util.List;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -51,4 +54,9 @@ public class JailTeleOutCommand implements Command {
return true;
}
public List<String> provideTabCompletions(JailManager jm, CommandSender sender, String... args) throws Exception {
//TODO implement
return Collections.emptyList();
}
}

View File

@ -1,5 +1,8 @@
package com.graywolf336.jail.command.subcommands;
import java.util.Collections;
import java.util.List;
import org.bukkit.command.CommandSender;
import com.graywolf336.jail.JailManager;
@ -52,4 +55,9 @@ public class JailTimeCommand implements Command {
return true;
}
public List<String> provideTabCompletions(JailManager jm, CommandSender sender, String... args) throws Exception {
//TODO implement
return Collections.emptyList();
}
}

View File

@ -1,6 +1,8 @@
package com.graywolf336.jail.command.subcommands;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import org.bukkit.command.CommandSender;
@ -53,4 +55,9 @@ public class JailTransferAllCommand implements Command {
return true;
}
public List<String> provideTabCompletions(JailManager jm, CommandSender sender, String... args) throws Exception {
//TODO implement
return Collections.emptyList();
}
}

View File

@ -1,6 +1,7 @@
package com.graywolf336.jail.command.subcommands;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
@ -136,4 +137,9 @@ public class JailTransferCommand implements Command {
return true;
}
public List<String> provideTabCompletions(JailManager jm, CommandSender sender, String... args) throws Exception {
//TODO implement
return Collections.emptyList();
}
}

View File

@ -1,5 +1,8 @@
package com.graywolf336.jail.command.subcommands;
import java.util.Collections;
import java.util.List;
import org.bukkit.command.CommandSender;
import com.graywolf336.jail.JailManager;
@ -23,4 +26,8 @@ public class JailVersionCommand implements Command {
return true;
}
public List<String> provideTabCompletions(JailManager jm, CommandSender sender, String... args) throws Exception {
//no tab completion required for version command
return Collections.emptyList();
}
}

View File

@ -1,5 +1,8 @@
package com.graywolf336.jail.command.subcommands;
import java.util.Collections;
import java.util.List;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -97,4 +100,9 @@ public class JailVoteCommand implements Command {
return true;
}
public List<String> provideTabCompletions(JailManager jm, CommandSender sender, String... args) throws Exception {
//TODO implement
return Collections.emptyList();
}
}