mirror of
https://github.com/exituser/Brewery.git
synced 2026-09-17 05:28:59 +00:00
Added Simple Command Completion
This commit is contained in:
@@ -108,6 +108,7 @@ public class P extends JavaPlugin {
|
||||
inventoryListener = new InventoryListener();
|
||||
worldListener = new WorldListener();
|
||||
getCommand("Brewery").setExecutor(new CommandListener());
|
||||
getCommand("Brewery").setTabCompleter(new TabListener());
|
||||
|
||||
p.getServer().getPluginManager().registerEvents(blockListener, p);
|
||||
p.getServer().getPluginManager().registerEvents(playerListener, p);
|
||||
|
||||
@@ -20,7 +20,6 @@ public class CommandListener implements CommandExecutor {
|
||||
|
||||
public P p = P.p;
|
||||
|
||||
// TODO add command complete
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.dre.brewery.listeners;
|
||||
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class TabListener implements TabCompleter {
|
||||
|
||||
private static final Map<String, List<String>> completions = new HashMap<>();
|
||||
private static final List<String> topCompletions = new ArrayList<>(2);
|
||||
|
||||
static {
|
||||
completions.put("", Arrays.asList("info", "unlabel"));
|
||||
topCompletions.add("brew");
|
||||
//topCompletions.add("brewery");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender commandSender, Command cmd, String command, String[] args) {
|
||||
if (args.length == 0) {
|
||||
return topCompletions;
|
||||
} else if (args.length == 1) {
|
||||
for (Map.Entry<String, List<String>> entry : completions.entrySet()) {
|
||||
List<String> list = new ArrayList<>();
|
||||
for (String comp : entry.getValue()) {
|
||||
if (comp.startsWith(args[0])) {
|
||||
list.add(comp);
|
||||
}
|
||||
}
|
||||
if (list.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user