Added team admin commands.

Still need to add tab complete. Not completely tested so there may be
bugs.
This commit is contained in:
tastybento 2017-08-27 16:17:45 -07:00
parent fe6159e87b
commit c565d5edf8
4 changed files with 351 additions and 60 deletions

View File

@ -17,11 +17,20 @@ general:
no-team: "You do not have a team!"
no-island: "You do not have an island!"
already-have-island: "You already have an island!"
no-safe-location: "No safe location found on island!"
not-leader: "You are not the leader of your island!"
offline-player: "That player is offline or doesn't exist."
unknown-player: "Unknown player!"
help:
admin:
team:
command: "info/makeleader/add/kick/delete - admin teams"
info: "info <player> - show info player's team"
makeleader: "makeleader <player> - make player the leader of a team"
add: "add <player1> <player2> - add player1 to player2's team"
kick: "kick <player> - remove player from team"
delete: "delete <player> - kicks all players from team leaving just the leader"
header: "&7=========== BSKYBLOCK ==========="
syntax: " &7/&b[label] &c[command] &a[args] &7: &e[info]"
syntax-alias-separator: "/"
@ -67,7 +76,16 @@ acidLore: |
Do
not drink!
Beware!
admin:
errors:
no-team: "Player does not have a team!"
no-island: "Player does not have an island!"
already-have-island: "Player already has an island!"
team:
error:
already-a-leader: "Player is already a leader"
alreadyInTeam: "Those players are already in the same team!"
player-is-a-team-leader: "Error: player is team leader."
adminDeleteIsland:
error: "Use &ldeleteisland confirm &r&cto delete the island you are on."
noid: "Cannot identify island."
@ -460,8 +478,8 @@ kick:
onlyLeaderCan: "Only the leader can kick people off the island!"
playerNotInTeam: "That player is not in your team!"
youCannotKickYourself: "You cannot kick yourself!"
nameRemoved: "[name] removed from the island."
nameRemovedYou: "[name] removed you from their island!"
nameRemoved: "[name] removed from the team."
nameRemovedYou: "[name] removed you from the team!"
warning: "Are you sure you want to kick the player? Type the command again to confirm."
lavaTip: "Tip: If obsidian was not intended, it can be scooped back up again with a bucket."
leave:
@ -492,8 +510,8 @@ makeleader:
errorRemoveAllPlayersFirst: "Remove all players from your team other than the player you are transferring to."
errorThatPlayerIsNotInTeam: "That player is not part of your island team!"
errorYouMustBeInTeam: "You must be in a team to transfer your island."
nameIsNowTheOwner: "[name] is now the owner of your island!"
youAreNowTheOwner: "You are now the owner of your island."
nameIsNowTheOwner: "[name] is now the island leader!"
youAreNowTheOwner: "You are now the island leader!"
minishop:
buy: "Buy(Left click)"
buyproblem: "There was a problem purchasing [description]"
@ -573,7 +591,7 @@ team:
color: "&b"
leader-color: "&a"
leader: " - Leader"
listingMembers: "Listing your island members"
listingMembers: "Listing island members"
teamchat:
helpChat: "turn on/off team chat"
noTeam: "You are not in a team!"

View File

@ -1,17 +1,33 @@
package us.tastybento.bskyblock.commands;
import java.util.Set;
import java.util.UUID;
import org.apache.commons.lang.math.NumberUtils;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.permissions.PermissionAttachmentInfo;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.api.commands.AbstractCommand;
import us.tastybento.bskyblock.api.events.team.PlayerAcceptInviteEvent;
import us.tastybento.bskyblock.config.Settings;
import us.tastybento.bskyblock.database.objects.Island;
import us.tastybento.bskyblock.util.Util;
import us.tastybento.bskyblock.util.VaultHelper;
public class AdminCommand extends AbstractCommand {
protected static final boolean DEBUG = false;
BSkyBlock plugin;
/**
* Handles admin commands
* @param plugin
*/
public AdminCommand(BSkyBlock plugin) {
super(plugin, Settings.ADMINCOMMAND, new String[0], true);
plugin.getCommand(Settings.ADMINCOMMAND).setExecutor(this);
@ -45,6 +61,259 @@ public class AdminCommand extends AbstractCommand {
}
});
/* /asadmin team - manage teams */
addArgument(new String[] {"team"}, new ArgumentHandler() {
@Override
public CanUseResp canUse(CommandSender sender) {
return new CanUseResp(!(sender instanceof Player)
|| VaultHelper.hasPerm(player, Settings.PERMPREFIX + "admin.team"));
}
@Override
public void execute(CommandSender sender, String[] args) {
/*
* Commands are:
* team info <player> - lists info on the player's team
* team add <player1> <player2> - adds player1 to player2's team. If player1 has an island, the island will become unowned.
* team kick <player> - removes player from the team.
* team makeleader <player> - makes the player the team leader. The old leader will become a team member.
* team delete <player> - kicks all the players from the team player is in. The leader remains as the island owner.
*
* Note that you do not have to specify the team leader.
*
*
*/
if (args.length == 2) {
// see if arg 1 is a player
UUID targetPlayer = getPlayers().getUUID(args[1]);
if (targetPlayer == null) {
Util.sendMessage(sender, ChatColor.RED + getLocale(playerUUID).get("general.errors.unknown-player"));
return;
}
// Check if player is in a team
if (!getPlayers().inTeam(targetPlayer)) {
Util.sendMessage(sender, ChatColor.RED + getLocale(playerUUID).get("general.errors.no-team"));
return;
}
switch (args[0].toLowerCase()) {
case "info":
Util.sendMessage(sender, getLocale(sender).get("team.listingMembers"));
// Display members in the list
for (UUID m : getIslands().getMembers(targetPlayer)) {
if (DEBUG)
plugin.getLogger().info("DEBUG: member " + m);
if (getIslands().getTeamLeader(targetPlayer).equals(m)) {
Util.sendMessage(sender, getLocale(sender).get("team.leader-color") + getPlayers().getName(m) + getLocale(sender).get("team.leader"));
} else {
Util.sendMessage(sender, getLocale(sender).get("team.color") + getPlayers().getName(m));
}
}
return;
case "makeleader":
// Check if already leader
if (getIslands().getTeamLeader(targetPlayer).equals(targetPlayer)) {
Util.sendMessage(sender, ChatColor.RED + "'" + args[1] + "' - " + getLocale(playerUUID).get("admin.team.error.already-a-leader"));
return;
}
getIslands().getIsland(targetPlayer).setOwner(targetPlayer);
Util.sendMessage(sender, ChatColor.GREEN
+ getLocale(sender).get("makeleader.nameIsNowTheOwner").replace("[name]", getPlayers().getName(targetPlayer)));
// Check if online
Player target = plugin.getServer().getPlayer(targetPlayer);
if (target == null) {
// TODO offline messaging
//plugin.getMessages().setMessage(targetPlayer, getLocale(playerUUID).get("makeleader.youAreNowTheOwner"));
} else {
// Online
Util.sendMessage(plugin.getServer().getPlayer(targetPlayer), ChatColor.GREEN + getLocale(targetPlayer).get("makeleader.youAreNowTheOwner"));
// Check if new leader has a lower range permission than the island size
boolean hasARangePerm = false;
int range = Settings.islandProtectionRange;
// Check for zero protection range
Island islandByOwner = getIslands().getIsland(targetPlayer);
if (islandByOwner.getProtectionRange() == 0) {
plugin.getLogger().warning("Player " + player.getName() + "'s island had a protection range of 0. Setting to default " + range);
islandByOwner.setProtectionRange(range);
}
for (PermissionAttachmentInfo perms : target.getEffectivePermissions()) {
if (perms.getPermission().startsWith(Settings.PERMPREFIX + "island.range.")) {
if (perms.getPermission().contains(Settings.PERMPREFIX + "island.range.*")) {
// Ignore
break;
} else {
String[] spl = perms.getPermission().split(Settings.PERMPREFIX + "island.range.");
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 {
hasARangePerm = true;
range = Math.max(range, Integer.valueOf(spl[1]));
}
}
}
}
}
// Only set the island range if the player has a perm to override the default
if (hasARangePerm) {
// Do some sanity checking
if (range % 2 != 0) {
range--;
}
// Get island range
// Range can go up or down
if (range != islandByOwner.getProtectionRange()) {
Util.sendMessage(sender, getLocale(targetPlayer).get("admin.SetRangeUpdated").replace("[number]", String.valueOf(range)));
Util.sendMessage(target, getLocale(targetPlayer).get("admin.SetRangeUpdated").replace("[number]", String.valueOf(range)));
plugin.getLogger().info(
"Makeleader: Island protection range changed from " + islandByOwner.getProtectionRange() + " to "
+ range + " for " + player.getName() + " due to permission.");
}
islandByOwner.setProtectionRange(range);
}
}
getIslands().save(true);
return;
case "kick":
if (getIslands().getTeamLeader(targetPlayer).equals(targetPlayer)) {
Util.sendMessage(sender, ChatColor.RED + "'" + args[1] + "' - " + getLocale(playerUUID).get("admin.team.error.player-is-a-team-leader"));
return;
}
// Remove from team
getIslands().setLeaveTeam(targetPlayer);
// Tell the player they kicked okay
Util.sendMessage(sender, ChatColor.GREEN + getLocale(sender).get("kick.nameRemoved").replace("[name]", getPlayers().getName(targetPlayer)));
// Tell the target if they are online
if (plugin.getServer().getPlayer(targetPlayer) != null) {
Player t = plugin.getServer().getPlayer(targetPlayer);
Util.sendMessage(t, ChatColor.RED + getLocale(targetPlayer).get("kick.nameRemovedYou").replace("[name]", player.getName()));
} else {
// TODO: Leave them an offline message
}
getIslands().save(true);
return;
case "delete":
UUID teamLeader = getIslands().getTeamLeader(targetPlayer);
for (UUID m : getIslands().getMembers(targetPlayer)) {
if (DEBUG)
plugin.getLogger().info("DEBUG: member " + m);
//Only the team leader gets to stay
if (!teamLeader.equals(m)) {
getIslands().setLeaveTeam(targetPlayer);
} else {
// Tell the player they kicked okay
Util.sendMessage(sender, ChatColor.GREEN + getLocale(sender).get("kick.nameRemoved").replace("[name]", getPlayers().getName(targetPlayer)));
// Tell the target if they are online
if (plugin.getServer().getPlayer(targetPlayer) != null) {
Player t = plugin.getServer().getPlayer(targetPlayer);
Util.sendMessage(t, ChatColor.RED + getLocale(targetPlayer).get("kick.nameRemovedYou").replace("[name]", player.getName()));
} else {
// TODO: Leave them an offline message
}
}
}
Util.sendMessage(sender, ChatColor.GREEN + getLocale(sender).get("general.success"));
getIslands().save(true);
return;
}
}
else if (args.length == 3) {
if (args[0].equalsIgnoreCase("add")) {
UUID targetPlayer = getPlayers().getUUID(args[1]);
if (targetPlayer == null) {
Util.sendMessage(sender, ChatColor.RED + "'" + args[1] + "' - " + getLocale(playerUUID).get("general.errors.unknown-player"));
return;
}
UUID targetPlayer2 = getPlayers().getUUID(args[2]);
if (targetPlayer2 == null) {
Util.sendMessage(sender, ChatColor.RED + "'" + args[2] + "' - " + getLocale(playerUUID).get("general.errors.unknown-player"));
return;
}
// Check if player2 has an island, if not, error
if (!getIslands().hasIsland(targetPlayer2)) {
Util.sendMessage(sender, ChatColor.RED + "'" + args[2] + "' - " + getLocale(playerUUID).get("admin.error.no-island"));
return;
}
// If player1 and 2 are already on the same team, error
if (getIslands().getMembers(targetPlayer2).contains(targetPlayer)) {
Util.sendMessage(sender, ChatColor.RED + getLocale(playerUUID).get("admin.team.error.alreadyInTeam"));
return;
}
// If player1 is in a team and the leader, error
if (getPlayers().inTeam(targetPlayer) && getIslands().getTeamLeader(targetPlayer).equals(targetPlayer)) {
Util.sendMessage(sender, ChatColor.RED + "'" + args[1] + "' - " + getLocale(playerUUID).get("admin.team.error.player-is-a-team-leader"));
return;
}
// Get the team's island
Island teamIsland = getIslands().getIsland(targetPlayer2);
// Move player to team's island
Location newHome = getIslands().getSafeHomeLocation(targetPlayer2, 1);
if (newHome != null) {
// A safe location could not be found...
getPlayers().setHomeLocation(targetPlayer, teamIsland.getCenter());
Util.sendMessage(sender, ChatColor.RED + getLocale(sender).get("general.errors.no-safe-location"));
} else {
// Set the player's home
getPlayers().setHomeLocation(targetPlayer, newHome);
}
// Check if player1 is online or not
Player player1 = plugin.getServer().getPlayer(targetPlayer);
if (player1 != null) {
// Put player into Spectator mode
player1.setGameMode(GameMode.SPECTATOR);
if (newHome != null)
player1.teleport(newHome);
// Put player back into normal mode
player1.setGameMode(GameMode.SURVIVAL);
Util.sendMessage(player1, ChatColor.GREEN + getLocale(sender).get("invite.youHaveJoinedAnIsland").replace("[label]", Settings.ISLANDCOMMAND));
}
// Remove player from any islands
getIslands().removePlayer(targetPlayer);
// Add the player as a team member of the new island
getIslands().setJoinTeam(teamIsland, targetPlayer);
// Reset deaths
if (Settings.teamJoinDeathReset) {
getPlayers().setDeaths(targetPlayer, 0);
}
// Tell island members
for (UUID member: teamIsland.getMembers()) {
// If online tell them
if (!member.equals(targetPlayer) && plugin.getServer().getPlayer(member) != null) {
Util.sendMessage(plugin.getServer().getPlayer(member),
ChatColor.GREEN + getLocale(sender).get("invite.hasJoinedYourIsland").replace("[name]", player.getName()));
}
}
getIslands().save(false);
if (DEBUG)
plugin.getLogger().info("DEBUG: After save " + getIslands().getIsland(targetPlayer2).getMembers().toString());
Util.sendMessage(sender, ChatColor.GREEN + getLocale(sender).get("general.success"));
return;
}
}
// Wrong command syntax or arguments, show help
Util.sendMessage(sender, plugin.getLocale(sender).get("help.admin.team.command"));
Util.sendMessage(sender, plugin.getLocale(sender).get("help.admin.team.info"));
Util.sendMessage(sender, plugin.getLocale(sender).get("help.admin.team.makeleader"));
Util.sendMessage(sender, plugin.getLocale(sender).get("help.admin.team.add"));
Util.sendMessage(sender, plugin.getLocale(sender).get("help.admin.team.kick"));
Util.sendMessage(sender, plugin.getLocale(sender).get("help.admin.team.delete"));
}
@Override
public Set<String> tabComplete(CommandSender sender, String[] args) {
return null;
}
@Override
public String[] usage(CommandSender sender){
return new String[] {null, plugin.getLocale(sender).get("help.admin.team.command")};
}
});
}
@Override
@ -54,7 +323,7 @@ public class AdminCommand extends AbstractCommand {
@Override
public void execute(CommandSender sender, String[] args) {
// TODO: Show help...
}

View File

@ -531,15 +531,15 @@ public class IslandCommand extends AbstractCommand {
@Override
public CanUseResp canUse(CommandSender sender) {
if (!VaultHelper.hasPerm(player, Settings.PERMPREFIX + "team")) {
return new CanUseResp(getLocale(sender).get("general.errors.no-permission"));
return new CanUseResp(ChatColor.RED + getLocale(sender).get("general.errors.no-permission"));
}
// 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)) {
return new CanUseResp(getLocale(sender).get("general.errors.not-leader"));
return new CanUseResp(ChatColor.RED + getLocale(sender).get("general.errors.not-leader"));
}
return new CanUseResp(getLocale(sender).get("invite.error.YouMustHaveIslandToInvite"));
return new CanUseResp(ChatColor.RED + getLocale(sender).get("invite.error.YouMustHaveIslandToInvite"));
}
return new CanUseResp(true);
}
@ -551,9 +551,9 @@ public class IslandCommand extends AbstractCommand {
//TODO
if (inviteList.containsKey(playerUUID)) {
OfflinePlayer inviter = plugin.getServer().getOfflinePlayer(inviteList.get(playerUUID));
Util.sendMessage(player, getLocale(sender).get("invite.nameHasInvitedYou").replace("[name]", inviter.getName()));
Util.sendMessage(player, ChatColor.GOLD + getLocale(sender).get("invite.nameHasInvitedYou").replace("[name]", inviter.getName()));
} else {
Util.sendMessage(player, getLocale(sender).get("help.island.invite"));
Util.sendMessage(player, ChatColor.GOLD + getLocale(sender).get("help.island.invite"));
}
return;
}
@ -561,29 +561,29 @@ public class IslandCommand extends AbstractCommand {
// Only online players can be invited
UUID invitedPlayerUUID = getPlayers().getUUID(args[0]);
if (invitedPlayerUUID == null) {
Util.sendMessage(player, getLocale(sender).get("general.errors.offline-player"));
Util.sendMessage(player, ChatColor.RED + getLocale(sender).get("general.errors.offline-player"));
return;
}
Player invitedPlayer = plugin.getServer().getPlayer(invitedPlayerUUID);
if (invitedPlayer == null) {
Util.sendMessage(player, getLocale(sender).get("general.errors.offline-player"));
Util.sendMessage(player, ChatColor.RED + getLocale(sender).get("general.errors.offline-player"));
return;
}
// Player cannot invite themselves
if (playerUUID.equals(invitedPlayerUUID)) {
Util.sendMessage(player, getLocale(sender).get("invite.error.YouCannotInviteYourself"));
Util.sendMessage(player, ChatColor.RED + getLocale(sender).get("invite.error.YouCannotInviteYourself"));
return;
}
// 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()) {
Util.sendMessage(player, getLocale(sender).get("invite.error.CoolDown").replace("[time]", String.valueOf(time)));
Util.sendMessage(player, ChatColor.RED + getLocale(sender).get("invite.error.CoolDown").replace("[time]", String.valueOf(time)));
return;
}
// Player cannot invite someone already on a team
if (getPlayers().inTeam(invitedPlayerUUID)) {
Util.sendMessage(player, getLocale(sender).get("invite.error.ThatPlayerIsAlreadyInATeam"));
Util.sendMessage(player, ChatColor.RED + getLocale(sender).get("invite.error.ThatPlayerIsAlreadyInATeam"));
return;
}
// Check if player has space on their team
@ -614,21 +614,21 @@ public class IslandCommand extends AbstractCommand {
// Players can only have one invite one at a time - interesting
if (inviteList.containsValue(playerUUID)) {
inviteList.inverse().remove(playerUUID);
Util.sendMessage(player, getLocale(sender).get("invite.removingInvite"));
Util.sendMessage(player, ChatColor.RED + getLocale(sender).get("invite.removingInvite"));
}
// 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);
Util.sendMessage(player, getLocale(sender).get("invite.inviteSentTo").replace("[name]", args[0]));
// Send message to online player
Util.sendMessage(Bukkit.getPlayer(invitedPlayerUUID), getLocale(invitedPlayerUUID).get("invite.nameHasInvitedYou").replace("[name]", player.getName()));
Util.sendMessage(Bukkit.getPlayer(invitedPlayerUUID),
Util.sendMessage(Bukkit.getPlayer(invitedPlayerUUID), ChatColor.GOLD + getLocale(invitedPlayerUUID).get("invite.nameHasInvitedYou").replace("[name]", player.getName()));
Util.sendMessage(Bukkit.getPlayer(invitedPlayerUUID),ChatColor.GOLD +
"/" + label + " [accept/reject]" + " " + getLocale(invitedPlayerUUID).get("invite.toAcceptOrReject"));
if (getPlayers().hasIsland(invitedPlayerUUID)) {
Util.sendMessage(Bukkit.getPlayer(invitedPlayerUUID), getLocale(invitedPlayerUUID).get("invite.warningYouWillLoseIsland"));
Util.sendMessage(Bukkit.getPlayer(invitedPlayerUUID), ChatColor.RED + getLocale(invitedPlayerUUID).get("invite.warningYouWillLoseIsland"));
}
} else {
Util.sendMessage(player, getLocale(sender).get("invite.error.YourIslandIsFull"));
Util.sendMessage(player, ChatColor.RED + getLocale(sender).get("invite.error.YourIslandIsFull"));
}
}
}
@ -654,7 +654,7 @@ public class IslandCommand extends AbstractCommand {
@Override
public CanUseResp canUse(CommandSender sender) {
if (!VaultHelper.hasPerm(player, Settings.PERMPREFIX + "team")) {
return new CanUseResp(getLocale(sender).get("general.errors.no-permission"));
return new CanUseResp(ChatColor.RED + getLocale(sender).get("general.errors.no-permission"));
}
// Can only use if you have an invite out there
return new CanUseResp(inviteList.inverse().containsKey(playerUUID));
@ -667,11 +667,11 @@ public class IslandCommand extends AbstractCommand {
Player invitee = plugin.getServer().getPlayer(inviteList.inverse().get(playerUUID));
if (invitee != null) {
inviteList.inverse().remove(playerUUID);
Util.sendMessage(invitee, getLocale(invitee.getUniqueId()).get("invite.nameHasUninvitedYou").replace("[name]", player.getName()));
Util.sendMessage(player, getLocale(sender).get("general.success"));
Util.sendMessage(invitee, ChatColor.RED + getLocale(invitee.getUniqueId()).get("invite.nameHasUninvitedYou").replace("[name]", player.getName()));
Util.sendMessage(player, ChatColor.GREEN + getLocale(sender).get("general.success"));
}
} else {
Util.sendMessage(player, getLocale(sender).get("help.island.invite"));
Util.sendMessage(player, ChatColor.YELLOW + getLocale(sender).get("help.island.invite"));
}
}
@ -692,7 +692,7 @@ public class IslandCommand extends AbstractCommand {
@Override
public CanUseResp canUse(CommandSender sender) {
if (!VaultHelper.hasPerm(player, Settings.PERMPREFIX + "team")) {
return new CanUseResp(getLocale(sender).get("general.errors.no-permission"));
return new CanUseResp(ChatColor.RED + getLocale(sender).get("general.errors.no-permission"));
}
// Can only leave if you are not the leader
return new CanUseResp(inTeam && !teamLeaderUUID.equals(playerUUID));
@ -704,19 +704,19 @@ public class IslandCommand extends AbstractCommand {
if (getPlayers().inTeam(playerUUID)) {
// Team leaders cannot leave
if (teamLeaderUUID != null && teamLeaderUUID.equals(playerUUID)) {
Util.sendMessage(player, getLocale(sender).get("leave.errorYouAreTheLeader"));
Util.sendMessage(player, ChatColor.RED + getLocale(sender).get("leave.errorYouAreTheLeader"));
return;
}
// Check for confirmation
if (Settings.leaveConfirmation && !leavingPlayers.contains(playerUUID)) {
leavingPlayers.add(playerUUID);
Util.sendMessage(player, getLocale(sender).get("leave.warning"));
Util.sendMessage(player, ChatColor.GOLD + getLocale(sender).get("leave.warning"));
plugin.getServer().getScheduler().runTaskLater(plugin, () -> {
// If the player is still on the list, remove them and cancel the leave
if (leavingPlayers.contains(playerUUID)) {
leavingPlayers.remove(playerUUID);
Util.sendMessage(player, getLocale(sender).get("leave.canceled"));
Util.sendMessage(player, ChatColor.RED + getLocale(sender).get("leave.canceled"));
}
}, Settings.leaveConfirmWait * 20L);
@ -734,11 +734,11 @@ public class IslandCommand extends AbstractCommand {
// cannot join again before the cool down ends
getPlayers().startInviteCoolDownTimer(playerUUID, getIslands().getIslandLocation(teamLeaderUUID));
Util.sendMessage(player, getLocale(sender).get("leave.youHaveLeftTheIsland"));
Util.sendMessage(player, ChatColor.GREEN + getLocale(sender).get("leave.youHaveLeftTheIsland"));
// Tell the leader if they are online
if (plugin.getServer().getPlayer(teamLeaderUUID) != null) {
Player leader = plugin.getServer().getPlayer(teamLeaderUUID);
Util.sendMessage(leader, getLocale(teamLeaderUUID).get("leave.nameHasLeftYourIsland").replace("[name]", player.getName()));
Util.sendMessage(leader, ChatColor.RED + getLocale(teamLeaderUUID).get("leave.nameHasLeftYourIsland").replace("[name]", player.getName()));
} else {
// TODO: Leave them a message
//plugin.getMessages().setMessage(teamLeader, plugin.myLocale(teamLeader).leavenameHasLeftYourIsland.replace("[name]", player.getName()));
@ -750,10 +750,10 @@ public class IslandCommand extends AbstractCommand {
player.teleport(player.getWorld().getSpawnLocation());
}
} else {
Util.sendMessage(player, getLocale(sender).get("leave.errorYouCannotLeaveIsland"));
Util.sendMessage(player, ChatColor.RED + getLocale(sender).get("leave.errorYouCannotLeaveIsland"));
}
} else {
Util.sendMessage(player, getLocale(sender).get("leave.errorYouMustBeInWorld"));
Util.sendMessage(player, ChatColor.RED + getLocale(sender).get("leave.errorYouMustBeInWorld"));
}
}
@ -774,7 +774,7 @@ public class IslandCommand extends AbstractCommand {
@Override
public CanUseResp canUse(CommandSender sender) {
if (!VaultHelper.hasPerm(player, Settings.PERMPREFIX + "team")) {
return new CanUseResp(getLocale(sender).get("general.errors.no-permission"));
return new CanUseResp(ChatColor.RED + getLocale(sender).get("general.errors.no-permission"));
}
return new CanUseResp(inTeam && teamLeaderUUID.equals(playerUUID));
@ -789,24 +789,24 @@ public class IslandCommand extends AbstractCommand {
// Only team members can be kicked
UUID targetPlayerUUID = getPlayers().getUUID(args[0]);
if (targetPlayerUUID == null || !getIslands().getMembers(playerUUID).contains(targetPlayerUUID)) {
Util.sendMessage(player, getLocale(sender).get("kick.error.notPartOfTeam"));
Util.sendMessage(player, ChatColor.RED + getLocale(sender).get("kick.error.notPartOfTeam"));
return;
}
// Player cannot kick themselves
if (playerUUID.equals(targetPlayerUUID)) {
Util.sendMessage(player, getLocale(sender).get("kick.error.youCannotKickYourself"));
Util.sendMessage(player, ChatColor.RED + getLocale(sender).get("kick.error.youCannotKickYourself"));
return;
}
// Check for confirmation
if (Settings.confirmKick && !kickingPlayers.contains(playerUUID)) {
kickingPlayers.add(playerUUID);
Util.sendMessage(player, getLocale(sender).get("kick.warning"));
Util.sendMessage(player, ChatColor.GOLD + getLocale(sender).get("kick.warning"));
plugin.getServer().getScheduler().runTaskLater(plugin, () -> {
// If the player is still on the list, remove them and cancel the leave
if (kickingPlayers.contains(playerUUID)) {
kickingPlayers.remove(playerUUID);
Util.sendMessage(player, getLocale(sender).get("kick.canceled"));
Util.sendMessage(player, ChatColor.RED + getLocale(sender).get("kick.canceled"));
}
}, Settings.confirmKickWait * 20L);
@ -823,11 +823,11 @@ public class IslandCommand extends AbstractCommand {
// cannot join again before the cool down ends
getPlayers().startInviteCoolDownTimer(targetPlayerUUID, getIslands().getIslandLocation(teamLeaderUUID));
// Tell the player they kicked okay
Util.sendMessage(player, getLocale(sender).get("kick.nameRemoved").replace("[name]", getPlayers().getName(targetPlayerUUID)));
Util.sendMessage(player, ChatColor.GREEN + getLocale(sender).get("kick.nameRemoved").replace("[name]", getPlayers().getName(targetPlayerUUID)));
// Tell the target if they are online
if (plugin.getServer().getPlayer(targetPlayerUUID) != null) {
Player target = plugin.getServer().getPlayer(targetPlayerUUID);
Util.sendMessage(target, getLocale(targetPlayerUUID).get("kick.nameRemovedYou").replace("[name]", player.getName()));
Util.sendMessage(target, ChatColor.RED + getLocale(targetPlayerUUID).get("kick.nameRemovedYou").replace("[name]", player.getName()));
} else {
// TODO: Leave them an offline message
}
@ -866,18 +866,18 @@ public class IslandCommand extends AbstractCommand {
public void execute(CommandSender sender, String[] args) {
// Check if player has been invited
if (!inviteList.containsKey(playerUUID)) {
Util.sendMessage(player, getLocale(sender).get("invite.error.NoOneInvitedYou"));
Util.sendMessage(player, ChatColor.RED + getLocale(sender).get("invite.error.NoOneInvitedYou"));
return;
}
// Check if player is already in a team
if (getPlayers().inTeam(playerUUID)) {
Util.sendMessage(player, getLocale(sender).get("invite.error.YouAreAlreadyOnATeam"));
Util.sendMessage(player, ChatColor.RED + getLocale(sender).get("invite.error.YouAreAlreadyOnATeam"));
return;
}
// Get the team leader
UUID prospectiveTeamLeaderUUID = inviteList.get(playerUUID);
if (!getIslands().hasIsland(prospectiveTeamLeaderUUID)) {
Util.sendMessage(player, getLocale(sender).get("invite.error.InvalidInvite"));
Util.sendMessage(player, ChatColor.RED + getLocale(sender).get("invite.error.InvalidInvite"));
inviteList.remove(playerUUID);
return;
}
@ -917,11 +917,11 @@ public class IslandCommand extends AbstractCommand {
// Fire event so add-ons can run commands, etc.
plugin.getServer().getPluginManager().callEvent(new PlayerAcceptInviteEvent(player));
Util.sendMessage(player, getLocale(sender).get("invite.youHaveJoinedAnIsland").replace("[label]", Settings.ISLANDCOMMAND));
Util.sendMessage(player, ChatColor.GREEN + getLocale(sender).get("invite.youHaveJoinedAnIsland").replace("[label]", Settings.ISLANDCOMMAND));
if (plugin.getServer().getPlayer(inviteList.get(playerUUID)) != null) {
Util.sendMessage(plugin.getServer().getPlayer(inviteList.get(playerUUID)),
getLocale(sender).get("invite.hasJoinedYourIsland").replace("[name]", player.getName()));
ChatColor.GREEN + getLocale(sender).get("invite.hasJoinedYourIsland").replace("[name]", player.getName()));
}
getIslands().save(false);
if (DEBUG)
@ -945,7 +945,7 @@ public class IslandCommand extends AbstractCommand {
@Override
public CanUseResp canUse(CommandSender sender) {
if (!VaultHelper.hasPerm(player, Settings.PERMPREFIX + "team")) {
return new CanUseResp(getLocale(sender).get("general.errors.no-permission"));
return new CanUseResp(ChatColor.RED + getLocale(sender).get("general.errors.no-permission"));
}
// Can use if invited
return new CanUseResp(inviteList.containsKey(player.getUniqueId()));
@ -955,18 +955,18 @@ public class IslandCommand extends AbstractCommand {
public void execute(CommandSender sender, String[] args) {
// Reject /island reject
if (inviteList.containsKey(player.getUniqueId())) {
Util.sendMessage(player, getLocale(playerUUID).get("reject.youHaveRejectedInvitation"));
Util.sendMessage(player, ChatColor.GREEN + getLocale(playerUUID).get("reject.youHaveRejectedInvitation"));
// If the player is online still then tell them directly
// about the rejection
if (Bukkit.getPlayer(inviteList.get(player.getUniqueId())) != null) {
Util.sendMessage(Bukkit.getPlayer(inviteList.get(playerUUID)),
getLocale(playerUUID).get("reject.nameHasRejectedInvite").replace("[name]", player.getName()));
ChatColor.RED + getLocale(playerUUID).get("reject.nameHasRejectedInvite").replace("[name]", player.getName()));
}
// Remove this player from the global invite list
inviteList.remove(player.getUniqueId());
} else {
// Someone typed /island reject and had not been invited
Util.sendMessage(player, getLocale(playerUUID).get("reject.youHaveNotBeenInvited"));
Util.sendMessage(player, ChatColor.RED + getLocale(playerUUID).get("reject.youHaveNotBeenInvited"));
}
}
@ -987,7 +987,7 @@ public class IslandCommand extends AbstractCommand {
@Override
public CanUseResp canUse(CommandSender sender) {
if (!VaultHelper.hasPerm(player, Settings.PERMPREFIX + "team")) {
return new CanUseResp(getLocale(sender).get("general.errors.no-permission"));
return new CanUseResp(ChatColor.RED + getLocale(sender).get("general.errors.no-permission"));
}
// Can use if in a team
return new CanUseResp(inTeam && teamLeaderUUID.equals(playerUUID));
@ -998,23 +998,23 @@ public class IslandCommand extends AbstractCommand {
plugin.getLogger().info("DEBUG: arg[0] = " + args[0]);
UUID targetPlayer = getPlayers().getUUID(args[0]);
if (targetPlayer == null) {
Util.sendMessage(player, getLocale(playerUUID).get("general.errors.unknown-player"));
Util.sendMessage(player, ChatColor.RED + getLocale(playerUUID).get("general.errors.unknown-player"));
return;
}
if (!getPlayers().inTeam(playerUUID)) {
Util.sendMessage(player, getLocale(playerUUID).get("makeleader.errorYouMustBeInTeam"));
Util.sendMessage(player, ChatColor.RED + getLocale(playerUUID).get("makeleader.errorYouMustBeInTeam"));
return;
}
if (!teamLeaderUUID.equals(playerUUID)) {
Util.sendMessage(player, getLocale(playerUUID).get("makeleader.errorNotYourIsland"));
Util.sendMessage(player, ChatColor.RED + getLocale(playerUUID).get("makeleader.errorNotYourIsland"));
return;
}
if (targetPlayer.equals(playerUUID)) {
Util.sendMessage(player, getLocale(playerUUID).get("makeleader.errorGeneralError"));
Util.sendMessage(player, ChatColor.RED + getLocale(playerUUID).get("makeleader.errorGeneralError"));
return;
}
if (!teamMembers.contains(targetPlayer)) {
Util.sendMessage(player, getLocale(playerUUID).get("makeleader.errorThatPlayerIsNotInTeam"));
Util.sendMessage(player, ChatColor.RED + getLocale(playerUUID).get("makeleader.errorThatPlayerIsNotInTeam"));
return;
}
// targetPlayer is the new leader
@ -1026,11 +1026,11 @@ public class IslandCommand extends AbstractCommand {
Player target = plugin.getServer().getPlayer(targetPlayer);
if (target == null) {
// TODO offline messaging
//plugin.getMessages().setMessage(targetPlayer, getLocale(playerUUID).get("makeLeader.youAreNowTheOwner"));
//plugin.getMessages().setMessage(targetPlayer, getLocale(playerUUID).get("makeleader.youAreNowTheOwner"));
} else {
// Online
Util.sendMessage(plugin.getServer().getPlayer(targetPlayer), getLocale(targetPlayer).get("makeLeader.youAreNowTheOwner"));
Util.sendMessage(plugin.getServer().getPlayer(targetPlayer), ChatColor.GREEN + getLocale(targetPlayer).get("makeleader.youAreNowTheOwner"));
// Check if new leader has a lower range permission than the island size
boolean hasARangePerm = false;
int range = Settings.islandProtectionRange;
@ -1339,11 +1339,11 @@ public class IslandCommand extends AbstractCommand {
@Override
public CanUseResp canUse(CommandSender sender) {
if (!VaultHelper.hasPerm(player, Settings.PERMPREFIX + "island.lock")) {
return new CanUseResp(getLocale(sender).get("general.errors.no-permission"));
return new CanUseResp(ChatColor.RED + getLocale(sender).get("general.errors.no-permission"));
}
if (!getIslands().hasIsland(playerUUID)) {
return new CanUseResp(getLocale(sender).get("general.errors.no-island"));
return new CanUseResp(ChatColor.RED + getLocale(sender).get("general.errors.no-island"));
}
return new CanUseResp(true);

View File

@ -115,6 +115,10 @@ public class IslandsManager {
}
}
/**
* Save the islands to the database
* @param async - if true, saving will be done async
*/
public void save(boolean async){
Runnable save = () -> {
for(Island island : islandsByLocation.values()){