Reworked command API

Implemented a recursive composite command that can be extended with
subcommands to infinity (and beyond!).

Composite command also tries to create help text and a list of help
commands. These are not current used and need more work.

This has not been tested yet completely.
This commit is contained in:
Tastybento 2017-12-21 23:03:39 -08:00
parent 18ad604b7b
commit f28936948a
21 changed files with 472 additions and 497 deletions

View File

@ -1,137 +0,0 @@
package us.tastybento.bskyblock.api.commands;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.config.BSBLocale;
import us.tastybento.bskyblock.database.managers.PlayersManager;
import us.tastybento.bskyblock.database.managers.island.IslandsManager;
public abstract class CommandArgument {
public BSkyBlock plugin = BSkyBlock.getPlugin();
private String label;
private List<String> aliases;
private String permission;
private boolean onlyPlayer;
private Map<String, CommandArgument> subCommands;
public CommandArgument(String label, String... aliases) {
this.label = label;
this.aliases = new ArrayList<>(Arrays.asList(aliases));
this.subCommands = new LinkedHashMap<>();
}
public CommandArgument() {}
public abstract boolean execute(User user, String[] args);
public abstract Set<String> tabComplete(User user, String[] args);
public String getLabel() {
return label;
}
public List<String> getAliases() {
return aliases;
}
public boolean hasSubCommmands() {
return !subCommands.isEmpty();
}
public Map<String, CommandArgument> getSubCommands() {
return subCommands;
}
public CommandArgument getSubCommand(String label) {
for (Map.Entry<String, CommandArgument> entry : subCommands.entrySet()) {
if (entry.getKey().equalsIgnoreCase(label)) return subCommands.get(label);
else if (entry.getValue().getAliases().contains(label)) return subCommands.get(entry.getValue().getLabel());
}
return null;
}
public void addSubCommand(CommandArgument subCommand) {
subCommands.putIfAbsent(subCommand.getLabel(), subCommand);
}
public void removeSubCommand(String label) {
subCommands.remove(label);
}
public void replaceSubCommand(CommandArgument subCommand) {
subCommands.put(subCommand.getLabel(), subCommand);
}
public String getPermission() {
return permission;
}
public void setPermission(String permission) {
this.permission = permission;
}
public boolean isOnlyPlayer() {
return onlyPlayer;
}
public void setOnlyPlayer(boolean onlyPlayer) {
this.onlyPlayer = onlyPlayer;
}
// These methods below just neaten up the code in the commands so "plugin." isn't always used
/**
* @param user
* @return true if sender is a player
*/
protected boolean isPlayer(User user) {
return (user.getPlayer() instanceof Player);
}
/**
* @param player
* @return true if player is in a team
*/
protected boolean inTeam(Player player) {
return plugin.getPlayers().inTeam(player.getUniqueId());
}
/**
* @param user
* @return UUID of player's team leader
*/
protected UUID getTeamLeader(User user) {
return plugin.getIslands().getTeamLeader(user.getUniqueId());
}
/**
* @param user
* @return set of UUIDs of all team members
*/
protected Set<UUID> getMembers(User user) {
return plugin.getIslands().getMembers(user.getUniqueId());
}
/**
* @return PlayersManager
*/
protected PlayersManager getPlayers() {
return plugin.getPlayers();
}
/**
* @return IslandsManager
*/
protected IslandsManager getIslands() {
return plugin.getIslands();
}
}

View File

@ -3,33 +3,43 @@ package us.tastybento.bskyblock.api.commands;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.PluginIdentifiableCommand;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.database.managers.PlayersManager;
import us.tastybento.bskyblock.database.managers.island.IslandsManager;
public abstract class CompositeCommand extends Command implements PluginIdentifiableCommand {
public abstract class CompositeCommand extends Command implements PluginIdentifiableCommand, TabCompleter {
private BSkyBlock plugin = BSkyBlock.getPlugin();
private String helpReference;
private String permission = null;
private boolean onlyPlayer = false;
private Map<String, CommandArgument> subCommands;
private final CompositeCommand parent;
private String permission = "";
protected BSkyBlock plugin = BSkyBlock.getPlugin();
public CompositeCommand(String label, String description){
private Map<String, CompositeCommand> subCommands;
/**
* Sub-command constructor
* @param parent - the parent composite command
* @param label - string label for this subcommand
* @param aliases - aliases for this subcommand
*/
public CompositeCommand(CompositeCommand parent, String label, String... aliases) {
super(label);
this.setDescription(description);
this.subCommands = new LinkedHashMap<>();
this.setup();
}
public CompositeCommand(String label, String description, String... aliases) {
super(label);
this.setDescription(description);
this.parent = parent;
// Add this sub-command to the parent
parent.getSubCommands().put(label, this);
this.setAliases(new ArrayList<>(Arrays.asList(aliases)));
this.subCommands = new LinkedHashMap<>();
@ -37,89 +47,64 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
this.setup();
}
public abstract void setup();
public abstract boolean execute(User user, String[] args);
public Map<String, CommandArgument> getSubCommands() {
return subCommands;
}
public CommandArgument getSubCommand(String label) {
for (Map.Entry<String, CommandArgument> entry : subCommands.entrySet()) {
if (entry.getKey().equalsIgnoreCase(label)) return subCommands.get(label);
else if (entry.getValue().getAliases().contains(label)) return subCommands.get(entry.getValue().getLabel());
}
return null;
}
public void addSubCommand(CommandArgument subCommand) {
subCommands.putIfAbsent(subCommand.getLabel(), subCommand);
}
public void removeSubCommand(String label) {
subCommands.remove(label);
}
public void replaceSubCommand(CommandArgument subCommand) {
subCommands.put(subCommand.getLabel(), subCommand);
}
@Override
public void setPermission(String permission) {
this.permission = permission;
}
@Override
public String getPermission() {
return this.permission;
}
public boolean isOnlyPlayer() {
return onlyPlayer;
}
public void setOnlyPlayer(boolean onlyPlayer) {
this.onlyPlayer = onlyPlayer;
/**
* This is the top-level command constructor for commands that have no parent.
* @param label - string for this command
* @param aliases - aliases for this command
*/
public CompositeCommand(String label, String... aliases) {
super(label);
this.setDescription(description);
this.setAliases(new ArrayList<>(Arrays.asList(aliases)));
this.parent = null;
this.subCommands = new LinkedHashMap<>();
this.setup();
}
/*
* This method deals with the command execution. It traverses the tree of
* subcommands until it finds the right object and then runs execute on it.
*/
@Override
public boolean execute(CommandSender sender, String label, String[] args) {
// Get the User instance for this sender
User user = User.getInstance(sender);
if (permission != null && user.hasPermission(permission)) {
// Check permissions
if (user.hasPermission(permission)) {
// Do the player part
if (onlyPlayer && user.isPlayer()) {
if (args.length >= 1) {
// Store the latest subCommand found
CommandArgument subCommand = null;
for (int i = 0; i < args.length; i++) {
// get the subcommand corresponding to the label
if (subCommand == null) subCommand = getSubCommand(args[i]);
else subCommand = subCommand.getSubCommand(args[i]);
if (subCommand != null) { // check if this subcommand exists
if (!subCommand.hasSubCommmands()) { // if it has not any subcommands
if (subCommand.getPermission() != null && user.hasPermission(subCommand.getPermission())) {
if (onlyPlayer && user.isPlayer()) {
subCommand.execute(user, args); //TODO: "cut" the args to only send the needed ones
} else {
user.sendMessage("general.errors.use-in-game");
}
} else {
user.sendMessage("general.errors.no-permission");
}
}
// else continue the loop
// TODO: adapt this part to make it works with arguments that are not subcommands
// Find the subCommand
CompositeCommand subCommand = this;
// Run through any arguments
for (int i = 0; i < args.length; i++) {
// get the subcommand corresponding to the arg
if (subCommand.hasSubCommmands()) {
if (subCommand.hasSubCommand(args[i])) {
// Step down one
subCommand = subCommand.getSubCommand(args[i]);
} else {
// Unknown command
user.sendMessage("general.errors.unknown-command");
return true;
}
// TODO: get the help
else {
//TODO: say "unknown command"
} else {
// We are at the end of the walk
// Check permission
if (user.hasPermission(subCommand.getPermission())) {
if (onlyPlayer && user.isPlayer()) {
// Execute the subcommand with trimmed args
subCommand.execute(user, Arrays.copyOfRange(args, i, args.length));
} else {
user.sendMessage("general.errors.use-in-game");
}
} else {
user.sendMessage("general.errors.no-permission");
}
}
} else {
// No args : execute the default behaviour
this.execute(user, args);
}
// else continue the loop
}
} else {
user.sendMessage("general.errors.use-in-game");
}
@ -129,9 +114,179 @@ public abstract class CompositeCommand extends Command implements PluginIdentifi
return true;
}
/**
* What will be executed when this command is run
* @param user
* @param args
* @return true or false
*/
public abstract boolean execute(User user, String[] args);
/**
* @return IslandsManager
*/
protected IslandsManager getIslands() {
return plugin.getIslands();
}
/**
* @param user
* @return set of UUIDs of all team members
*/
protected Set<UUID> getMembers(User user) {
return plugin.getIslands().getMembers(user.getUniqueId());
}
/**
* @return the parent command objectx
*/
public CompositeCommand getParent() {
return parent;
}
@Override
public String getPermission() {
return this.permission;
}
/**
* @return PlayersManager
*/
protected PlayersManager getPlayers() {
return plugin.getPlayers();
}
@Override
public BSkyBlock getPlugin() {
return plugin;
}
/**
* Returns the CompositeCommand object refering to this command label
* @param label - command label or alias
* @return CompositeCommand or null if none found
*/
public CompositeCommand getSubCommand(String label) {
for (Map.Entry<String, CompositeCommand> entry : subCommands.entrySet()) {
if (entry.getKey().equalsIgnoreCase(label)) return subCommands.get(label);
else if (entry.getValue().getAliases().contains(label)) return subCommands.get(entry.getValue().getLabel());
}
return null;
}
/**
* Recursively obtain a list of all sub command help references
* TODO: use this in conjunction with a user's request for help
* @return a list of this command and all sub commands help references
*/
public List<String> getSubCommandHelp() {
return getSubCommandHelp("");
}
private List<String> getSubCommandHelp(String helpRef) {
CompositeCommand subCommand = this;
List<String> result = new ArrayList<>();
result.add(helpRef + " " + helpReference);
while (subCommand.hasSubCommmands()) {
result.addAll(subCommand.getSubCommandList(helpReference));
}
return result;
}
/**
* Recursively obtain a list of all sub commands
* @return a list of this command and all sub commands
*/
public List<String> getSubCommandList() {
return getSubCommandList("");
}
private List<String> getSubCommandList(String label) {
CompositeCommand subCommand = this;
List<String> result = new ArrayList<>();
result.add(label + " " + getLabel());
while (subCommand.hasSubCommmands()) {
result.addAll(subCommand.getSubCommandList(getLabel()));
}
return result;
}
public Map<String, CompositeCommand> getSubCommands() {
return subCommands;
}
/**
* @param user
* @return UUID of player's team leader
*/
protected UUID getTeamLeader(User user) {
return plugin.getIslands().getTeamLeader(user.getUniqueId());
}
/**
* @param subCommand
* @return true if this command has this sub command
*/
private boolean hasSubCommand(String subCommand) {
return subCommands.containsKey(subCommand);
}
/**
* @return true if this command has subcommands
*/
protected boolean hasSubCommmands() {
return !subCommands.isEmpty();
}
/**
* @param player
* @return true if player is in a team
*/
protected boolean inTeam(Player player) {
return plugin.getPlayers().inTeam(player.getUniqueId());
}
public boolean isOnlyPlayer() {
return onlyPlayer;
}
/**
* @param user
* @return true if sender is a player
*/
protected boolean isPlayer(User user) {
return (user.getPlayer() instanceof Player);
}
@Override
public List<String> onTabComplete(final CommandSender sender, final Command command, final String label, final String[] args) {
return new ArrayList<>(subCommands.keySet());
}
/**
* Set the locale string that gives help for this command
* @param helpReference
*/
public void setHelp(String helpReference) {
this.helpReference = helpReference;
}
public void setOnlyPlayer(boolean onlyPlayer) {
this.onlyPlayer = onlyPlayer;
}
@Override
public void setPermission(String permission) {
this.permission = permission;
}
/**
* Anything that needs to be set up for this command.
* This is where you register subcommands.
*/
public abstract void setup();
}

View File

@ -127,7 +127,7 @@ public class User {
}
public boolean hasPermission(String string) {
return sender.hasPermission(string);
return string == null ? false : sender.hasPermission(string);
}
public boolean isOnline() {

View File

@ -1,7 +1,5 @@
package us.tastybento.bskyblock.commands;
import org.bukkit.command.CommandSender;
import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.commands.admin.AdminVersionCommand;
@ -11,11 +9,13 @@ public class AdminCommand extends CompositeCommand {
public AdminCommand() {
super(Settings.ADMINCOMMAND, "Admin commands", "bsb");
this.setPermission(Settings.PERMPREFIX + "admin.*");
this.setOnlyPlayer(false);
}
@Override
public void setup() {
this.addSubCommand(new AdminVersionCommand());
new AdminVersionCommand(this);
}
@Override

View File

@ -1,7 +1,5 @@
package us.tastybento.bskyblock.commands;
import org.bukkit.command.CommandSender;
import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.commands.island.IslandAboutCommand;
@ -11,25 +9,42 @@ import us.tastybento.bskyblock.commands.island.IslandResetCommand;
import us.tastybento.bskyblock.commands.island.IslandResetnameCommand;
import us.tastybento.bskyblock.commands.island.IslandSethomeCommand;
import us.tastybento.bskyblock.commands.island.IslandSetnameCommand;
import us.tastybento.bskyblock.commands.island.teams.IslandInviteAcceptCommand;
import us.tastybento.bskyblock.commands.island.teams.IslandInviteRejectCommand;
import us.tastybento.bskyblock.commands.island.teams.IslandLeaveCommand;
import us.tastybento.bskyblock.commands.island.teams.IslandTeamCommand;
import us.tastybento.bskyblock.commands.island.teams.IslandTeamInviteCommand;
import us.tastybento.bskyblock.commands.island.teams.IslandTeamPromoteCommand;
import us.tastybento.bskyblock.commands.island.teams.IslandTeamUninviteCommand;
import us.tastybento.bskyblock.config.Settings;
public class IslandCommand extends CompositeCommand {
public IslandCommand() {
super(Settings.ISLANDCOMMAND, "Main player command", "is");
this.setOnlyPlayer(true);
}
/* (non-Javadoc)
* @see us.tastybento.bskyblock.api.commands.CompositeCommand#setup()
*/
@Override
public void setup() {
this.addSubCommand(new IslandAboutCommand());
this.addSubCommand(new IslandCreateCommand());
this.addSubCommand(new IslandGoCommand());
this.addSubCommand(new IslandResetCommand());
this.addSubCommand(new IslandResetnameCommand());
this.addSubCommand(new IslandSethomeCommand());
this.addSubCommand(new IslandSetnameCommand());
this.addSubCommand(new IslandTeamCommand());
new IslandAboutCommand(this);
new IslandCreateCommand(this);
new IslandGoCommand(this);
new IslandResetCommand(this);
new IslandResetnameCommand(this);
new IslandSethomeCommand(this);
new IslandSetnameCommand(this);
new IslandTeamCommand(this);
new IslandTeamInviteCommand(this);
new IslandInviteAcceptCommand(this);
new IslandInviteRejectCommand(this);
new IslandLeaveCommand(this);
new IslandTeamPromoteCommand(this);
new IslandTeamUninviteCommand(this);
}
@Override
@ -37,4 +52,5 @@ public class IslandCommand extends CompositeCommand {
user.sendLegacyMessage("You successfully did /is !");
return true;
}
}

View File

@ -1,14 +1,12 @@
package us.tastybento.bskyblock.commands.admin;
import java.util.Set;
import us.tastybento.bskyblock.api.commands.CommandArgument;
import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.commands.User;
public class AdminVersionCommand extends CommandArgument {
public class AdminVersionCommand extends CompositeCommand {
public AdminVersionCommand() {
super("version");
public AdminVersionCommand(CompositeCommand adminCommand) {
super(adminCommand, "version");
}
@Override
@ -17,8 +15,8 @@ public class AdminVersionCommand extends CommandArgument {
}
@Override
public Set<String> tabComplete(User user, String[] args) {
public void setup() {
// TODO Auto-generated method stub
return null;
}
}

View File

@ -1,15 +1,17 @@
package us.tastybento.bskyblock.commands.island;
import java.util.Set;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.api.commands.CommandArgument;
import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.commands.User;
public class IslandAboutCommand extends CommandArgument {
public class IslandAboutCommand extends CompositeCommand {
public IslandAboutCommand() {
super("about", "ab");
/**
* About
* @param islandCommand
*/
public IslandAboutCommand(CompositeCommand islandCommand) {
super(islandCommand, "about", "ab");
}
@Override
@ -47,7 +49,8 @@ public class IslandAboutCommand extends CommandArgument {
}
@Override
public Set<String> tabComplete(User sender, String[] args) {
return null;
public void setup() {
// TODO Auto-generated method stub
}
}

View File

@ -4,14 +4,14 @@
package us.tastybento.bskyblock.commands.island;
import java.io.IOException;
import java.util.Set;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import us.tastybento.bskyblock.api.commands.CommandArgument;
import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.api.events.island.IslandEvent.Reason;
import us.tastybento.bskyblock.commands.IslandCommand;
import us.tastybento.bskyblock.config.Settings;
import us.tastybento.bskyblock.database.managers.island.NewIsland;
@ -19,10 +19,12 @@ import us.tastybento.bskyblock.database.managers.island.NewIsland;
* @author ben
*
*/
public class IslandCreateCommand extends CommandArgument {
public class IslandCreateCommand extends CompositeCommand {
public IslandCreateCommand() {
super("create", "auto");
public IslandCreateCommand(IslandCommand islandCommand) {
super(islandCommand, "create", "auto");
this.setPermission(Settings.PERMPREFIX + "island.create");
this.setOnlyPlayer(true);
}
/* (non-Javadoc)
@ -30,34 +32,16 @@ public class IslandCreateCommand extends CommandArgument {
*/
@Override
public boolean execute(User user, String[] args) {
if (!isPlayer(user)) {
user.sendMessage("general.errors.use-in-game");
return true;
}
Player player = (Player)user;
if (!player.hasPermission(Settings.PERMPREFIX + "island.create")) {
user.sendMessage(ChatColor.RED + "general.errors.no-permission");
}
if (getIslands().hasIsland(player.getUniqueId())) {
if (getIslands().hasIsland(user.getUniqueId())) {
user.sendMessage(ChatColor.RED + "general.errors.already-have-island");
}
if (inTeam(player)) {
if (getPlayers().inTeam(user.getUniqueId())) {
return false;
}
createIsland(player);
createIsland(user.getPlayer());
return true;
}
/* (non-Javadoc)
* @see us.tastybento.bskyblock.api.commands.CommandArgument#tabComplete(org.bukkit.command.CommandSender, java.lang.String[])
*/
@Override
public Set<String> tabComplete(User user, String[] args) {
// TODO Auto-generated method stub
return null;
}
/**
* Creates an island for player
*
@ -77,4 +61,10 @@ public class IslandCreateCommand extends CommandArgument {
}
}
@Override
public void setup() {
// TODO Auto-generated method stub
}
}

View File

@ -3,14 +3,12 @@
*/
package us.tastybento.bskyblock.commands.island;
import java.util.Set;
import org.apache.commons.lang.math.NumberUtils;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import us.tastybento.bskyblock.api.commands.CommandArgument;
import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.commands.IslandCommand;
import us.tastybento.bskyblock.config.Settings;
import us.tastybento.bskyblock.util.Util;
@ -18,10 +16,12 @@ import us.tastybento.bskyblock.util.Util;
* @author ben
*
*/
public class IslandGoCommand extends CommandArgument {
public class IslandGoCommand extends CompositeCommand {
public IslandGoCommand() {
super("go", "home", "h");
public IslandGoCommand(IslandCommand islandCommand) {
super(islandCommand, "go", "home", "h");
this.setPermission(Settings.PERMPREFIX + "island.home");
this.setOnlyPlayer(true);
}
/* (non-Javadoc)
@ -29,40 +29,24 @@ public class IslandGoCommand extends CommandArgument {
*/
@Override
public boolean execute(User user, String[] args) {
if (!isPlayer(user)) {
user.sendMessage("general.errors.use-in-game");
return true;
}
Player player = (Player)user;
if (!player.hasPermission(Settings.PERMPREFIX + "island.home")) {
user.sendMessage(ChatColor.RED + "general.errors.no-permission");
return true;
}
if (!getIslands().hasIsland(player.getUniqueId())) {
if (!getIslands().hasIsland(user.getUniqueId())) {
user.sendMessage(ChatColor.RED + "general.errors.no-island");
return true;
}
if (args.length == 1 && NumberUtils.isDigits(args[0])) {
int homeValue = Integer.valueOf(args[0]);
int maxHomes = Util.getPermValue(player, Settings.PERMPREFIX + "island.maxhomes", Settings.maxHomes);
int maxHomes = Util.getPermValue(user.getPlayer(), Settings.PERMPREFIX + "island.maxhomes", Settings.maxHomes);
if (homeValue > 1 && homeValue <= maxHomes) {
getIslands().homeTeleport(player, homeValue);
getIslands().homeTeleport(user.getPlayer(), homeValue);
return true;
}
}
getIslands().homeTeleport(player);
getIslands().homeTeleport(user.getPlayer());
return true;
}
/* (non-Javadoc)
* @see us.tastybento.bskyblock.api.commands.CommandArgument#tabComplete(org.bukkit.command.CommandSender, java.lang.String[])
*/
@Override
public Set<String> tabComplete(User user, String[] args) {
// TODO Auto-generated method stub
return null;
public void setup() {
}
}

View File

@ -1,50 +1,41 @@
package us.tastybento.bskyblock.commands.island;
import java.io.IOException;
import java.util.Set;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
import us.tastybento.bskyblock.api.commands.CommandArgument;
import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.api.events.island.IslandEvent.Reason;
import us.tastybento.bskyblock.config.Settings;
import us.tastybento.bskyblock.database.managers.island.NewIsland;
import us.tastybento.bskyblock.database.objects.Island;
public class IslandResetCommand extends CommandArgument {
public class IslandResetCommand extends CompositeCommand {
private static final boolean DEBUG = false;
public IslandResetCommand() {
super("reset", "restart");
public IslandResetCommand(CompositeCommand command) {
super(command, "reset", "restart");
this.setPermission(Settings.PERMPREFIX + "island.create");
this.setOnlyPlayer(true);
}
@Override
public boolean execute(User user, String[] args) {
if (!isPlayer(user)) {
user.sendMessage("general.errors.use-in-game");
return true;
}
Player player = (Player)user;
if (!player.hasPermission(Settings.PERMPREFIX + "island.reset")) {
user.sendMessage("general.errors.no-permission");
return true;
}
if (!getIslands().hasIsland(player.getUniqueId())) {
if (!getIslands().hasIsland(user.getUniqueId())) {
user.sendMessage("general.errors.no-island");
return true;
}
if (!getIslands().isOwner(player.getUniqueId())) {
if (!getIslands().isOwner(user.getUniqueId())) {
return false;
}
if (inTeam(player)) {
if (plugin.getPlayers().inTeam(user.getUniqueId())) {
user.sendMessage("island.reset.MustRemovePlayers");
return true;
}
Player player = user.getPlayer();
player.setGameMode(GameMode.SPECTATOR);
// Get the player's old island
Island oldIsland = getIslands().getIsland(player.getUniqueId());
@ -65,15 +56,15 @@ public class IslandResetCommand extends CommandArgument {
.build();
} catch (IOException e) {
plugin.getLogger().severe("Could not create island for player.");
user.sendMessage(ChatColor.RED + "general.errors.general");
user.sendMessage("general.errors.general");
e.printStackTrace();
}
return true;
}
@Override
public Set<String> tabComplete(User user, String[] args) {
public void setup() {
// TODO Auto-generated method stub
return null;
}
}

View File

@ -3,13 +3,12 @@
*/
package us.tastybento.bskyblock.commands.island;
import java.util.Set;
import java.util.UUID;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import us.tastybento.bskyblock.api.commands.CommandArgument;
import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.config.Settings;
@ -17,10 +16,13 @@ import us.tastybento.bskyblock.config.Settings;
* @author ben
*
*/
public class IslandResetnameCommand extends CommandArgument {
public class IslandResetnameCommand extends CompositeCommand {
public IslandResetnameCommand(CompositeCommand command) {
super(command, "setname");
this.setPermission(Settings.PERMPREFIX + "island.name");
this.setOnlyPlayer(true);
public IslandResetnameCommand() {
super("setname");
}
/* (non-Javadoc)
@ -28,25 +30,16 @@ public class IslandResetnameCommand extends CommandArgument {
*/
@Override
public boolean execute(User user, String[] args) {
if (!isPlayer(user)) {
user.sendMessage("general.errors.use-in-game");
return true;
}
Player player = (Player)user;
Player player = user.getPlayer();
UUID playerUUID = player.getUniqueId();
if (!player.hasPermission(Settings.PERMPREFIX + "island.name")) {
user.sendMessage(ChatColor.RED + "general.errors.no-permission");
return true;
}
if (!getIslands().hasIsland(playerUUID)) {
user.sendMessage(ChatColor.RED + "general.errors.no-island");
user.sendMessage("general.errors.no-island");
return true;
}
if (!getIslands().isOwner(playerUUID)) {
user.sendMessage(ChatColor.RED + "general.errors.not-leader");
user.sendMessage("general.errors.not-leader");
return true;
}
// Explain command
@ -78,13 +71,10 @@ public class IslandResetnameCommand extends CommandArgument {
return true;
}
/* (non-Javadoc)
* @see us.tastybento.bskyblock.api.commands.CommandArgument#tabComplete(org.bukkit.command.CommandSender, java.lang.String[])
*/
@Override
public Set<String> tabComplete(User user, String[] args) {
public void setup() {
// TODO Auto-generated method stub
return null;
}
}

View File

@ -1,45 +1,36 @@
package us.tastybento.bskyblock.commands.island;
import java.util.Set;
import java.util.UUID;
import org.bukkit.ChatColor;
import us.tastybento.bskyblock.api.commands.CommandArgument;
import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.config.Settings;
import us.tastybento.bskyblock.util.Util;
public class IslandSethomeCommand extends CommandArgument {
public class IslandSethomeCommand extends CompositeCommand {
public IslandSethomeCommand() {
super("sethome");
public IslandSethomeCommand(CompositeCommand command) {
super(command, "sethome");
this.setPermission(Settings.PERMPREFIX + "island.sethome");
this.setOnlyPlayer(true);
}
@Override
public boolean execute(User user, String[] args) {
if (!isPlayer(user)) {
user.sendMessage(ChatColor.RED + "general.errors.use-in-game");
return true;
}
UUID playerUUID = user.getUniqueId();
if (!user.hasPermission(Settings.PERMPREFIX + "island.sethome")) {
user.sendMessage(ChatColor.RED + "general.errors.no-permission");
return true;
}
// Check island
if (plugin.getIslands().getIsland(user.getUniqueId()) == null) {
user.sendMessage(ChatColor.RED + "general.errors.no-island");
user.sendMessage("general.errors.no-island");
return true;
}
if (!plugin.getIslands().playerIsOnIsland(user.getPlayer())) {
user.sendMessage(ChatColor.RED + "sethome.error.NotOnIsland");
user.sendMessage("sethome.error.NotOnIsland");
return true;
}
if (args.length == 0) {
// island sethome
plugin.getPlayers().setHomeLocation(playerUUID, user.getLocation());
user.sendMessage(ChatColor.GREEN + "sethome.homeSet");
user.sendMessage("sethome.homeSet");
} else if (args.length == 1) {
// Dynamic home sizes with permissions
int maxHomes = Util.getPermValue(user.getPlayer(), Settings.PERMPREFIX + "island.maxhomes", Settings.maxHomes);
@ -52,21 +43,21 @@ public class IslandSethomeCommand extends CommandArgument {
user.sendMessage("sethome.error.NumHomes", "[max]", String.valueOf(maxHomes));
} else {
plugin.getPlayers().setHomeLocation(playerUUID, user.getLocation(), number);
user.sendMessage(ChatColor.GREEN + "sethome.homeSet");
user.sendMessage("sethome.homeSet");
}
} catch (Exception e) {
user.sendMessage(ChatColor.RED + "sethome.error.NumHomes", "[max]", String.valueOf(maxHomes));
user.sendMessage("sethome.error.NumHomes", "[max]", String.valueOf(maxHomes));
}
} else {
user.sendMessage(ChatColor.RED + "general.errors.no-permission");
user.sendMessage("general.errors.no-permission");
}
}
return true;
}
@Override
public Set<String> tabComplete(User user, String[] args) {
public void setup() {
// TODO Auto-generated method stub
return null;
}
}

View File

@ -3,13 +3,12 @@
*/
package us.tastybento.bskyblock.commands.island;
import java.util.Set;
import java.util.UUID;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import us.tastybento.bskyblock.api.commands.CommandArgument;
import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.config.Settings;
@ -17,10 +16,13 @@ import us.tastybento.bskyblock.config.Settings;
* @author ben
*
*/
public class IslandSetnameCommand extends CommandArgument {
public class IslandSetnameCommand extends CompositeCommand {
public IslandSetnameCommand(CompositeCommand command) {
super(command, "resetname");
this.setPermission(Settings.PERMPREFIX + "island.name");
this.setOnlyPlayer(true);
public IslandSetnameCommand() {
super("resetname");
}
/* (non-Javadoc)
@ -28,18 +30,9 @@ public class IslandSetnameCommand extends CommandArgument {
*/
@Override
public boolean execute(User user, String[] args) {
if (!isPlayer(user)) {
user.sendMessage("general.errors.use-in-game");
return true;
}
Player player = (Player)user;
Player player = user.getPlayer();
UUID playerUUID = player.getUniqueId();
if (!player.hasPermission(Settings.PERMPREFIX + "island.name")) {
user.sendMessage(ChatColor.RED + "general.errors.no-permission");
return true;
}
if (!getIslands().hasIsland(playerUUID)) {
user.sendMessage(ChatColor.RED + "general.errors.no-island");
return true;
@ -56,13 +49,10 @@ public class IslandSetnameCommand extends CommandArgument {
return true;
}
/* (non-Javadoc)
* @see us.tastybento.bskyblock.api.commands.CommandArgument#tabComplete(org.bukkit.command.CommandSender, java.lang.String[])
*/
@Override
public Set<String> tabComplete(User user, String[] args) {
public void setup() {
// TODO Auto-generated method stub
return null;
}
}

View File

@ -6,17 +6,16 @@ import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import us.tastybento.bskyblock.api.commands.CommandArgument;
import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.config.Settings;
public abstract class AbstractIslandTeamCommandArgument extends CommandArgument {
public abstract class AbstractTeamCommand extends CompositeCommand {
protected final static boolean DEBUG = false;
protected BiMap<UUID, UUID> inviteList = HashBiMap.create();
@ -28,22 +27,10 @@ public abstract class AbstractIslandTeamCommandArgument extends CommandArgument
// TODO: It would be good if these could be auto-provided
protected User user;
public AbstractIslandTeamCommandArgument(String label, String... aliases) {
super(label,aliases);
public AbstractTeamCommand(CompositeCommand command, String label, String... aliases) {
super(command, label,aliases);
}
protected boolean checkTeamPerm() {
if (!isPlayer(user)) {
user.sendMessage("general.errors.use-in-game");
return false;
}
if (!user.hasPermission(Settings.PERMPREFIX + "team")) {
user.sendMessage(ChatColor.RED + "general.errors.no-permission");
return false;
}
return true;
}
/**
* Sets a timeout for player into the Hashmap resetWaitTime
*

View File

@ -1,12 +1,11 @@
package us.tastybento.bskyblock.commands.island.teams;
import java.util.Set;
import java.util.UUID;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.Location;
import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.api.events.IslandBaseEvent;
import us.tastybento.bskyblock.api.events.team.TeamEvent;
@ -14,33 +13,33 @@ import us.tastybento.bskyblock.api.events.team.TeamEvent.TeamReason;
import us.tastybento.bskyblock.config.Settings;
import us.tastybento.bskyblock.database.objects.Island;
public class IslandInviteAcceptCommand extends AbstractIslandTeamCommandArgument {
public class IslandInviteAcceptCommand extends AbstractTeamCommand {
public IslandInviteAcceptCommand() {
super("accept");
public IslandInviteAcceptCommand(CompositeCommand islandCommand) {
super(islandCommand, "accept");
this.setPermission(Settings.PERMPREFIX + "island.team");
this.setOnlyPlayer(true);
}
@Override
public boolean execute(User user, String[] args) {
// Check team perm and get variables set
if (!checkTeamPerm()) return true;
UUID playerUUID = user.getUniqueId();
if(!inviteList.containsKey(playerUUID))
return true;
// Check if player has been invited
if (!inviteList.containsKey(playerUUID)) {
user.sendMessage(ChatColor.RED + "invite.error.NoOneInvitedYou");
user.sendMessage("invite.error.NoOneInvitedYou");
return true;
}
// Check if player is already in a team
if (getPlayers().inTeam(playerUUID)) {
user.sendMessage(ChatColor.RED + "invite.error.YouAreAlreadyOnATeam");
user.sendMessage("invite.error.YouAreAlreadyOnATeam");
return true;
}
// Get the team leader
UUID prospectiveTeamLeaderUUID = inviteList.get(playerUUID);
if (!getIslands().hasIsland(prospectiveTeamLeaderUUID)) {
user.sendMessage(ChatColor.RED + "invite.error.InvalidInvite");
user.sendMessage("invite.error.InvalidInvite");
inviteList.remove(playerUUID);
return true;
}
@ -87,10 +86,10 @@ public class IslandInviteAcceptCommand extends AbstractIslandTeamCommandArgument
// Put player back into normal mode
user.setGameMode(GameMode.SURVIVAL);
user.sendMessage(ChatColor.GREEN + "invite.youHaveJoinedAnIsland", "[label]", Settings.ISLANDCOMMAND);
user.sendMessage("invite.youHaveJoinedAnIsland", "[label]", Settings.ISLANDCOMMAND);
User inviter = User.getInstance(inviteList.get(playerUUID));
if (inviter != null) {
inviter.sendMessage(ChatColor.GREEN + "invite.hasJoinedYourIsland", "[name]", user.getName());
inviter.sendMessage("invite.hasJoinedYourIsland", "[name]", user.getName());
}
getIslands().save(false);
if (DEBUG)
@ -98,9 +97,9 @@ public class IslandInviteAcceptCommand extends AbstractIslandTeamCommandArgument
return true;
}
@Override
public Set<String> tabComplete(User user, String[] args) {
return null;
public void setup() {
// TODO Auto-generated method stub
}
}

View File

@ -1,25 +1,25 @@
package us.tastybento.bskyblock.commands.island.teams;
import java.util.Set;
import java.util.UUID;
import org.bukkit.ChatColor;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.api.events.IslandBaseEvent;
import us.tastybento.bskyblock.api.events.team.TeamEvent;
import us.tastybento.bskyblock.api.events.team.TeamEvent.TeamReason;
import us.tastybento.bskyblock.commands.IslandCommand;
import us.tastybento.bskyblock.config.Settings;
public class IslandInviteRejectCommand extends AbstractIslandTeamCommandArgument {
public class IslandInviteRejectCommand extends AbstractTeamCommand {
public IslandInviteRejectCommand() {
super("reject");
public IslandInviteRejectCommand(IslandCommand islandCommand) {
super(islandCommand, "reject");
this.setPermission(Settings.PERMPREFIX + "island.team");
this.setOnlyPlayer(true);
}
@Override
public boolean execute(User user, String[] args) {
// Check team perm and get variables set
if (!checkTeamPerm()) return true;
UUID playerUUID = user.getUniqueId();
// Reject /island reject
if (inviteList.containsKey(playerUUID)) {
@ -35,24 +35,24 @@ public class IslandInviteRejectCommand extends AbstractIslandTeamCommandArgument
// Remove this player from the global invite list
inviteList.remove(user.getUniqueId());
user.sendMessage(ChatColor.GREEN + "reject.youHaveRejectedInvitation");
user.sendMessage("reject.youHaveRejectedInvitation");
// If the leader is online tell them directly
// about the rejection
User inviter = User.getInstance(inviteList.get(playerUUID));
if (inviter != null) {
inviter.sendMessage(
ChatColor.RED + "reject.nameHasRejectedInvite", "[name]", user.getName());
inviter.sendMessage("reject.nameHasRejectedInvite", "[name]", user.getName());
}
} else {
// Someone typed /island reject and had not been invited
user.sendMessage(ChatColor.RED + "reject.youHaveNotBeenInvited");
user.sendMessage("reject.youHaveNotBeenInvited");
}
return true;
}
@Override
public Set<String> tabComplete(User user, String[] args) {
return null;
public void setup() {
// TODO Auto-generated method stub
}
}

View File

@ -1,13 +1,16 @@
package us.tastybento.bskyblock.commands.island.teams;
import java.util.Set;
import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.config.Settings;
public class IslandLeaveCommand extends AbstractIslandTeamCommandArgument {
public class IslandLeaveCommand extends AbstractTeamCommand {
public IslandLeaveCommand(CompositeCommand islandCommand) {
super(islandCommand, "leave");
this.setPermission(Settings.PERMPREFIX + "island.team");
this.setOnlyPlayer(true);
public IslandLeaveCommand() {
super("leave");
}
@Override
@ -17,10 +20,11 @@ public class IslandLeaveCommand extends AbstractIslandTeamCommandArgument {
}
@Override
public Set<String> tabComplete(User user, String[] args) {
public void setup() {
// TODO Auto-generated method stub
return null;
}
}

View File

@ -7,25 +7,26 @@ import org.apache.commons.lang.math.NumberUtils;
import org.bukkit.ChatColor;
import org.bukkit.permissions.PermissionAttachmentInfo;
import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.api.events.IslandBaseEvent;
import us.tastybento.bskyblock.api.events.team.TeamEvent;
import us.tastybento.bskyblock.api.events.team.TeamEvent.TeamReason;
import us.tastybento.bskyblock.config.Settings;
public class IslandTeamCommand extends AbstractIslandTeamCommandArgument {
public class IslandTeamCommand extends AbstractTeamCommand {
private static final boolean DEBUG = false;
public IslandTeamCommand() {
super("team");
this.addSubCommand(new IslandTeamInviteCommand());
public IslandTeamCommand(CompositeCommand islandCommand) {
super(islandCommand, "team");
this.setPermission(Settings.PERMPREFIX + "island.team");
this.setOnlyPlayer(true);
}
@Override
public boolean execute(User user, String[] args) {
// Check team perm and get variables set
if (!checkTeamPerm()) return true;
UUID playerUUID = user.getUniqueId();
if (DEBUG)
plugin.getLogger().info("DEBUG: executing team command for " + playerUUID);
@ -84,7 +85,6 @@ public class IslandTeamCommand extends AbstractIslandTeamCommandArgument {
}
@Override
public Set<String> tabComplete(User user, String[] args) {
return null;
public void setup() {
}
}

View File

@ -1,14 +1,18 @@
package us.tastybento.bskyblock.commands.island.teams;
import java.util.HashSet;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import org.apache.commons.lang.math.NumberUtils;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.permissions.PermissionAttachmentInfo;
import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.api.events.IslandBaseEvent;
import us.tastybento.bskyblock.api.events.team.TeamEvent;
@ -16,16 +20,16 @@ import us.tastybento.bskyblock.api.events.team.TeamEvent.TeamReason;
import us.tastybento.bskyblock.config.Settings;
import us.tastybento.bskyblock.util.Util;
public class IslandTeamInviteCommand extends AbstractIslandTeamCommandArgument {
public class IslandTeamInviteCommand extends AbstractTeamCommand {
public IslandTeamInviteCommand() {
super("invite");
public IslandTeamInviteCommand(CompositeCommand islandTeamCommand) {
super(islandTeamCommand, "invite");
this.setPermission(Settings.PERMPREFIX + "island.team");
this.setOnlyPlayer(true);
}
@Override
public boolean execute(User user, String[] args) {
// Check team perm and get variables set
if (!checkTeamPerm()) return true;
UUID playerUUID = user.getUniqueId();
// Player issuing the command must have an island
if (!getPlayers().hasIsland(playerUUID)) {
@ -131,11 +135,18 @@ public class IslandTeamInviteCommand extends AbstractIslandTeamCommandArgument {
}
@Override
public Set<String> tabComplete(User user, String[] args) {
public List<String> onTabComplete(final CommandSender sender, final Command command, final String label, final String[] args) {
User user = User.getInstance(sender);
if (args.length == 0 || !isPlayer(user)) {
// Don't show every player on the server. Require at least the first letter
return null;
}
return new HashSet<>(Util.getOnlinePlayerList(user));
return new ArrayList<>(Util.getOnlinePlayerList(user));
}
@Override
public void setup() {
// TODO Auto-generated method stub
}
}

View File

@ -1,13 +1,15 @@
package us.tastybento.bskyblock.commands.island.teams;
import java.util.HashSet;
import java.util.Set;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import org.apache.commons.lang.math.NumberUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.permissions.PermissionAttachmentInfo;
import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.api.events.IslandBaseEvent;
import us.tastybento.bskyblock.api.events.team.TeamEvent;
@ -15,16 +17,16 @@ import us.tastybento.bskyblock.api.events.team.TeamEvent.TeamReason;
import us.tastybento.bskyblock.config.Settings;
import us.tastybento.bskyblock.database.objects.Island;
public class IslandTeamPromoteCommand extends AbstractIslandTeamCommandArgument {
public class IslandTeamPromoteCommand extends AbstractTeamCommand {
public IslandTeamPromoteCommand() {
super("promote", "makeleader");
public IslandTeamPromoteCommand(CompositeCommand islandCommand) {
super(islandCommand, "promote", "makeleader");
this.setPermission(Settings.PERMPREFIX + "island.team");
this.setOnlyPlayer(true);
}
@Override
public boolean execute(User user, String[] args) {
// Check team perm and get variables set
if (!checkTeamPerm()) return true;
UUID playerUUID = user.getUniqueId();
// Can use if in a team
boolean inTeam = plugin.getPlayers().inTeam(playerUUID);
@ -35,23 +37,23 @@ public class IslandTeamPromoteCommand extends AbstractIslandTeamCommandArgument
plugin.getLogger().info("DEBUG: arg[0] = " + args[0]);
UUID targetUUID = getPlayers().getUUID(args[0]);
if (targetUUID == null) {
user.sendMessage(ChatColor.RED + "general.errors.unknown-player");
user.sendMessage("general.errors.unknown-player");
return true;
}
if (!getPlayers().inTeam(playerUUID)) {
user.sendMessage(ChatColor.RED + "makeleader.errorYouMustBeInTeam");
user.sendMessage("makeleader.errorYouMustBeInTeam");
return true;
}
if (!teamLeaderUUID.equals(playerUUID)) {
user.sendMessage(ChatColor.RED + "makeleader.errorNotYourIsland");
user.sendMessage("makeleader.errorNotYourIsland");
return true;
}
if (targetUUID.equals(playerUUID)) {
user.sendMessage(ChatColor.RED + "makeleader.errorGeneralError");
user.sendMessage("makeleader.errorGeneralError");
return true;
}
if (!plugin.getIslands().getMembers(playerUUID).contains(targetUUID)) {
user.sendMessage(ChatColor.RED + "makeleader.errorThatPlayerIsNotInTeam");
user.sendMessage("makeleader.errorThatPlayerIsNotInTeam");
return true;
}
// Fire event so add-ons can run commands, etc.
@ -66,8 +68,7 @@ public class IslandTeamPromoteCommand extends AbstractIslandTeamCommandArgument
// target is the new leader
getIslands().getIsland(playerUUID).setOwner(targetUUID);
user.sendMessage(ChatColor.GREEN
+ "makeleader.nameIsNowTheOwner", "[name]", getPlayers().getName(targetUUID));
user.sendMessage("makeleader.nameIsNowTheOwner", "[name]", getPlayers().getName(targetUUID));
// Check if online
User target = User.getInstance(targetUUID);
@ -130,11 +131,18 @@ public class IslandTeamPromoteCommand extends AbstractIslandTeamCommandArgument
}
@Override
public Set<String> tabComplete(User user, String[] args) {
Set<String> result = new HashSet<>();
public List<String> onTabComplete(final CommandSender sender, final Command command, final String label, final String[] args) {
User user = User.getInstance(sender);
List<String> result = new ArrayList<>();
for (UUID member : plugin.getIslands().getMembers(user.getUniqueId())) {
result.add(plugin.getServer().getOfflinePlayer(member).getName());
}
return result;
}
@Override
public void setup() {
// TODO Auto-generated method stub
}
}

View File

@ -1,33 +1,27 @@
package us.tastybento.bskyblock.commands.island.teams;
import java.util.Set;
import java.util.UUID;
import org.bukkit.ChatColor;
import us.tastybento.bskyblock.api.commands.CompositeCommand;
import us.tastybento.bskyblock.api.commands.User;
import us.tastybento.bskyblock.api.events.IslandBaseEvent;
import us.tastybento.bskyblock.api.events.team.TeamEvent;
import us.tastybento.bskyblock.api.events.team.TeamEvent.TeamReason;
import us.tastybento.bskyblock.config.Settings;
public class IslandTeamUninviteCommand extends AbstractIslandTeamCommandArgument {
public class IslandTeamUninviteCommand extends AbstractTeamCommand {
public IslandTeamUninviteCommand() {
super("uninvite");
public IslandTeamUninviteCommand(CompositeCommand islandCommand) {
super(islandCommand, "uninvite");
this.setPermission(Settings.PERMPREFIX + "island.team");
this.setOnlyPlayer(true);
}
@Override
public boolean execute(User user, String[] args) {
if (!isPlayer(user)) {
user.sendMessage("general.errors.use-in-game");
return true;
}
UUID playerUUID = user.getUniqueId();
if (!user.hasPermission(Settings.PERMPREFIX + "team")) {
user.sendMessage(ChatColor.RED + "general.errors.no-permission");
return true;
}
// Can only use if you have an invite out there
if(!inviteList.inverse().containsKey(playerUUID)) {
return true;
@ -55,8 +49,9 @@ public class IslandTeamUninviteCommand extends AbstractIslandTeamCommandArgument
return false;
}
@Override
public Set<String> tabComplete(User user, String[] args) {
return null;
@Override
public void setup() {
// TODO Auto-generated method stub
}
}