Fixed tabComplete showing messages

Changed the response for canUse to return an error code because the
error could be different depending on the reason. For tabComplete no
error is shown, but for commands, the error can be shown.

Implemented the invite and uninvite commands and filled in the team
command.
This commit is contained in:
tastybento 2017-08-05 12:45:10 -07:00
parent f515623e26
commit c5d0a09a76
5 changed files with 194 additions and 143 deletions

View File

@ -297,6 +297,7 @@ invite:
help: "Use [/[label] invite <playername>] to invite a player to your island." help: "Use [/[label] invite <playername>] to invite a player to your island."
inviteSentTo: "Invite sent to [name]" inviteSentTo: "Invite sent to [name]"
nameHasInvitedYou: "[name] has invited you to join their island!" nameHasInvitedYou: "[name] has invited you to join their island!"
nameHasUninvitedYou: "[name] has removed the invite to join their island!"
onlyIslandOwnerCanInvite: "Only the leader can invite!" onlyIslandOwnerCanInvite: "Only the leader can invite!"
removingInvite: "Removing your previous invite." removingInvite: "Removing your previous invite."
toAcceptOrReject: "to accept or reject the invite." toAcceptOrReject: "to accept or reject the invite."

View File

@ -51,8 +51,8 @@ public abstract class AbstractCommand implements CommandExecutor, TabCompleter {
if (help) { if (help) {
addArgument(new String[]{"help", "?"}, new ArgumentHandler() { addArgument(new String[]{"help", "?"}, new ArgumentHandler() {
@Override @Override
public boolean canUse(CommandSender sender) { public CanUseResp canUse(CommandSender sender) {
return true; // If the player has access to this command, he can get help return new CanUseResp(true); // If the player has access to this command, he can get help
} }
@Override @Override
@ -80,7 +80,7 @@ public abstract class AbstractCommand implements CommandExecutor, TabCompleter {
* *
*/ */
public interface ArgumentHandler { public interface ArgumentHandler {
boolean canUse(CommandSender sender); CanUseResp canUse(CommandSender sender);
void execute(CommandSender sender, String[] args); void execute(CommandSender sender, String[] args);
List<String> tabComplete(CommandSender sender, String[] args); List<String> tabComplete(CommandSender sender, String[] args);
String[] usage(CommandSender sender); String[] usage(CommandSender sender);
@ -88,7 +88,7 @@ public abstract class AbstractCommand implements CommandExecutor, TabCompleter {
public abstract void setup(); public abstract void setup();
public abstract boolean canUse(CommandSender sender); public abstract CanUseResp canUse(CommandSender sender);
public abstract void execute(CommandSender sender, String[] args); public abstract void execute(CommandSender sender, String[] args);
public void addArgument(String[] names, ArgumentHandler handler) { public void addArgument(String[] names, ArgumentHandler handler) {
@ -144,10 +144,11 @@ public abstract class AbstractCommand implements CommandExecutor, TabCompleter {
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
checkForPlayer(sender); checkForPlayer(sender);
if (this.canUse(sender)) { CanUseResp canUse = this.canUse(sender);
if (canUse.isAllowed()) {
if(args.length >= 1) { if(args.length >= 1) {
ArgumentHandler handler = getHandler(args[0]); // Store the handler to save some calculations ArgumentHandler handler = getHandler(args[0]); // Store the handler to save some calculations
if (handler != null && handler.canUse(sender)) { if (handler != null && handler.canUse(sender).isAllowed()) {
handler.execute(sender, clean(Arrays.copyOfRange(args, 1, args.length))); handler.execute(sender, clean(Arrays.copyOfRange(args, 1, args.length)));
} else if (help) { } else if (help) {
if (argumentsMap.containsKey("help")) { if (argumentsMap.containsKey("help")) {
@ -161,6 +162,9 @@ public abstract class AbstractCommand implements CommandExecutor, TabCompleter {
// No args // No args
this.execute(sender, args); this.execute(sender, args);
} }
} else {
// Sender cannot use this command - tell them why
Util.sendMessage(sender, canUse.errorResponse);
} }
return true; return true;
} }
@ -170,16 +174,16 @@ public abstract class AbstractCommand implements CommandExecutor, TabCompleter {
List<String> options = new ArrayList<String>(); List<String> options = new ArrayList<String>();
checkForPlayer(sender); checkForPlayer(sender);
String lastArg = (args.length != 0 ? args[args.length - 1] : ""); String lastArg = (args.length != 0 ? args[args.length - 1] : "");
if (canUse(sender)) { if (canUse(sender).isAllowed()) {
if (args.length <= 1) { if (args.length <= 1) {
// Go through every argument, check if player can use it and if so, add it in tab options // Go through every argument, check if player can use it and if so, add it in tab options
for(String argument : argumentsMap.keySet()) { for(String argument : argumentsMap.keySet()) {
if (getHandler(argument).canUse(sender)) options.add(argument); if (getHandler(argument).canUse(sender).isAllowed()) options.add(argument);
} }
} else { } else {
// If player can execute the argument, get its tab-completer options // If player can execute the argument, get its tab-completer options
ArgumentHandler handler = getHandler(args[0]); ArgumentHandler handler = getHandler(args[0]);
if (handler != null && handler.canUse(sender)) { if (handler != null && handler.canUse(sender).isAllowed()) {
// We remove the 1st arg - and remove any blank args caused by hitting space before the tab // We remove the 1st arg - and remove any blank args caused by hitting space before the tab
List<String> tabOptions = handler.tabComplete(sender, clean(Arrays.copyOfRange(args, 1, args.length))); List<String> tabOptions = handler.tabComplete(sender, clean(Arrays.copyOfRange(args, 1, args.length)));
if (tabOptions != null) options.addAll(tabOptions); if (tabOptions != null) options.addAll(tabOptions);
@ -214,4 +218,58 @@ public abstract class AbstractCommand implements CommandExecutor, TabCompleter {
} }
} }
/**
* Response class for the canUse check
* @author tastybento
*
*/
public class CanUseResp {
private boolean allowed;
private String errorResponse; // May be shown if required
/**
* Cannot use situation
* @param errorResponse - error response
*/
public CanUseResp(String errorResponse) {
this.allowed = false;
this.errorResponse = errorResponse;
}
/**
* Can or cannot use situation, no error response.
* @param b
*/
public CanUseResp(boolean b) {
this.allowed = b;
this.errorResponse = "";
}
/**
* @return the allowed
*/
public boolean isAllowed() {
return allowed;
}
/**
* @param allowed the allowed to set
*/
public void setAllowed(boolean allowed) {
this.allowed = allowed;
}
/**
* @return the errorResponse
*/
public String getErrorResponse() {
return errorResponse;
}
/**
* @param errorResponse the errorResponse to set
*/
public void setErrorResponse(String errorResponse) {
this.errorResponse = errorResponse;
}
}
} }

View File

@ -24,9 +24,9 @@ public class AdminCommand extends AbstractCommand {
addArgument(new String[] {"delete"}, new ArgumentHandler() { addArgument(new String[] {"delete"}, new ArgumentHandler() {
@Override @Override
public boolean canUse(CommandSender sender) { public CanUseResp canUse(CommandSender sender) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return true; return new CanUseResp(true);
} }
@Override @Override
@ -49,9 +49,9 @@ public class AdminCommand extends AbstractCommand {
} }
@Override @Override
public boolean canUse(CommandSender sender) { public CanUseResp canUse(CommandSender sender) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return true; return new CanUseResp(true);
} }
@Override @Override

View File

@ -1,17 +1,19 @@
package us.tastybento.bskyblock.commands; package us.tastybento.bskyblock.commands;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import org.apache.commons.lang.math.NumberUtils; import org.apache.commons.lang.math.NumberUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.permissions.PermissionAttachmentInfo; import org.bukkit.permissions.PermissionAttachmentInfo;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import us.tastybento.bskyblock.BSkyBlock; import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.api.commands.AbstractCommand; import us.tastybento.bskyblock.api.commands.AbstractCommand;
import us.tastybento.bskyblock.config.Settings; import us.tastybento.bskyblock.config.Settings;
@ -32,7 +34,7 @@ public class IslandCommand extends AbstractCommand {
* Invite list - invited player name string (key), inviter name string * Invite list - invited player name string (key), inviter name string
* (value) * (value)
*/ */
private final HashMap<UUID, UUID> inviteList = new HashMap<UUID, UUID>(); private final BiMap<UUID, UUID> inviteList = HashBiMap.create();
public IslandCommand(BSkyBlock plugin) { public IslandCommand(BSkyBlock plugin) {
@ -43,20 +45,18 @@ public class IslandCommand extends AbstractCommand {
} }
@Override @Override
public boolean canUse(CommandSender sender) { public CanUseResp canUse(CommandSender sender) {
if(!(sender instanceof Player)){ if(!(sender instanceof Player)){
Util.sendMessage(sender, plugin.getLocale(sender).get("general.errors.use-in-game")); return new CanUseResp(plugin.getLocale(sender).get("general.errors.use-in-game"));
return false;
} }
Player player = (Player) sender; Player player = (Player) sender;
// Basic permission check to even use /island // Basic permission check to even use /island
if(!VaultHelper.hasPerm(player, Settings.PERMPREFIX + "island.create")){ if(!VaultHelper.hasPerm(player, Settings.PERMPREFIX + "island.create")){
Util.sendMessage(player, ChatColor.RED + plugin.getLocale(player).get("general.errors.no-permission")); return new CanUseResp(ChatColor.RED + plugin.getLocale(player).get("general.errors.no-permission"));
return false;
} }
return true; return new CanUseResp(true);
} }
@Override @Override
@ -81,8 +81,8 @@ public class IslandCommand extends AbstractCommand {
addArgument(new String[] {"about"}, new ArgumentHandler() { addArgument(new String[] {"about"}, new ArgumentHandler() {
@Override @Override
public boolean canUse(CommandSender sender) { public CanUseResp canUse(CommandSender sender) {
return true; return new CanUseResp(true);
} }
@Override @Override
@ -133,9 +133,9 @@ public class IslandCommand extends AbstractCommand {
addArgument(new String[] {"go", "home", "h"}, new ArgumentHandler() { addArgument(new String[] {"go", "home", "h"}, new ArgumentHandler() {
@Override @Override
public boolean canUse(CommandSender sender) { public CanUseResp canUse(CommandSender sender) {
return true; return new CanUseResp(true);
} }
@Override @Override
@ -166,9 +166,9 @@ public class IslandCommand extends AbstractCommand {
addArgument(new String[] {"spawn"}, new ArgumentHandler() { addArgument(new String[] {"spawn"}, new ArgumentHandler() {
@Override @Override
public boolean canUse(CommandSender sender) { public CanUseResp canUse(CommandSender sender) {
return false; return new CanUseResp(false);
} }
@Override @Override
@ -192,9 +192,9 @@ public class IslandCommand extends AbstractCommand {
addArgument(new String[] {"create", "auto"}, new ArgumentHandler() { addArgument(new String[] {"create", "auto"}, new ArgumentHandler() {
@Override @Override
public boolean canUse(CommandSender sender) { public CanUseResp canUse(CommandSender sender) {
return true; return new CanUseResp(true);
} }
@Override @Override
@ -225,9 +225,9 @@ public class IslandCommand extends AbstractCommand {
addArgument(new String[] {"info"}, new ArgumentHandler() { addArgument(new String[] {"info"}, new ArgumentHandler() {
@Override @Override
public boolean canUse(CommandSender sender) { public CanUseResp canUse(CommandSender sender) {
return false; return new CanUseResp(false);
} }
@Override @Override
@ -252,9 +252,9 @@ public class IslandCommand extends AbstractCommand {
addArgument(new String[] {"controlpanel", "cp"}, new ArgumentHandler() { addArgument(new String[] {"controlpanel", "cp"}, new ArgumentHandler() {
@Override @Override
public boolean canUse(CommandSender sender) { public CanUseResp canUse(CommandSender sender) {
return false; return new CanUseResp(false);
} }
@Override @Override
@ -279,9 +279,9 @@ public class IslandCommand extends AbstractCommand {
addArgument(new String[] {"reset", "restart"}, new ArgumentHandler() { addArgument(new String[] {"reset", "restart"}, new ArgumentHandler() {
@Override @Override
public boolean canUse(CommandSender sender) { public CanUseResp canUse(CommandSender sender) {
return true; return new CanUseResp(true);
} }
@Override @Override
@ -324,9 +324,9 @@ public class IslandCommand extends AbstractCommand {
addArgument(new String[] {"sethome"}, new ArgumentHandler() { addArgument(new String[] {"sethome"}, new ArgumentHandler() {
@Override @Override
public boolean canUse(CommandSender sender) { public CanUseResp canUse(CommandSender sender) {
return false; return new CanUseResp(false);
} }
@Override @Override
@ -351,25 +351,22 @@ public class IslandCommand extends AbstractCommand {
addArgument(new String[] {"name"}, new ArgumentHandler() { addArgument(new String[] {"name"}, new ArgumentHandler() {
@Override @Override
public boolean canUse(CommandSender sender) { public CanUseResp canUse(CommandSender sender) {
Player player = (Player) sender; Player player = (Player) sender;
if(!VaultHelper.hasPerm(player, Settings.PERMPREFIX + "island.name")){ if(!VaultHelper.hasPerm(player, Settings.PERMPREFIX + "island.name")){
Util.sendMessage(player, ChatColor.RED + plugin.getLocale(player).get("general.errors.no-permission")); return new CanUseResp(ChatColor.RED + plugin.getLocale(player).get("general.errors.no-permission"));
return false;
} }
if(!plugin.getIslands().hasIsland(player.getUniqueId())){ if(!plugin.getIslands().hasIsland(player.getUniqueId())){
Util.sendMessage(player, ChatColor.RED + plugin.getLocale(player).get("general.errors.no-island")); return new CanUseResp(ChatColor.RED + plugin.getLocale(player).get("general.errors.no-island"));
return false;
} }
if(!plugin.getIslands().isOwner(player.getUniqueId())){ if(!plugin.getIslands().isOwner(player.getUniqueId())){
Util.sendMessage(player, ChatColor.RED + plugin.getLocale(player).get("general.errors.not-leader")); return new CanUseResp(ChatColor.RED + plugin.getLocale(player).get("general.errors.not-leader"));
return false;
} }
return true; return new CanUseResp(true);
} }
@Override @Override
@ -420,25 +417,22 @@ public class IslandCommand extends AbstractCommand {
addArgument(new String[] {"resetname"}, new ArgumentHandler() { addArgument(new String[] {"resetname"}, new ArgumentHandler() {
@Override @Override
public boolean canUse(CommandSender sender) { public CanUseResp canUse(CommandSender sender) {
Player player = (Player) sender; Player player = (Player) sender;
if(!VaultHelper.hasPerm(player, Settings.PERMPREFIX + "island.name")){ if(!VaultHelper.hasPerm(player, Settings.PERMPREFIX + "island.name")){
Util.sendMessage(player, ChatColor.RED + plugin.getLocale(player).get("general.errors.no-permission")); return new CanUseResp(ChatColor.RED + plugin.getLocale(player).get("general.errors.no-permission"));
return false;
} }
if(!plugin.getIslands().hasIsland(player.getUniqueId())){ if(!plugin.getIslands().hasIsland(player.getUniqueId())){
Util.sendMessage(player, ChatColor.RED + plugin.getLocale(player).get("general.errors.no-island")); return new CanUseResp(ChatColor.RED + plugin.getLocale(player).get("general.errors.no-island"));
return false;
} }
if(!plugin.getIslands().isOwner(player.getUniqueId())){ if(!plugin.getIslands().isOwner(player.getUniqueId())){
Util.sendMessage(player, ChatColor.RED + plugin.getLocale(player).get("general.errors.not-leader")); return new CanUseResp(ChatColor.RED + plugin.getLocale(player).get("general.errors.not-leader"));
return false;
} }
return true; return new CanUseResp(true);
} }
@Override @Override
@ -465,9 +459,9 @@ public class IslandCommand extends AbstractCommand {
addArgument(new String[] {"limits"}, new ArgumentHandler() { addArgument(new String[] {"limits"}, new ArgumentHandler() {
@Override @Override
public boolean canUse(CommandSender sender) { public CanUseResp canUse(CommandSender sender) {
return false; return new CanUseResp(false);
} }
@Override @Override
@ -492,13 +486,15 @@ public class IslandCommand extends AbstractCommand {
addArgument(new String[] {"team"}, new ArgumentHandler() { addArgument(new String[] {"team"}, new ArgumentHandler() {
@Override @Override
public boolean canUse(CommandSender sender) { public CanUseResp canUse(CommandSender sender) {
if (sender instanceof Player) { if (sender instanceof Player) {
if (VaultHelper.hasPerm((Player)sender, Settings.PERMPREFIX + "team.create")) { if (!VaultHelper.hasPerm((Player)sender, Settings.PERMPREFIX + "team.create")) {
return true; return new CanUseResp(ChatColor.RED + plugin.getLocale(player).get("general.errors.no-permission"));
} else {
return new CanUseResp(true);
} }
} }
return false; return new CanUseResp(plugin.getLocale(sender).get("general.errors.use-in-game"));
} }
@Override @Override
@ -564,21 +560,14 @@ public class IslandCommand extends AbstractCommand {
addArgument(new String[] {"invite"}, new ArgumentHandler() { addArgument(new String[] {"invite"}, new ArgumentHandler() {
@Override @Override
public boolean canUse(CommandSender sender) { public CanUseResp canUse(CommandSender sender) {
plugin.getLogger().info("DEBUG: invite player command canUse check");
if (isPlayer) { if (isPlayer) {
plugin.getLogger().info("DEBUG: is player");
if (VaultHelper.hasPerm(player, Settings.PERMPREFIX + "team.create")) { if (VaultHelper.hasPerm(player, Settings.PERMPREFIX + "team.create")) {
plugin.getLogger().info("DEBUG: " + player.getName() + " has perm"); return new CanUseResp(true);
return true;
} else {
plugin.getLogger().info("DEBUG: " + player.getName() + " does not have perm");
} }
} else { return new CanUseResp(ChatColor.RED + plugin.getLocale(player).get("general.errors.no-permission"));
plugin.getLogger().info("DEBUG: is not a player");
} }
plugin.getLogger().info("DEBUG: does not have perm: " + Settings.PERMPREFIX + "team.create"); return new CanUseResp(false);
return false;
} }
@Override @Override
@ -586,6 +575,12 @@ public class IslandCommand extends AbstractCommand {
if (args.length == 0) { if (args.length == 0) {
// Invite label with no name, i.e., /island invite - tells the player who has invited them so far // Invite label with no name, i.e., /island invite - tells the player who has invited them so far
//TODO //TODO
if (inviteList.containsKey(playerUUID)) {
OfflinePlayer inviter = plugin.getServer().getOfflinePlayer(inviteList.get(playerUUID));
Util.sendMessage(player, ChatColor.GREEN + plugin.getLocale(sender).get("invite.nameHasInvitedYou").replace("[name]", inviter.getName()));
} else {
Util.sendMessage(player, ChatColor.RED + plugin.getLocale(sender).get("island.help.Invite"));
}
return; return;
} }
if (args.length == 1) { if (args.length == 1) {
@ -653,7 +648,7 @@ public class IslandCommand extends AbstractCommand {
// Players can only have one invite out at a // Players can only have one invite out at a
// time - interesting // time - interesting
if (inviteList.containsValue(playerUUID)) { if (inviteList.containsValue(playerUUID)) {
inviteList.remove(Util.getKeyByValue(inviteList, player.getUniqueId())); inviteList.inverse().remove(playerUUID);
Util.sendMessage(player, ChatColor.YELLOW + plugin.getLocale(sender).get("invite.removingInvite")); Util.sendMessage(player, ChatColor.YELLOW + plugin.getLocale(sender).get("invite.removingInvite"));
} }
// Put the invited player (key) onto the // Put the invited player (key) onto the
@ -662,7 +657,7 @@ public class IslandCommand extends AbstractCommand {
// then this invite will overwrite the // then this invite will overwrite the
// previous invite! // previous invite!
inviteList.put(invitedPlayerUUID, player.getUniqueId()); inviteList.put(invitedPlayerUUID, player.getUniqueId());
Util.sendMessage(player, ChatColor.GREEN + plugin.getLocale(sender).get("invite.inviteSentTo").replace("[name]", args[1])); Util.sendMessage(player, ChatColor.GREEN + plugin.getLocale(sender).get("invite.inviteSentTo").replace("[name]", args[0]));
// Send message to online player // Send message to online player
Util.sendMessage(Bukkit.getPlayer(invitedPlayerUUID), plugin.getLocale(invitedPlayerUUID).get("invite.nameHasInvitedYou").replace("[name]", player.getName())); Util.sendMessage(Bukkit.getPlayer(invitedPlayerUUID), plugin.getLocale(invitedPlayerUUID).get("invite.nameHasInvitedYou").replace("[name]", player.getName()));
Util.sendMessage(Bukkit.getPlayer(invitedPlayerUUID), Util.sendMessage(Bukkit.getPlayer(invitedPlayerUUID),
@ -686,12 +681,12 @@ public class IslandCommand extends AbstractCommand {
// If the inviter already has an invite out, remove // If the inviter already has an invite out, remove
// it // it
if (inviteList.containsValue(playerUUID)) { if (inviteList.containsValue(playerUUID)) {
inviteList.remove(Util.getKeyByValue(inviteList, player.getUniqueId())); inviteList.inverse().remove(playerUUID);
Util.sendMessage(player, ChatColor.YELLOW + plugin.getLocale(sender).get("invite.removingInvite")); Util.sendMessage(player, ChatColor.YELLOW + plugin.getLocale(sender).get("invite.removingInvite"));
} }
// Place the player and invitee on the invite list // Place the player and invitee on the invite list
inviteList.put(invitedPlayerUUID, player.getUniqueId()); inviteList.put(invitedPlayerUUID, player.getUniqueId());
Util.sendMessage(player, ChatColor.GREEN + plugin.getLocale(sender).get("invite.inviteSentTo").replace("[name]", args[1])); Util.sendMessage(player, ChatColor.GREEN + plugin.getLocale(sender).get("invite.inviteSentTo").replace("[name]", args[0]));
Util.sendMessage(Bukkit.getPlayer(invitedPlayerUUID), plugin.getLocale(invitedPlayerUUID).get("invite.nameHasInvitedYou").replace("[name]", player.getName())); Util.sendMessage(Bukkit.getPlayer(invitedPlayerUUID), plugin.getLocale(invitedPlayerUUID).get("invite.nameHasInvitedYou").replace("[name]", player.getName()));
Util.sendMessage(Bukkit.getPlayer(invitedPlayerUUID), Util.sendMessage(Bukkit.getPlayer(invitedPlayerUUID),
ChatColor.WHITE + "/" + label + " [accept/reject]" + ChatColor.YELLOW + " " + plugin.getLocale(invitedPlayerUUID).get("invite.toAcceptOrReject")); ChatColor.WHITE + "/" + label + " [accept/reject]" + ChatColor.YELLOW + " " + plugin.getLocale(invitedPlayerUUID).get("invite.toAcceptOrReject"));
@ -717,7 +712,7 @@ public class IslandCommand extends AbstractCommand {
@Override @Override
public String[] usage(CommandSender sender){ public String[] usage(CommandSender sender){
return new String[] {"<player>", plugin.getLocale(sender).get("help.island.invite")}; return new String[] {"<player>", plugin.getLocale(sender).get("island.help.Invite")};
} }
}); });
@ -725,15 +720,30 @@ public class IslandCommand extends AbstractCommand {
addArgument(new String[] {"uninvite"}, new ArgumentHandler() { addArgument(new String[] {"uninvite"}, new ArgumentHandler() {
@Override @Override
public boolean canUse(CommandSender sender) { public CanUseResp canUse(CommandSender sender) {
if (isPlayer) {
return false; if (VaultHelper.hasPerm(player, Settings.PERMPREFIX + "team.create")) {
return new CanUseResp(true);
}
return new CanUseResp(ChatColor.RED + plugin.getLocale(player).get("general.errors.no-permission"));
}
return new CanUseResp(false);
} }
@Override @Override
public void execute(CommandSender sender, String[] args) { public void execute(CommandSender sender, String[] args) {
// Invite label with no name, i.e., /island invite - tells the player who has invited them so far
if (inviteList.inverse().containsKey(playerUUID)) {
Player invitee = plugin.getServer().getPlayer(inviteList.inverse().get(playerUUID));
if (invitee != null) {
inviteList.inverse().remove(playerUUID);
Util.sendMessage(invitee, ChatColor.RED + plugin.getLocale(invitee.getUniqueId()).get("invite.nameHasUninvitedYou").replace("[name]", player.getName()));
Util.sendMessage(player, ChatColor.GREEN + plugin.getLocale(playerUUID).get("general.success"));
}
} else {
Util.sendMessage(player, ChatColor.RED + plugin.getLocale(sender).get("island.help.Invite"));
}
return;
} }
@Override @Override
@ -752,9 +762,9 @@ public class IslandCommand extends AbstractCommand {
addArgument(new String[] {"leave"}, new ArgumentHandler() { addArgument(new String[] {"leave"}, new ArgumentHandler() {
@Override @Override
public boolean canUse(CommandSender sender) { public CanUseResp canUse(CommandSender sender) {
return false; return new CanUseResp(false);
} }
@Override @Override
@ -779,9 +789,9 @@ public class IslandCommand extends AbstractCommand {
addArgument(new String[] {"kick"}, new ArgumentHandler() { addArgument(new String[] {"kick"}, new ArgumentHandler() {
@Override @Override
public boolean canUse(CommandSender sender) { public CanUseResp canUse(CommandSender sender) {
return false; return new CanUseResp(false);
} }
@Override @Override
@ -806,9 +816,9 @@ public class IslandCommand extends AbstractCommand {
addArgument(new String[] {"accept"}, new ArgumentHandler() { addArgument(new String[] {"accept"}, new ArgumentHandler() {
@Override @Override
public boolean canUse(CommandSender sender) { public CanUseResp canUse(CommandSender sender) {
return false; return new CanUseResp(false);
} }
@Override @Override
@ -833,9 +843,9 @@ public class IslandCommand extends AbstractCommand {
addArgument(new String[] {"reject"}, new ArgumentHandler() { addArgument(new String[] {"reject"}, new ArgumentHandler() {
@Override @Override
public boolean canUse(CommandSender sender) { public CanUseResp canUse(CommandSender sender) {
return false; return new CanUseResp(false);
} }
@Override @Override
@ -860,9 +870,9 @@ public class IslandCommand extends AbstractCommand {
addArgument(new String[] {"makeleader", "transfer"}, new ArgumentHandler() { addArgument(new String[] {"makeleader", "transfer"}, new ArgumentHandler() {
@Override @Override
public boolean canUse(CommandSender sender) { public CanUseResp canUse(CommandSender sender) {
return false; return new CanUseResp(false);
} }
@Override @Override
@ -887,9 +897,9 @@ public class IslandCommand extends AbstractCommand {
addArgument(new String[] {"teamchat", "tc"}, new ArgumentHandler() { addArgument(new String[] {"teamchat", "tc"}, new ArgumentHandler() {
@Override @Override
public boolean canUse(CommandSender sender) { public CanUseResp canUse(CommandSender sender) {
return false; return new CanUseResp(false);
} }
@Override @Override
@ -914,9 +924,9 @@ public class IslandCommand extends AbstractCommand {
addArgument(new String[] {"biomes"}, new ArgumentHandler() { addArgument(new String[] {"biomes"}, new ArgumentHandler() {
@Override @Override
public boolean canUse(CommandSender sender) { public CanUseResp canUse(CommandSender sender) {
return false; return new CanUseResp(false);
} }
@Override @Override
@ -941,9 +951,9 @@ public class IslandCommand extends AbstractCommand {
addArgument(new String[] {"expel"}, new ArgumentHandler() { addArgument(new String[] {"expel"}, new ArgumentHandler() {
@Override @Override
public boolean canUse(CommandSender sender) { public CanUseResp canUse(CommandSender sender) {
return false; return new CanUseResp(false);
} }
@Override @Override
@ -968,9 +978,9 @@ public class IslandCommand extends AbstractCommand {
addArgument(new String[] {"expelall", "expel!"}, new ArgumentHandler() { addArgument(new String[] {"expelall", "expel!"}, new ArgumentHandler() {
@Override @Override
public boolean canUse(CommandSender sender) { public CanUseResp canUse(CommandSender sender) {
return false; return new CanUseResp(false);
} }
@Override @Override
@ -995,9 +1005,9 @@ public class IslandCommand extends AbstractCommand {
addArgument(new String[] {"ban"}, new ArgumentHandler() { addArgument(new String[] {"ban"}, new ArgumentHandler() {
@Override @Override
public boolean canUse(CommandSender sender) { public CanUseResp canUse(CommandSender sender) {
return false; return new CanUseResp(false);
} }
@Override @Override
@ -1022,9 +1032,9 @@ public class IslandCommand extends AbstractCommand {
addArgument(new String[] {"unban"}, new ArgumentHandler() { addArgument(new String[] {"unban"}, new ArgumentHandler() {
@Override @Override
public boolean canUse(CommandSender sender) { public CanUseResp canUse(CommandSender sender) {
return false; return new CanUseResp(false);
} }
@Override @Override
@ -1049,9 +1059,9 @@ public class IslandCommand extends AbstractCommand {
addArgument(new String[] {"banlist", "bl"}, new ArgumentHandler() { addArgument(new String[] {"banlist", "bl"}, new ArgumentHandler() {
@Override @Override
public boolean canUse(CommandSender sender) { public CanUseResp canUse(CommandSender sender) {
return false; return new CanUseResp(false);
} }
@Override @Override
@ -1076,9 +1086,9 @@ public class IslandCommand extends AbstractCommand {
addArgument(new String[] {"trust"}, new ArgumentHandler() { addArgument(new String[] {"trust"}, new ArgumentHandler() {
@Override @Override
public boolean canUse(CommandSender sender) { public CanUseResp canUse(CommandSender sender) {
return false; return new CanUseResp(false);
} }
@Override @Override
@ -1103,9 +1113,9 @@ public class IslandCommand extends AbstractCommand {
addArgument(new String[] {"untrust"}, new ArgumentHandler() { addArgument(new String[] {"untrust"}, new ArgumentHandler() {
@Override @Override
public boolean canUse(CommandSender sender) { public CanUseResp canUse(CommandSender sender) {
return false; return new CanUseResp(false);
} }
@Override @Override
@ -1130,9 +1140,9 @@ public class IslandCommand extends AbstractCommand {
addArgument(new String[] {"trustlist", "tl"}, new ArgumentHandler() { addArgument(new String[] {"trustlist", "tl"}, new ArgumentHandler() {
@Override @Override
public boolean canUse(CommandSender sender) { public CanUseResp canUse(CommandSender sender) {
return false; return new CanUseResp(false);
} }
@Override @Override
@ -1157,9 +1167,9 @@ public class IslandCommand extends AbstractCommand {
addArgument(new String[] {"coop"}, new ArgumentHandler() { addArgument(new String[] {"coop"}, new ArgumentHandler() {
@Override @Override
public boolean canUse(CommandSender sender) { public CanUseResp canUse(CommandSender sender) {
return false; return new CanUseResp(false);
} }
@Override @Override
@ -1184,9 +1194,9 @@ public class IslandCommand extends AbstractCommand {
addArgument(new String[] {"uncoop"}, new ArgumentHandler() { addArgument(new String[] {"uncoop"}, new ArgumentHandler() {
@Override @Override
public boolean canUse(CommandSender sender) { public CanUseResp canUse(CommandSender sender) {
return false; return new CanUseResp(false);
} }
@Override @Override
@ -1211,9 +1221,9 @@ public class IslandCommand extends AbstractCommand {
addArgument(new String[] {"cooplist", "cl"}, new ArgumentHandler() { addArgument(new String[] {"cooplist", "cl"}, new ArgumentHandler() {
@Override @Override
public boolean canUse(CommandSender sender) { public CanUseResp canUse(CommandSender sender) {
return false; return new CanUseResp(false);
} }
@Override @Override
@ -1238,20 +1248,18 @@ public class IslandCommand extends AbstractCommand {
addArgument(new String[] {"lock", "unlock"}, new ArgumentHandler() { addArgument(new String[] {"lock", "unlock"}, new ArgumentHandler() {
@Override @Override
public boolean canUse(CommandSender sender) { public CanUseResp canUse(CommandSender sender) {
Player player = (Player) sender; Player player = (Player) sender;
if(!VaultHelper.hasPerm(player, Settings.PERMPREFIX + "island.lock")){ if(!VaultHelper.hasPerm(player, Settings.PERMPREFIX + "island.lock")){
Util.sendMessage(player, ChatColor.RED + plugin.getLocale(player).get("general.errors.no-permission")); return new CanUseResp(ChatColor.RED + plugin.getLocale(player).get("general.errors.no-permission"));
return false;
} }
if(!plugin.getIslands().hasIsland(player.getUniqueId())){ if(!plugin.getIslands().hasIsland(player.getUniqueId())){
Util.sendMessage(player, ChatColor.RED + plugin.getLocale(player).get("general.errors.no-island")); return new CanUseResp(ChatColor.RED + plugin.getLocale(player).get("general.errors.no-island"));
return false;
} }
return true; return new CanUseResp(true);
} }
@Override @Override
@ -1285,9 +1293,9 @@ public class IslandCommand extends AbstractCommand {
addArgument(new String[] {"settings"}, new ArgumentHandler() { addArgument(new String[] {"settings"}, new ArgumentHandler() {
@Override @Override
public boolean canUse(CommandSender sender) { public CanUseResp canUse(CommandSender sender) {
return false; return new CanUseResp(false);
} }
@Override @Override
@ -1312,9 +1320,9 @@ public class IslandCommand extends AbstractCommand {
addArgument(new String[] {"language", "lang"}, new ArgumentHandler() { addArgument(new String[] {"language", "lang"}, new ArgumentHandler() {
@Override @Override
public boolean canUse(CommandSender sender) { public CanUseResp canUse(CommandSender sender) {
return false; return new CanUseResp(false);
} }
@Override @Override

View File

@ -285,22 +285,6 @@ public class Util {
return inWorld(block.getLocation()); return inWorld(block.getLocation());
} }
/**
* One-to-one relationship, you can return the first matched key
*
* @param map
* @param value
* @return key
*/
public static <T, E> T getKeyByValue(Map<T, E> map, E value) {
for (Entry<T, E> entry : map.entrySet()) {
if (value.equals(entry.getValue())) {
return entry.getKey();
}
}
return null;
}
/** /**
* Return a list of online players this player can see, i.e. are not invisible * Return a list of online players this player can see, i.e. are not invisible
* @param player - if null, all player names on the server are shown * @param player - if null, all player names on the server are shown