use of com.wasteofplastic.acidisland.ASLocale in project acidisland by tastybento.
the class IslandCmd method onCommand.
/*
* (non-Javadoc)
* @see
* org.bukkit.command.CommandExecutor#onCommand(org.bukkit.command.CommandSender
* , org.bukkit.command.Command, java.lang.String, java.lang.String[])
*/
@Override
public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] split) {
if (!(sender instanceof Player)) {
Util.sendMessage(sender, plugin.myLocale().errorUseInGame);
return false;
}
final Player player = (Player) sender;
// Basic permissions check to even use /island
if (!VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.create")) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).islanderrorYouDoNotHavePermission);
return true;
}
/*
* Grab data for this player - may be null or empty
* playerUUID is the unique ID of the player who issued the command
*/
final UUID playerUUID = player.getUniqueId();
if (playerUUID == null) {
plugin.getLogger().severe("Player " + sender.getName() + " has a null UUID - this should never happen!");
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorCommandNotReady + " (No UUID)");
return true;
}
final UUID teamLeader = plugin.getPlayers().getTeamLeader(playerUUID);
List<UUID> teamMembers = new ArrayList<UUID>();
if (teamLeader != null) {
teamMembers = plugin.getPlayers().getMembers(teamLeader);
}
// Island name (can have spaces)
if (split.length > 1 && split[0].equalsIgnoreCase("name")) {
// Naming of island
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.name") && plugin.getPlayers().hasIsland(playerUUID)) {
String name = split[1];
for (int i = 2; i < split.length; i++) {
name = name + " " + split[i];
}
if (name.length() < Settings.minNameLength) {
Util.sendMessage(player, ChatColor.RED + (plugin.myLocale(player.getUniqueId()).errorTooShort).replace("[length]", String.valueOf(Settings.minNameLength)));
return true;
}
if (name.length() > Settings.maxNameLength) {
Util.sendMessage(player, ChatColor.RED + (plugin.myLocale(player.getUniqueId()).errorTooLong).replace("[length]", String.valueOf(Settings.maxNameLength)));
return true;
}
plugin.getGrid().setIslandName(playerUUID, ChatColor.translateAlternateColorCodes('&', name));
Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(player.getUniqueId()).generalSuccess);
return true;
} else {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoPermission);
return true;
}
}
// The target player's UUID
UUID targetPlayer = null;
// Check if a player has an island or is in a team
switch(split.length) {
// /island command by itself
case 0:
// New island
if (plugin.getPlayers().getIslandLocation(playerUUID) == null && !plugin.getPlayers().inTeam(playerUUID)) {
// Check if the max number of islands is made already
if (Settings.maxIslands > 0 && plugin.getGrid().getIslandCount() > Settings.maxIslands) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorMaxIslands);
return true;
}
// Check if player has resets left
if (plugin.getPlayers().getResetsLeft(playerUUID) == 0) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).islandResetNoMore);
return true;
}
// Create new island for player
Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(player.getUniqueId()).islandnew);
chooseIsland(player);
return true;
} else {
// Check if this should open the Control Panel or not
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.controlpanel") && plugin.getPlayers().getControlPanel(playerUUID)) {
Util.runCommand(player, Settings.ISLANDCOMMAND + " cp");
} else {
// Check permission
if (!VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.go")) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoPermission);
return true;
}
if (!player.getWorld().getName().equalsIgnoreCase(Settings.worldName) || Settings.allowTeleportWhenFalling || !PlayerEvents.isFalling(playerUUID) || (player.isOp() && !Settings.damageOps)) {
// Teleport home
plugin.getGrid().homeTeleport(player);
if (Settings.islandRemoveMobs) {
plugin.getGrid().removeMobs(player.getLocation());
}
} else {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorCommandNotReady);
}
}
return true;
}
case 1:
if (split[0].equalsIgnoreCase("value")) {
// Explain command
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.value")) {
// Check they are on their island
if (!plugin.getGrid().playerIsOnIsland(player)) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNotOnIsland);
return true;
}
ItemStack item = player.getItemInHand();
double multiplier = 1;
if (item != null && item.getType().isBlock()) {
// Get permission multiplier
for (PermissionAttachmentInfo perms : player.getEffectivePermissions()) {
if (perms.getPermission().startsWith(Settings.PERMPREFIX + "island.multiplier.")) {
String[] spl = perms.getPermission().split(Settings.PERMPREFIX + "island.multiplier.");
// Get the max value should there be more than one
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 {
multiplier = Math.max(multiplier, Integer.valueOf(spl[1]));
}
}
}
// Do some sanity checking
if (multiplier < 1) {
multiplier = 1;
}
}
// Player height
if (player.getLocation().getBlockY() < Settings.seaHeight) {
multiplier *= Settings.underWaterMultiplier;
}
// Get the value. Try the specific item
int value = 0;
if (Settings.blockValues.containsKey(item.getData())) {
value = (int) ((double) Settings.blockValues.get(item.getData()) * multiplier);
} else if (Settings.blockValues.containsKey(new MaterialData(item.getType()))) {
value = (int) ((double) Settings.blockValues.get(new MaterialData(item.getType())) * multiplier);
}
if (value > 0) {
// [name] placed here may be worth [value]
Util.sendMessage(player, ChatColor.GREEN + (plugin.myLocale(player.getUniqueId()).islandblockValue.replace("[name]", Util.prettifyText(item.getType().name())).replace("[value]", String.valueOf(value))));
} else {
// [name] is worthless
Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(player.getUniqueId()).islandblockWorthless.replace("[name]", Util.prettifyText(item.getType().name())));
}
} else {
// That is not a block
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNotABlock);
}
return true;
}
} else if (split[0].equalsIgnoreCase("name")) {
// Explain command
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.name") && plugin.getPlayers().hasIsland(playerUUID)) {
Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " name <name>: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandHelpName);
return true;
}
} else if (split[0].equalsIgnoreCase("resetname")) {
// Convert name to a UUID
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.name") && plugin.getPlayers().hasIsland(playerUUID)) {
// Has an island
plugin.getGrid().setIslandName(playerUUID, null);
Util.sendMessage(sender, plugin.myLocale().generalSuccess);
}
return true;
}
if (split[0].equalsIgnoreCase("coop")) {
// Explain command
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "coop")) {
Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " coop <player>: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpCoop);
return true;
}
} else if (split[0].equalsIgnoreCase("uncoop")) {
// Explain command
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "coop")) {
Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " uncoop <player>: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpUnCoop);
return true;
}
} else if (split[0].equalsIgnoreCase("expel")) {
// Explain command
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.expel")) {
Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " expel <player>: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpExpel);
return true;
}
} else if (split[0].equalsIgnoreCase("teamchat") || split[0].equalsIgnoreCase("tc")) {
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "team.chat")) {
// Check if this command is on or not
if (!Settings.teamChat) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale().errorUnknownCommand);
return false;
}
// Check if in team
if (plugin.getPlayers().inTeam(playerUUID)) {
// Check if team members are online
boolean online = false;
for (UUID teamMember : plugin.getPlayers().getMembers(playerUUID)) {
if (!teamMember.equals(playerUUID) && plugin.getServer().getPlayer(teamMember) != null) {
online = true;
}
}
if (!online) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).teamChatNoTeamAround);
Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(playerUUID).teamChatStatusOff);
plugin.getChatListener().unSetPlayer(playerUUID);
return true;
}
if (plugin.getChatListener().isTeamChat(playerUUID)) {
// Toggle
Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(playerUUID).teamChatStatusOff);
plugin.getChatListener().unSetPlayer(playerUUID);
} else {
Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(playerUUID).teamChatStatusOn);
plugin.getChatListener().setPlayer(playerUUID);
}
} else {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).teamChatNoTeam);
}
} else {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).errorNoPermission);
}
return true;
}
if (split[0].equalsIgnoreCase("banlist")) {
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.ban")) {
// Show banned players
Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(playerUUID).adminInfoBannedPlayers + ":");
List<UUID> bannedList = plugin.getPlayers().getBanList(playerUUID);
if (bannedList.isEmpty()) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).banNone);
} else {
for (UUID bannedPlayers : bannedList) {
Util.sendMessage(player, plugin.myLocale(playerUUID).helpColor + plugin.getPlayers().getName(bannedPlayers));
}
}
return true;
} else {
Util.sendMessage(player, plugin.myLocale(playerUUID).errorNoPermission);
}
return true;
} else if (split[0].equalsIgnoreCase("ban")) {
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.ban")) {
// Just show ban help
Util.sendMessage(player, plugin.myLocale(playerUUID).helpColor + "/" + label + " ban <player>: " + ChatColor.WHITE + plugin.myLocale(playerUUID).islandhelpBan);
} else {
Util.sendMessage(player, plugin.myLocale(playerUUID).errorNoPermission);
}
return true;
} else if (split[0].equalsIgnoreCase("unban") && VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.ban")) {
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.ban")) {
// Just show unban help
Util.sendMessage(player, plugin.myLocale(playerUUID).helpColor + "/" + label + " unban <player>: " + ChatColor.WHITE + plugin.myLocale(playerUUID).islandhelpUnban);
} else {
Util.sendMessage(player, plugin.myLocale(playerUUID).errorNoPermission);
}
return true;
} else if (split[0].equalsIgnoreCase("make")) {
// plugin.getLogger().info("DEBUG: /is make called");
if (!pendingNewIslandSelection.contains(playerUUID)) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale().errorUnknownCommand);
return false;
}
pendingNewIslandSelection.remove(playerUUID);
Island oldIsland = plugin.getGrid().getIsland(player.getUniqueId());
newIsland(player);
if (resettingIsland.contains(playerUUID)) {
resettingIsland.remove(playerUUID);
resetPlayer(player, oldIsland);
}
return true;
} else if (split[0].equalsIgnoreCase("lang")) {
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.lang")) {
Util.sendMessage(player, "/" + label + " lang <#>");
displayLocales(player);
} else {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).errorNoPermission);
}
return true;
} else if (split[0].equalsIgnoreCase("settings")) {
// Show what the plugin settings are
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.settings")) {
try {
player.openInventory(plugin.getSettingsPanel().islandGuardPanel(player));
} catch (Exception e) {
if (DEBUG)
e.printStackTrace();
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorCommandNotReady);
}
} else {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoPermission);
}
return true;
} else if (split[0].equalsIgnoreCase("lock")) {
if (!VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.lock")) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoPermission);
return true;
}
// plugin.getLogger().info("DEBUG: perms ok");
// Find out which island they want to lock
Island island = plugin.getGrid().getIsland(playerUUID);
if (island == null) {
// plugin.getLogger().info("DEBUG: player has no island in grid");
// Player has no island in the grid
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoIsland);
return true;
} else {
if (!island.isLocked()) {
// Remove any visitors
for (Player target : plugin.getServer().getOnlinePlayers()) {
if (target == null || target.hasMetadata("NPC") || target.isOp() || player.equals(target) || VaultHelper.checkPerm(target, Settings.PERMPREFIX + "mod.bypassprotect"))
continue;
// See if target is on this player's island and not a coop player
if (plugin.getGrid().isOnIsland(player, target) && !CoopPlay.getInstance().getCoopPlayers(island.getCenter()).contains(target.getUniqueId())) {
// Send them home
if (plugin.getPlayers().inTeam(target.getUniqueId()) || plugin.getPlayers().hasIsland(target.getUniqueId())) {
plugin.getGrid().homeTeleport(target);
} else {
// Just move target to spawn
if (!target.performCommand(Settings.SPAWNCOMMAND)) {
target.teleport(player.getWorld().getSpawnLocation());
}
}
Util.sendMessage(target, ChatColor.RED + plugin.myLocale(target.getUniqueId()).expelExpelled);
plugin.getLogger().info(player.getName() + " expelled " + target.getName() + " from their island when locking.");
// Yes they are
Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(player.getUniqueId()).expelSuccess.replace("[name]", target.getName()));
}
}
Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(playerUUID).lockLocking);
plugin.getMessages().tellOfflineTeam(playerUUID, plugin.myLocale(playerUUID).lockPlayerLocked.replace("[name]", player.getName()));
plugin.getMessages().tellTeam(playerUUID, plugin.myLocale(playerUUID).lockPlayerLocked.replace("[name]", player.getName()));
island.setLocked(true);
} else {
Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(playerUUID).lockUnlocking);
plugin.getMessages().tellOfflineTeam(playerUUID, plugin.myLocale(playerUUID).lockPlayerUnlocked.replace("[name]", player.getName()));
plugin.getMessages().tellTeam(playerUUID, plugin.myLocale(playerUUID).lockPlayerUnlocked.replace("[name]", player.getName()));
island.setLocked(false);
}
return true;
}
} else if (split[0].equalsIgnoreCase("go")) {
if (!VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.go")) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoPermission);
return true;
}
if (!plugin.getPlayers().hasIsland(playerUUID) && !plugin.getPlayers().inTeam(playerUUID)) {
// Player has no island
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).errorNoIsland);
return true;
}
// Teleport home
plugin.getGrid().homeTeleport(player);
if (Settings.islandRemoveMobs) {
plugin.getGrid().removeMobs(player.getLocation());
}
return true;
} else if (split[0].equalsIgnoreCase("about")) {
Util.sendMessage(player, ChatColor.GOLD + "About " + ChatColor.GREEN + plugin.getDescription().getName() + ChatColor.GOLD + " v" + ChatColor.AQUA + plugin.getDescription().getVersion() + ChatColor.GOLD + ":");
Util.sendMessage(player, ChatColor.GOLD + "This plugin is free software: you can redistribute");
Util.sendMessage(player, ChatColor.GOLD + "it and/or modify it under the terms of the GNU");
Util.sendMessage(player, ChatColor.GOLD + "General Public License as published by the Free");
Util.sendMessage(player, ChatColor.GOLD + "Software Foundation, either version 3 of the License,");
Util.sendMessage(player, ChatColor.GOLD + "or (at your option) any later version.");
Util.sendMessage(player, ChatColor.GOLD + "This plugin is distributed in the hope that it");
Util.sendMessage(player, ChatColor.GOLD + "will be useful, but WITHOUT ANY WARRANTY; without");
Util.sendMessage(player, ChatColor.GOLD + "even the implied warranty of MERCHANTABILITY or");
Util.sendMessage(player, ChatColor.GOLD + "FITNESS FOR A PARTICULAR PURPOSE. See the");
Util.sendMessage(player, ChatColor.GOLD + "GNU General Public License for more details.");
Util.sendMessage(player, ChatColor.GOLD + "You should have received a copy of the GNU");
Util.sendMessage(player, ChatColor.GOLD + "General Public License along with this plugin.");
Util.sendMessage(player, ChatColor.GOLD + "If not, see <http://www.gnu.org/licenses/>.");
Util.sendMessage(player, ChatColor.GOLD + "Souce code is available on GitHub.");
Util.sendMessage(player, ChatColor.GOLD + "(c) 2014 - 2017 by tastybento, Poslovitch");
return true;
// Spawn enderman
// Enderman enderman = (Enderman)
// player.getWorld().spawnEntity(player.getLocation().add(new
// Vector(5,0,5)), EntityType.ENDERMAN);
// enderman.setCustomName("TastyBento's Ghost");
// enderman.setCarriedMaterial(new
// MaterialData(Material.GRASS));
}
if (split[0].equalsIgnoreCase("controlpanel") || split[0].equalsIgnoreCase("cp")) {
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.controlpanel")) {
if (ControlPanel.controlPanel.containsKey(ControlPanel.getDefaultPanelName())) {
player.openInventory(ControlPanel.controlPanel.get(ControlPanel.getDefaultPanelName()));
return true;
} else {
Util.sendMessage(player, plugin.myLocale(playerUUID).errorCommandNotReady);
plugin.getLogger().severe("There is a problem with the controlpanel.yml file - it is probably corrupted. Delete it and let it be regenerated.");
return true;
}
}
}
if (split[0].equalsIgnoreCase("minishop") || split[0].equalsIgnoreCase("ms")) {
if (Settings.useEconomy && Settings.useMinishop) {
// Check island
if (plugin.getGrid().getIsland(player.getUniqueId()) == null) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoIsland);
return true;
}
if (player.getWorld().equals(ASkyBlock.getIslandWorld()) || player.getWorld().equals(ASkyBlock.getNetherWorld())) {
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.minishop")) {
if (ControlPanel.miniShop != null) {
player.openInventory(ControlPanel.miniShop);
} else {
Util.sendMessage(player, plugin.myLocale(playerUUID).errorCommandNotReady);
plugin.getLogger().severe("Player tried to open the minishop, but it does not exist. Look for errors in the console about the minishop loading.");
}
return true;
}
} else {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorWrongWorld);
return true;
}
} else {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorMinishopDisabled);
return true;
}
}
// /island <command>
if (split[0].equalsIgnoreCase("warp")) {
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.warp")) {
Util.sendMessage(player, ChatColor.YELLOW + "/island warp <player>: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpWarp);
return true;
}
} else if (split[0].equalsIgnoreCase("warps")) {
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.warp")) {
// Step through warp table
Collection<UUID> warpList = plugin.getWarpSignsListener().listWarps();
if (warpList.isEmpty()) {
Util.sendMessage(player, ChatColor.YELLOW + plugin.myLocale(player.getUniqueId()).warpserrorNoWarpsYet);
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.addwarp") && plugin.getGrid().playerIsOnIsland(player)) {
Util.sendMessage(player, ChatColor.YELLOW + plugin.myLocale().warpswarpTip);
}
return true;
} else {
if (Settings.useWarpPanel) {
// Try the warp panel
player.openInventory(plugin.getWarpPanel().getWarpPanel(0));
} else {
Boolean hasWarp = false;
String wlist = "";
for (UUID w : warpList) {
if (w == null)
continue;
if (wlist.isEmpty()) {
wlist = plugin.getPlayers().getName(w);
} else {
wlist += ", " + plugin.getPlayers().getName(w);
}
if (w.equals(playerUUID)) {
hasWarp = true;
}
}
Util.sendMessage(player, ChatColor.YELLOW + plugin.myLocale(player.getUniqueId()).warpswarpsAvailable + ": " + ChatColor.WHITE + wlist);
if (!hasWarp && (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.addwarp"))) {
Util.sendMessage(player, ChatColor.YELLOW + plugin.myLocale().warpswarpTip);
}
}
return true;
}
}
} else if (split[0].equalsIgnoreCase("restart") || split[0].equalsIgnoreCase("reset")) {
if (!VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.reset")) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoPermission);
return true;
}
// Check this player has an island
if (!plugin.getPlayers().hasIsland(playerUUID)) {
// No so just start an island
Util.runCommand(player, Settings.ISLANDCOMMAND);
return true;
}
if (plugin.getPlayers().inTeam(playerUUID)) {
if (!plugin.getPlayers().getTeamLeader(playerUUID).equals(playerUUID)) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).islandresetOnlyOwner);
} else {
Util.sendMessage(player, ChatColor.YELLOW + plugin.myLocale(player.getUniqueId()).islandresetMustRemovePlayers);
}
return true;
}
// Check if the player has used up all their resets
if (plugin.getPlayers().getResetsLeft(playerUUID) == 0) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).islandResetNoMore);
return true;
}
if (plugin.getPlayers().getResetsLeft(playerUUID) > 0) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).resetYouHave.replace("[number]", String.valueOf(plugin.getPlayers().getResetsLeft(playerUUID))));
}
if (!onRestartWaitTime(player) || Settings.resetWait == 0 || player.isOp()) {
// Kick off the confirmation
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).islandresetConfirm.replace("[seconds]", String.valueOf(Settings.resetConfirmWait)));
if (!confirm.containsKey(playerUUID) || !confirm.get(playerUUID)) {
confirm.put(playerUUID, true);
plugin.getServer().getScheduler().runTaskLater(plugin, new Runnable() {
@Override
public void run() {
confirm.put(playerUUID, false);
}
}, (Settings.resetConfirmWait * 20));
}
return true;
} else {
Util.sendMessage(player, ChatColor.YELLOW + plugin.myLocale(player.getUniqueId()).islandresetWait.replace("[time]", String.valueOf(getResetWaitTime(player))));
}
return true;
} else if (split[0].equalsIgnoreCase("confirm")) {
// This is where the actual reset is done
if (confirm.containsKey(playerUUID) && confirm.get(playerUUID)) {
confirm.remove(playerUUID);
// Actually RESET the island
Util.sendMessage(player, ChatColor.YELLOW + plugin.myLocale(player.getUniqueId()).islandresetPleaseWait);
if (plugin.getPlayers().getResetsLeft(playerUUID) == 0) {
Util.sendMessage(player, ChatColor.YELLOW + plugin.myLocale(player.getUniqueId()).islandResetNoMore);
}
if (plugin.getPlayers().getResetsLeft(playerUUID) > 0) {
Util.sendMessage(player, ChatColor.YELLOW + plugin.myLocale(player.getUniqueId()).resetYouHave.replace("[number]", String.valueOf(plugin.getPlayers().getResetsLeft(playerUUID))));
}
// Show a schematic panel if the player has a choice
// Get the schematics that this player is eligible to use
List<Schematic> schems = getSchematics(player, false);
// plugin.getLogger().info("DEBUG: size of schematics for this player = " + schems.size());
Island oldIsland = plugin.getGrid().getIsland(player.getUniqueId());
if (schems.isEmpty()) {
// No schematics - use default island
newIsland(player);
resetPlayer(player, oldIsland);
} else if (schems.size() == 1) {
// Hobson's choice
newIsland(player, schems.get(0));
resetPlayer(player, oldIsland);
} else {
// A panel can only be shown if there is >1 viable schematic
if (Settings.useSchematicPanel) {
pendingNewIslandSelection.add(playerUUID);
resettingIsland.add(playerUUID);
player.openInventory(plugin.getSchematicsPanel().getPanel(player));
} else {
// No panel
// Check schematics for specific permission
schems = getSchematics(player, true);
if (schems.isEmpty()) {
newIsland(player);
} else if (Settings.chooseIslandRandomly) {
// Choose an island randomly from the list
newIsland(player, schems.get(random.nextInt(schems.size())));
} else {
// Do the first one in the list
newIsland(player, schems.get(0));
}
resetPlayer(player, oldIsland);
}
}
return true;
} else {
Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/island restart: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpRestart);
return true;
}
} else if (split[0].equalsIgnoreCase("sethome")) {
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.sethome")) {
// Check island
if (plugin.getGrid().getIsland(player.getUniqueId()) == null) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoIsland);
return true;
}
plugin.getGrid().homeSet(player);
return true;
} else {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).errorNoPermission);
return true;
}
} else if (split[0].equalsIgnoreCase("help")) {
Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + plugin.myLocale(player.getUniqueId()).helpHeader.replace("[plugin]", plugin.getDescription().getName()).replace("[version]", plugin.getDescription().getVersion()));
if (Settings.useControlPanel) {
Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + ": " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpControlPanel);
} else {
Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + ": " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpIsland);
}
// Dynamic home sizes with permissions
int maxHomes = Settings.maxHomes;
for (PermissionAttachmentInfo perms : player.getEffectivePermissions()) {
if (perms.getPermission().startsWith(Settings.PERMPREFIX + "island.maxhomes.")) {
if (perms.getPermission().startsWith(Settings.PERMPREFIX + "island.maxhomes.*")) {
maxHomes = Settings.maxHomes;
break;
} else {
// Get the max value should there be more than one
String[] spl = perms.getPermission().split(Settings.PERMPREFIX + "island.maxhomes.");
if (spl.length > 1) {
// Check that it is a number
if (!NumberUtils.isDigits(spl[1])) {
plugin.getLogger().severe("Player " + player.getName() + " has permission: " + perms.getPermission() + " <-- the last part MUST be a number! Ignoring...");
} else {
maxHomes = Math.max(maxHomes, Integer.valueOf(spl[1]));
}
}
}
}
// Do some sanity checking
if (maxHomes < 1) {
maxHomes = 1;
}
}
if (maxHomes > 1 && VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.go")) {
Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " go <1 - " + maxHomes + ">: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpTeleport);
} else if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.go")) {
Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " go: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpTeleport);
}
if (plugin.getGrid() != null && plugin.getGrid().getSpawn() != null && VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.spawn")) {
Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " spawn: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpSpawn);
}
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.controlpanel")) {
Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " controlpanel or cp [on/off]: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpControlPanel);
}
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.reset")) {
Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " reset: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpRestart);
}
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.sethome")) {
if (maxHomes > 1) {
Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " sethome <1 - " + maxHomes + ">: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpSetHome);
} else {
Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " sethome: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpSetHome);
}
}
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.info")) {
Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " level: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpLevel);
Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " level <player>: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpLevelPlayer);
}
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.name") && plugin.getPlayers().hasIsland(playerUUID)) {
Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " name <name>: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandHelpName);
}
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.topten")) {
Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " top: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpTop);
}
if (Settings.useEconomy && VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.minishop")) {
Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " minishop or ms: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpMiniShop);
}
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.value")) {
Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " value: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpValue);
}
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.warp")) {
Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " warps: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpWarps);
Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " warp <player>: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpWarp);
}
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "team.create")) {
Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " team: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpTeam);
Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " invite <player>: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpInvite);
Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " leave: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpLeave);
}
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "team.kick")) {
Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " kick <player>: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpKick);
}
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "team.join")) {
Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " <accept/reject>: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpAcceptReject);
}
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "team.makeleader")) {
Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " makeleader <player>: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpMakeLeader);
}
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "team.chat") && plugin.getPlayers().inTeam(playerUUID)) {
Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " teamchat: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).teamChatHelp);
}
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.biomes")) {
Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " biomes: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpBiome);
}
// if (!Settings.allowPvP) {
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.expel")) {
Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " expel <player>: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpExpel);
}
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.ban")) {
Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " ban <player>: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpBan);
Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " banlist <player>: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpBanList);
Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " unban <player>: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpUnban);
}
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "coop")) {
Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " coop <player>: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpCoop);
Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " uncoop <player>: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpUnCoop);
Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " listcoops: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpListCoops);
}
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.lock")) {
Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " lock: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandHelpLock);
}
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.name") && plugin.getPlayers().hasIsland(playerUUID)) {
Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " resetname: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpResetName);
}
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.settings")) {
Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " settings: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandHelpSettings);
}
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.challenges")) {
Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + plugin.myLocale(player.getUniqueId()).islandHelpChallenges);
}
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.lang")) {
Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " lang <#>: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandHelpSelectLanguage);
}
/*
if (player.getInventory().getItemInMainHand() != null) {
net.minecraft.server.v1_11_R1.ItemStack stack = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand());
NBTTagCompound tagCompound = stack.getTag();
Bukkit.getLogger().info("DEBUG: tag = " + tagCompound);
}
*/
return true;
} else if (split[0].equalsIgnoreCase("listcoops")) {
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "coop")) {
if (!plugin.getPlayers().hasIsland(playerUUID)) {
// Player has no island
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoIsland);
return true;
}
Island island = plugin.getGrid().getIsland(playerUUID);
boolean none = true;
for (UUID uuid : CoopPlay.getInstance().getCoopPlayers(island.getCenter())) {
Util.sendMessage(player, ChatColor.GREEN + plugin.getPlayers().getName(uuid));
none = false;
}
if (none) {
Util.sendMessage(player, plugin.myLocale(playerUUID).helpColor + "/" + label + " coop <player>: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpCoop);
} else {
Util.sendMessage(player, plugin.myLocale(playerUUID).helpColor + plugin.myLocale(playerUUID).coopUseExpel);
}
return true;
}
} else if (split[0].equalsIgnoreCase("biomes")) {
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.biomes")) {
// Only the team leader can do this
if (teamLeader != null && !teamLeader.equals(playerUUID)) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).levelerrornotYourIsland);
return true;
}
if (!plugin.getPlayers().hasIsland(playerUUID)) {
// Player has no island
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoIsland);
return true;
}
if (!plugin.getGrid().playerIsOnIsland(player)) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).challengeserrorNotOnIsland);
return true;
}
// Not allowed in the nether
if (plugin.getPlayers().getIslandLocation(playerUUID).getWorld().getEnvironment().equals(Environment.NETHER)) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorWrongWorld);
return true;
}
// Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "[Biomes]");
Inventory inv = plugin.getBiomes().getBiomePanel(player);
if (inv != null) {
player.openInventory(inv);
}
return true;
} else {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoPermission);
return true;
}
} else if (split[0].equalsIgnoreCase("spawn") && plugin.getGrid().getSpawn() != null) {
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.spawn")) {
// go to spawn
Location l = ASkyBlock.getIslandWorld().getSpawnLocation();
l.add(new Vector(0.5, 0, 0.5));
Island spawn = plugin.getGrid().getSpawn();
if (spawn != null && spawn.getSpawnPoint() != null) {
l = spawn.getSpawnPoint();
}
player.teleport(l);
} else {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).errorNoPermission);
}
return true;
} else if (split[0].equalsIgnoreCase("top")) {
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.topten")) {
TopTen.topTenShow(player);
return true;
} else {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).errorNoPermission);
return true;
}
} else if (split[0].equalsIgnoreCase("level")) {
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.info")) {
if (!plugin.getPlayers().inTeam(playerUUID) && !plugin.getPlayers().hasIsland(playerUUID)) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoIsland);
return true;
} else {
if (!VaultHelper.checkPerm(player, Settings.PERMPREFIX + "intopten")) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).topTenerrorExcluded.replace("[perm]", Settings.PERMPREFIX + "intopten"));
}
calculateIslandLevel(player, playerUUID);
return true;
}
} else {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).errorNoPermission);
return true;
}
} else if (split[0].equalsIgnoreCase("invite")) {
// player how many more people they can invite
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "team.create")) {
Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).invitehelp);
// If the player who is doing the inviting has a team
if (plugin.getPlayers().inTeam(playerUUID)) {
// Check to see if the player is the leader
if (teamLeader.equals(playerUUID)) {
// Check to see if the team is already full
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) {
Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(player.getUniqueId()).inviteyouCanInvite.replace("[number]", String.valueOf(maxSize - teamMembers.size())));
} else {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).inviteerrorYourIslandIsFull);
}
return true;
}
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).inviteerrorYouMustHaveIslandToInvite);
return true;
}
return true;
} else {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).errorNoPermission);
return true;
}
} else if (split[0].equalsIgnoreCase("coopaccept")) {
// Accept an invite command
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "coop")) {
if (coopInviteList.containsKey(playerUUID)) {
// Check if inviter is online
Player inviter = plugin.getServer().getPlayer(coopInviteList.get(playerUUID));
if (inviter == null || !inviter.isOnline()) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorOfflinePlayer);
coopInviteList.remove(playerUUID);
return true;
}
if (CoopPlay.getInstance().addCoopPlayer(inviter, player)) {
// Tell everyone what happened
Util.sendMessage(inviter, ChatColor.GREEN + plugin.myLocale(inviter.getUniqueId()).coopSuccess.replace("[name]", player.getName()));
Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(playerUUID).coopMadeYouCoop.replace("[name]", inviter.getName()));
// TODO: Give perms if the player is on the coop island
}
setResetWaitTime(player);
// Remove the invite
coopInviteList.remove(playerUUID);
return true;
}
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorCommandNotReady);
return true;
} else {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).errorNoPermission);
return true;
}
} else if (split[0].equalsIgnoreCase("accept")) {
// Accept an invite command
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "team.join")) {
// one
if (!plugin.getPlayers().inTeam(playerUUID) && inviteList.containsKey(playerUUID)) {
// If the invitee has an island of their own
if (plugin.getPlayers().hasIsland(playerUUID)) {
plugin.getLogger().info(player.getName() + "'s island will be deleted because they joined a party.");
plugin.deletePlayerIsland(playerUUID, true);
plugin.getLogger().info("Island deleted.");
}
// Add the player to the team
addPlayertoTeam(playerUUID, inviteList.get(playerUUID));
// team (leader is not in a team yet)
if (!plugin.getPlayers().inTeam(inviteList.get(playerUUID))) {
// Add the leader to their own team
addPlayertoTeam(inviteList.get(playerUUID), inviteList.get(playerUUID));
}
setResetWaitTime(player);
if (Settings.teamJoinDeathReset) {
plugin.getPlayers().setDeaths(player.getUniqueId(), 0);
}
plugin.getGrid().homeTeleport(player);
plugin.resetPlayer(player);
if (!player.hasPermission(Settings.PERMPREFIX + "command.newteamexempt")) {
// plugin.getLogger().info("DEBUG: Executing new island commands");
runCommands(Settings.teamStartCommands, player);
}
Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(playerUUID).inviteyouHaveJoinedAnIsland);
if (plugin.getServer().getPlayer(inviteList.get(playerUUID)) != null) {
Util.sendMessage(plugin.getServer().getPlayer(inviteList.get(playerUUID)), ChatColor.GREEN + plugin.myLocale(inviteList.get(playerUUID)).invitehasJoinedYourIsland.replace("[name]", player.getName()));
}
// Remove the invite
inviteList.remove(player.getUniqueId());
plugin.getGrid().saveGrid();
return true;
}
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorCommandNotReady);
return true;
} else {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).errorNoPermission);
return true;
}
} else if (split[0].equalsIgnoreCase("coopreject")) {
// Reject /island coopreject
if (coopInviteList.containsKey(playerUUID)) {
Util.sendMessage(player, ChatColor.YELLOW + plugin.myLocale(playerUUID).rejectyouHaveRejectedInvitation);
// about the rejection
if (Bukkit.getPlayer(inviteList.get(playerUUID)) != null) {
Util.sendMessage(Bukkit.getPlayer(inviteList.get(playerUUID)), ChatColor.RED + plugin.myLocale(inviteList.get(playerUUID)).rejectnameHasRejectedInvite.replace("[name]", player.getName()));
}
// Remove this player from the global invite list
coopInviteList.remove(playerUUID);
} else {
// Someone typed /island coopreject and had not been invited
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).rejectyouHaveNotBeenInvited);
}
return true;
} else if (split[0].equalsIgnoreCase("reject")) {
// Reject /island reject
if (inviteList.containsKey(player.getUniqueId())) {
Util.sendMessage(player, ChatColor.YELLOW + plugin.myLocale(playerUUID).rejectyouHaveRejectedInvitation);
// about the rejection
if (Bukkit.getPlayer(inviteList.get(player.getUniqueId())) != null) {
Util.sendMessage(Bukkit.getPlayer(inviteList.get(playerUUID)), ChatColor.RED + plugin.myLocale(inviteList.get(playerUUID)).rejectnameHasRejectedInvite.replace("[name]", player.getName()));
}
// Remove this player from the global invite list
inviteList.remove(playerUUID);
} else {
// Someone typed /island reject and had not been invited
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).rejectyouHaveNotBeenInvited);
}
return true;
} else if (split[0].equalsIgnoreCase("leave")) {
// Leave team command
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "team.join")) {
if (player.getWorld().equals(ASkyBlock.getIslandWorld()) || (Settings.createNether && Settings.newNether && ASkyBlock.getNetherWorld() != null && player.getWorld().equals(ASkyBlock.getNetherWorld()))) {
if (plugin.getPlayers().inTeam(playerUUID)) {
if (plugin.getPlayers().getTeamLeader(playerUUID) != null && plugin.getPlayers().getTeamLeader(playerUUID).equals(playerUUID)) {
Util.sendMessage(player, ChatColor.YELLOW + plugin.myLocale(player.getUniqueId()).leaveerrorYouAreTheLeader);
return true;
}
// Check for confirmation
if (!leavingPlayers.contains(playerUUID)) {
leavingPlayers.add(playerUUID);
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).leaveWarning);
new BukkitRunnable() {
@Override
public void run() {
// If the player is still on the list, remove them and cancel the leave
if (leavingPlayers.contains(playerUUID)) {
leavingPlayers.remove(playerUUID);
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).leaveCanceled);
}
}
}.runTaskLater(plugin, Settings.resetConfirmWait * 20L);
return true;
}
// Remove from confirmation list
leavingPlayers.remove(playerUUID);
// Remove from team
if (!removePlayerFromTeam(playerUUID, teamLeader)) {
// If this is canceled, fail silently
return true;
}
// Clear any coop inventories
// CoopPlay.getInstance().returnAllInventories(player);
// Remove any of the target's coop invitees and grab
// their stuff
CoopPlay.getInstance().clearMyInvitedCoops(player);
CoopPlay.getInstance().clearMyCoops(player);
// Log the location that this player left so they
// cannot join again before the cool down ends
plugin.getPlayers().startInviteCoolDownTimer(playerUUID, plugin.getPlayers().getTeamIslandLocation(teamLeader));
// Remove any warps
plugin.getWarpSignsListener().removeWarp(playerUUID);
Util.sendMessage(player, ChatColor.YELLOW + plugin.myLocale(player.getUniqueId()).leaveyouHaveLeftTheIsland);
// Tell the leader if they are online
if (plugin.getServer().getPlayer(teamLeader) != null) {
Player leader = plugin.getServer().getPlayer(teamLeader);
Util.sendMessage(leader, ChatColor.RED + plugin.myLocale(teamLeader).leavenameHasLeftYourIsland.replace("[name]", player.getName()));
} else {
// Leave them a message
plugin.getMessages().setMessage(teamLeader, ChatColor.RED + plugin.myLocale(teamLeader).leavenameHasLeftYourIsland.replace("[name]", player.getName()));
}
// teamMembers.remove(playerUUID);
if (teamMembers.size() < 2) {
// plugin.getLogger().info("DEBUG: Party is less than 2 - removing leader from team");
if (!removePlayerFromTeam(teamLeader, teamLeader)) {
// If this is canceled, return silently.
return true;
}
}
// Clear all player variables and save
plugin.resetPlayer(player);
if (!player.performCommand(Settings.SPAWNCOMMAND)) {
player.teleport(player.getWorld().getSpawnLocation());
}
return true;
} else {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).leaveerrorYouCannotLeaveIsland);
return true;
}
} else {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).leaveerrorYouMustBeInWorld);
}
return true;
} else {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).errorNoPermission);
return true;
}
} else if (split[0].equalsIgnoreCase("team")) {
if (plugin.getPlayers().inTeam(playerUUID)) {
if (teamLeader.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) {
Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(player.getUniqueId()).inviteyouCanInvite.replace("[number]", String.valueOf(maxSize - teamMembers.size())));
} else {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).inviteerrorYourIslandIsFull);
}
}
Util.sendMessage(player, ChatColor.YELLOW + plugin.myLocale(player.getUniqueId()).teamlistingMembers + ":");
// Display members in the list
for (UUID m : plugin.getPlayers().getMembers(teamLeader)) {
Util.sendMessage(player, ChatColor.WHITE + plugin.getPlayers().getName(m));
}
} else if (inviteList.containsKey(playerUUID)) {
Util.sendMessage(player, ChatColor.YELLOW + plugin.myLocale(player.getUniqueId()).invitenameHasInvitedYou.replace("[name]", plugin.getPlayers().getName(inviteList.get(playerUUID))));
Util.sendMessage(player, ChatColor.WHITE + "/" + label + " [accept/reject]" + ChatColor.YELLOW + plugin.myLocale(player.getUniqueId()).invitetoAcceptOrReject);
} else {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).kickerrorNoTeam);
}
return true;
} else {
// Incorrect syntax
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).errorUnknownCommand);
return true;
}
break;
/*
* Commands that have two parameters
*/
case 2:
if (split[0].equalsIgnoreCase("controlpanel") || split[0].equalsIgnoreCase("cp")) {
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.controlpanel")) {
if (split[1].equalsIgnoreCase("on")) {
plugin.getPlayers().setControlPanel(playerUUID, true);
} else if (split[1].equalsIgnoreCase("off")) {
plugin.getPlayers().setControlPanel(playerUUID, false);
}
Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(playerUUID).generalSuccess);
return true;
} else {
Util.sendMessage(player, plugin.myLocale(playerUUID).errorNoPermission);
return true;
}
} else if (split[0].equalsIgnoreCase("warps")) {
if (Settings.useWarpPanel) {
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.warp")) {
// Step through warp table
Set<UUID> warpList = plugin.getWarpSignsListener().listWarps();
if (warpList.isEmpty()) {
Util.sendMessage(player, ChatColor.YELLOW + plugin.myLocale(player.getUniqueId()).warpserrorNoWarpsYet);
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.addwarp") && plugin.getGrid().playerIsOnIsland(player)) {
Util.sendMessage(player, ChatColor.YELLOW + plugin.myLocale().warpswarpTip);
}
return true;
} else {
// Try the warp panel
int panelNum = 0;
try {
panelNum = Integer.valueOf(split[1]) - 1;
} catch (Exception e) {
panelNum = 0;
}
player.openInventory(plugin.getWarpPanel().getWarpPanel(panelNum));
return true;
}
} else {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).errorNoPermission);
}
} else {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).errorUnknownCommand);
return true;
}
} else if (split[0].equalsIgnoreCase("make")) {
// plugin.getLogger().info("DEBUG: /is make '" + split[1] + "' called");
if (!pendingNewIslandSelection.contains(playerUUID)) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).errorUnknownCommand);
return true;
}
pendingNewIslandSelection.remove(playerUUID);
// Create a new island using schematic
if (!schematics.containsKey(split[1])) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).errorUnknownCommand);
return true;
} else {
Schematic schematic = schematics.get(split[1]);
// Check perm again
if (schematic.getPerm().isEmpty() || VaultHelper.checkPerm(player, schematic.getPerm())) {
Island oldIsland = plugin.getGrid().getIsland(player.getUniqueId());
newIsland(player, schematic);
if (resettingIsland.contains(playerUUID)) {
resettingIsland.remove(playerUUID);
resetPlayer(player, oldIsland);
}
return true;
} else {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).errorNoPermission);
return true;
}
}
} else if (split[0].equalsIgnoreCase("lang")) {
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.lang")) {
if (!NumberUtils.isDigits(split[1])) {
Util.sendMessage(player, ChatColor.RED + "/" + label + " lang <#>");
displayLocales(player);
return true;
} else {
try {
int index = Integer.valueOf(split[1]);
if (index < 1 || index > plugin.getAvailableLocales().size()) {
Util.sendMessage(player, ChatColor.RED + "/" + label + " lang <#>");
displayLocales(player);
return true;
}
for (ASLocale locale : plugin.getAvailableLocales().values()) {
if (locale.getIndex() == index) {
plugin.getPlayers().setLocale(playerUUID, locale.getLocaleName());
Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(playerUUID).generalSuccess);
return true;
}
}
// Not in the list
Util.sendMessage(player, ChatColor.RED + "/" + label + " lang <#>");
displayLocales(player);
} catch (Exception e) {
Util.sendMessage(player, ChatColor.RED + "/" + label + " lang <#>");
displayLocales(player);
}
}
return true;
} else {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).errorNoPermission);
return true;
}
} else // Multi home
if (split[0].equalsIgnoreCase("go")) {
if (!plugin.getPlayers().hasIsland(playerUUID) && !plugin.getPlayers().inTeam(playerUUID)) {
// Player has no island
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoIsland);
return true;
}
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.sethome")) {
int number = 1;
try {
number = Integer.valueOf(split[1]);
// plugin.getLogger().info("DEBUG: number = " + number);
if (number < 1) {
plugin.getGrid().homeTeleport(player, 1);
} else {
// Dynamic home sizes with permissions
int maxHomes = Settings.maxHomes;
for (PermissionAttachmentInfo perms : player.getEffectivePermissions()) {
if (perms.getPermission().startsWith(Settings.PERMPREFIX + "island.maxhomes.")) {
if (perms.getPermission().contains(Settings.PERMPREFIX + "island.maxhomes.*")) {
maxHomes = Settings.maxHomes;
break;
} else {
// Get the max value should there be more than one
String[] spl = perms.getPermission().split(Settings.PERMPREFIX + "island.maxhomes.");
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 {
maxHomes = Math.max(maxHomes, Integer.valueOf(spl[1]));
}
}
}
}
// Do some sanity checking
if (maxHomes < 1) {
maxHomes = 1;
}
}
if (number > maxHomes) {
if (maxHomes > 1) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).setHomeerrorNumHomes.replace("[max]", String.valueOf(maxHomes)));
} else {
plugin.getGrid().homeTeleport(player, 1);
}
} else {
// Teleport home
plugin.getGrid().homeTeleport(player, number);
}
}
} catch (Exception e) {
// Teleport home
plugin.getGrid().homeTeleport(player, 1);
}
if (Settings.islandRemoveMobs) {
plugin.getGrid().removeMobs(player.getLocation());
}
} else {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoPermission);
}
return true;
} else if (split[0].equalsIgnoreCase("sethome")) {
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.sethome")) {
Island island = plugin.getGrid().getIsland(playerUUID);
if (island == null) {
// plugin.getLogger().info("DEBUG: player has no island in grid");
// Player has no island in the grid
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoIsland);
return true;
}
// Dynamic home sizes with permissions
int maxHomes = Settings.maxHomes;
for (PermissionAttachmentInfo perms : player.getEffectivePermissions()) {
if (perms.getPermission().startsWith(Settings.PERMPREFIX + "island.maxhomes.")) {
// Get the max value should there be more than one
if (perms.getPermission().contains(Settings.PERMPREFIX + "island.maxhomes.*")) {
maxHomes = Settings.maxHomes;
break;
} else {
String[] spl = perms.getPermission().split(Settings.PERMPREFIX + "island.maxhomes.");
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 {
maxHomes = Math.max(maxHomes, Integer.valueOf(spl[1]));
}
}
}
}
// Do some sanity checking
if (maxHomes < 1) {
maxHomes = 1;
}
}
if (maxHomes > 1) {
// Check the number given is a number
int number = 0;
try {
number = Integer.valueOf(split[1]);
if (number < 1 || number > maxHomes) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).setHomeerrorNumHomes.replace("[max]", String.valueOf(maxHomes)));
} else {
plugin.getGrid().homeSet(player, number);
}
} catch (Exception e) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).setHomeerrorNumHomes.replace("[max]", String.valueOf(maxHomes)));
}
} else {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoPermission);
}
return true;
}
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoPermission);
return true;
} else if (split[0].equalsIgnoreCase("warp")) {
// Warp somewhere command
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.warp")) {
final Set<UUID> warpList = plugin.getWarpSignsListener().listWarps();
if (warpList.isEmpty()) {
Util.sendMessage(player, ChatColor.YELLOW + plugin.myLocale(player.getUniqueId()).warpserrorNoWarpsYet);
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.addwarp")) {
Util.sendMessage(player, ChatColor.YELLOW + plugin.myLocale().warpswarpTip);
} else {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoPermission);
}
return true;
} else {
// Check if this is part of a name
UUID foundWarp = null;
for (UUID warp : warpList) {
if (warp == null)
continue;
if (plugin.getPlayers().getName(warp) != null) {
if (plugin.getPlayers().getName(warp).toLowerCase().equals(split[1].toLowerCase())) {
foundWarp = warp;
break;
} else if (plugin.getPlayers().getName(warp).toLowerCase().startsWith(split[1].toLowerCase())) {
foundWarp = warp;
}
}
}
if (foundWarp == null) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).warpserrorDoesNotExist);
return true;
} else {
// Warp exists!
final Location warpSpot = plugin.getWarpSignsListener().getWarp(foundWarp);
// Check if the warp spot is safe
if (warpSpot == null) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).warpserrorNotReadyYet);
plugin.getLogger().warning("Null warp found, owned by " + plugin.getPlayers().getName(foundWarp));
return true;
}
// Find out if island is locked
Island island = plugin.getGrid().getIslandAt(warpSpot);
// Check bans
if (island != null && plugin.getPlayers().isBanned(island.getOwner(), playerUUID)) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).banBanned.replace("[name]", plugin.getPlayers().getName(island.getOwner())));
if (!VaultHelper.checkPerm(player, Settings.PERMPREFIX + "mod.bypassprotect") && !VaultHelper.checkPerm(player, Settings.PERMPREFIX + "mod.bypasslock")) {
return true;
}
}
if (island != null && island.isLocked() && !player.isOp() && !VaultHelper.checkPerm(player, Settings.PERMPREFIX + "mod.bypasslock") && !VaultHelper.checkPerm(player, Settings.PERMPREFIX + "mod.bypassprotect")) {
// Always inform that the island is locked
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).lockIslandLocked);
// Check if this is the owner, team member or coop
if (!plugin.getGrid().locationIsAtHome(player, true, warpSpot)) {
// plugin.getLogger().info("DEBUG: not at home");
return true;
}
}
boolean pvp = false;
if ((warpSpot.getWorld().equals(ASkyBlock.getIslandWorld()) && island.getIgsFlag(SettingsFlag.PVP)) || (warpSpot.getWorld().equals(ASkyBlock.getNetherWorld()) && island.getIgsFlag(SettingsFlag.NETHER_PVP))) {
pvp = true;
}
// Find out which direction the warp is facing
Block b = warpSpot.getBlock();
if (b.getType().equals(Material.SIGN_POST) || b.getType().equals(Material.WALL_SIGN)) {
Sign sign = (Sign) b.getState();
org.bukkit.material.Sign s = (org.bukkit.material.Sign) sign.getData();
BlockFace directionFacing = s.getFacing();
Location inFront = b.getRelative(directionFacing).getLocation();
Location oneDown = b.getRelative(directionFacing).getRelative(BlockFace.DOWN).getLocation();
if ((GridManager.isSafeLocation(inFront))) {
warpPlayer(player, inFront, foundWarp, directionFacing, pvp);
return true;
} else if (b.getType().equals(Material.WALL_SIGN) && GridManager.isSafeLocation(oneDown)) {
// Try one block down if this is a wall sign
warpPlayer(player, oneDown, foundWarp, directionFacing, pvp);
return true;
}
} else {
// Warp has been removed
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).warpserrorDoesNotExist);
plugin.getWarpSignsListener().removeWarp(warpSpot);
return true;
}
if (!(GridManager.isSafeLocation(warpSpot))) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).warpserrorNotSafe);
// WALL_SIGN's will always be unsafe if the place in front is obscured.
if (b.getType().equals(Material.SIGN_POST)) {
plugin.getLogger().warning("Unsafe warp found at " + warpSpot.toString() + " owned by " + plugin.getPlayers().getName(foundWarp));
}
return true;
} else {
final Location actualWarp = new Location(warpSpot.getWorld(), warpSpot.getBlockX() + 0.5D, warpSpot.getBlockY(), warpSpot.getBlockZ() + 0.5D);
player.teleport(actualWarp);
if (pvp) {
Util.sendMessage(player, ChatColor.BOLD + "" + ChatColor.RED + plugin.myLocale(player.getUniqueId()).igs.get(SettingsFlag.PVP) + " " + plugin.myLocale(player.getUniqueId()).igsAllowed);
if (plugin.getServer().getVersion().contains("(MC: 1.8") || plugin.getServer().getVersion().contains("(MC: 1.7")) {
player.getWorld().playSound(player.getLocation(), Sound.valueOf("ARROW_HIT"), 1F, 1F);
} else {
player.getWorld().playSound(player.getLocation(), Sound.ENTITY_ARROW_HIT, 1F, 1F);
}
} else {
if (plugin.getServer().getVersion().contains("(MC: 1.8") || plugin.getServer().getVersion().contains("(MC: 1.7")) {
player.getWorld().playSound(player.getLocation(), Sound.valueOf("BAT_TAKEOFF"), 1F, 1F);
} else {
player.getWorld().playSound(player.getLocation(), Sound.ENTITY_BAT_TAKEOFF, 1F, 1F);
}
}
return true;
}
}
}
} else {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoPermission);
return true;
}
} else if (split[0].equalsIgnoreCase("level")) {
// island level <name> command
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.info")) {
// Find out if the target has an island
final UUID targetPlayerUUID = plugin.getPlayers().getUUID(split[1]);
// Invited player must be known
if (targetPlayerUUID == null) {
// plugin.getLogger().info("DEBUG: unknown player");
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorUnknownPlayer);
return true;
}
// Check if this player has an island or not
if (plugin.getPlayers().hasIsland(targetPlayerUUID) || plugin.getPlayers().inTeam(targetPlayerUUID)) {
calculateIslandLevel(player, targetPlayerUUID);
} else {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoIslandOther);
}
return true;
} else {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoPermission);
return true;
}
} else if (split[0].equalsIgnoreCase("invite")) {
// Team invite a player command
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "team.create")) {
// Only online players can be invited
Player invitedPlayer = plugin.getServer().getPlayer(split[1]);
if (invitedPlayer == null) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorOfflinePlayer);
return true;
}
final UUID invitedPlayerUUID = invitedPlayer.getUniqueId();
// Player issuing the command must have an island
if (!plugin.getPlayers().hasIsland(player.getUniqueId())) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).inviteerrorYouMustHaveIslandToInvite);
return true;
}
// Player cannot invite themselves
if (player.getUniqueId().equals(invitedPlayer.getUniqueId())) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).inviteerrorYouCannotInviteYourself);
return true;
}
// Check if this player can be invited to this island, or
// whether they are still on cooldown
long time = plugin.getPlayers().getInviteCoolDownTime(invitedPlayerUUID, plugin.getPlayers().getIslandLocation(playerUUID));
if (time > 0 && !player.isOp()) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).inviteerrorCoolDown.replace("[time]", String.valueOf(time)));
return true;
}
// the leader, etc
if (plugin.getPlayers().inTeam(player.getUniqueId())) {
// Leader?
if (teamLeader.equals(player.getUniqueId())) {
// Invited player is free and not in a team
if (!plugin.getPlayers().inTeam(invitedPlayerUUID)) {
// Player has space in 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) {
// time - interesting
if (inviteList.containsValue(playerUUID)) {
inviteList.remove(getKeyByValue(inviteList, player.getUniqueId()));
Util.sendMessage(player, ChatColor.YELLOW + plugin.myLocale(player.getUniqueId()).inviteremovingInvite);
}
// 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, player.getUniqueId());
Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(player.getUniqueId()).inviteinviteSentTo.replace("[name]", invitedPlayer.getName()));
// Send message to online player
Util.sendMessage(Bukkit.getPlayer(invitedPlayerUUID), plugin.myLocale(invitedPlayerUUID).invitenameHasInvitedYou.replace("[name]", player.getName()));
Util.sendMessage(Bukkit.getPlayer(invitedPlayerUUID), ChatColor.WHITE + "/" + label + " [accept/reject]" + ChatColor.YELLOW + " " + plugin.myLocale(invitedPlayerUUID).invitetoAcceptOrReject);
if (plugin.getPlayers().hasIsland(invitedPlayerUUID)) {
Util.sendMessage(Bukkit.getPlayer(invitedPlayerUUID), ChatColor.RED + plugin.myLocale(invitedPlayerUUID).invitewarningYouWillLoseIsland);
}
// Start timeout on invite
if (Settings.inviteTimeout > 0) {
plugin.getServer().getScheduler().runTaskLater(plugin, new Runnable() {
@Override
public void run() {
if (inviteList.containsKey(invitedPlayerUUID) && inviteList.get(invitedPlayerUUID).equals(playerUUID)) {
inviteList.remove(invitedPlayerUUID);
if (plugin.getServer().getPlayer(playerUUID) != null) {
Util.sendMessage(plugin.getServer().getPlayer(playerUUID), ChatColor.YELLOW + plugin.myLocale(player.getUniqueId()).inviteremovingInvite);
}
if (plugin.getServer().getPlayer(invitedPlayerUUID) != null) {
Util.sendMessage(plugin.getServer().getPlayer(invitedPlayerUUID), ChatColor.YELLOW + plugin.myLocale(player.getUniqueId()).inviteremovingInvite);
}
}
}
}, Settings.inviteTimeout);
}
} else {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).inviteerrorYourIslandIsFull);
}
} else {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).inviteerrorThatPlayerIsAlreadyInATeam);
}
} else {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).inviteerrorYouMustHaveIslandToInvite);
}
} else {
// Check if invitee is in a team or not
if (!plugin.getPlayers().inTeam(invitedPlayerUUID)) {
// it
if (inviteList.containsValue(playerUUID)) {
inviteList.remove(getKeyByValue(inviteList, player.getUniqueId()));
Util.sendMessage(player, ChatColor.YELLOW + plugin.myLocale(player.getUniqueId()).inviteremovingInvite);
}
// Place the player and invitee on the invite list
inviteList.put(invitedPlayerUUID, player.getUniqueId());
Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(player.getUniqueId()).inviteinviteSentTo.replace("[name]", invitedPlayer.getName()));
Util.sendMessage(Bukkit.getPlayer(invitedPlayerUUID), plugin.myLocale(invitedPlayerUUID).invitenameHasInvitedYou.replace("[name]", player.getName()));
Util.sendMessage(Bukkit.getPlayer(invitedPlayerUUID), ChatColor.WHITE + "/" + label + " [accept/reject]" + ChatColor.YELLOW + " " + plugin.myLocale(invitedPlayerUUID).invitetoAcceptOrReject);
// + invitedPlayerUUID.toString());
if (plugin.getPlayers().hasIsland(invitedPlayerUUID)) {
// plugin.getLogger().info("DEBUG: invited player has island");
Util.sendMessage(Bukkit.getPlayer(invitedPlayerUUID), ChatColor.RED + plugin.myLocale(invitedPlayerUUID).invitewarningYouWillLoseIsland);
}
// Start timeout on invite
if (Settings.inviteTimeout > 0) {
plugin.getServer().getScheduler().runTaskLater(plugin, new Runnable() {
@Override
public void run() {
if (inviteList.containsKey(invitedPlayerUUID) && inviteList.get(invitedPlayerUUID).equals(playerUUID)) {
inviteList.remove(invitedPlayerUUID);
if (plugin.getServer().getPlayer(playerUUID) != null) {
Util.sendMessage(plugin.getServer().getPlayer(playerUUID), ChatColor.YELLOW + plugin.myLocale(player.getUniqueId()).inviteremovingInvite);
}
if (plugin.getServer().getPlayer(invitedPlayerUUID) != null) {
Util.sendMessage(plugin.getServer().getPlayer(invitedPlayerUUID), ChatColor.YELLOW + plugin.myLocale(player.getUniqueId()).inviteremovingInvite);
}
}
}
}, Settings.inviteTimeout);
}
} else {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).inviteerrorThatPlayerIsAlreadyInATeam);
}
}
return true;
} else {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoPermission);
return true;
}
} else if (split[0].equalsIgnoreCase("coop")) {
// Give a player coop privileges
if (!VaultHelper.checkPerm(player, Settings.PERMPREFIX + "coop")) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoPermission);
return true;
}
// Only online players can be cooped
Player target = plugin.getServer().getPlayer(split[1]);
if (target == null) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorOfflinePlayer);
return true;
}
final UUID targetPlayerUUID = target.getUniqueId();
// Player issuing the command must have an island
if (!plugin.getPlayers().hasIsland(playerUUID) && !plugin.getPlayers().inTeam(playerUUID)) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).inviteerrorYouMustHaveIslandToInvite);
return true;
}
// Player cannot invite themselves
if (playerUUID.equals(targetPlayerUUID)) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).inviteerrorYouCannotInviteYourself);
return true;
}
// If target player is already on the team ignore
if (plugin.getPlayers().getMembers(playerUUID).contains(targetPlayerUUID)) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).coopOnYourTeam);
return true;
}
// Target has to have an island
if (!plugin.getPlayers().inTeam(targetPlayerUUID)) {
if (!plugin.getPlayers().hasIsland(targetPlayerUUID)) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoIslandOther);
return true;
}
}
// Check if this player can be invited to this island, or
// whether they are still on cooldown
long time = plugin.getPlayers().getInviteCoolDownTime(targetPlayerUUID, plugin.getPlayers().getIslandLocation(playerUUID));
if (time > 0 && !player.isOp()) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).inviteerrorCoolDown.replace("[time]", String.valueOf(time)));
return true;
}
// Send out coop invite
Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(player.getUniqueId()).inviteinviteSentTo.replace("[name]", target.getName()));
Util.sendMessage(target, ChatColor.GREEN + plugin.myLocale(targetPlayerUUID).coopHasInvited.replace("[name]", player.getName()));
Util.sendMessage(target, ChatColor.GREEN + Settings.ISLANDCOMMAND + " coopaccept/coopreject " + plugin.myLocale(targetPlayerUUID).invitetoAcceptOrReject);
coopInviteList.put(targetPlayerUUID, playerUUID);
if (Settings.inviteTimeout > 0) {
plugin.getServer().getScheduler().runTaskLater(plugin, new Runnable() {
@Override
public void run() {
if (coopInviteList.containsKey(targetPlayerUUID) && inviteList.get(targetPlayerUUID).equals(playerUUID)) {
inviteList.remove(targetPlayerUUID);
if (plugin.getServer().getPlayer(playerUUID) != null) {
Util.sendMessage(plugin.getServer().getPlayer(playerUUID), ChatColor.YELLOW + plugin.myLocale(player.getUniqueId()).inviteremovingInvite);
}
if (plugin.getServer().getPlayer(targetPlayerUUID) != null) {
Util.sendMessage(plugin.getServer().getPlayer(targetPlayerUUID), ChatColor.YELLOW + plugin.myLocale(player.getUniqueId()).inviteremovingInvite);
}
}
}
}, Settings.inviteTimeout);
}
return true;
} else if (split[0].equalsIgnoreCase("expel")) {
if (!VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.expel")) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoPermission);
return true;
}
// Find out who they want to expel
UUID targetPlayerUUID = plugin.getPlayers().getUUID(split[1]);
if (targetPlayerUUID == null) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorUnknownPlayer);
return true;
}
// Target should not be themselves
if (targetPlayerUUID.equals(playerUUID)) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).expelNotYourself);
return true;
}
// Target cannot be op
Player target = plugin.getServer().getPlayer(targetPlayerUUID);
if (target != null) {
if (target.isOp() || VaultHelper.checkPerm(target, Settings.PERMPREFIX + "mod.bypassprotect") || VaultHelper.checkPerm(target, Settings.PERMPREFIX + "mod.bypassexpel")) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).expelFail.replace("[name]", target.getName()));
return true;
}
}
// Remove them from the coop list
boolean coop = CoopPlay.getInstance().removeCoopPlayer(player, targetPlayerUUID);
if (coop) {
if (target != null) {
Util.sendMessage(target, ChatColor.RED + plugin.myLocale(target.getUniqueId()).coopRemoved.replace("[name]", player.getName()));
} else {
plugin.getMessages().setMessage(targetPlayerUUID, ChatColor.RED + plugin.myLocale(targetPlayerUUID).coopRemoved.replace("[name]", player.getName()));
}
Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(player.getUniqueId()).coopRemoveSuccess.replace("[name]", plugin.getPlayers().getName(targetPlayerUUID)));
}
// See if target is on this player's island
if (target != null && plugin.getGrid().isOnIsland(player, target)) {
// helping out
if (plugin.getPlayers().inTeam(targetPlayerUUID) || plugin.getPlayers().hasIsland(targetPlayerUUID)) {
plugin.getGrid().homeTeleport(target);
} else {
// Just move target to spawn
if (!target.performCommand(Settings.SPAWNCOMMAND)) {
target.teleport(player.getWorld().getSpawnLocation());
/*
* target.sendBlockChange(target.getWorld().
* getSpawnLocation()
* ,target.getWorld().getSpawnLocation().getBlock().
* getType()
* ,target.getWorld().getSpawnLocation().getBlock().
* getData());
*/
}
}
Util.sendMessage(target, ChatColor.RED + plugin.myLocale(target.getUniqueId()).expelExpelled);
plugin.getLogger().info(player.getName() + " expelled " + target.getName() + " from their island.");
// Yes they are
Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(player.getUniqueId()).expelSuccess.replace("[name]", target.getName()));
} else if (!coop) {
// No they're not
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).expelNotOnIsland);
}
return true;
} else if (split[0].equalsIgnoreCase("uncoop")) {
if (!VaultHelper.checkPerm(player, Settings.PERMPREFIX + "coop")) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoPermission);
return true;
}
// Find out who they want to uncoop
UUID targetPlayerUUID = plugin.getPlayers().getUUID(split[1]);
if (targetPlayerUUID == null) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorUnknownPlayer);
return true;
}
// Target should not be themselves
if (targetPlayerUUID.equals(playerUUID)) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).expelNotYourself);
return true;
}
OfflinePlayer target = plugin.getServer().getOfflinePlayer(targetPlayerUUID);
// Remove them from the coop list
boolean coop = CoopPlay.getInstance().removeCoopPlayer(player, targetPlayerUUID);
if (coop) {
if (target != null && target.isOnline()) {
Util.sendMessage(target.getPlayer(), ChatColor.RED + plugin.myLocale(target.getUniqueId()).coopRemoved.replace("[name]", player.getName()));
} else {
plugin.getMessages().setMessage(targetPlayerUUID, ChatColor.RED + plugin.myLocale(targetPlayerUUID).coopRemoved.replace("[name]", player.getName()));
}
Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(player.getUniqueId()).coopRemoveSuccess.replace("[name]", plugin.getPlayers().getName(targetPlayerUUID)));
} else {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).coopNotInCoop.replace("[name]", plugin.getPlayers().getName(targetPlayerUUID)));
}
return true;
} else if (split[0].equalsIgnoreCase("ban")) {
if (!VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.ban")) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoPermission);
return true;
}
// Find out who they want to ban
final UUID targetPlayerUUID = plugin.getPlayers().getUUID(split[1]);
// Player must be known
if (targetPlayerUUID == null) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorUnknownPlayer);
return true;
}
// Target should not be themselves
if (targetPlayerUUID.equals(playerUUID)) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).banNotYourself);
return true;
}
// Target cannot be on the same team
if (plugin.getPlayers().inTeam(playerUUID) && plugin.getPlayers().inTeam(targetPlayerUUID)) {
if (plugin.getPlayers().getTeamLeader(playerUUID).equals(plugin.getPlayers().getTeamLeader(targetPlayerUUID))) {
// Same team!
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).banNotTeamMember);
return true;
}
}
// Check that the player is not banned already
if (plugin.getPlayers().isBanned(playerUUID, targetPlayerUUID)) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).banAlreadyBanned.replace("[name]", split[1]));
return true;
}
// Check online/offline status
Player target = plugin.getServer().getPlayer(targetPlayerUUID);
// Get offline player
OfflinePlayer offlineTarget = plugin.getServer().getOfflinePlayer(targetPlayerUUID);
// Target cannot be op
if (offlineTarget.isOp()) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).banFail.replace("[name]", split[1]));
return true;
}
if (target != null) {
// Do not ban players with the mod.noban permission
if (VaultHelper.checkPerm(target, Settings.PERMPREFIX + "admin.noban")) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).banFail.replace("[name]", split[1]));
return true;
}
// Remove them from the coop list
boolean coop = CoopPlay.getInstance().removeCoopPlayer(player, target);
if (coop) {
Util.sendMessage(target, ChatColor.RED + plugin.myLocale(target.getUniqueId()).coopRemoved.replace("[name]", player.getName()));
Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(player.getUniqueId()).coopRemoveSuccess.replace("[name]", target.getName()));
}
// See if target is on this player's island and if so send them away
if (plugin.getGrid().isOnIsland(player, target)) {
// helping out
if (plugin.getPlayers().inTeam(targetPlayerUUID) || plugin.getPlayers().hasIsland(targetPlayerUUID)) {
plugin.getGrid().homeTeleport(target);
} else {
// Just move target to spawn
if (!target.performCommand(Settings.SPAWNCOMMAND)) {
target.teleport(player.getWorld().getSpawnLocation());
}
}
}
// Notifications
// Target
Util.sendMessage(target, ChatColor.RED + plugin.myLocale(targetPlayerUUID).banBanned.replace("[name]", player.getName()));
} else {
// Offline notification
plugin.getMessages().setMessage(targetPlayerUUID, ChatColor.RED + plugin.myLocale(targetPlayerUUID).banBanned.replace("[name]", player.getName()));
}
// Console
plugin.getLogger().info(player.getName() + " banned " + split[1] + " from their island.");
// Player
Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(player.getUniqueId()).banSuccess.replace("[name]", split[1]));
// Tell team
plugin.getMessages().tellTeam(playerUUID, ChatColor.GREEN + plugin.myLocale(player.getUniqueId()).banSuccess.replace("[name]", split[1]));
plugin.getMessages().tellOfflineTeam(playerUUID, ChatColor.GREEN + plugin.myLocale(player.getUniqueId()).banSuccess.replace("[name]", split[1]));
// Ban the sucker
plugin.getPlayers().ban(playerUUID, targetPlayerUUID);
plugin.getGrid().saveGrid();
return true;
} else if (split[0].equalsIgnoreCase("unban")) {
if (!VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.ban")) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoPermission);
return true;
}
// Find out who they want to unban
final UUID targetPlayerUUID = plugin.getPlayers().getUUID(split[1]);
// Player must be known
if (targetPlayerUUID == null) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorUnknownPlayer);
return true;
}
// Target should not be themselves
if (targetPlayerUUID.equals(playerUUID)) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).banNotYourself);
return true;
}
// Check that the player is actually banned
if (!plugin.getPlayers().isBanned(playerUUID, targetPlayerUUID)) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).banNotBanned.replace("[name]", split[1]));
return true;
}
// Notifications
// Online check
Player target = plugin.getServer().getPlayer(targetPlayerUUID);
// Target
if (target != null) {
// Online
Util.sendMessage(target, ChatColor.RED + plugin.myLocale(target.getUniqueId()).banLifted.replace("[name]", player.getName()));
} else {
plugin.getMessages().setMessage(targetPlayerUUID, ChatColor.GREEN + plugin.myLocale(targetPlayerUUID).banLifted.replace("[name]", player.getName()));
}
// OfflinePlayer offlineTarget = plugin.getServer().getOfflinePlayer(targetPlayerUUID);
// Player
Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(player.getUniqueId()).banLiftedSuccess.replace("[name]", split[1]));
// Console
plugin.getLogger().info(player.getName() + " unbanned " + split[1] + " from their island.");
// Tell team
plugin.getMessages().tellTeam(playerUUID, ChatColor.GREEN + plugin.myLocale(player.getUniqueId()).banLiftedSuccess.replace("[name]", split[1]));
plugin.getMessages().tellOfflineTeam(playerUUID, ChatColor.GREEN + plugin.myLocale(player.getUniqueId()).banLiftedSuccess.replace("[name]", split[1]));
// Unban the redeemed one
plugin.getPlayers().unBan(playerUUID, targetPlayerUUID);
plugin.getGrid().saveGrid();
return true;
} else if (split[0].equalsIgnoreCase("kick") || split[0].equalsIgnoreCase("remove")) {
// command
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "team.kick")) {
if (!plugin.getPlayers().inTeam(playerUUID)) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).kickerrorNoTeam);
return true;
}
// Only leaders can kick
if (teamLeader != null && !teamLeader.equals(playerUUID)) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).kickerrorOnlyLeaderCan);
return true;
}
// The main thing to do is check if the player name to kick
// is in the list of players in the team.
targetPlayer = null;
for (UUID member : teamMembers) {
if (plugin.getPlayers().getName(member).equalsIgnoreCase(split[1])) {
targetPlayer = member;
}
}
if (targetPlayer == null) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).kickerrorNotPartOfTeam);
return true;
}
if (teamMembers.contains(targetPlayer)) {
// themselves
if (player.getUniqueId().equals(targetPlayer)) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).leaveerrorLeadersCannotLeave);
return true;
}
// Try to kick player
if (!removePlayerFromTeam(targetPlayer, teamLeader)) {
// If this is canceled, fail silently
return true;
}
// Log the location that this player left so they
// cannot join again before the cool down ends
plugin.getPlayers().startInviteCoolDownTimer(targetPlayer, plugin.getPlayers().getIslandLocation(playerUUID));
if (Settings.resetChallenges) {
// Reset the player's challenge status
plugin.getPlayers().resetAllChallenges(targetPlayer, false);
}
// Reset the island level
plugin.getPlayers().setIslandLevel(targetPlayer, 0);
TopTen.topTenAddEntry(playerUUID, 0);
// If target is online
Player target = plugin.getServer().getPlayer(targetPlayer);
if (target != null) {
// plugin.getLogger().info("DEBUG: player is online");
Util.sendMessage(target, ChatColor.RED + plugin.myLocale(targetPlayer).kicknameRemovedYou.replace("[name]", player.getName()));
// Clear any coop inventories
// CoopPlay.getInstance().returnAllInventories(target);
// Remove any of the target's coop invitees and
// anyone they invited
CoopPlay.getInstance().clearMyInvitedCoops(target);
CoopPlay.getInstance().clearMyCoops(target);
// leader
if (target.getWorld().equals(ASkyBlock.getIslandWorld())) {
if (!Settings.kickedKeepInv) {
for (ItemStack i : target.getInventory().getContents()) {
if (i != null) {
try {
// Fire an event to see if this item should be dropped or not
// Some plugins may not want items to be dropped
Item drop = player.getWorld().dropItemNaturally(player.getLocation(), i);
PlayerDropItemEvent event = new PlayerDropItemEvent(target, drop);
plugin.getServer().getPluginManager().callEvent(event);
} catch (Exception e) {
}
}
}
// plugin.resetPlayer(target); <- no good if
// reset inventory is false
// Clear their inventory and equipment and set
// them as survival
// Javadocs are
target.getInventory().clear();
// wrong - this
// does not
// clear armor slots! So...
// plugin.getLogger().info("DEBUG: Clearing kicked player's inventory");
target.getInventory().setArmorContents(null);
target.getInventory().setHelmet(null);
target.getInventory().setChestplate(null);
target.getInventory().setLeggings(null);
target.getInventory().setBoots(null);
target.getEquipment().clear();
// Update the inventory
target.updateInventory();
}
}
if (!target.performCommand(Settings.SPAWNCOMMAND)) {
target.teleport(ASkyBlock.getIslandWorld().getSpawnLocation());
}
} else {
// Offline
if (DEBUG)
plugin.getLogger().info("DEBUG: player is offline " + targetPlayer.toString());
// Tell offline player they were kicked
plugin.getMessages().setMessage(targetPlayer, ChatColor.RED + plugin.myLocale(player.getUniqueId()).kicknameRemovedYou.replace("[name]", player.getName()));
}
// Remove any warps
plugin.getWarpSignsListener().removeWarp(targetPlayer);
// Tell leader they removed the player
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).kicknameRemoved.replace("[name]", split[1]));
// removePlayerFromTeam(targetPlayer, teamLeader);
teamMembers.remove(targetPlayer);
if (teamMembers.size() < 2) {
if (!removePlayerFromTeam(player.getUniqueId(), teamLeader)) {
// If cancelled, return silently
return true;
}
}
plugin.getPlayers().save(targetPlayer);
} else {
plugin.getLogger().warning("Player " + player.getName() + " failed to remove " + plugin.getPlayers().getName(targetPlayer));
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).kickerrorNotPartOfTeam);
}
return true;
} else {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoPermission);
return true;
}
} else if (split[0].equalsIgnoreCase("makeleader")) {
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "team.makeleader")) {
targetPlayer = plugin.getPlayers().getUUID(split[1]);
if (targetPlayer == null) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorUnknownPlayer);
return true;
}
if (targetPlayer.equals(playerUUID)) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).makeLeadererrorGeneralError);
return true;
}
if (!plugin.getPlayers().inTeam(player.getUniqueId())) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).makeLeadererrorYouMustBeInTeam);
return true;
}
if (plugin.getPlayers().getMembers(player.getUniqueId()).size() > 2) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).makeLeadererrorRemoveAllPlayersFirst);
plugin.getLogger().info(player.getName() + " tried to transfer his island, but failed because >2 people in a team");
return true;
}
if (plugin.getPlayers().inTeam(player.getUniqueId())) {
if (teamLeader.equals(player.getUniqueId())) {
if (teamMembers.contains(targetPlayer)) {
// Remove the target player from the team
if (!removePlayerFromTeam(targetPlayer, teamLeader, true)) {
// If cancelled, return silently
return true;
}
// Remove the leader from the team
if (!removePlayerFromTeam(teamLeader, teamLeader, true)) {
// If cancelled, return silently
return true;
}
Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(player.getUniqueId()).makeLeadernameIsNowTheOwner.replace("[name]", plugin.getPlayers().getName(targetPlayer)));
// plugin.getLogger().info("DEBUG: " +
// plugin.getPlayers().getIslandLevel(teamLeader));
// Transfer the data from the old leader to the
// new one
plugin.getGrid().transferIsland(player.getUniqueId(), targetPlayer);
// Create a new team with
addPlayertoTeam(player.getUniqueId(), targetPlayer);
addPlayertoTeam(targetPlayer, targetPlayer);
// Check if online
Player target = plugin.getServer().getPlayer(targetPlayer);
if (target == null) {
plugin.getMessages().setMessage(targetPlayer, plugin.myLocale(player.getUniqueId()).makeLeaderyouAreNowTheOwner);
} else {
// Online
Util.sendMessage(plugin.getServer().getPlayer(targetPlayer), ChatColor.GREEN + plugin.myLocale(targetPlayer).makeLeaderyouAreNowTheOwner);
// 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 = plugin.getGrid().getIsland(targetPlayer);
if (islandByOwner.getProtectionSize() == 0) {
plugin.getLogger().warning("Player " + player.getName() + "'s island had a protection range of 0. Setting to default " + range);
islandByOwner.setProtectionSize(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--;
}
// Range can go up or down
if (range != islandByOwner.getProtectionSize()) {
Util.sendMessage(player, ChatColor.GOLD + plugin.myLocale(targetPlayer).adminSetRangeUpdated.replace("[number]", String.valueOf(range)));
Util.sendMessage(target, ChatColor.GOLD + plugin.myLocale(targetPlayer).adminSetRangeUpdated.replace("[number]", String.valueOf(range)));
plugin.getLogger().info("Makeleader: Island protection range changed from " + islandByOwner.getProtectionSize() + " to " + range + " for " + player.getName() + " due to permission.");
}
islandByOwner.setProtectionSize(range);
}
}
plugin.getGrid().saveGrid();
return true;
}
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).makeLeadererrorThatPlayerIsNotInTeam);
} else {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).makeLeadererrorNotYourIsland);
}
} else {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).makeLeadererrorGeneralError);
}
return true;
} else {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoPermission);
return true;
}
} else {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).errorUnknownCommand);
return true;
}
break;
}
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).errorUnknownCommand);
return true;
}
use of com.wasteofplastic.acidisland.ASLocale in project acidisland by tastybento.
the class AdminCmd method onCommand.
/*
* (non-Javadoc)
* @see
* org.bukkit.command.CommandExecutor#onCommand(org.bukkit.command.CommandSender
* , org.bukkit.command.Command, java.lang.String, java.lang.String[])
*/
@Override
public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] split) {
// Console commands
Player player;
if (sender instanceof Player) {
player = (Player) sender;
if (player.getUniqueId() == null) {
return false;
}
if (split.length > 0) {
// Admin-only commands : reload, register, delete and purge
if (split[0].equalsIgnoreCase("reload") || split[0].equalsIgnoreCase("register") || split[0].equalsIgnoreCase("delete") || split[0].equalsIgnoreCase("purge") || split[0].equalsIgnoreCase("confirm") || split[0].equalsIgnoreCase("setspawn") || split[0].equalsIgnoreCase("deleteisland") || split[0].equalsIgnoreCase("setrange") || split[0].equalsIgnoreCase("reserve") || split[0].equalsIgnoreCase("addrange") || split[0].equalsIgnoreCase("unregister") || split[0].equalsIgnoreCase("clearresetall") || split[0].equalsIgnoreCase("settingsreset") || split[0].equalsIgnoreCase("cobblestats") || split[0].equalsIgnoreCase("setlanguage")) {
if (!checkAdminPerms(player, split)) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoPermission);
return true;
}
} else {
// Mod commands
if (!checkModPerms(player, split)) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoPermission);
return true;
}
}
}
}
// Island name (can have spaces)
if (split.length > 1 && split[0].equalsIgnoreCase("name")) {
final UUID playerUUID = plugin.getPlayers().getUUID(split[1], true);
// + playerUUID);
if (!plugin.getPlayers().isAKnownPlayer(playerUUID)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorUnknownPlayer);
return true;
} else {
if (split.length == 2) {
// Say the island name
Util.sendMessage(sender, plugin.getGrid().getIslandName(playerUUID));
} else {
String name = split[2];
for (int i = 3; i < split.length; i++) {
name = name + " " + split[i];
}
if (name.length() < Settings.minNameLength) {
Util.sendMessage(sender, ChatColor.RED + (plugin.myLocale().errorTooShort).replace("[length]", String.valueOf(Settings.minNameLength)));
return true;
}
if (name.length() > Settings.maxNameLength) {
Util.sendMessage(sender, ChatColor.RED + (plugin.myLocale().errorTooLong).replace("[length]", String.valueOf(Settings.maxNameLength)));
return true;
}
plugin.getGrid().setIslandName(playerUUID, ChatColor.translateAlternateColorCodes('&', name));
Util.sendMessage(sender, ChatColor.GREEN + plugin.myLocale().generalSuccess);
}
return true;
}
}
// Check for zero parameters e.g., /asadmin
switch(split.length) {
case 0:
help(sender, label);
return true;
case 1:
if (split[0].equalsIgnoreCase("setlanguage")) {
Util.sendMessage(sender, plugin.myLocale().helpColor + plugin.myLocale().adminHelpsetLanguage);
return true;
}
if (split[0].equalsIgnoreCase("listchallengeresets")) {
// Reset the challenge now
for (String challenge : plugin.getChallenges().getRepeatingChallengeResets()) {
Util.sendMessage(sender, ChatColor.GREEN + challenge);
}
return true;
} else if (split[0].equalsIgnoreCase("cobblestats")) {
if (LavaCheck.getStats().size() == 0) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().banNone);
return true;
}
// Display by level
for (Long level : LavaCheck.getStats().keySet()) {
if (level == Long.MIN_VALUE) {
Util.sendMessage(sender, plugin.myLocale().challengeslevel + ": Default");
} else {
Util.sendMessage(sender, plugin.myLocale().challengeslevel + ": " + level);
}
// Collect and sort
Collection<String> result = new TreeSet<String>(Collator.getInstance());
for (Material mat : LavaCheck.getStats().get(level).elementSet()) {
result.add(" " + Util.prettifyText(mat.toString()) + ": " + LavaCheck.getStats().get(level).count(mat) + "/" + LavaCheck.getStats().get(level).size() + " or " + ((long) ((double) LavaCheck.getStats().get(level).count(mat) / LavaCheck.getStats().get(level).size() * 100)) + "% (config = " + String.valueOf(LavaCheck.getConfigChances(level, mat)) + "%)");
}
// Send to player
for (String r : result) {
Util.sendMessage(sender, r);
}
}
return true;
}
if (split[0].equalsIgnoreCase("setdeaths")) {
Util.sendMessage(sender, plugin.myLocale().helpColor + label + " setdeaths <player> <number>:" + ChatColor.WHITE + " " + plugin.myLocale().adminHelpsetDeaths);
return true;
} else if (split[0].equalsIgnoreCase("settingsreset")) {
Util.sendMessage(sender, plugin.myLocale().helpColor + label + " settingsreset help");
return true;
} else if (Settings.teamChat && split[0].equalsIgnoreCase("spy")) {
if (!(sender instanceof Player)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().adminLockerrorInGame);
return true;
}
player = (Player) sender;
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "mod.spy") || player.isOp()) {
if (plugin.getChatListener().toggleSpy(player.getUniqueId())) {
Util.sendMessage(sender, ChatColor.GREEN + plugin.myLocale().teamChatSpyStatusOn);
} else {
Util.sendMessage(sender, ChatColor.GREEN + plugin.myLocale().teamChatSpyStatusOff);
}
return true;
}
} else if (split[0].equalsIgnoreCase("lock")) {
// Just /asadmin lock
if (!(sender instanceof Player)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().adminLockerrorInGame);
return true;
}
player = (Player) sender;
Island island = plugin.getGrid().getIslandAt(player.getLocation());
// Check if island exists
if (island == null) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNotOnIsland);
return true;
} else {
Player owner = plugin.getServer().getPlayer(island.getOwner());
if (island.isLocked()) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().lockUnlocking);
island.setLocked(false);
if (owner != null) {
Util.sendMessage(owner, plugin.myLocale(owner.getUniqueId()).adminLockadminUnlockedIsland);
} else {
plugin.getMessages().setMessage(island.getOwner(), plugin.myLocale(island.getOwner()).adminLockadminUnlockedIsland);
}
} else {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().lockLocking);
island.setLocked(true);
if (owner != null) {
Util.sendMessage(owner, plugin.myLocale(owner.getUniqueId()).adminLockadminLockedIsland);
} else {
plugin.getMessages().setMessage(island.getOwner(), plugin.myLocale(island.getOwner()).adminLockadminLockedIsland);
}
}
return true;
}
} else // Find farms
if (split[0].equalsIgnoreCase("topbreeders")) {
// Go through each island and find how many farms there are
Util.sendMessage(sender, plugin.myLocale().adminTopBreedersFinding);
// TreeMap<Integer, List<UUID>> topEntityIslands = new TreeMap<Integer, List<UUID>>();
// Generate the stats
Util.sendMessage(sender, plugin.myLocale().adminTopBreedersChecking.replace("[number]", String.valueOf(plugin.getGrid().getOwnershipMap().size())));
// Try just finding every entity
final List<Entity> allEntities = ASkyBlock.getIslandWorld().getEntities();
final World islandWorld = ASkyBlock.getIslandWorld();
final World netherWorld = ASkyBlock.getNetherWorld();
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
@Override
public void run() {
Map<UUID, Multiset<EntityType>> result = new HashMap<UUID, Multiset<EntityType>>();
// Find out where the entities are
for (Entity entity : allEntities) {
// System.out.println("DEBUG " + entity.getType().toString());
if (entity.getLocation().getWorld().equals(islandWorld) || entity.getLocation().getWorld().equals(netherWorld)) {
// System.out.println("DEBUG in world");
if (entity instanceof Creature && !(entity instanceof Player)) {
// System.out.println("DEBUG creature");
// Find out where it is
Island island = plugin.getGrid().getIslandAt(entity.getLocation());
if (island != null && !island.isSpawn()) {
// System.out.println("DEBUG on island");
// Add to result
UUID owner = island.getOwner();
Multiset<EntityType> count = result.get(owner);
if (count == null) {
// New entry for owner
// System.out.println("DEBUG new entry for owner");
count = HashMultiset.create();
}
count.add(entity.getType());
result.put(owner, count);
}
}
}
}
// Sort by the number of entities on each island
TreeMap<Integer, List<UUID>> topEntityIslands = new TreeMap<Integer, List<UUID>>();
for (Entry<UUID, Multiset<EntityType>> entry : result.entrySet()) {
int numOfEntities = entry.getValue().size();
List<UUID> players = topEntityIslands.get(numOfEntities);
if (players == null) {
players = new ArrayList<UUID>();
}
players.add(entry.getKey());
topEntityIslands.put(numOfEntities, players);
}
final TreeMap<Integer, List<UUID>> topBreeders = topEntityIslands;
final Map<UUID, Multiset<EntityType>> finalResult = result;
// Now display results in sync thread
plugin.getServer().getScheduler().runTask(plugin, new Runnable() {
@Override
public void run() {
if (topBreeders.isEmpty()) {
Util.sendMessage(sender, plugin.myLocale().adminTopBreedersNothing);
return;
}
int rank = 1;
// Display, largest first
for (int numOfEntities : topBreeders.descendingKeySet()) {
// Only bother if there's more that 5 animals
if (numOfEntities > 5) {
// There can be multiple owners in the same position
List<UUID> owners = topBreeders.get(numOfEntities);
// Go through the owners one by one
for (UUID owner : owners) {
Util.sendMessage(sender, "#" + rank + " " + plugin.getPlayers().getName(owner) + " = " + numOfEntities);
String content = "";
Multiset<EntityType> entityCount = finalResult.get(owner);
for (EntityType entity : entityCount.elementSet()) {
int num = entityCount.count(entity);
String color = ChatColor.GREEN.toString();
if (num > 10 && num <= 20) {
color = ChatColor.YELLOW.toString();
} else if (num > 20 && num <= 40) {
color = ChatColor.GOLD.toString();
} else if (num > 40) {
color = ChatColor.RED.toString();
}
content += Util.prettifyText(entity.toString()) + " x " + color + num + ChatColor.WHITE + ", ";
}
int lastComma = content.lastIndexOf(",");
// lastComma);
if (lastComma > 0) {
content = content.substring(0, lastComma);
}
Util.sendMessage(sender, " " + content);
}
rank++;
if (rank > 10) {
break;
}
}
}
// If we didn't show anything say so
if (rank == 1) {
Util.sendMessage(sender, plugin.myLocale().adminTopBreedersNothing);
}
}
});
}
});
return true;
}
// Delete island
if (split[0].equalsIgnoreCase("deleteisland")) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().adminDeleteIslandError);
return true;
}
// Set spawn
if (split[0].equalsIgnoreCase("setspawn")) {
// Find the closest island
if (!(sender instanceof Player)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorUseInGame);
return true;
}
player = (Player) sender;
// Island spawn must be in the island world
if (!player.getLocation().getWorld().getName().equals(Settings.worldName)) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorWrongWorld);
return true;
}
// The island location is calculated based on the grid
Location closestIsland = getClosestIsland(player.getLocation());
Island oldSpawn = plugin.getGrid().getSpawn();
Island newSpawn = plugin.getGrid().getIslandAt(closestIsland);
if (newSpawn != null && newSpawn.isSpawn()) {
// Already spawn, so just set the world spawn coords
plugin.getGrid().setSpawnPoint(player.getLocation());
// ASkyBlock.getIslandWorld().setSpawnLocation(player.getLocation().getBlockX(), player.getLocation().getBlockY(), player.getLocation().getBlockZ());
Util.sendMessage(sender, ChatColor.GREEN + plugin.myLocale().adminSetSpawnset);
return true;
}
// Space otherwise occupied - find if anyone owns it
if (newSpawn != null && newSpawn.getOwner() != null) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().adminSetSpawnownedBy.replace("[name]", plugin.getPlayers().getName(newSpawn.getOwner())));
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().adminSetSpawnmove);
return true;
}
if (oldSpawn != null) {
Util.sendMessage(sender, ChatColor.GOLD + "Changing spawn island location. Warning: old spawn island location at " + oldSpawn.getCenter().getBlockX() + "," + oldSpawn.getCenter().getBlockZ() + " will be at risk of being overwritten with new islands. Recommend to clear that old area.");
plugin.getGrid().deleteSpawn();
}
// New spawn site is free, so make it official
if (newSpawn == null) {
// Make the new spawn
newSpawn = plugin.getGrid().addIsland(closestIsland.getBlockX(), closestIsland.getBlockZ());
// Set the default spawn island settings
newSpawn.setSpawnDefaults();
}
plugin.getGrid().setSpawn(newSpawn);
plugin.getGrid().setSpawnPoint(player.getLocation());
// ASkyBlock.getIslandWorld().setSpawnLocation(player.getLocation().getBlockX(), player.getLocation().getBlockY(), player.getLocation().getBlockZ());
Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale().adminSetSpawnsetting.replace("[location]", player.getLocation().getBlockX() + "," + player.getLocation().getBlockZ()));
Util.sendMessage(player, ChatColor.YELLOW + plugin.myLocale().adminSetSpawncenter.replace("[location]", newSpawn.getCenter().getBlockX() + "," + newSpawn.getCenter().getBlockZ()));
Util.sendMessage(player, ChatColor.YELLOW + (plugin.myLocale().adminSetSpawnlimits.replace("[min]", newSpawn.getMinX() + "," + newSpawn.getMinZ())).replace("[max]", (newSpawn.getMinX() + newSpawn.getIslandDistance() - 1) + "," + (newSpawn.getMinZ() + newSpawn.getIslandDistance() - 1)));
Util.sendMessage(player, ChatColor.YELLOW + plugin.myLocale().adminSetSpawnrange.replace("[number]", String.valueOf(newSpawn.getProtectionSize())));
Util.sendMessage(player, ChatColor.YELLOW + (plugin.myLocale().adminSetSpawncoords.replace("[min]", newSpawn.getMinProtectedX() + ", " + newSpawn.getMinProtectedZ())).replace("[max]", +(newSpawn.getMinProtectedX() + newSpawn.getProtectionSize() - 1) + ", " + (newSpawn.getMinProtectedZ() + newSpawn.getProtectionSize() - 1)));
if (newSpawn.isLocked()) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale().adminSetSpawnlocked);
}
// Save grid async
plugin.getGrid().saveGrid(true);
return true;
} else if (split[0].equalsIgnoreCase("info") || split[0].equalsIgnoreCase("setrange")) {
// Find the closest island
if (!(sender instanceof Player)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorUseInGame);
return true;
}
Location closestIsland = getClosestIsland(((Player) sender).getLocation());
if (closestIsland == null) {
Util.sendMessage(sender, ChatColor.RED + "Sorry, could not find an island. Move closer?");
return true;
}
Island island = plugin.getGrid().getIslandAt(closestIsland);
if (island != null && island.isSpawn()) {
Util.sendMessage(sender, ChatColor.GREEN + plugin.myLocale().adminInfotitle);
Util.sendMessage(sender, ChatColor.YELLOW + plugin.myLocale().adminSetSpawncenter.replace("[location]", island.getCenter().getBlockX() + "," + island.getCenter().getBlockZ()));
Util.sendMessage(sender, ChatColor.YELLOW + (plugin.myLocale().adminSetSpawnlimits.replace("[min]", island.getMinX() + "," + island.getMinZ())).replace("[max]", (island.getMinX() + island.getIslandDistance() - 1) + "," + (island.getMinZ() + island.getIslandDistance() - 1)));
Util.sendMessage(sender, ChatColor.YELLOW + plugin.myLocale().adminSetSpawnrange.replace("[number]", String.valueOf(island.getProtectionSize())));
Util.sendMessage(sender, ChatColor.YELLOW + (plugin.myLocale().adminSetSpawncoords.replace("[min]", island.getMinProtectedX() + ", " + island.getMinProtectedZ())).replace("[max]", +(island.getMinProtectedX() + island.getProtectionSize() - 1) + ", " + (island.getMinProtectedZ() + island.getProtectionSize() - 1)));
if (island.isLocked()) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().adminSetSpawnlocked);
}
return true;
}
if (island == null) {
plugin.getLogger().info("Get island at was null" + closestIsland);
}
UUID target = plugin.getPlayers().getPlayerFromIslandLocation(closestIsland);
if (target == null) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().adminInfounowned);
return true;
}
showInfo(target, sender);
return true;
} else if (split[0].equalsIgnoreCase("resetsign")) {
// Find the closest island
if (!(sender instanceof Player)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorUseInGame);
return true;
}
player = (Player) sender;
if (!VaultHelper.checkPerm(player, Settings.PERMPREFIX + "mod.signadmin") && !player.isOp()) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoPermission);
return true;
}
// Find out whether the player is looking at a warp sign
// Look at what the player was looking at
BlockIterator iter = new BlockIterator(player, 10);
Block lastBlock = iter.next();
while (iter.hasNext()) {
lastBlock = iter.next();
if (lastBlock.getType() == Material.AIR)
continue;
break;
}
if (!lastBlock.getType().equals(Material.SIGN_POST)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale(player.getUniqueId()).adminResetSignNoSign);
return true;
}
// Check if it is a warp sign
Sign sign = (Sign) lastBlock.getState();
Util.sendMessage(sender, ChatColor.GREEN + plugin.myLocale(player.getUniqueId()).adminResetSignFound);
// Find out whose island this is
// plugin.getLogger().info("DEBUG: closest bedrock: " +
// closestBedRock.toString());
UUID target = plugin.getPlayers().getPlayerFromIslandLocation(player.getLocation());
if (target == null) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale(player.getUniqueId()).adminInfounowned);
return true;
}
if (plugin.getWarpSignsListener().addWarp(target, lastBlock.getLocation())) {
// Change sign color to green
sign.setLine(0, ChatColor.GREEN + plugin.myLocale().warpswelcomeLine);
sign.update(true, false);
Util.sendMessage(sender, ChatColor.GREEN + plugin.myLocale(player.getUniqueId()).adminResetSignRescued.replace("[name]", plugin.getPlayers().getName(target)));
return true;
}
// Warp already exists
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale(player.getUniqueId()).adminResetSignErrorExists.replace("[name]", plugin.getWarpSignsListener().getWarpOwner(lastBlock.getLocation())));
return true;
} else if (split[0].equalsIgnoreCase("reload")) {
// Remove temp permissions
plugin.getPlayerEvents().removeAllTempPerms();
plugin.reloadConfig();
PluginConfig.loadPluginConfig(plugin);
plugin.getChallenges().reloadChallengeConfig();
if (Settings.useEconomy && VaultHelper.setupEconomy()) {
ControlPanel.loadShop();
} else {
Settings.useEconomy = false;
}
ControlPanel.loadControlPanel();
if (Settings.updateCheck) {
plugin.checkUpdates();
} else {
plugin.setUpdateCheck(null);
}
plugin.getIslandCmd().loadSchematics();
if (plugin.getAcidTask() != null)
plugin.getAcidTask().runAcidItemRemovalTask();
// Give back any temporary permissions
plugin.getPlayerEvents().giveAllTempPerms();
// Reset resets if the admin changes it to or from unlimited
for (Player players : plugin.getServer().getOnlinePlayers()) {
UUID playerUUID = players.getUniqueId();
if (plugin.getPlayers().hasIsland(playerUUID) || plugin.getPlayers().inTeam(playerUUID)) {
if (Settings.resetLimit < plugin.getPlayers().getResetsLeft(playerUUID) || (Settings.resetLimit >= 0 && plugin.getPlayers().getResetsLeft(playerUUID) < 0)) {
plugin.getPlayers().setResetsLeft(playerUUID, Settings.resetLimit);
}
}
}
Util.sendMessage(sender, ChatColor.YELLOW + plugin.myLocale().reloadconfigReloaded);
return true;
} else if (split[0].equalsIgnoreCase("topten")) {
Util.sendMessage(sender, ChatColor.YELLOW + plugin.myLocale().adminTopTengenerating);
TopTen.topTenCreate(sender);
return true;
} else if (split[0].equalsIgnoreCase("purge")) {
if (purgeFlag) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().purgealreadyRunning);
return true;
}
Util.sendMessage(sender, ChatColor.YELLOW + plugin.myLocale().purgeusage.replace("[label]", label));
return true;
} else if (split[0].equalsIgnoreCase("confirm")) {
if (!confirmReq) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().confirmerrorTimeLimitExpired);
return true;
} else {
// Tell purge routine to go
confirmOK = true;
confirmReq = false;
}
return true;
} else // clearesetall - clears all player resets
if (split[0].equalsIgnoreCase("clearresetall")) {
if (asyncPending) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorCommandNotReady);
return true;
}
// Do online players first
plugin.getPlayers().clearResets(Settings.resetLimit);
// Do offline players
final File playerFolder = plugin.getPlayersFolder();
// Set the pending flag
asyncPending = true;
// Check against player files
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
@Override
public void run() {
// System.out.println("DEBUG: Running async task");
int done = 0;
// Check files against potentialUnowned
FilenameFilter ymlFilter = new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
String lowercaseName = name.toLowerCase();
if (lowercaseName.endsWith(".yml")) {
return true;
} else {
return false;
}
}
};
for (File file : playerFolder.listFiles(ymlFilter)) {
List<String> playerFileContents = new ArrayList<String>();
done++;
try {
Scanner scanner = new Scanner(file);
while (scanner.hasNextLine()) {
final String lineFromFile = scanner.nextLine();
if (lineFromFile.contains("resetsLeft:")) {
playerFileContents.add("resetsLeft: " + Settings.resetLimit);
} else {
playerFileContents.add(lineFromFile);
}
}
scanner.close();
// Write file
try (FileWriter writer = new FileWriter(file)) {
for (String str : playerFileContents) {
writer.write(str + "\n");
}
}
if (done % 500 == 0) {
final int update = done;
plugin.getServer().getScheduler().runTask(plugin, new Runnable() {
@Override
public void run() {
// Tell player
Util.sendMessage(sender, ChatColor.GREEN + plugin.myLocale().clearedResetLimit + " [" + update + " players]...");
}
});
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// System.out.println("DEBUG: scanning done");
asyncPending = false;
Util.sendMessage(sender, ChatColor.YELLOW + plugin.myLocale().clearedResetLimit + " [" + done + " players] completed.");
}
});
return true;
} else {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorUnknownCommand);
return false;
}
case 2:
if (split[0].equalsIgnoreCase("setlanguage")) {
if (asyncPending) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorCommandNotReady);
return true;
}
if (plugin.getAvailableLocales().keySet().contains(split[1])) {
// Change the config.yml setting without removing comments
try {
Util.setConfig("defaultlanguage", Settings.defaultLanguage, split[1]);
} catch (IOException e) {
Util.sendMessage(sender, ChatColor.RED + e.getMessage());
return true;
// e.printStackTrace();
}
plugin.getConfig().set("general.defaultlanguage", split[1]);
Settings.defaultLanguage = split[1];
// Load languages
HashMap<String, ASLocale> availableLocales = new HashMap<String, ASLocale>();
FileLister fl = new FileLister(plugin);
try {
int index = 1;
for (String code : fl.list()) {
// plugin.getLogger().info("DEBUG: lang file = " + code);
availableLocales.put(code, new ASLocale(plugin, code, index++));
}
} catch (IOException e1) {
plugin.getLogger().severe("Could not add locales!");
}
if (!availableLocales.containsKey(Settings.defaultLanguage)) {
plugin.getLogger().severe("'" + Settings.defaultLanguage + ".yml' not found in /locale folder. Using /locale/en-US.yml");
Settings.defaultLanguage = "en-US";
availableLocales.put(Settings.defaultLanguage, new ASLocale(plugin, Settings.defaultLanguage, 0));
}
plugin.setAvailableLocales(availableLocales);
// Run through all the players and set their languages
for (UUID onlinePlayer : plugin.getPlayers().getOnlineCachedPlayers()) {
plugin.getPlayers().setLocale(onlinePlayer, Settings.defaultLanguage);
}
// Prepare for the async check - make final
final File playerFolder = plugin.getPlayersFolder();
// Set the pending flag
asyncPending = true;
// Change player files
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
@Override
public void run() {
try {
Util.setPlayerYamlConfig(playerFolder, "locale", Settings.defaultLanguage);
// Run sync task
plugin.getServer().getScheduler().runTask(plugin, new Runnable() {
@Override
public void run() {
Util.sendMessage(sender, ChatColor.GREEN + plugin.myLocale().generalSuccess);
asyncPending = false;
}
});
} catch (final IOException e) {
// Run sync task
plugin.getServer().getScheduler().runTask(plugin, new Runnable() {
@Override
public void run() {
Util.sendMessage(sender, ChatColor.RED + e.getMessage());
asyncPending = false;
}
});
}
// System.out.println("DEBUG: scanning done");
}
});
Util.sendMessage(sender, ChatColor.RED + plugin.getAvailableLocales().keySet().toString());
}
return true;
} else if (split[0].equalsIgnoreCase("level")) {
// Convert name to a UUID
final UUID playerUUID = plugin.getPlayers().getUUID(split[1], true);
// + playerUUID);
if (playerUUID == null) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorUnknownPlayer);
return true;
} else {
if (sender instanceof Player) {
plugin.getIslandCmd().calculateIslandLevel(sender, playerUUID, false);
} else {
plugin.getIslandCmd().calculateIslandLevel(sender, playerUUID, true);
}
return true;
}
}
if (split[0].equalsIgnoreCase("clearchallengereset")) {
split[1] = split[1].toLowerCase();
if (!Settings.challengeList.contains(split[1])) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().resetChallengeerrorChallengeDoesNotExist);
return true;
}
// Clear challenge reset
plugin.getChallenges().clearChallengeReset(split[1]);
Util.sendMessage(sender, ChatColor.GREEN + plugin.myLocale().generalSuccess);
return true;
} else if (split[0].equalsIgnoreCase("resetchallengeforall")) {
if (!Settings.challengeList.contains(split[1].toLowerCase())) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().resetChallengeerrorChallengeDoesNotExist);
return true;
}
// Reset the challenge now
plugin.getChallenges().resetChallengeForAll(split[1].toLowerCase(), 0L, "");
Util.sendMessage(sender, ChatColor.GREEN + plugin.myLocale().generalSuccess);
return true;
} else if (split[0].equalsIgnoreCase("settingsreset")) {
plugin.reloadConfig();
PluginConfig.loadPluginConfig(plugin);
if (split[1].equalsIgnoreCase("all")) {
Util.sendMessage(sender, ChatColor.GREEN + plugin.myLocale().settingsResetInProgress);
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
@Override
public void run() {
for (Island island : plugin.getGrid().getOwnedIslands().values()) {
island.setIgsDefaults();
}
for (Island island : plugin.getGrid().getUnownedIslands().values()) {
island.setIgsDefaults();
}
plugin.getGrid().saveGrid();
// Go back to non-async world
plugin.getServer().getScheduler().runTask(plugin, new Runnable() {
@Override
public void run() {
// Reset any warp signs
plugin.getWarpPanel().updateAllWarpText();
Util.sendMessage(sender, ChatColor.GREEN + plugin.myLocale().settingsResetDone);
}
});
}
});
return true;
} else {
// Check if there is a flag here
for (SettingsFlag flag : SettingsFlag.values()) {
if (split[1].equalsIgnoreCase(flag.toString())) {
Util.sendMessage(sender, ChatColor.GREEN + plugin.myLocale().settingsResetInProgress);
final SettingsFlag flagToSet = flag;
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
@Override
public void run() {
for (Island island : plugin.getGrid().getOwnedIslands().values()) {
island.setIgsFlag(flagToSet, Settings.defaultIslandSettings.get(flagToSet));
}
for (Island island : plugin.getGrid().getUnownedIslands().values()) {
island.setIgsFlag(flagToSet, Settings.defaultIslandSettings.get(flagToSet));
}
plugin.getGrid().saveGrid();
// Go back to non-async world
plugin.getServer().getScheduler().runTask(plugin, new Runnable() {
@Override
public void run() {
if (flagToSet.equals(SettingsFlag.PVP) || flagToSet.equals(SettingsFlag.NETHER_PVP)) {
// Reset any warp signs
plugin.getWarpPanel().updateAllWarpText();
}
Util.sendMessage(sender, ChatColor.GREEN + plugin.myLocale().settingsResetDone);
}
});
}
});
return true;
}
}
// Show help
Util.sendMessage(sender, plugin.myLocale().helpColor + "/" + label + " settingsreset [help | all | flag]:" + ChatColor.WHITE + " " + plugin.myLocale().adminHelpSettingsReset);
Util.sendMessage(sender, ChatColor.GREEN + "flag options: ");
String commaList = "all";
for (SettingsFlag flag : SettingsFlag.values()) {
commaList += ", " + flag.toString();
}
Util.sendMessage(sender, commaList);
return true;
}
}
// Resetsign <player> - makes a warp sign for player
if (split[0].equalsIgnoreCase("resetsign")) {
// Find the closest island
if (!(sender instanceof Player)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorUseInGame);
return true;
}
Player p = (Player) sender;
if (!VaultHelper.checkPerm(p, Settings.PERMPREFIX + "mod.signadmin") && !p.isOp()) {
Util.sendMessage(p, ChatColor.RED + plugin.myLocale(p.getUniqueId()).errorNoPermission);
return true;
}
// Convert target name to a UUID
final UUID playerUUID = plugin.getPlayers().getUUID(split[1], true);
if (!plugin.getPlayers().isAKnownPlayer(playerUUID)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorUnknownPlayer);
} else {
// Check if this player has an island
if (!plugin.getPlayers().hasIsland(playerUUID) && !plugin.getPlayers().inTeam(playerUUID)) {
// No island
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorNoIslandOther);
return true;
}
// Has an island
// Find out whether the player is looking at a warp sign
// Look at what the player was looking at
BlockIterator iter = new BlockIterator(p, 10);
Block lastBlock = iter.next();
while (iter.hasNext()) {
lastBlock = iter.next();
if (lastBlock.getType() == Material.AIR)
continue;
break;
}
// Check if it is a sign
if (!lastBlock.getType().equals(Material.SIGN_POST)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale(p.getUniqueId()).adminResetSignNoSign);
return true;
}
Sign sign = (Sign) lastBlock.getState();
// Check if the sign is within the right island boundary
Location islandLoc = plugin.getPlayers().getIslandLocation(playerUUID);
Island island = plugin.getGrid().getIslandAt(islandLoc);
if (island == null) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale(p.getUniqueId()).errorNoIsland);
return true;
}
if (!island.inIslandSpace(sign.getLocation())) {
Util.sendMessage(p, ChatColor.RED + plugin.myLocale(p.getUniqueId()).adminSetHomeNotOnPlayersIsland);
} else {
Util.sendMessage(sender, ChatColor.GREEN + plugin.myLocale(p.getUniqueId()).adminResetSignFound);
// Find out if this player is allowed to have a sign on this island
if (plugin.getWarpSignsListener().addWarp(playerUUID, lastBlock.getLocation())) {
// Change sign color to green
sign.setLine(0, ChatColor.GREEN + plugin.myLocale().warpswelcomeLine);
sign.update();
Util.sendMessage(p, ChatColor.GREEN + plugin.myLocale(p.getUniqueId()).adminResetSignRescued.replace("[name]", plugin.getPlayers().getName(playerUUID)));
return true;
}
// Warp already exists
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale(p.getUniqueId()).adminResetSignErrorExists.replace("[name]", plugin.getWarpSignsListener().getWarpOwner(lastBlock.getLocation())));
}
}
return true;
} else // Delete the island you are on
if (split[0].equalsIgnoreCase("deleteisland")) {
if (!split[1].equalsIgnoreCase("confirm")) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().adminDeleteIslandError);
return true;
}
// Get the island I am on
Island island = plugin.getGrid().getIslandAt(((Player) sender).getLocation());
if (island == null) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().adminDeleteIslandnoid);
return true;
}
// Try to get the owner of this island
UUID owner = island.getOwner();
String name = "unknown";
if (owner != null) {
name = plugin.getPlayers().getName(owner);
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().adminSetSpawnownedBy.replace("[name]", name));
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().adminDeleteIslanduse.replace("[name]", name));
return true;
} else {
Util.sendMessage(sender, ChatColor.YELLOW + plugin.myLocale().deleteremoving.replace("[name]", name));
deleteIslands(island, sender);
return true;
}
} else if (split[0].equalsIgnoreCase("resetname")) {
// Convert name to a UUID
final UUID playerUUID = plugin.getPlayers().getUUID(split[1], true);
if (!plugin.getPlayers().isAKnownPlayer(playerUUID)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorUnknownPlayer);
} else {
// Check if this player has an island
if (!plugin.getPlayers().hasIsland(playerUUID) && !plugin.getPlayers().inTeam(playerUUID)) {
// No island
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorNoIslandOther);
return true;
}
// Has an island
plugin.getGrid().setIslandName(playerUUID, null);
Util.sendMessage(sender, plugin.myLocale().generalSuccess);
}
return true;
} else if (split[0].equalsIgnoreCase("resethome")) {
// Convert name to a UUID
final UUID playerUUID = plugin.getPlayers().getUUID(split[1], true);
if (!plugin.getPlayers().isAKnownPlayer(playerUUID)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorUnknownPlayer);
} else {
// Check if this player has an island
if (!plugin.getPlayers().hasIsland(playerUUID) && !plugin.getPlayers().inTeam(playerUUID)) {
// No island
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorNoIslandOther);
return true;
}
// Has an island
Location safeHome = plugin.getGrid().getSafeHomeLocation(playerUUID, 1);
if (safeHome == null) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().adminSetHomeNoneFound);
} else {
plugin.getPlayers().setHomeLocation(playerUUID, safeHome);
Util.sendMessage(sender, ChatColor.GREEN + plugin.myLocale().adminSetHomeHomeSet.replace("[location]", safeHome.getBlockX() + ", " + safeHome.getBlockY() + "," + safeHome.getBlockZ()));
}
}
return true;
} else if (split[0].equalsIgnoreCase("sethome")) {
if (!(sender instanceof Player)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().adminLockerrorInGame);
return true;
}
player = (Player) sender;
// Convert name to a UUID
final UUID playerUUID = plugin.getPlayers().getUUID(split[1], true);
if (!plugin.getPlayers().isAKnownPlayer(playerUUID)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorUnknownPlayer);
} else {
// Check if this player has an island
if (!plugin.getPlayers().hasIsland(playerUUID) && !plugin.getPlayers().inTeam(playerUUID)) {
// No island
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoIslandOther);
return true;
}
// Has an island
Location islandLoc = plugin.getPlayers().getIslandLocation(playerUUID);
Island island = plugin.getGrid().getIslandAt(islandLoc);
// Check the player is within the island boundaries
if (island == null || !island.inIslandSpace(player.getLocation())) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).adminSetHomeNotOnPlayersIsland);
} else {
// Check that the location is safe
if (!GridManager.isSafeLocation(player.getLocation())) {
// Not safe
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).adminSetHomeNoneFound);
} else {
// Success
plugin.getPlayers().setHomeLocation(playerUUID, player.getLocation());
Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(player.getUniqueId()).adminSetHomeHomeSet.replace("[location]", player.getLocation().getBlockX() + ", " + player.getLocation().getBlockY() + "," + player.getLocation().getBlockZ()));
}
}
}
return true;
} else // Set protection for the island the player is on
if (split[0].equalsIgnoreCase("setrange")) {
if (!(sender instanceof Player)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().adminLockerrorInGame);
return true;
}
player = (Player) sender;
UUID playerUUID = player.getUniqueId();
Island island = plugin.getGrid().getIslandAt(player.getLocation());
// Check if island exists
if (island == null) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale().errorNotOnIsland);
return true;
} else {
int newRange = 10;
int maxRange = Settings.islandDistance;
// If spawn do something different
if (island.isSpawn()) {
try {
newRange = Integer.valueOf(split[1]);
} catch (Exception e) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).adminSetRangeInvalid);
return true;
}
Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(playerUUID).adminSetRangeSet.replace("[number]", String.valueOf(newRange)));
if (newRange > maxRange) {
Util.sendMessage(player, ChatColor.RED + "" + ChatColor.BOLD + plugin.myLocale(playerUUID).adminSetRangeWarning.replace("[max]", String.valueOf(maxRange)));
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).adminSetRangeWarning2);
}
island.setProtectionSize(newRange);
Util.sendMessage(player, ChatColor.YELLOW + plugin.myLocale().adminSetSpawncenter.replace("[location]", island.getCenter().getBlockX() + "," + island.getCenter().getBlockZ()));
Util.sendMessage(player, ChatColor.YELLOW + plugin.myLocale().adminSetSpawnlimits.replace("[min]", island.getMinX() + "," + island.getMinZ()).replace("[max]", (island.getMinX() + island.getIslandDistance() - 1) + "," + (island.getMinZ() + island.getIslandDistance() - 1)));
Util.sendMessage(player, ChatColor.YELLOW + plugin.myLocale().adminSetSpawnrange.replace("[number]", String.valueOf(island.getProtectionSize())));
Util.sendMessage(player, ChatColor.YELLOW + plugin.myLocale().adminSetSpawncoords.replace("[min]", island.getMinProtectedX() + ", " + island.getMinProtectedZ()).replace("[max]", +(island.getMinProtectedX() + island.getProtectionSize() - 1) + ", " + (island.getMinProtectedZ() + island.getProtectionSize() - 1)));
if (island.isLocked()) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale().adminSetSpawnlocked);
}
} else {
try {
newRange = Integer.valueOf(split[1]);
} catch (Exception e) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).adminSetRangeInvalid + " " + plugin.myLocale(playerUUID).adminSetRangeTip.replace("[max]", String.valueOf(maxRange)));
return true;
}
if (newRange < 10 || newRange > maxRange) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).adminSetRangeInvalid + " " + plugin.myLocale(playerUUID).adminSetRangeTip.replace("[max]", String.valueOf(maxRange)));
return true;
}
island.setProtectionSize(newRange);
Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(playerUUID).adminSetRangeSet.replace("[number]", String.valueOf(newRange)));
showInfo(island.getOwner(), sender);
}
return true;
}
} else // Add/remove protection for the island the player is on
if (split[0].equalsIgnoreCase("addrange")) {
if (!(sender instanceof Player)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().adminLockerrorInGame);
return true;
}
player = (Player) sender;
UUID playerUUID = player.getUniqueId();
Island island = plugin.getGrid().getIslandAt(player.getLocation());
// Check if island exists
if (island == null) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale().errorNotOnIsland);
return true;
} else {
int newRange = island.getProtectionSize();
int maxRange = Settings.islandDistance;
// If spawn do something different
if (island.isSpawn()) {
try {
newRange = Integer.valueOf(split[1]) + island.getProtectionSize();
} catch (Exception e) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).adminSetRangeInvalid);
return true;
}
Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(playerUUID).adminSetRangeSet.replace("[number]", String.valueOf(newRange)));
if (newRange > maxRange) {
Util.sendMessage(player, ChatColor.RED + "" + ChatColor.BOLD + plugin.myLocale(playerUUID).adminSetRangeWarning.replace("[max]", String.valueOf(maxRange)));
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).adminSetRangeWarning2);
}
island.setProtectionSize(newRange);
Util.sendMessage(player, ChatColor.YELLOW + plugin.myLocale().adminSetSpawncenter.replace("[location]", island.getCenter().getBlockX() + "," + island.getCenter().getBlockZ()));
Util.sendMessage(player, ChatColor.YELLOW + plugin.myLocale().adminSetSpawnlimits.replace("[min]", island.getMinX() + "," + island.getMinZ()).replace("[max]", (island.getMinX() + island.getIslandDistance() - 1) + "," + (island.getMinZ() + island.getIslandDistance() - 1)));
Util.sendMessage(player, ChatColor.YELLOW + plugin.myLocale().adminSetSpawnrange.replace("[number]", String.valueOf(island.getProtectionSize())));
Util.sendMessage(player, ChatColor.YELLOW + plugin.myLocale().adminSetSpawncoords.replace("[min]", island.getMinProtectedX() + ", " + island.getMinProtectedZ()).replace("[max]", +(island.getMinProtectedX() + island.getProtectionSize() - 1) + ", " + (island.getMinProtectedZ() + island.getProtectionSize() - 1)));
if (island.isLocked()) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale().adminSetSpawnlocked);
}
} else {
try {
newRange = Integer.valueOf(split[1]) + island.getProtectionSize();
} catch (Exception e) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).adminSetRangeInvalid + " " + plugin.myLocale(playerUUID).adminSetRangeTip.replace("[max]", String.valueOf(maxRange)));
return true;
}
if (newRange < 10 || newRange > maxRange) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).adminSetRangeInvalid + " " + plugin.myLocale(playerUUID).adminSetRangeTip.replace("[max]", String.valueOf(maxRange)));
return true;
}
island.setProtectionSize(newRange);
Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(playerUUID).adminSetRangeSet.replace("[number]", String.valueOf(newRange)));
showInfo(island.getOwner(), sender);
}
return true;
}
}
if (split[0].equalsIgnoreCase("purge")) {
// Protect island from purging
if (split[1].equalsIgnoreCase("allow") || split[1].equalsIgnoreCase("disallow")) {
// Find the closest island
if (!(sender instanceof Player)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().adminLockerrorInGame);
return true;
}
Player p = (Player) sender;
// Island spawn must be in the island world
if (!p.getLocation().getWorld().equals(ASkyBlock.getIslandWorld()) && !p.getLocation().getWorld().equals(ASkyBlock.getNetherWorld())) {
Util.sendMessage(p, ChatColor.RED + plugin.myLocale(p.getUniqueId()).errorWrongWorld);
return true;
}
Island island = plugin.getGrid().getIslandAt(p.getLocation());
if (island == null) {
Util.sendMessage(p, ChatColor.RED + plugin.myLocale(p.getUniqueId()).errorNoIslandOther);
return true;
}
if (split[1].equalsIgnoreCase("disallow")) {
island.setPurgeProtected(true);
} else {
island.setPurgeProtected(false);
}
if (island.isPurgeProtected()) {
Util.sendMessage(p, ChatColor.GREEN + plugin.myLocale(p.getUniqueId()).adminPreventPurge);
} else {
Util.sendMessage(p, ChatColor.GREEN + plugin.myLocale(p.getUniqueId()).adminAllowPurge);
}
return true;
}
// this flag stops a repeat
if (purgeFlag) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().purgealreadyRunning);
return true;
}
if (split[1].equalsIgnoreCase("unowned")) {
countUnowned(sender);
return true;
}
// Set the flag
purgeFlag = true;
// See if this purge unowned
// Convert days to hours - no other limit checking?
final int time;
try {
time = Integer.parseInt(split[1]) * 24;
} catch (Exception e) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().purgeusage.replace("[label]", label));
purgeFlag = false;
return true;
}
Util.sendMessage(sender, ChatColor.YELLOW + plugin.myLocale().purgecalculating.replace("[time]", split[1]));
// Check who has not been online since the time
for (Entry<UUID, Island> entry : plugin.getGrid().getOwnershipMap().entrySet()) {
// Only do this if it isn't protected
if (entry.getKey() != null && !entry.getValue().isPurgeProtected()) {
if (Bukkit.getOfflinePlayer(entry.getKey()).hasPlayedBefore()) {
long offlineTime = Bukkit.getOfflinePlayer(entry.getKey()).getLastPlayed();
offlineTime = (System.currentTimeMillis() - offlineTime) / 3600000L;
if (offlineTime > time && plugin.getPlayers().getIslandLevel(entry.getKey()) < Settings.abandonedIslandLevel) {
removeList.add(entry.getKey());
}
} else {
removeList.add(entry.getKey());
}
}
}
if (removeList.isEmpty()) {
Util.sendMessage(sender, ChatColor.YELLOW + plugin.myLocale().purgenoneFound);
purgeFlag = false;
return true;
}
Util.sendMessage(sender, ChatColor.YELLOW + plugin.myLocale().purgethisWillRemove.replace("[number]", String.valueOf(removeList.size())).replace("[level]", String.valueOf(Settings.abandonedIslandLevel)));
long runtime = removeList.size() * 2L;
Util.sendMessage(sender, ChatColor.YELLOW + plugin.myLocale().purgeEstimatedRunTime.replace("[time]", String.format("%d h %02d m %02d s", runtime / 3600, (runtime % 3600) / 60, (runtime % 60))));
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().purgewarning);
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().purgetypeConfirm.replace("[label]", label));
if (removeList.size() > Settings.maxPurge) {
Util.sendMessage(sender, plugin.myLocale().purgeLimit.replace("[number]", String.valueOf(Settings.maxPurge)));
Iterator<UUID> it = removeList.iterator();
int count = 1;
while (it.hasNext()) {
it.next();
if (count++ > Settings.maxPurge) {
it.remove();
}
}
}
confirmReq = true;
confirmOK = false;
confirmTimer = 0;
new BukkitRunnable() {
@Override
public void run() {
// cancels
if (confirmTimer++ > 10) {
// Ten seconds is up!
confirmReq = false;
confirmOK = false;
purgeFlag = false;
removeList.clear();
Util.sendMessage(sender, ChatColor.YELLOW + plugin.myLocale().purgepurgeCancelled);
this.cancel();
} else if (confirmOK) {
// Set up a repeating task to run every 2
// seconds to remove
// islands one by one and then cancel when
// done
final int total = removeList.size();
new BukkitRunnable() {
@Override
public void run() {
if (removeList.isEmpty() && purgeFlag) {
purgeFlag = false;
Util.sendMessage(sender, ChatColor.YELLOW + plugin.myLocale().purgefinished);
this.cancel();
}
if (removeList.size() > 0 && purgeFlag) {
// Check if the player is online
if (plugin.getServer().getPlayer(removeList.get(0)) == null) {
// Check the level
if (plugin.getPlayers().getIslandLevel(removeList.get(0)) < Settings.abandonedIslandLevel) {
Util.sendMessage(sender, ChatColor.YELLOW + "[" + (total - removeList.size() + 1) + "/" + total + "] " + plugin.myLocale().purgeremovingName.replace("[name]", plugin.getPlayers().getName(removeList.get(0))));
plugin.deletePlayerIsland(removeList.get(0), true);
}
} else {
Util.sendMessage(sender, ChatColor.YELLOW + "[" + (total - removeList.size() + 1) + "/" + total + "] " + "Skipping online player...");
}
removeList.remove(0);
}
// Util.sendMessage(sender, "Now waiting...");
}
}.runTaskTimer(plugin, 0L, 20L);
confirmReq = false;
confirmOK = false;
this.cancel();
}
}
}.runTaskTimer(plugin, 0L, 40L);
return true;
} else if (split[0].equalsIgnoreCase("lock")) {
// Convert name to a UUID
final UUID playerUUID = plugin.getPlayers().getUUID(split[1], true);
if (!plugin.getPlayers().isAKnownPlayer(playerUUID)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorUnknownPlayer);
return true;
} else {
Island island = plugin.getGrid().getIsland(playerUUID);
if (island != null) {
Player owner = plugin.getServer().getPlayer(island.getOwner());
if (island.isLocked()) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().lockUnlocking);
island.setLocked(false);
if (owner != null) {
owner.sendMessage(plugin.myLocale(owner.getUniqueId()).adminLockadminUnlockedIsland);
} else {
plugin.getMessages().setMessage(island.getOwner(), plugin.myLocale(island.getOwner()).adminLockadminUnlockedIsland);
}
} else {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().lockLocking);
island.setLocked(true);
if (owner != null) {
Util.sendMessage(owner, plugin.myLocale(owner.getUniqueId()).adminLockadminLockedIsland);
} else {
plugin.getMessages().setMessage(island.getOwner(), plugin.myLocale(island.getOwner()).adminLockadminLockedIsland);
}
}
} else {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorNoIslandOther);
}
return true;
}
} else if (split[0].equalsIgnoreCase("setdeaths")) {
// Convert name to a UUID
final UUID playerUUID = plugin.getPlayers().getUUID(split[1], true);
if (!plugin.getPlayers().isAKnownPlayer(playerUUID)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorUnknownPlayer);
return true;
} else {
Util.sendMessage(sender, ChatColor.GREEN + plugin.getPlayers().getName(playerUUID) + " " + plugin.getPlayers().getDeaths(playerUUID) + " " + plugin.myLocale().deaths);
Util.sendMessage(sender, plugin.myLocale().helpColor + label + " setdeaths <player> <number>:" + ChatColor.WHITE + " " + plugin.myLocale().adminHelpsetDeaths);
return true;
}
} else if (split[0].equalsIgnoreCase("clearreset")) {
// Convert name to a UUID
final UUID playerUUID = plugin.getPlayers().getUUID(split[1], true);
if (!plugin.getPlayers().isAKnownPlayer(playerUUID)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorUnknownPlayer);
return true;
} else {
plugin.getPlayers().setResetsLeft(playerUUID, Settings.resetLimit);
Util.sendMessage(sender, ChatColor.YELLOW + plugin.myLocale().clearedResetLimit + " [" + Settings.resetLimit + "]");
return true;
}
} else if (split[0].equalsIgnoreCase("tp")) {
if (!(sender instanceof Player)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorUnknownCommand);
return true;
}
player = (Player) sender;
// Convert name to a UUID
final UUID targetUUID = plugin.getPlayers().getUUID(split[1], true);
if (!plugin.getPlayers().isAKnownPlayer(targetUUID)) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorUnknownPlayer);
return true;
} else {
if (plugin.getPlayers().hasIsland(targetUUID) || plugin.getPlayers().inTeam(targetUUID)) {
// Teleport to the over world
Location warpSpot = plugin.getPlayers().getIslandLocation(targetUUID).toVector().toLocation(ASkyBlock.getIslandWorld());
String failureMessage = ChatColor.RED + plugin.myLocale(player.getUniqueId()).adminTpManualWarp.replace("[location]", warpSpot.getBlockX() + " " + warpSpot.getBlockY() + " " + warpSpot.getBlockZ());
// Try the player's home first
Location home = plugin.getPlayers().getHomeLocation(targetUUID);
plugin.getGrid();
if (home != null && home.getWorld().equals(ASkyBlock.getIslandWorld()) && GridManager.isSafeLocation(home)) {
player.teleport(home);
return true;
}
// Other wise, go to a safe spot
new SafeTeleportBuilder(plugin).entity(player).location(warpSpot).failureMessage(failureMessage).build();
return true;
}
Util.sendMessage(sender, plugin.myLocale().errorNoIslandOther);
return true;
}
} else if (split[0].equalsIgnoreCase("tpnether")) {
if (!Settings.createNether || !Settings.newNether || ASkyBlock.getNetherWorld() == null) {
return false;
}
if (!(sender instanceof Player)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorUnknownCommand);
return true;
}
player = (Player) sender;
// Convert name to a UUID
final UUID targetUUID = plugin.getPlayers().getUUID(split[1], true);
if (!plugin.getPlayers().isAKnownPlayer(targetUUID)) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorUnknownPlayer);
return true;
} else {
if (plugin.getPlayers().hasIsland(targetUUID) || plugin.getPlayers().inTeam(targetUUID)) {
// Teleport to the nether
Location warpSpot = plugin.getPlayers().getIslandLocation(targetUUID).toVector().toLocation(ASkyBlock.getNetherWorld());
String failureMessage = ChatColor.RED + plugin.myLocale(player.getUniqueId()).adminTpManualWarp.replace("[location]", warpSpot.getBlockX() + " " + warpSpot.getBlockY() + " " + warpSpot.getBlockZ());
// Try the player's home first
Location home = plugin.getPlayers().getHomeLocation(targetUUID);
plugin.getGrid();
if (home != null && home.getWorld().equals(ASkyBlock.getNetherWorld()) && GridManager.isSafeLocation(home)) {
player.teleport(home);
return true;
}
new SafeTeleportBuilder(plugin).entity(player).location(warpSpot).failureMessage(failureMessage).build();
return true;
}
Util.sendMessage(sender, plugin.myLocale().errorNoIslandOther);
return true;
}
} else if (split[0].equalsIgnoreCase("delete")) {
// Convert name to a UUID
final UUID playerUUID = plugin.getPlayers().getUUID(split[1], true);
if (!plugin.getPlayers().isAKnownPlayer(playerUUID)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorUnknownPlayer);
return true;
} else {
// This now deletes the player and cleans them up even if
// they don't have an island
Util.sendMessage(sender, ChatColor.YELLOW + plugin.myLocale().deleteremoving.replace("[name]", split[1]));
// If they are online and in ASkyBlock then delete their
// stuff too
Player target = plugin.getServer().getPlayer(playerUUID);
if (target != null) {
// Clear any coop inventories
// CoopPlay.getInstance().returnAllInventories(target);
// Remove any of the target's coop invitees and grab
// their stuff
CoopPlay.getInstance().clearMyInvitedCoops(target);
CoopPlay.getInstance().clearMyCoops(target);
plugin.resetPlayer(target);
}
// plugin.getLogger().info("DEBUG: deleting player");
plugin.deletePlayerIsland(playerUUID, true);
return true;
}
} else if (split[0].equalsIgnoreCase("reserve")) {
// Reserves a spot for the player's next island
if (sender instanceof Player) {
player = (Player) sender;
// Convert name to a UUID
final UUID playerUUID = plugin.getPlayers().getUUID(split[1], true);
if (!plugin.getPlayers().isAKnownPlayer(playerUUID)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorUnknownPlayer);
return true;
} else {
// Check the spot
Location islandLoc = plugin.getGrid().getClosestIsland(player.getLocation());
Island island = plugin.getGrid().getIslandAt(islandLoc);
if (island == null) {
// Empty spot, reserve it!
plugin.getIslandCmd().reserveLocation(playerUUID, islandLoc);
Util.sendMessage(sender, ChatColor.GREEN + " [" + islandLoc.getBlockX() + ", " + islandLoc.getBlockZ() + "] " + plugin.myLocale().generalSuccess);
} else {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().adminReserveIslandExists);
}
return true;
}
} else {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorUnknownCommand);
}
return true;
} else if (split[0].equalsIgnoreCase("register")) {
if (sender instanceof Player) {
// Convert name to a UUID
final UUID playerUUID = plugin.getPlayers().getUUID(split[1], true);
// plugin.getLogger().info("DEBUG: UUID is " + playerUUID);
if (!plugin.getPlayers().isAKnownPlayer(playerUUID)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorUnknownPlayer);
return true;
} else {
if (adminSetPlayerIsland(sender, ((Player) sender).getLocation(), playerUUID)) {
Util.sendMessage(sender, ChatColor.GREEN + plugin.myLocale().registersettingIsland.replace("[name]", split[1]));
plugin.getGrid().saveGrid();
} else {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().registererrorBedrockNotFound);
}
return true;
}
} else {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorUnknownCommand);
}
return true;
} else if (split[0].equalsIgnoreCase("unregister")) {
// Convert name to a UUID
final UUID playerUUID = plugin.getPlayers().getUUID(split[1], true);
if (!plugin.getPlayers().isAKnownPlayer(playerUUID)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorUnknownPlayer);
return true;
} else {
if (plugin.getPlayers().inTeam(playerUUID)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().adminUnregisterOnTeam);
return true;
}
Location island = plugin.getPlayers().getIslandLocation(playerUUID);
if (island == null) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorNoIslandOther);
return true;
}
// Delete player, but keep blocks
Util.sendMessage(sender, ChatColor.GREEN + plugin.myLocale().adminUnregisterKeepBlocks.replace("[location]", +plugin.getPlayers().getIslandLocation(playerUUID).getBlockX() + "," + plugin.getPlayers().getIslandLocation(playerUUID).getBlockZ()));
plugin.deletePlayerIsland(playerUUID, false);
plugin.getGrid().saveGrid();
return true;
}
} else if (split[0].equalsIgnoreCase("info")) {
// Convert name to a UUID
final UUID playerUUID = plugin.getPlayers().getUUID(split[1], true);
// + playerUUID);
if (!plugin.getPlayers().isAKnownPlayer(playerUUID)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorUnknownPlayer);
return true;
} else {
showInfo(playerUUID, sender);
return true;
}
} else if (split[0].equalsIgnoreCase("resetallchallenges")) {
// Convert name to a UUID
final UUID playerUUID = plugin.getPlayers().getUUID(split[1], true);
if (!plugin.getPlayers().isAKnownPlayer(playerUUID)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorUnknownPlayer);
return true;
}
plugin.getPlayers().resetAllChallenges(playerUUID, true);
Util.sendMessage(sender, ChatColor.YELLOW + plugin.myLocale().resetChallengessuccess.replace("[name]", split[1]));
return true;
} else {
return false;
}
case 3:
if (split[0].equalsIgnoreCase("resetchallengeforall")) {
if (!Settings.challengeList.contains(split[1].toLowerCase())) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().resetChallengeerrorChallengeDoesNotExist);
return true;
}
// Convert repeat to time in millis
split[2] = split[2].trim();
// plugin.getLogger().info("DEBUG: " + split[2]);
if (split[2].length() > 1 && (split[2].toLowerCase().endsWith("m") || split[2].toLowerCase().endsWith("h") || split[2].toLowerCase().endsWith("d"))) {
char unit = split[2].charAt(split[2].length() - 1);
String value = split[2].substring(0, split[2].length() - 1);
try {
long repeat = 0;
int number = Integer.valueOf(value);
switch(unit) {
case 'm':
// Minutes
repeat = 60000L * number;
break;
case 'h':
repeat = 60000L * 60 * number;
break;
case 'd':
repeat = 60000L * 60 * 24 * number;
break;
}
// Reset all the players online
plugin.getChallenges().resetChallengeForAll(split[1].toLowerCase(), repeat, split[2]);
Util.sendMessage(sender, ChatColor.GREEN + plugin.myLocale().generalSuccess);
} catch (Exception e) {
e.printStackTrace();
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().adminResetChallengeForAllError);
return true;
}
} else {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().adminResetChallengeForAllError);
return true;
}
return true;
} else // Confirm purge unowned
if (split[0].equalsIgnoreCase("purge")) {
if (purgeFlag) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().purgealreadyRunning);
return true;
}
// Check if this is purge unowned
if (split[1].equalsIgnoreCase("unowned") && split[2].equalsIgnoreCase("confirm")) {
if (!purgeUnownedConfirm) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().confirmerrorTimeLimitExpired);
return true;
} else {
purgeUnownedConfirm = false;
// Purge the unowned islands
purgeUnownedIslands(sender);
return true;
}
}
}
// Add or remove protection range
if (split[0].equalsIgnoreCase("addrange")) {
// Convert name to a UUID
UUID playerUUID = plugin.getPlayers().getUUID(split[1], true);
// Check if player exists
if (!plugin.getPlayers().isAKnownPlayer(playerUUID)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorUnknownPlayer);
return true;
}
// Check if the target is in a team and if so, the leader needs to be adjusted
if (plugin.getPlayers().inTeam(playerUUID)) {
playerUUID = plugin.getPlayers().getTeamLeader(playerUUID);
}
// Get the range that this player has now
Island island = plugin.getGrid().getIsland(playerUUID);
if (island == null) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorNoIslandOther);
return true;
} else {
int newRange = 0;
int maxRange = Settings.islandDistance;
try {
newRange = Integer.valueOf(split[2]) + island.getProtectionSize();
} catch (Exception e) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().adminSetRangeInvalid + " " + plugin.myLocale().adminSetRangeTip.replace("[max]", String.valueOf(maxRange)));
return true;
}
if (newRange < 10 || newRange > maxRange) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().adminSetRangeInvalid + " " + plugin.myLocale().adminSetRangeTip.replace("[max]", String.valueOf(maxRange)));
return true;
}
island.setProtectionSize(newRange);
Util.sendMessage(sender, ChatColor.GREEN + plugin.myLocale().adminSetRangeSet.replace("[number]", String.valueOf(newRange)));
showInfo(playerUUID, sender);
plugin.getGrid().saveGrid();
return true;
}
} else if (split[0].equalsIgnoreCase("setrange")) {
// Convert name to a UUID
UUID playerUUID = plugin.getPlayers().getUUID(split[1], true);
// Check if player exists
if (!plugin.getPlayers().isAKnownPlayer(playerUUID)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorUnknownPlayer);
return true;
}
// Check if the target is in a team and if so, the leader needs to be adjusted
if (plugin.getPlayers().inTeam(playerUUID)) {
playerUUID = plugin.getPlayers().getTeamLeader(playerUUID);
}
// Get the range that this player has now
Island island = plugin.getGrid().getIsland(playerUUID);
if (island == null) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorNoIslandOther);
return true;
} else {
int newRange = 0;
int maxRange = Settings.islandDistance;
try {
newRange = Integer.valueOf(split[2]);
} catch (Exception e) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().adminSetRangeInvalid + " " + plugin.myLocale().adminSetRangeTip.replace("[max]", String.valueOf(maxRange)));
return true;
}
if (newRange < 10 || newRange > maxRange) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().adminSetRangeInvalid + " " + plugin.myLocale().adminSetRangeTip.replace("[max]", String.valueOf(maxRange)));
return true;
}
island.setProtectionSize(newRange);
Util.sendMessage(sender, ChatColor.GREEN + plugin.myLocale().adminSetRangeSet.replace("[number]", String.valueOf(newRange)));
showInfo(playerUUID, sender);
plugin.getGrid().saveGrid();
return true;
}
} else if (split[0].equalsIgnoreCase("setdeaths")) {
// Convert name to a UUID
final UUID playerUUID = plugin.getPlayers().getUUID(split[1], true);
if (!plugin.getPlayers().isAKnownPlayer(playerUUID)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorUnknownPlayer);
return true;
} else {
try {
int newDeaths = Integer.valueOf(split[2]);
int oldDeaths = plugin.getPlayers().getDeaths(playerUUID);
plugin.getPlayers().setDeaths(playerUUID, newDeaths);
Util.sendMessage(sender, ChatColor.GREEN + plugin.getPlayers().getName(playerUUID) + " " + oldDeaths + " >>> " + newDeaths + " " + plugin.myLocale().deaths);
} catch (Exception e) {
Util.sendMessage(sender, ChatColor.GREEN + plugin.getPlayers().getName(playerUUID) + " " + plugin.getPlayers().getDeaths(playerUUID) + " " + plugin.myLocale().deaths);
Util.sendMessage(sender, plugin.myLocale().helpColor + label + " setdeaths <player> <number>:" + ChatColor.WHITE + " " + plugin.myLocale().adminHelpsetDeaths);
return true;
}
return true;
}
}
// Change biomes
if (split[0].equalsIgnoreCase("setbiome")) {
// Convert name to a UUID
UUID playerUUID = plugin.getPlayers().getUUID(split[1], true);
// Check if player exists
if (!plugin.getPlayers().isAKnownPlayer(playerUUID)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorUnknownPlayer);
return true;
}
// Check if the target is in a team and if so, the leader
if (plugin.getPlayers().inTeam(playerUUID)) {
playerUUID = plugin.getPlayers().getTeamLeader(playerUUID);
}
Island island = plugin.getGrid().getIsland(playerUUID);
if (island == null) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorNoIsland);
return true;
}
// Check if biome is valid
Biome biome = null;
String biomeName = split[2].toUpperCase();
try {
biome = Biome.valueOf(biomeName);
biomeName = biome.name();
if (!plugin.getConfig().contains("biomes." + biomeName)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().biomeUnknown);
// shown
for (Biome b : Biome.values()) {
if (plugin.getConfig().contains("biomes." + b.name())) {
Util.sendMessage(sender, b.name());
}
}
return true;
}
// Get friendly name
biomeName = plugin.getConfig().getString("biomes." + biomeName + ".friendlyname", Util.prettifyText(biomeName));
} catch (Exception e) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().biomeUnknown);
for (Biome b : Biome.values()) {
if (plugin.getConfig().contains("biomes." + b.name())) {
Util.sendMessage(sender, b.name());
}
}
return true;
}
// Okay clear to set biome
// Actually set the biome
new SetBiome(plugin, island, biome, sender);
Util.sendMessage(sender, ChatColor.GREEN + plugin.myLocale().biomeSet.replace("[biome]", biomeName));
Player targetPlayer = plugin.getServer().getPlayer(playerUUID);
if (targetPlayer != null) {
// Online
Util.sendMessage(targetPlayer, "[Admin] " + ChatColor.GREEN + plugin.myLocale(playerUUID).biomeSet.replace("[biome]", biomeName));
} else {
plugin.getMessages().setMessage(playerUUID, "[Admin] " + ChatColor.GREEN + plugin.myLocale(playerUUID).biomeSet.replace("[biome]", biomeName));
}
return true;
} else // team kick <player> and team delete <leader>
if (split[0].equalsIgnoreCase("team")) {
// Convert name to a UUID
final UUID playerUUID = plugin.getPlayers().getUUID(split[2], true);
if (!plugin.getPlayers().isAKnownPlayer(playerUUID)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorUnknownPlayer);
return true;
}
if (split[1].equalsIgnoreCase("kick")) {
// Remove player from team
if (!plugin.getPlayers().inTeam(playerUUID)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorNoTeam);
return true;
}
UUID teamLeader = plugin.getPlayers().getTeamLeader(playerUUID);
if (teamLeader == null) {
// Clear the player of all team-related items
if (!plugin.getPlayers().setLeaveTeam(playerUUID)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorBlockedByAPI);
return true;
}
plugin.getPlayers().setHomeLocation(playerUUID, null);
plugin.getPlayers().setIslandLocation(playerUUID, null);
// Remove any warps
plugin.getWarpSignsListener().removeWarp(playerUUID);
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().kicknameRemoved.replace("[name]", split[2]));
plugin.getPlayers().save(playerUUID);
return true;
}
// Payer is not a team leader
if (!teamLeader.equals(playerUUID)) {
// Clear the player of all team-related items
if (!plugin.getPlayers().setLeaveTeam(playerUUID)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorBlockedByAPI);
return true;
}
plugin.getPlayers().setHomeLocation(playerUUID, null);
plugin.getPlayers().setIslandLocation(playerUUID, null);
// Clear the leader of this player and if they now have
// no team, remove the team
plugin.getPlayers().removeMember(teamLeader, playerUUID);
if (plugin.getPlayers().getMembers(teamLeader).size() < 2) {
if (!plugin.getPlayers().setLeaveTeam(teamLeader)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorBlockedByAPI);
return true;
}
}
// Remove any warps
plugin.getWarpSignsListener().removeWarp(playerUUID);
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().kicknameRemoved.replace("[name]", split[2]));
plugin.getPlayers().save(playerUUID);
return true;
} else {
Util.sendMessage(sender, ChatColor.RED + (plugin.myLocale().adminTeamKickLeader.replace("[label]", label)).replace("[name]", split[2]));
return true;
}
} else {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorUnknownCommand);
return false;
}
} else if (split[0].equalsIgnoreCase("completechallenge")) {
// Convert name to a UUID
final UUID playerUUID = plugin.getPlayers().getUUID(split[1], true);
if (!plugin.getPlayers().isAKnownPlayer(playerUUID)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorUnknownPlayer);
return true;
}
if (plugin.getPlayers().checkChallenge(playerUUID, split[2].toLowerCase()) || !plugin.getPlayers().get(playerUUID).challengeExists(split[2].toLowerCase())) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().completeChallengeerrorChallengeDoesNotExist);
return true;
}
plugin.getPlayers().get(playerUUID).completeChallenge(split[2].toLowerCase());
plugin.getPlayers().save(playerUUID);
Util.sendMessage(sender, ChatColor.YELLOW + plugin.myLocale().completeChallengechallangeCompleted.replace("[challengename]", split[2].toLowerCase()).replace("[name]", split[1]));
return true;
} else if (split[0].equalsIgnoreCase("resetchallenge")) {
// Convert name to a UUID
final UUID playerUUID = plugin.getPlayers().getUUID(split[1], true);
if (!plugin.getPlayers().isAKnownPlayer(playerUUID)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorUnknownPlayer);
return true;
}
if (!plugin.getPlayers().checkChallenge(playerUUID, split[2].toLowerCase()) || !plugin.getPlayers().get(playerUUID).challengeExists(split[2].toLowerCase())) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().resetChallengeerrorChallengeDoesNotExist);
return true;
}
plugin.getPlayers().resetChallenge(playerUUID, split[2].toLowerCase());
plugin.getPlayers().save(playerUUID);
Util.sendMessage(sender, ChatColor.YELLOW + plugin.myLocale().resetChallengechallengeReset.replace("[challengename]", split[2].toLowerCase()).replace("[name]", split[1]));
return true;
} else if (split[0].equalsIgnoreCase("info") && split[1].equalsIgnoreCase("challenges")) {
// Convert name to a UUID
final UUID playerUUID = plugin.getPlayers().getUUID(split[2], true);
// + playerUUID);
if (!plugin.getPlayers().isAKnownPlayer(playerUUID)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorUnknownPlayer);
return true;
} else {
showInfoChallenges(playerUUID, sender);
return true;
}
}
return false;
case 4:
// Team add <player> <leader>
if (split[0].equalsIgnoreCase("team") && split[1].equalsIgnoreCase("add")) {
// Convert names to UUIDs
final UUID playerUUID = plugin.getPlayers().getUUID(split[2], true);
final Player targetPlayer = plugin.getServer().getPlayer(playerUUID);
final UUID teamLeader = plugin.getPlayers().getUUID(split[3], true);
if (!plugin.getPlayers().isAKnownPlayer(playerUUID) || !plugin.getPlayers().isAKnownPlayer(teamLeader)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorUnknownPlayer);
return true;
}
if (playerUUID.equals(teamLeader)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().adminTeamAddLeaderToOwn);
return true;
}
// See if leader has an island
if (!plugin.getPlayers().hasIsland(teamLeader)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().adminTeamAddLeaderNoIsland);
return true;
}
// Check to see if this player is already in a team
if (plugin.getPlayers().inTeam(playerUUID)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().inviteerrorThatPlayerIsAlreadyInATeam);
return true;
}
// then add it
if (!plugin.getPlayers().getMembers(teamLeader).contains(teamLeader)) {
// Set up the team leader
if (!plugin.getPlayers().setJoinTeam(teamLeader, teamLeader, plugin.getPlayers().getIslandLocation(teamLeader))) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorBlockedByAPI);
return true;
}
plugin.getPlayers().addTeamMember(teamLeader, teamLeader);
Util.sendMessage(sender, ChatColor.GOLD + plugin.myLocale().adminTeamAddedLeader);
}
// This is a hack to clear any pending invitations
if (targetPlayer != null) {
Util.runCommand(targetPlayer, Settings.ISLANDCOMMAND + " decline");
}
// If the invitee has an island of their own
if (plugin.getPlayers().hasIsland(playerUUID)) {
Location islandLoc = plugin.getPlayers().getIslandLocation(playerUUID);
if (islandLoc != null) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().adminTeamNowUnowned.replace("[name]", plugin.getPlayers().getName(playerUUID)).replace("[location]", islandLoc.getBlockX() + " " + islandLoc.getBlockZ()));
}
}
// Remove their old island affiliation - do not delete the
// island just in case
plugin.deletePlayerIsland(playerUUID, false);
// Join the team and set the team island location and leader
plugin.getPlayers().setJoinTeam(playerUUID, teamLeader, plugin.getPlayers().getIslandLocation(teamLeader));
// Configure the best home location for this player
if (plugin.getPlayers().getHomeLocation(teamLeader) != null) {
plugin.getPlayers().setHomeLocation(playerUUID, plugin.getPlayers().getHomeLocation(teamLeader));
Util.sendMessage(sender, ChatColor.GREEN + plugin.myLocale().adminTeamSettingHome);
} else {
plugin.getPlayers().setHomeLocation(playerUUID, plugin.getPlayers().getIslandLocation(teamLeader));
Util.sendMessage(sender, ChatColor.GREEN + plugin.myLocale().adminTeamSettingHome);
}
// it
if (!plugin.getPlayers().getMembers(teamLeader).contains(playerUUID)) {
plugin.getPlayers().addTeamMember(teamLeader, playerUUID);
Util.sendMessage(sender, ChatColor.GREEN + plugin.myLocale().adminTeamAddingPlayer);
} else {
Util.sendMessage(sender, ChatColor.GOLD + plugin.myLocale().adminTeamAlreadyOnTeam);
}
// Teleport the player if they are online
if (targetPlayer != null) {
plugin.getGrid().homeTeleport(targetPlayer);
}
plugin.getGrid().saveGrid();
return true;
} else {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorUnknownCommand);
return false;
}
default:
return false;
}
}
Aggregations