Added a number of Island commands.

Note that the team invite/uninvite are not linked yet.
This commit is contained in:
Tastybento 2017-12-13 18:35:39 -08:00
parent 539c48cc85
commit 4b9762fb81
11 changed files with 848 additions and 19 deletions

View File

@ -1,11 +1,24 @@
package us.tastybento.bskyblock.api.commands;
import org.bukkit.command.CommandSender;
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 java.util.*;
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 Map<String, CommandArgument> subCommands;
@ -54,4 +67,65 @@ public abstract class CommandArgument {
public void replaceSubCommand(CommandArgument subCommand) {
subCommands.put(subCommand.getLabel(), subCommand);
}
// These methods below just neaten up the code in the commands so "plugin." isn't always used
/**
* @param sender
* @return true if sender is a player
*/
protected boolean isPlayer(CommandSender sender) {
return (sender instanceof Player);
}
/**
* @param player
* @return true if player is in a team
*/
protected boolean inTeam(Player player) {
return plugin.getPlayers().inTeam(player.getUniqueId());
}
/**
* @param player
* @return UUID of player's team leader
*/
protected UUID getTeamLeader(Player player) {
return plugin.getIslands().getTeamLeader(player.getUniqueId());
}
/**
* @param player
* @return set of UUIDs of all team members
*/
protected Set<UUID> getMembers(Player player) {
return plugin.getIslands().getMembers(player.getUniqueId());
}
/**
* @return PlayersManager
*/
protected PlayersManager getPlayers() {
return plugin.getPlayers();
}
/**
* @return IslandsManager
*/
protected IslandsManager getIslands() {
return plugin.getIslands();
}
/**
* @param sender
* @return Locale for sender
*/
protected BSBLocale getLocale(CommandSender sender) {
return plugin.getLocale(sender);
}
/**
* @param uuid
* @return Locale for UUID
*/
protected BSBLocale getLocale(UUID uuid) {
return plugin.getLocale(uuid);
}
}

View File

@ -0,0 +1,85 @@
/**
*
*/
package us.tastybento.bskyblock.commands.island;
import java.io.IOException;
import java.util.Set;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import us.tastybento.bskyblock.api.commands.CommandArgument;
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.util.VaultHelper;
/**
* @author ben
*
*/
public class IslandCreate extends CommandArgument {
/**
* @param label
* @param aliases
*/
public IslandCreate() {
super("create", "auto");
}
/* (non-Javadoc)
* @see us.tastybento.bskyblock.api.commands.CommandArgument#execute(org.bukkit.command.CommandSender, java.lang.String[])
*/
@Override
public boolean execute(CommandSender sender, String[] args) {
if (!isPlayer(sender)) {
sender.sendMessage(getLocale(sender).get("general.errors.use-in-game"));
return true;
}
Player player = (Player)sender;
if (!VaultHelper.hasPerm(player, Settings.PERMPREFIX + "island.create")) {
sender.sendMessage(ChatColor.RED + getLocale(sender).get("general.errors.no-permission"));
}
if (getIslands().hasIsland(player.getUniqueId())) {
sender.sendMessage(ChatColor.RED + getLocale(sender).get("general.errors.already-have-island"));
}
if (inTeam(player)) {
return false;
}
createIsland(player);
return true;
}
/* (non-Javadoc)
* @see us.tastybento.bskyblock.api.commands.CommandArgument#tabComplete(org.bukkit.command.CommandSender, java.lang.String[])
*/
@Override
public Set<String> tabComplete(CommandSender sender, String[] args) {
// TODO Auto-generated method stub
return null;
}
/**
* Creates an island for player
*
* @param player
*/
protected void createIsland(Player player) {
//TODO: Add panels, make a selection.
try {
NewIsland.builder()
.player(player)
.reason(Reason.CREATE)
.build();
} catch (IOException e) {
plugin.getLogger().severe("Could not create island for player.");
player.sendMessage(ChatColor.RED + plugin.getLocale(player).get("general.errors.general"));
e.printStackTrace();
}
}
}

View File

@ -1,4 +0,0 @@
package us.tastybento.bskyblock.commands.island;
public class IslandCreateCommand {
}

View File

@ -0,0 +1,73 @@
/**
*
*/
package us.tastybento.bskyblock.commands.island;
import java.util.Set;
import org.apache.commons.lang.math.NumberUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import us.tastybento.bskyblock.api.commands.CommandArgument;
import us.tastybento.bskyblock.config.Settings;
import us.tastybento.bskyblock.util.Util;
import us.tastybento.bskyblock.util.VaultHelper;
/**
* @author ben
*
*/
public class IslandGo extends CommandArgument {
/**
* @param label
* @param aliases
*/
public IslandGo() {
super("go", "home", "h");
}
/* (non-Javadoc)
* @see us.tastybento.bskyblock.api.commands.CommandArgument#execute(org.bukkit.command.CommandSender, java.lang.String[])
*/
@Override
public boolean execute(CommandSender sender, String[] args) {
if (!isPlayer(sender)) {
sender.sendMessage(getLocale(sender).get("general.errors.use-in-game"));
return true;
}
Player player = (Player)sender;
if (!VaultHelper.hasPerm(player, Settings.PERMPREFIX + "island.home")) {
sender.sendMessage(ChatColor.RED + getLocale(sender).get("general.errors.no-permission"));
return true;
}
if (!getIslands().hasIsland(player.getUniqueId())) {
sender.sendMessage(ChatColor.RED + getLocale(sender).get("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);
if (homeValue > 1 && homeValue <= maxHomes) {
getIslands().homeTeleport(player, homeValue);
return true;
}
}
getIslands().homeTeleport(player);
return true;
}
/* (non-Javadoc)
* @see us.tastybento.bskyblock.api.commands.CommandArgument#tabComplete(org.bukkit.command.CommandSender, java.lang.String[])
*/
@Override
public Set<String> tabComplete(CommandSender sender, String[] args) {
// TODO Auto-generated method stub
return null;
}
}

View File

@ -1,4 +1,80 @@
package us.tastybento.bskyblock.commands.island;
public class IslandResetCommand {
import java.io.IOException;
import java.util.Set;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import us.tastybento.bskyblock.api.commands.CommandArgument;
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;
import us.tastybento.bskyblock.util.VaultHelper;
public class IslandResetCommand extends CommandArgument {
private static final boolean DEBUG = false;
public IslandResetCommand() {
super("reset", "restart");
}
@Override
public boolean execute(CommandSender sender, String[] args) {
if (!isPlayer(sender)) {
sender.sendMessage(getLocale(sender).get("general.errors.use-in-game"));
return true;
}
Player player = (Player)sender;
if (!VaultHelper.hasPerm(player, Settings.PERMPREFIX + "island.reset")) {
sender.sendMessage(getLocale(sender).get("general.errors.no-permission"));
return true;
}
if (!getIslands().hasIsland(player.getUniqueId())) {
sender.sendMessage(getLocale(sender).get("general.errors.no-island"));
return true;
}
if (!getIslands().isOwner(player.getUniqueId())) {
return false;
}
if (inTeam(player)) {
sender.sendMessage(getLocale(sender).get("island.reset.MustRemovePlayers"));
return true;
}
player.setGameMode(GameMode.SPECTATOR);
// Get the player's old island
Island oldIsland = getIslands().getIsland(player.getUniqueId());
if (DEBUG)
plugin.getLogger().info("DEBUG: old island is at " + oldIsland.getCenter().getBlockX() + "," + oldIsland.getCenter().getBlockZ());
// Remove them from this island (it still exists and will be deleted later)
getIslands().removePlayer(player.getUniqueId());
if (DEBUG)
plugin.getLogger().info("DEBUG: old island's owner is " + oldIsland.getOwner());
// Create new island and then delete the old one
if (DEBUG)
plugin.getLogger().info("DEBUG: making new island ");
try {
NewIsland.builder()
.player(player)
.reason(Reason.RESET)
.oldIsland(oldIsland)
.build();
} catch (IOException e) {
plugin.getLogger().severe("Could not create island for player.");
sender.sendMessage(ChatColor.RED + plugin.getLocale(sender).get("general.errors.general"));
e.printStackTrace();
}
return true;
}
@Override
public Set<String> tabComplete(CommandSender sender, String[] args) {
// TODO Auto-generated method stub
return null;
}
}

View File

@ -0,0 +1,95 @@
/**
*
*/
package us.tastybento.bskyblock.commands.island;
import java.util.Set;
import java.util.UUID;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import us.tastybento.bskyblock.api.commands.CommandArgument;
import us.tastybento.bskyblock.config.Settings;
import us.tastybento.bskyblock.util.VaultHelper;
/**
* @author ben
*
*/
public class IslandResetName extends CommandArgument {
/**
* @param label
* @param aliases
*/
public IslandResetName() {
super("setname");
}
/* (non-Javadoc)
* @see us.tastybento.bskyblock.api.commands.CommandArgument#execute(org.bukkit.command.CommandSender, java.lang.String[])
*/
@Override
public boolean execute(CommandSender sender, String[] args) {
if (!isPlayer(sender)) {
sender.sendMessage(getLocale(sender).get("general.errors.use-in-game"));
return true;
}
Player player = (Player)sender;
UUID playerUUID = player.getUniqueId();
if (!VaultHelper.hasPerm(player, Settings.PERMPREFIX + "island.name")) {
sender.sendMessage(ChatColor.RED + getLocale(sender).get("general.errors.no-permission"));
return true;
}
if (!getIslands().hasIsland(playerUUID)) {
sender.sendMessage(ChatColor.RED + getLocale(sender).get("general.errors.no-island"));
return true;
}
if (!getIslands().isOwner(playerUUID)) {
sender.sendMessage(ChatColor.RED + getLocale(sender).get("general.errors.not-leader"));
return true;
}
// Explain command
if (args.length == 1) {
//TODO Util.sendMessage(player, getHelpMessage(player, label, args[0], usage(sender, label)));
return true;
}
// Naming the island
String name = args[1];
for (int i = 2; i < args.length; i++) name += " " + args[i];
// Check if the name isn't too short or too long
if (name.length() < Settings.nameMinLength) {
sender.sendMessage(getLocale(sender).get("general.errors.too-short").replace("[length]", String.valueOf(Settings.nameMinLength)));
return true;
}
if (name.length() > Settings.nameMaxLength) {
sender.sendMessage(getLocale(sender).get("general.errors.too-long").replace("[length]", String.valueOf(Settings.nameMaxLength)));
return true;
}
// Set the name
if (VaultHelper.hasPerm(player, Settings.PERMPREFIX + "island.name.format"))
getIslands().getIsland(player.getUniqueId()).setName(ChatColor.translateAlternateColorCodes('&', name));
else getIslands().getIsland(playerUUID).setName(name);
sender.sendMessage(getLocale(sender).get("general.success"));
return true;
}
/* (non-Javadoc)
* @see us.tastybento.bskyblock.api.commands.CommandArgument#tabComplete(org.bukkit.command.CommandSender, java.lang.String[])
*/
@Override
public Set<String> tabComplete(CommandSender sender, String[] args) {
// TODO Auto-generated method stub
return null;
}
}

View File

@ -0,0 +1,73 @@
/**
*
*/
package us.tastybento.bskyblock.commands.island;
import java.util.Set;
import java.util.UUID;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import us.tastybento.bskyblock.api.commands.CommandArgument;
import us.tastybento.bskyblock.config.Settings;
import us.tastybento.bskyblock.util.VaultHelper;
/**
* @author ben
*
*/
public class IslandSetName extends CommandArgument {
/**
* @param label
* @param aliases
*/
public IslandSetName() {
super("resetname");
}
/* (non-Javadoc)
* @see us.tastybento.bskyblock.api.commands.CommandArgument#execute(org.bukkit.command.CommandSender, java.lang.String[])
*/
@Override
public boolean execute(CommandSender sender, String[] args) {
if (!isPlayer(sender)) {
sender.sendMessage(getLocale(sender).get("general.errors.use-in-game"));
return true;
}
Player player = (Player)sender;
UUID playerUUID = player.getUniqueId();
if (!VaultHelper.hasPerm(player, Settings.PERMPREFIX + "island.name")) {
sender.sendMessage(ChatColor.RED + getLocale(sender).get("general.errors.no-permission"));
return true;
}
if (!getIslands().hasIsland(playerUUID)) {
sender.sendMessage(ChatColor.RED + getLocale(sender).get("general.errors.no-island"));
return true;
}
if (!getIslands().isOwner(playerUUID)) {
sender.sendMessage(ChatColor.RED + getLocale(sender).get("general.errors.not-leader"));
return true;
}
// Resets the island name
getIslands().getIsland(playerUUID).setName(null);
sender.sendMessage(getLocale(sender).get("general.success"));
return true;
}
/* (non-Javadoc)
* @see us.tastybento.bskyblock.api.commands.CommandArgument#tabComplete(org.bukkit.command.CommandSender, java.lang.String[])
*/
@Override
public Set<String> tabComplete(CommandSender sender, String[] args) {
// TODO Auto-generated method stub
return null;
}
}

View File

@ -1,4 +1,75 @@
package us.tastybento.bskyblock.commands.island;
public class IslandSethomeCommand {
import java.util.Set;
import java.util.UUID;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import us.tastybento.bskyblock.api.commands.CommandArgument;
import us.tastybento.bskyblock.config.Settings;
import us.tastybento.bskyblock.util.Util;
import us.tastybento.bskyblock.util.VaultHelper;
public class IslandSethomeCommand extends CommandArgument {
public IslandSethomeCommand() {
super("sethome");
}
@Override
public boolean execute(CommandSender sender, String[] args) {
if (!isPlayer(sender)) {
sender.sendMessage(getLocale(sender).get("general.errors.use-in-game"));
return true;
}
Player player = (Player)sender;
UUID playerUUID = player.getUniqueId();
if (!VaultHelper.hasPerm(player, Settings.PERMPREFIX + "island.sethome")) {
sender.sendMessage(ChatColor.RED + getLocale(sender).get("general.errors.no-permission"));
return true;
}
// Check island
if (plugin.getIslands().getIsland(player.getUniqueId()) == null) {
sender.sendMessage(ChatColor.RED + plugin.getLocale(playerUUID).get("general.errors.no-island"));
return true;
}
if (!plugin.getIslands().playerIsOnIsland(player)) {
sender.sendMessage(ChatColor.RED + plugin.getLocale(playerUUID).get("sethome.error.NotOnIsland"));
return true;
}
if (args.length == 0) {
// island sethome
plugin.getPlayers().setHomeLocation(playerUUID, player.getLocation());
sender.sendMessage(ChatColor.GREEN + plugin.getLocale(playerUUID).get("sethome.homeSet"));
} else if (args.length == 1) {
// Dynamic home sizes with permissions
int maxHomes = Util.getPermValue(player, Settings.PERMPREFIX + "island.maxhomes", Settings.maxHomes);
if (maxHomes > 1) {
// Check the number given is a number
int number = 0;
try {
number = Integer.valueOf(args[0]);
if (number < 1 || number > maxHomes) {
sender.sendMessage(ChatColor.RED + plugin.getLocale(playerUUID).get("sethome.error.NumHomes").replace("[max]",String.valueOf(maxHomes)));
} else {
plugin.getPlayers().setHomeLocation(playerUUID, player.getLocation(), number);
sender.sendMessage(ChatColor.GREEN + plugin.getLocale(playerUUID).get("sethome.homeSet"));
}
} catch (Exception e) {
sender.sendMessage(ChatColor.RED + plugin.getLocale(playerUUID).get("sethome.error.NumHomes").replace("[max]",String.valueOf(maxHomes)));
}
} else {
sender.sendMessage(ChatColor.RED + plugin.getLocale(playerUUID).get("general.errors.no-permission"));
}
}
return true;
}
@Override
public Set<String> tabComplete(CommandSender sender, String[] args) {
// TODO Auto-generated method stub
return null;
}
}

View File

@ -1,12 +1,24 @@
package us.tastybento.bskyblock.commands.island;
import org.bukkit.command.CommandSender;
import us.tastybento.bskyblock.api.commands.CommandArgument;
import java.util.Set;
import java.util.UUID;
import org.apache.commons.lang.math.NumberUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.permissions.PermissionAttachmentInfo;
import us.tastybento.bskyblock.api.commands.CommandArgument;
import us.tastybento.bskyblock.api.events.team.TeamEvent;
import us.tastybento.bskyblock.api.events.team.TeamEvent.TeamReason;
import us.tastybento.bskyblock.config.Settings;
import us.tastybento.bskyblock.util.VaultHelper;
public class IslandTeamCommand extends CommandArgument {
private static final boolean DEBUG = false;
public IslandTeamCommand() {
super("team");
this.addSubCommand(new IslandTeamInviteCommand());
@ -14,8 +26,70 @@ public class IslandTeamCommand extends CommandArgument {
@Override
public boolean execute(CommandSender sender, String[] args) {
sender.sendMessage("Hey, you've got a pretty team there :D");
return false;
if (!isPlayer(sender)) {
sender.sendMessage(getLocale(sender).get("general.errors.use-in-game"));
return true;
}
Player player = (Player)sender;
UUID playerUUID = player.getUniqueId();
if (!VaultHelper.hasPerm(player, Settings.PERMPREFIX + "team")) {
sender.sendMessage(ChatColor.RED + getLocale(sender).get("general.errors.no-permission"));
return true;
}
if (DEBUG)
plugin.getLogger().info("DEBUG: executing team command for " + playerUUID);
// Fire event so add-ons can run commands, etc.
TeamEvent event = TeamEvent.builder()
.island(getIslands()
.getIsland(playerUUID))
.reason(TeamReason.INFO)
.involvedPlayer(playerUUID)
.build();
plugin.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) return true;
UUID teamLeaderUUID = getTeamLeader(player);
Set<UUID> teamMembers = getMembers(player);
if (teamLeaderUUID.equals(playerUUID)) {
int maxSize = Settings.maxTeamSize;
for (PermissionAttachmentInfo perms : player.getEffectivePermissions()) {
if (perms.getPermission().startsWith(Settings.PERMPREFIX + "team.maxsize.")) {
if (perms.getPermission().contains(Settings.PERMPREFIX + "team.maxsize.*")) {
maxSize = Settings.maxTeamSize;
break;
} else {
// Get the max value should there be more than one
String[] spl = perms.getPermission().split(Settings.PERMPREFIX + "team.maxsize.");
if (spl.length > 1) {
if (!NumberUtils.isDigits(spl[1])) {
plugin.getLogger().severe("Player " + player.getName() + " has permission: " + perms.getPermission() + " <-- the last part MUST be a number! Ignoring...");
} else {
maxSize = Math.max(maxSize, Integer.valueOf(spl[1]));
}
}
}
}
// Do some sanity checking
if (maxSize < 1) maxSize = 1;
}
if (teamMembers.size() < maxSize) {
sender.sendMessage(getLocale(sender).get("invite.youCanInvite").replace("[number]", String.valueOf(maxSize - teamMembers.size())));
} else {
sender.sendMessage(ChatColor.RED + getLocale(sender).get("invite.error.YourIslandIsFull"));
}
}
sender.sendMessage(getLocale(sender).get("team.listingMembers"));
// Display members in the list
for (UUID m : teamMembers) {
if (DEBUG)
plugin.getLogger().info("DEBUG: member " + m);
if (teamLeaderUUID.equals(m)) {
sender.sendMessage(getLocale(sender).get("team.leader-color") + getPlayers().getName(m) + getLocale(sender).get("team.leader"));
} else {
sender.sendMessage(getLocale(sender).get("team.color") + getPlayers().getName(m));
}
}
return true;
}
@Override

View File

@ -1,11 +1,34 @@
package us.tastybento.bskyblock.commands.island;
import org.bukkit.command.CommandSender;
import us.tastybento.bskyblock.api.commands.CommandArgument;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import org.apache.commons.lang.math.NumberUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.permissions.PermissionAttachmentInfo;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import us.tastybento.bskyblock.api.commands.CommandArgument;
import us.tastybento.bskyblock.api.events.team.TeamEvent;
import us.tastybento.bskyblock.api.events.team.TeamEvent.TeamReason;
import us.tastybento.bskyblock.config.Settings;
import us.tastybento.bskyblock.util.Util;
import us.tastybento.bskyblock.util.VaultHelper;
public class IslandTeamInviteCommand extends CommandArgument {
/**
* Invite list - invited player name string (key), inviter name string
* (value)
*/
private final BiMap<UUID, UUID> inviteList = HashBiMap.create();
public IslandTeamInviteCommand() {
super("invite");
@ -13,12 +36,127 @@ public class IslandTeamInviteCommand extends CommandArgument {
@Override
public boolean execute(CommandSender sender, String[] args) {
sender.sendMessage("Wants to invite some people, hu?");
if (!isPlayer(sender)) {
sender.sendMessage(getLocale(sender).get("general.errors.use-in-game"));
return true;
}
Player player = (Player)sender;
UUID playerUUID = player.getUniqueId();
if (!VaultHelper.hasPerm(player, Settings.PERMPREFIX + "team")) {
sender.sendMessage(ChatColor.RED + getLocale(sender).get("general.errors.no-permission"));
return true;
}
// Player issuing the command must have an island
if (!getPlayers().hasIsland(playerUUID)) {
// If the player is in a team, they are not the leader
if (getPlayers().inTeam(playerUUID)) {
player.sendMessage(ChatColor.RED + getLocale(sender).get("general.errors.not-leader"));
}
player.sendMessage(ChatColor.RED + getLocale(sender).get("invite.error.YouMustHaveIslandToInvite"));
}
if (args.length == 0 || args.length > 1) {
// Invite label with no name, i.e., /island invite - tells the player who has invited them so far
//TODO
if (inviteList.containsKey(playerUUID)) {
OfflinePlayer inviter = plugin.getServer().getOfflinePlayer(inviteList.get(playerUUID));
player.sendMessage(ChatColor.GOLD + getLocale(sender).get("invite.nameHasInvitedYou").replace("[name]", inviter.getName()));
} else {
player.sendMessage(ChatColor.GOLD + getLocale(sender).get("help.island.invite"));
}
return true;
}
if (args.length == 1) {
// Only online players can be invited
UUID invitedPlayerUUID = getPlayers().getUUID(args[0]);
if (invitedPlayerUUID == null) {
player.sendMessage(ChatColor.RED + getLocale(sender).get("general.errors.offline-player"));
return true;
}
Player invitedPlayer = plugin.getServer().getPlayer(invitedPlayerUUID);
if (invitedPlayer == null) {
player.sendMessage(ChatColor.RED + getLocale(sender).get("general.errors.offline-player"));
return true;
}
// Player cannot invite themselves
if (playerUUID.equals(invitedPlayerUUID)) {
player.sendMessage(ChatColor.RED + getLocale(sender).get("invite.error.YouCannotInviteYourself"));
return true;
}
// Check if this player can be invited to this island, or
// whether they are still on cooldown
long time = getPlayers().getInviteCoolDownTime(invitedPlayerUUID, getIslands().getIslandLocation(playerUUID));
if (time > 0 && !player.isOp()) {
player.sendMessage(ChatColor.RED + getLocale(sender).get("invite.error.CoolDown").replace("[time]", String.valueOf(time)));
return true;
}
// Player cannot invite someone already on a team
if (getPlayers().inTeam(invitedPlayerUUID)) {
player.sendMessage(ChatColor.RED + getLocale(sender).get("invite.error.ThatPlayerIsAlreadyInATeam"));
return true;
}
Set<UUID> teamMembers = getMembers(player);
// Check if player has space on their team
int maxSize = Settings.maxTeamSize;
// Dynamic team sizes with permissions
for (PermissionAttachmentInfo perms : player.getEffectivePermissions()) {
if (perms.getPermission().startsWith(Settings.PERMPREFIX + "team.maxsize.")) {
if (perms.getPermission().contains(Settings.PERMPREFIX + "team.maxsize.*")) {
maxSize = Settings.maxTeamSize;
break;
} else {
// Get the max value should there be more than one
String[] spl = perms.getPermission().split(Settings.PERMPREFIX + "team.maxsize.");
if (spl.length > 1) {
if (!NumberUtils.isDigits(spl[1])) {
plugin.getLogger().severe("Player " + player.getName() + " has permission: " + perms.getPermission() + " <-- the last part MUST be a number! Ignoring...");
} else {
maxSize = Math.max(maxSize, Integer.valueOf(spl[1]));
}
}
}
}
// Do some sanity checking
if (maxSize < 1) maxSize = 1;
}
if (teamMembers.size() < maxSize) {
// If that player already has an invite out then retract it.
// Players can only have one invite one at a time - interesting
if (inviteList.containsValue(playerUUID)) {
inviteList.inverse().remove(playerUUID);
player.sendMessage(ChatColor.RED + getLocale(sender).get("invite.removingInvite"));
}
// Fire event so add-ons can run commands, etc.
TeamEvent event = TeamEvent.builder()
.island(getIslands().getIsland(playerUUID))
.reason(TeamReason.INVITE)
.involvedPlayer(invitedPlayerUUID)
.build();
plugin.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) return true;
// Put the invited player (key) onto the list with inviter (value)
// If someone else has invited a player, then this invite will overwrite the previous invite!
inviteList.put(invitedPlayerUUID, playerUUID);
player.sendMessage(getLocale(sender).get("invite.inviteSentTo").replace("[name]", args[0]));
// Send message to online player
Bukkit.getPlayer(invitedPlayerUUID).sendMessage(ChatColor.GOLD + getLocale(invitedPlayerUUID).get("invite.nameHasInvitedYou").replace("[name]", player.getName()));
Bukkit.getPlayer(invitedPlayerUUID).sendMessage(ChatColor.GOLD +
"/" + getLabel() + " [accept/reject]" + " " + getLocale(invitedPlayerUUID).get("invite.toAcceptOrReject"));
if (getPlayers().hasIsland(invitedPlayerUUID)) {
Bukkit.getPlayer(invitedPlayerUUID).sendMessage(ChatColor.RED + getLocale(invitedPlayerUUID).get("invite.warningYouWillLoseIsland"));
}
} else {
player.sendMessage(ChatColor.RED + getLocale(sender).get("invite.error.YourIslandIsFull"));
}
}
return false;
}
@Override
public Set<String> tabComplete(CommandSender sender, String[] args) {
return null;
if (args.length == 0 || !(sender instanceof Player)) {
// Don't show every player on the server. Require at least the first letter
return null;
}
return new HashSet<>(Util.getOnlinePlayerList((Player) sender));
}
}

View File

@ -1,4 +1,78 @@
package us.tastybento.bskyblock.commands.island;
public class IslandTeamUninviteCommand {
import java.util.Set;
import java.util.UUID;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
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.events.team.TeamEvent;
import us.tastybento.bskyblock.api.events.team.TeamEvent.TeamReason;
import us.tastybento.bskyblock.config.Settings;
import us.tastybento.bskyblock.util.VaultHelper;
public class IslandTeamUninviteCommand extends CommandArgument {
/**
* TODO: this actually needs to be the same as what is in the IslandTeamInvite class!
*/
private final BiMap<UUID, UUID> inviteList = HashBiMap.create();
public IslandTeamUninviteCommand() {
super("uninvite");
}
@Override
public boolean execute(CommandSender sender, String[] args) {
if (!isPlayer(sender)) {
sender.sendMessage(getLocale(sender).get("general.errors.use-in-game"));
return true;
}
Player player = (Player)sender;
UUID playerUUID = player.getUniqueId();
if (!VaultHelper.hasPerm(player, Settings.PERMPREFIX + "team")) {
sender.sendMessage(ChatColor.RED + getLocale(sender).get("general.errors.no-permission"));
return true;
}
// Get the invite list
// TODO
// Can only use if you have an invite out there
if(!inviteList.inverse().containsKey(playerUUID)) {
return true;
}
// Fire event so add-ons can run commands, etc.
TeamEvent event = TeamEvent.builder()
.island(getIslands()
.getIsland(playerUUID))
.reason(TeamReason.UNINVITE)
.involvedPlayer(playerUUID)
.build();
plugin.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) return true;
if (inviteList.inverse().containsKey(playerUUID)) {
Player invitee = plugin.getServer().getPlayer(inviteList.inverse().get(playerUUID));
if (invitee != null) {
inviteList.inverse().remove(playerUUID);
invitee.sendMessage(ChatColor.RED + getLocale(invitee.getUniqueId()).get("invite.nameHasUninvitedYou").replace("[name]", player.getName()));
player.sendMessage(ChatColor.GREEN + getLocale(sender).get("general.success"));
}
} else {
player.sendMessage(ChatColor.YELLOW + getLocale(sender).get("help.island.invite"));
}
return false;
}
@Override
public Set<String> tabComplete(CommandSender sender, String[] args) {
// TODO Auto-generated method stub
return null;
}
}