57 lines
1.6 KiB
Java

package gg.malloc.defense.commands;
import org.bukkit.command.Command;
import org.bukkit.command.TabExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import gg.malloc.defense.engine.GameRunner;
import gg.malloc.defense.Plugin;
import java.util.ArrayList;
import java.util.List;
public class JoinGameCommand implements TabExecutor {
Plugin m_plugin;
public JoinGameCommand(Plugin plugin) {
m_plugin = plugin;
}
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
ArrayList<String> ret = new ArrayList<>();
if (args.length == 1) {
String proposal = args[0].toLowerCase();
for(String arena : m_plugin.arenaNames()) {
if (proposal.startsWith(arena.toLowerCase())) {
ret.add(arena);
}
}
}
return ret;
}
@Override
public boolean onCommand(CommandSender sender, Command command, String s, String[] args) {
if (args.length != 1) {
sender.sendMessage("Usage: join <game>");
return true;
}
if (sender instanceof Player) {
Player player = (Player)sender;
String arenaName = args[0];
sender.sendMessage("Joining arena '" + arenaName + "'...");
GameRunner runner = m_plugin.getRunnerForArenaName(arenaName);
if (runner == null) {
sender.sendMessage("No such arena '" + arenaName + "'");
return true;
}
m_plugin.addPlayerToArena(arenaName, player);
} else {
sender.sendMessage("Only players may use htis command.");
}
return true;
}
}