· 6 years ago · Mar 14, 2019, 12:54 AM
1/*******************************************************************************
2 * This file is part of ASkyBlock.
3 *
4 * ASkyBlock is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * ASkyBlock is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with ASkyBlock. If not, see <http://www.gnu.org/licenses/>.
16 *******************************************************************************/
17package com.wasteofplastic.askyblock.commands;
18
19import java.io.File;
20import java.io.IOException;
21import java.util.ArrayList;
22import java.util.Calendar;
23import java.util.Collection;
24import java.util.Collections;
25import java.util.Comparator;
26import java.util.HashMap;
27import java.util.HashSet;
28import java.util.List;
29import java.util.Map;
30import java.util.Map.Entry;
31import java.util.Random;
32import java.util.Set;
33import java.util.TreeMap;
34import java.util.UUID;
35
36import com.wasteofplastic.askyblock.events.*;
37import org.apache.commons.lang.StringUtils;
38import org.apache.commons.lang.math.NumberUtils;
39import org.bukkit.Bukkit;
40import org.bukkit.ChatColor;
41import org.bukkit.Location;
42import org.bukkit.Material;
43import org.bukkit.OfflinePlayer;
44import org.bukkit.Sound;
45import org.bukkit.World.Environment;
46import org.bukkit.block.Biome;
47import org.bukkit.block.Block;
48import org.bukkit.block.BlockFace;
49import org.bukkit.block.Sign;
50import org.bukkit.command.Command;
51import org.bukkit.command.CommandExecutor;
52import org.bukkit.command.CommandSender;
53import org.bukkit.command.TabCompleter;
54import org.bukkit.configuration.ConfigurationSection;
55import org.bukkit.entity.EntityType;
56import org.bukkit.entity.Item;
57import org.bukkit.entity.Player;
58import org.bukkit.event.player.PlayerDropItemEvent;
59import org.bukkit.inventory.Inventory;
60import org.bukkit.inventory.ItemStack;
61import org.bukkit.material.MaterialData;
62import org.bukkit.permissions.PermissionAttachmentInfo;
63import org.bukkit.potion.Potion;
64import org.bukkit.potion.PotionType;
65import org.bukkit.scheduler.BukkitRunnable;
66import org.bukkit.scheduler.BukkitTask;
67import org.bukkit.util.Vector;
68
69import com.wasteofplastic.askyblock.ASLocale;
70import com.wasteofplastic.askyblock.ASkyBlock;
71import com.wasteofplastic.askyblock.CoopPlay;
72import com.wasteofplastic.askyblock.DeleteIslandChunk;
73import com.wasteofplastic.askyblock.GridManager;
74import com.wasteofplastic.askyblock.Island;
75import com.wasteofplastic.askyblock.Island.SettingsFlag;
76import com.wasteofplastic.askyblock.LevelCalcByChunk;
77import com.wasteofplastic.askyblock.Settings;
78import com.wasteofplastic.askyblock.TopTen;
79import com.wasteofplastic.askyblock.Island.SettingsFlag;
80import com.wasteofplastic.askyblock.events.IslandJoinEvent;
81import com.wasteofplastic.askyblock.events.IslandLeaveEvent;
82import com.wasteofplastic.askyblock.events.IslandNewEvent;
83import com.wasteofplastic.askyblock.events.IslandPreTeleportEvent;
84import com.wasteofplastic.askyblock.events.IslandResetEvent;
85import com.wasteofplastic.askyblock.listeners.PlayerEvents;
86import com.wasteofplastic.askyblock.panels.ControlPanel;
87import com.wasteofplastic.askyblock.schematics.Schematic;
88import com.wasteofplastic.askyblock.schematics.Schematic.PasteReason;
89import com.wasteofplastic.askyblock.util.Util;
90import com.wasteofplastic.askyblock.util.VaultHelper;
91
92@SuppressWarnings("deprecation")
93public class IslandCmd implements CommandExecutor, TabCompleter {
94 private static final boolean DEBUG = false;
95 public boolean levelCalcFreeFlag = true;
96 private static HashMap<String, Schematic> schematics = new HashMap<>();
97 private ASkyBlock plugin;
98 // The island reset confirmation
99 private HashMap<UUID, Boolean> confirm = new HashMap<>();
100 // Last island
101 Location last = null;
102 // List of players in the middle of choosing an island schematic
103 private Set<UUID> pendingNewIslandSelection = new HashSet<UUID>();
104 private Set<UUID> resettingIsland = new HashSet<UUID>();
105 /**
106 * Invite list - invited player name string (key), inviter name string
107 * (value)
108 */
109 private final HashMap<UUID, UUID> inviteList = new HashMap<>();
110 private final HashMap<UUID, UUID> coopInviteList = new HashMap<>();
111 // private PlayerCache players;
112 // The time a player has to wait until they can reset their island again
113 private HashMap<UUID, Long> resetWaitTime = new HashMap<>();
114 // Level calc cool down
115 private HashMap<UUID, Long> levelWaitTime = new HashMap<>();
116
117 // Level calc checker
118 BukkitTask checker = null;
119 // To choose an island randomly
120 private final Random random = new Random();
121 private HashMap<UUID, Location> islandSpot = new HashMap<>();
122 private List<UUID> leavingPlayers = new ArrayList<>();
123 private boolean creatingTopTen;
124
125 /**
126 * Constructor
127 *
128 * @param aSkyBlock
129 */
130 public IslandCmd(ASkyBlock aSkyBlock) {
131 // Plugin instance
132 this.plugin = aSkyBlock;
133 // Load schematics
134 loadSchematics();
135 }
136
137 /**
138 * Loads schematics from the config.yml file. If the default
139 * island is not included, it will be made up
140 */
141 public void loadSchematics() {
142 // Check if there is a schematic folder and make it if it does not exist
143 File schematicFolder = new File(plugin.getDataFolder(), "schematics");
144 if (!schematicFolder.exists()) {
145 schematicFolder.mkdir();
146 }
147 // Clear the schematic list that is kept in memory
148 schematics.clear();
149 // Load the default schematic if it exists
150 // Set up the default schematic
151 File schematicFile = new File(schematicFolder, "island.schematic");
152 File netherFile = new File(schematicFolder, "nether.schematic");
153 if (!schematicFile.exists()) {
154 //plugin.getLogger().info("Default schematic does not exist...");
155 // Only copy if the default exists
156 if (plugin.getResource("schematics/island.schematic") != null) {
157 plugin.getLogger().info("Default schematic does not exist, saving it...");
158 plugin.saveResource("schematics/island.schematic", false);
159 // Add it to schematics
160 try {
161 schematics.put("default",new Schematic(plugin, schematicFile));
162 } catch (IOException e) {
163 plugin.getLogger().severe("Could not load default schematic!");
164 e.printStackTrace();
165 }
166 // If this is repeated later due to the schematic config, fine, it will only add info
167 } else {
168 // No islands.schematic in the jar, so just make the default using
169 // built-in island generation
170 schematics.put("default",new Schematic(plugin));
171 }
172 plugin.getLogger().info("Loaded default nether schematic");
173 } else {
174 // It exists, so load it
175 try {
176 schematics.put("default",new Schematic(plugin, schematicFile));
177 plugin.getLogger().info("Loaded default island schematic.");
178 } catch (IOException e) {
179 plugin.getLogger().severe("Could not load default schematic!");
180 e.printStackTrace();
181 }
182 }
183 // Add the nether default too
184 if (!netherFile.exists()) {
185 if (plugin.getResource("schematics/nether.schematic") != null) {
186 plugin.saveResource("schematics/nether.schematic", false);
187
188 // Add it to schematics
189 try {
190 Schematic netherIsland = new Schematic(plugin, netherFile);
191 netherIsland.setVisible(false);
192 schematics.put("nether", netherIsland);
193 plugin.getLogger().info("Loaded default nether schematic.");
194 } catch (IOException e) {
195 plugin.getLogger().severe("Could not load default nether schematic!");
196 e.printStackTrace();
197 }
198 } else {
199 plugin.getLogger().severe("Could not find default nether schematic!");
200 }
201 } else {
202 // It exists, so load it
203 try {
204 Schematic netherIsland = new Schematic(plugin, netherFile);
205 netherIsland.setVisible(false);
206 schematics.put("nether", netherIsland);
207 plugin.getLogger().info("Loaded default nether schematic.");
208 } catch (IOException e) {
209 plugin.getLogger().severe("Could not load default nether schematic!");
210 e.printStackTrace();
211 }
212 }
213 // Set up some basic settings just in case the schematics section is missing
214 if (schematics.containsKey("default")) {
215 schematics.get("default").setIcon(Material.GRASS);
216 schematics.get("default").setOrder(1);
217 schematics.get("default").setName("The Original");
218 schematics.get("default").setDescription("");
219 schematics.get("default").setPartnerName("nether");
220 schematics.get("default").setBiome(Settings.defaultBiome);
221 schematics.get("default").setIcon(Material.GRASS);
222 if (Settings.chestItems.length == 0) {
223 schematics.get("default").setUseDefaultChest(false);
224 } else {
225 schematics.get("default").setUseDefaultChest(true);
226 }
227 }
228 if (schematics.containsKey("nether")) {
229 schematics.get("nether").setName("NetherBlock Island");
230 schematics.get("nether").setDescription("Nether Island");
231 schematics.get("nether").setPartnerName("default");
232 schematics.get("nether").setBiome(Biome.HELL);
233 schematics.get("nether").setIcon(Material.NETHERRACK);
234 schematics.get("nether").setVisible(false);
235 schematics.get("nether").setPasteEntities(true);
236 if (Settings.chestItems.length == 0) {
237 schematics.get("nether").setUseDefaultChest(false);
238 }
239 }
240
241 // Load the schematics from config.yml
242 ConfigurationSection schemSection = plugin.getConfig().getConfigurationSection("schematicsection");
243 if (plugin.getConfig().contains("schematicsection")) {
244 Settings.useSchematicPanel = schemSection.getBoolean("useschematicspanel", false);
245 Settings.chooseIslandRandomly = schemSection.getBoolean("chooseislandrandomly", false);
246 ConfigurationSection schematicsSection = schemSection.getConfigurationSection("schematics");
247 // Section exists, so go through the various sections
248 for (String key : schematicsSection.getKeys(false)) {
249 try {
250 Schematic newSchem = null;
251 // Check the file exists
252 //plugin.getLogger().info("DEBUG: schematics." + key + ".filename" );
253 String filename = schemSection.getString("schematics." + key + ".filename","");
254 if (!filename.isEmpty()) {
255 //plugin.getLogger().info("DEBUG: filename = " + filename);
256 // Check if this file exists or if it is in the jar
257 schematicFile = new File(schematicFolder, filename);
258 // See if the file exists
259 if (schematicFile.exists()) {
260 newSchem = new Schematic(plugin, schematicFile);
261 } else if (plugin.getResource("schematics/"+filename) != null) {
262 plugin.saveResource("schematics/"+filename, false);
263 newSchem = new Schematic(plugin, schematicFile);
264 }
265 } else {
266 //plugin.getLogger().info("DEBUG: filename is empty");
267 if (key.equalsIgnoreCase("default")) {
268 //Øplugin.getLogger().info("DEBUG: key is default, so use this one");
269 newSchem = schematics.get("default");
270 } else {
271 plugin.getLogger().severe("Schematic " + key + " does not have a filename. Skipping!");
272 }
273 }
274 if (newSchem != null) {
275 // Set the heading
276 newSchem.setHeading(key);
277 // Order
278 newSchem.setOrder(schemSection.getInt("schematics." + key + ".order", 0));
279 // Load the rest of the settings
280 // Icon
281 try {
282
283 Material icon;
284 String iconString = schemSection.getString("schematics." + key + ".icon","MAP").toUpperCase();
285 // Support damage values
286 String[] split = iconString.split(":");
287 if (StringUtils.isNumeric(split[0])) {
288 icon = Material.getMaterial(Integer.parseInt(split[0]));
289 if (icon == null) {
290 icon = Material.MAP;
291 plugin.getLogger().severe("Schematic's icon could not be found. Try using quotes like '17:2'");
292 }
293 } else {
294 icon = Material.valueOf(split[0]);
295 }
296 int damage = 0;
297 if (split.length == 2) {
298 if (StringUtils.isNumeric(split[1])) {
299 damage = Integer.parseInt(split[1]);
300 }
301 }
302 newSchem.setIcon(icon, damage);
303 } catch (Exception e) {
304 //e.printStackTrace();
305 newSchem.setIcon(Material.MAP);
306 }
307 // Friendly name
308 String name = ChatColor.translateAlternateColorCodes('&', schemSection.getString("schematics." + key + ".name",""));
309 newSchem.setName(name);
310 // Rating - Rating is not used right now
311 int rating = schemSection.getInt("schematics." + key + ".rating",50);
312 if (rating <1) {
313 rating = 1;
314 } else if (rating > 100) {
315 rating = 100;
316 }
317 newSchem.setRating(rating);
318 // Cost
319 double cost = schemSection.getDouble("schematics." + key + ".cost", 0D);
320 if (cost < 0) {
321 cost = 0;
322 }
323 newSchem.setCost(cost);
324 // Description
325 String description = ChatColor.translateAlternateColorCodes('&', schemSection.getString("schematics." + key + ".description",""));
326 description = description.replace("[rating]",String.valueOf(rating));
327 if (Settings.useEconomy) {
328 description = description.replace("[cost]", String.valueOf(cost));
329 }
330 newSchem.setDescription(description);
331 // Permission
332 String perm = schemSection.getString("schematics." + key + ".permission","");
333 newSchem.setPerm(perm);
334 // Use default chest
335 newSchem.setUseDefaultChest(schemSection.getBoolean("schematics." + key + ".useDefaultChest", true));
336 // Biomes - overrides default if it exists
337 String biomeString = schemSection.getString("schematics." + key + ".biome",Settings.defaultBiome.toString());
338 Biome biome = null;
339 try {
340 biome = Biome.valueOf(biomeString);
341 newSchem.setBiome(biome);
342 } catch (Exception e) {
343 plugin.getLogger().severe("Could not parse biome " + biomeString + " using default instead.");
344 }
345 // Use physics - overrides default if it exists
346 newSchem.setUsePhysics(schemSection.getBoolean("schematics." + key + ".usephysics",Settings.usePhysics));
347 // Paste Entities or not
348 newSchem.setPasteEntities(schemSection.getBoolean("schematics." + key + ".pasteentities",false));
349 // Paste air or not.
350 newSchem.setPasteAir(schemSection.getBoolean("schematics." + key + ".pasteair",true));
351 // Visible in GUI or not
352 newSchem.setVisible(schemSection.getBoolean("schematics." + key + ".show",true));
353 // Partner schematic
354 if (biome != null && biome.equals(Biome.HELL)) {
355 // Default for nether biomes is the default overworld island
356 newSchem.setPartnerName(schemSection.getString("schematics." + key + ".partnerSchematic","default"));
357 } else {
358 // Default for overworld biomes is nether island
359 newSchem.setPartnerName(schemSection.getString("schematics." + key + ".partnerSchematic","nether"));
360 }
361 // Island companion
362 List<String> companion = schemSection.getStringList("schematics." + key + ".companion");
363 List<EntityType> companionTypes = new ArrayList<EntityType>();
364 if (!companion.isEmpty()) {
365 for (String companionType : companion) {
366 companionType = companionType.toUpperCase();
367 if (companionType.equalsIgnoreCase("NOTHING")) {
368 companionTypes.add(null);
369 } else {
370 try {
371 EntityType type = EntityType.valueOf(companionType);
372 companionTypes.add(type);
373 } catch (Exception e) {
374 plugin.getLogger()
375 .warning(
376 "Island companion is not recognized in schematic '" + name + "'.");
377 }
378 }
379 }
380 newSchem.setIslandCompanion(companionTypes);
381 }
382 // Companion names
383 List<String> companionNames = schemSection.getStringList("schematics." + key + ".companionnames");
384 if (!companionNames.isEmpty()) {
385 List<String> names = new ArrayList<String>();
386 for (String companionName : companionNames) {
387 names.add(ChatColor.translateAlternateColorCodes('&', companionName));
388 }
389 newSchem.setCompanionNames(names);
390 }
391 // Get chest items
392 final List<String> chestItems = schemSection.getStringList("schematics." + key + ".chestItems");
393 if (!chestItems.isEmpty()) {
394 ItemStack[] tempChest = new ItemStack[chestItems.size()];
395 int i = 0;
396 for (String chestItemString : chestItems) {
397 //plugin.getLogger().info("DEBUG: chest item = " + chestItemString);
398 try {
399 String[] amountdata = chestItemString.split(":");
400 if (amountdata[0].equals("POTION")) {
401 if (amountdata.length == 3) {
402 Potion chestPotion = new Potion(PotionType.valueOf(amountdata[1]));
403 tempChest[i++] = chestPotion.toItemStack(Integer.parseInt(amountdata[2]));
404 } else if (amountdata.length == 4) {
405 // Extended or splash potions
406 if (amountdata[2].equals("EXTENDED")) {
407 Potion chestPotion = new Potion(PotionType.valueOf(amountdata[1])).extend();
408 tempChest[i++] = chestPotion.toItemStack(Integer.parseInt(amountdata[3]));
409 } else if (amountdata[2].equals("SPLASH")) {
410 Potion chestPotion = new Potion(PotionType.valueOf(amountdata[1])).splash();
411 tempChest[i++] = chestPotion.toItemStack(Integer.parseInt(amountdata[3]));
412 } else if (amountdata[2].equals("EXTENDEDSPLASH")) {
413 Potion chestPotion = new Potion(PotionType.valueOf(amountdata[1])).extend().splash();
414 tempChest[i++] = chestPotion.toItemStack(Integer.parseInt(amountdata[3]));
415 }
416 }
417 } else {
418 Material mat;
419 if (StringUtils.isNumeric(amountdata[0])) {
420 mat = Material.getMaterial(Integer.parseInt(amountdata[0]));
421 } else {
422 mat = Material.getMaterial(amountdata[0].toUpperCase());
423 }
424 if (amountdata.length == 2) {
425 tempChest[i++] = new ItemStack(mat, Integer.parseInt(amountdata[1]));
426 } else if (amountdata.length == 3) {
427 tempChest[i++] = new ItemStack(mat, Integer.parseInt(amountdata[2]), Short.parseShort(amountdata[1]));
428 }
429 }
430 } catch (java.lang.IllegalArgumentException ex) {
431 plugin.getLogger().severe("Problem loading chest item for schematic '" + name + "' so skipping it: " + chestItemString);
432 plugin.getLogger().severe("Error is : " + ex.getMessage());
433 plugin.getLogger().info("Potential potion types are: ");
434 for (PotionType c : PotionType.values())
435 plugin.getLogger().info(c.name());
436 } catch (Exception e) {
437 plugin.getLogger().severe("Problem loading chest item for schematic '" + name + "' so skipping it: " + chestItemString);
438 plugin.getLogger().info("Potential material types are: ");
439 for (Material c : Material.values())
440 plugin.getLogger().info(c.name());
441 // e.printStackTrace();
442 }
443 }
444
445 // Store it
446 newSchem.setDefaultChestItems(tempChest);
447 }
448 // Player spawn block
449 String spawnBlock = schemSection.getString("schematics." + key + ".spawnblock");
450 if (spawnBlock != null) {
451 // Check to see if this block is a valid material
452 try {
453 Material playerSpawnBlock;
454 if (StringUtils.isNumeric(spawnBlock)) {
455 playerSpawnBlock = Material.getMaterial(Integer.parseInt(spawnBlock));
456 } else {
457 playerSpawnBlock = Material.valueOf(spawnBlock.toUpperCase());
458 }
459 if (newSchem.setPlayerSpawnBlock(playerSpawnBlock)) {
460 plugin.getLogger().info("Player will spawn at the " + playerSpawnBlock.toString());
461 } else {
462 plugin.getLogger().severe("Problem with schematic '" + name + "'. Spawn block '" + spawnBlock + "' not found in schematic or there is more than one. Skipping...");
463 }
464 } catch (Exception e) {
465 plugin.getLogger().severe("Problem with schematic '" + name + "'. Spawn block '" + spawnBlock + "' is unknown. Skipping...");
466 }
467 } else {
468 // plugin.getLogger().info("No spawn block found");
469 }
470 // Level handicap
471 newSchem.setLevelHandicap(schemSection.getInt("schematics." + key + ".levelHandicap", 0));
472
473 // Store it
474 schematics.put(key, newSchem);
475 if (perm.isEmpty()) {
476 perm = "all players";
477 } else {
478 perm = "player with " + perm + " permission";
479 }
480 plugin.getLogger().info("Loading schematic " + ChatColor.stripColor(name) + " (" + filename + ") for " + perm + ", order " + newSchem.getOrder());
481 } else {
482 plugin.getLogger().warning("Could not find " + filename + " in the schematics folder! Skipping...");
483 }
484 } catch (IOException e) {
485 plugin.getLogger().info("Error loading schematic in section " + key + ". Skipping...");
486 }
487 }
488 if (schematics.isEmpty()) {
489 tip();
490 }
491 }
492 }
493
494 private void tip() {
495 // There is no section in config.yml. Save the default schematic anyway
496 plugin.getLogger().warning("***************************************************************");
497 plugin.getLogger().warning("* 'schematics' section in config.yml has been deprecated. *");
498 plugin.getLogger().warning("* See 'schematicsection' in config.new.yml for replacement. *");
499 plugin.getLogger().warning("***************************************************************");
500 }
501
502 /**
503 * Adds a player to a team. The player and the teamleader MAY be the same
504 *
505 * @param playerUUID - the player's UUID
506 * @param teamLeader
507 * @return true if the player is successfully added
508 */
509 public boolean addPlayertoTeam(final UUID playerUUID, final UUID teamLeader) {
510 // Set the player's team giving the team leader's name and the team's
511 // island
512 // location
513 if (!plugin.getPlayers().setJoinTeam(playerUUID, teamLeader, plugin.getPlayers().getIslandLocation(teamLeader))) {
514 return false;
515 }
516 // If the player's name and the team leader are NOT the same when this
517 // method is called then set the player's home location to the leader's
518 // home location
519 // if it exists, and if not set to the island location
520 if (!playerUUID.equals(teamLeader)) {
521 // Clear any old home locations
522 plugin.getPlayers().clearHomeLocations(playerUUID);
523 // Set homes and spawn point home locations if they exist
524 for (Entry<Integer,Location> homes : plugin.getPlayers().getHomeLocations(teamLeader).entrySet()) {
525 if (homes.getKey() < 2) {
526 plugin.getPlayers().setHomeLocation(playerUUID, homes.getValue(), homes.getKey());
527 }
528 }
529 if (plugin.getPlayers().getHomeLocation(teamLeader,1) == null) {
530 plugin.getPlayers().setHomeLocation(playerUUID, plugin.getPlayers().getIslandLocation(teamLeader));
531 // plugin.getLogger().info("DEBUG: Setting player's home to the team island location");
532 }
533
534 // If the leader's member list does not contain player then add it
535 if (!plugin.getPlayers().getMembers(teamLeader).contains(playerUUID)) {
536 plugin.getPlayers().addTeamMember(teamLeader, playerUUID);
537 }
538 // If the leader's member list does not contain their own name then
539 // add it
540 if (!plugin.getPlayers().getMembers(teamLeader).contains(teamLeader)) {
541 plugin.getPlayers().addTeamMember(teamLeader, teamLeader);
542 }
543 // Fire event
544 final Island island = plugin.getGrid().getIsland(teamLeader);
545 final IslandJoinEvent event = new IslandJoinEvent(playerUUID, island);
546 plugin.getServer().getPluginManager().callEvent(event);
547 }
548 return true;
549 }
550
551 /**
552 * Removes a player from a team run by teamleader
553 *
554 * @param playerUUID - the player's UUID
555 * @param teamLeader
556 * @return true if successful, false if not
557 */
558 public boolean removePlayerFromTeam(final UUID playerUUID, final UUID teamLeader) {
559 return removePlayerFromTeam(playerUUID, teamLeader, false);
560 }
561
562 /**
563 * Removes a player from a team run by teamleader
564 *
565 * @param playerUUID - the player's UUID
566 * @param teamLeader
567 * @param makeLeader - true if this is the result of switching leader
568 * @return true if successful, false if not
569 */
570 public boolean removePlayerFromTeam(final UUID playerUUID, final UUID teamLeader, boolean makeLeader) {
571 // Remove player from the team
572 plugin.getPlayers().removeMember(teamLeader, playerUUID);
573 // If player is online
574 // If player is not the leader of their own team
575 if (teamLeader == null || !playerUUID.equals(teamLeader)) {
576 if (!plugin.getPlayers().setLeaveTeam(playerUUID)) {
577 return false;
578 }
579 //plugin.getPlayers().setHomeLocation(player, null);
580 plugin.getPlayers().clearHomeLocations(playerUUID);
581 plugin.getPlayers().setIslandLocation(playerUUID, null);
582 plugin.getPlayers().setTeamIslandLocation(playerUUID, null);
583 if (!makeLeader) {
584 OfflinePlayer offlinePlayer = plugin.getServer().getOfflinePlayer(playerUUID);
585 if (offlinePlayer.isOnline()) {
586 // Check perms
587 if (!((Player)offlinePlayer).hasPermission(Settings.PERMPREFIX + "command.leaveexempt")) {
588 runCommands(Settings.leaveCommands, offlinePlayer);
589 }
590 } else {
591 // If offline, all commands are run, sorry
592 runCommands(Settings.leaveCommands, offlinePlayer);
593 }
594 // Deduct a reset
595 if (Settings.leaversLoseReset && Settings.resetLimit >= 0) {
596 int resetsLeft = plugin.getPlayers().getResetsLeft(playerUUID);
597 if (resetsLeft > 0) {
598 resetsLeft--;
599 plugin.getPlayers().setResetsLeft(playerUUID, resetsLeft);
600 }
601 }
602 }
603 // Fire event
604 if (teamLeader != null) {
605 final Island island = plugin.getGrid().getIsland(teamLeader);
606 final IslandLeaveEvent event = new IslandLeaveEvent(playerUUID, island);
607 plugin.getServer().getPluginManager().callEvent(event);
608 }
609 } else {
610 // Ex-Leaders keeps their island, but the rest of the team members are
611 // removed
612 if (!plugin.getPlayers().setLeaveTeam(playerUUID)) {
613 // Event was cancelled for some reason
614 return false;
615 }
616 }
617 return true;
618 }
619
620 /**
621 * List schematics this player can access. If @param ignoreNoPermission is true, then only
622 * schematics with a specific permission set will be checked. I.e., no common schematics will
623 * be returned (including the default one).
624 * @param player
625 * @param ignoreNoPermission
626 * @return List of schematics this player can use based on their permission level
627 */
628 public List<Schematic> getSchematics(Player player, boolean ignoreNoPermission) {
629 List<Schematic> result = new ArrayList<Schematic>();
630 // Find out what schematics this player can choose from
631 //Bukkit.getLogger().info("DEBUG: Checking schematics for " + player.getName());
632 for (Schematic schematic : schematics.values()) {
633 //Bukkit.getLogger().info("DEBUG: schematic name is '"+ schematic.getName() + "'");
634 //Bukkit.getLogger().info("DEBUG: perm is " + schematic.getPerm());
635 if ((!ignoreNoPermission && schematic.getPerm().isEmpty()) || VaultHelper.checkPerm(player, schematic.getPerm())) {
636 //Bukkit.getLogger().info("DEBUG: player can use this schematic");
637 // Only add if it's visible
638 if (schematic.isVisible()) {
639 // Check if it's a nether island, but the nether is not enables
640 if (schematic.getBiome().equals(Biome.HELL)) {
641 if (Settings.createNether && Settings.newNether && ASkyBlock.getNetherWorld() != null) {
642 result.add(schematic);
643 }
644 } else {
645 result.add(schematic);
646 }
647 }
648
649 }
650 }
651 // Sort according to order
652 Collections.sort(result, new Comparator<Schematic>() {
653
654 @Override
655 public int compare(Schematic o1, Schematic o2) {
656 return ((o2.getOrder() < o1.getOrder()) ? 1 : -1);
657 }
658
659 });
660 return result;
661 }
662
663 /**
664 * @return the schematics
665 */
666 public static HashMap<String, Schematic> getSchematics() {
667 return schematics;
668 }
669
670 /**
671 * Makes the default island for the player
672 * @param player
673 */
674 public void newIsland(final Player player) {
675 //plugin.getLogger().info("DEBUG: Making default island");
676 newIsland(player, schematics.get("default"));
677 }
678
679 /**
680 * Makes an island using schematic. No permission checks are made. They have to be decided
681 * before this method is called.
682 * @param player
683 * @param schematic
684 */
685 public void newIsland(final Player player, final Schematic schematic) {
686 //long time = System.nanoTime();
687 final UUID playerUUID = player.getUniqueId();
688 boolean firstTime = false;
689 if (!plugin.getPlayers().hasIsland(playerUUID)) {
690 firstTime = true;
691 }
692 //plugin.getLogger().info("DEBUG: finding island location");
693 Location next = getNextIsland(player.getUniqueId());
694 //plugin.getLogger().info("DEBUG: found " + next);
695 // Set the player's parameters to this island
696 plugin.getPlayers().setHasIsland(playerUUID, true);
697 // Clear any old home locations (they should be clear, but just in case)
698 plugin.getPlayers().clearHomeLocations(playerUUID);
699 // Set the player's island location to this new spot
700 plugin.getPlayers().setIslandLocation(playerUUID, next);
701
702 // Set the biome
703 //BiomesPanel.setIslandBiome(next, schematic.getBiome());
704 // Teleport to the new home
705 if (schematic.isPlayerSpawn()) {
706 // Set home and teleport
707 plugin.getPlayers().setHomeLocation(playerUUID, schematic.getPlayerSpawn(next), 1);
708 // Save it for later reference
709 plugin.getPlayers().setHomeLocation(playerUUID, schematic.getPlayerSpawn(next), -1);
710 }
711
712 // Sets a flag to temporarily disable cleanstone generation
713 plugin.setNewIsland(true);
714 //plugin.getBiomes();
715
716 // Create island based on schematic
717 if (schematic != null) {
718 //plugin.getLogger().info("DEBUG: pasting schematic " + schematic.getName() + " " + schematic.getPerm());
719 //plugin.getLogger().info("DEBUG: nether world is " + ASkyBlock.getNetherWorld());
720 // Paste the starting island. If it is a HELL biome, then we start in the Nether
721 if (Settings.createNether && schematic.isInNether() && Settings.newNether && ASkyBlock.getNetherWorld() != null) {
722 // Nether start
723 // Paste the overworld if it exists
724 if (!schematic.getPartnerName().isEmpty() && schematics.containsKey(schematic.getPartnerName())) {
725 // A partner schematic is available
726 pastePartner(schematics.get(schematic.getPartnerName()),next, player);
727 }
728 // Switch home location to the Nether
729 next = next.toVector().toLocation(ASkyBlock.getNetherWorld());
730 // Set the player's island location to this new spot
731 plugin.getPlayers().setIslandLocation(playerUUID, next);
732 schematic.pasteSchematic(next, player, true, firstTime ? PasteReason.NEW_ISLAND: PasteReason.RESET);
733 } else {
734 // Over world start
735 //plugin.getLogger().info("DEBUG: pasting");
736 //long timer = System.nanoTime();
737 // Paste the island and teleport the player home
738 schematic.pasteSchematic(next, player, true, firstTime ? PasteReason.NEW_ISLAND: PasteReason.RESET);
739 //double diff = (System.nanoTime() - timer)/1000000;
740 //plugin.getLogger().info("DEBUG: nano time = " + diff + " ms");
741 //plugin.getLogger().info("DEBUG: pasted overworld");
742 if (Settings.createNether && Settings.newNether && ASkyBlock.getNetherWorld() != null) {
743 // Paste the other world schematic
744 final Location netherLoc = next.toVector().toLocation(ASkyBlock.getNetherWorld());
745 if (schematic.getPartnerName().isEmpty()) {
746 // This will paste the over world schematic again
747 //plugin.getLogger().info("DEBUG: pasting nether");
748 pastePartner(schematic, netherLoc, player);
749 //plugin.getLogger().info("DEBUG: pasted nether");
750 } else {
751 if (schematics.containsKey(schematic.getPartnerName())) {
752 //plugin.getLogger().info("DEBUG: pasting partner");
753 // A partner schematic is available
754 pastePartner(schematics.get(schematic.getPartnerName()),netherLoc, player);
755 } else {
756 plugin.getLogger().severe("Partner schematic heading '" + schematic.getPartnerName() + "' does not exist");
757 }
758 }
759 }
760 }
761 // Record the rating of this schematic - not used for anything right now
762 plugin.getPlayers().setStartIslandRating(playerUUID, schematic.getRating());
763 }
764 // Clear the cleanstone flag so events can happen again
765 plugin.setNewIsland(false);
766 // Add to the grid
767 Island myIsland = plugin.getGrid().addIsland(next.getBlockX(), next.getBlockZ(), playerUUID);
768 myIsland.setLevelHandicap(schematic.getLevelHandicap());
769 // Save the player so that if the server is reset weird things won't happen
770 plugin.getPlayers().save(playerUUID);
771
772 // Start the reset cooldown
773 if (!firstTime) {
774 setResetWaitTime(player);
775 }
776 // Set the custom protection range if appropriate
777 // Dynamic island range sizes with permissions
778 int range = Settings.islandProtectionRange;
779 for (PermissionAttachmentInfo perms : player.getEffectivePermissions()) {
780 if (perms.getPermission().startsWith(Settings.PERMPREFIX + "island.range.")) {
781 if (perms.getPermission().contains(Settings.PERMPREFIX + "island.range.*")) {
782 range = Settings.islandProtectionRange;
783 break;
784 } else {
785 String[] spl = perms.getPermission().split(Settings.PERMPREFIX + "island.range.");
786 if (spl.length > 1) {
787 if (!NumberUtils.isDigits(spl[1])) {
788 plugin.getLogger().severe("Player " + player.getName() + " has permission: " + perms.getPermission() + " <-- the last part MUST be a number! Ignoring...");
789 } else {
790 range = Math.max(range, Integer.valueOf(spl[1]));
791 }
792 }
793 }
794 }
795 }
796 // Do some sanity checking
797 if (range % 2 != 0) {
798 range--;
799 plugin.getLogger().warning("Protection range must be even, using " + range + " for " + player.getName());
800 }
801 if (range > Settings.islandDistance) {
802 plugin.getLogger().warning("Player has " + Settings.PERMPREFIX + "island.range." + range);
803 range = Settings.islandDistance;
804 plugin.getLogger().warning(
805 "Island protection range must be " + Settings.islandDistance + " or less. Setting to: " + range);
806 }
807 myIsland.setProtectionSize(range);
808
809 // Save grid just in case there's a crash
810 plugin.getGrid().saveGrid();
811 // Done - fire event
812 final IslandNewEvent event = new IslandNewEvent(player,schematic, myIsland);
813 plugin.getServer().getPluginManager().callEvent(event);
814 //plugin.getLogger().info("DEBUG: Done! " + (System.nanoTime()- time) * 0.000001);
815 }
816
817 /**
818 * Does a delayed pasting of the partner island
819 * @param schematic
820 * @param player
821 */
822 private void pastePartner(final Schematic schematic, final Location loc, final Player player) {
823 plugin.getServer().getScheduler().runTaskLater(plugin, new Runnable() {
824
825 @Override
826 public void run() {
827 schematic.pasteSchematic(loc, player, false, PasteReason.PARTNER);
828 if (schematic.isPlayerSpawn()) {
829 // Set partner home
830 plugin.getPlayers().setHomeLocation(player.getUniqueId(), schematic.getPlayerSpawn(loc), -2);
831 }
832 }}, 60L);
833
834 }
835
836 /**
837 * Pastes a schematic at a location for the player
838 * @param schematic
839 * @param loc
840 * @param player
841 * @param reason
842 */
843 public void pasteSchematic(final Schematic schematic, final Location loc, final Player player, PasteReason reason) {
844 schematic.pasteSchematic(loc, player, false, reason);
845 }
846
847 /**
848 * Get the location of next free island spot
849 * @param playerUUID - the player's UUID
850 * @return Location of island spot
851 */
852 private Location getNextIsland(UUID playerUUID) {
853 // See if there is a reserved spot
854 if (islandSpot.containsKey(playerUUID)) {
855 Location next = plugin.getGrid().getClosestIsland(islandSpot.get(playerUUID));
856 // Single shot only
857 islandSpot.remove(playerUUID);
858 // Check if it is already occupied (shouldn't be)
859 Island island = plugin.getGrid().getIslandAt(next);
860 if (island == null || island.getOwner() == null) {
861 // it's still free
862 return next;
863 }
864 // Else, fall back to the random pick
865 }
866 // Find the next free spot
867 if (last == null) {
868 last = new Location(ASkyBlock.getIslandWorld(), Settings.islandXOffset + Settings.islandStartX, Settings.islandHeight, Settings.islandZOffset + Settings.islandStartZ);
869 }
870 Location next = last.clone();
871
872 while (plugin.getGrid().islandAtLocation(next) || islandSpot.containsValue(next)) {
873 next = nextGridLocation(next);
874 }
875 // Make the last next, last
876 last = next.clone();
877 return next;
878 }
879
880
881
882
883
884
885 /**
886 * Finds the next free island spot based off the last known island Uses
887 * island_distance setting from the config file Builds up in a grid fashion
888 *
889 * @param lastIsland
890 * @return Location of next free island
891 */
892 private Location nextGridLocation(final Location lastIsland) {
893 // plugin.getLogger().info("DEBUG nextIslandLocation");
894 final int x = lastIsland.getBlockX();
895 final int z = lastIsland.getBlockZ();
896 final Location nextPos = lastIsland;
897 if (x < z) {
898 if (-1 * x < z) {
899 nextPos.setX(nextPos.getX() + Settings.islandDistance);
900 return nextPos;
901 }
902 nextPos.setZ(nextPos.getZ() + Settings.islandDistance);
903 return nextPos;
904 }
905 if (x > z) {
906 if (-1 * x >= z) {
907 nextPos.setX(nextPos.getX() - Settings.islandDistance);
908 return nextPos;
909 }
910 nextPos.setZ(nextPos.getZ() - Settings.islandDistance);
911 return nextPos;
912 }
913 if (x <= 0) {
914 nextPos.setZ(nextPos.getZ() + Settings.islandDistance);
915 return nextPos;
916 }
917 nextPos.setZ(nextPos.getZ() - Settings.islandDistance);
918 return nextPos;
919 }
920
921 /**
922 * Calculates the island level
923 *
924 * @param sender
925 * - Player object of player who is asking
926 * @param targetPlayer
927 * - UUID of the player's island that is being requested
928 * @return - true if successful.
929 */
930 public boolean calculateIslandLevel(final CommandSender sender, final UUID targetPlayer) {
931 return calculateIslandLevel(sender, targetPlayer, false);
932 }
933
934 /**
935 * Calculates the island level
936 * @param sender - asker of the level info
937 * @param targetPlayer
938 * @param report - if true, a detailed report will be provided
939 * @return - false if this is cannot be done
940 */
941 public boolean calculateIslandLevel(final CommandSender sender, final UUID targetPlayer, boolean report) {
942 if (sender instanceof Player) {
943 Player asker = (Player)sender;
944 // Player asking for their own island calc
945 if (asker.getUniqueId().equals(targetPlayer) || asker.isOp() || VaultHelper.checkPerm(asker, Settings.PERMPREFIX + "mod.info")) {
946 // Newer better system - uses chunks
947 if (!onLevelWaitTime(asker) || Settings.levelWait <= 0 || asker.isOp() || VaultHelper.checkPerm(asker, Settings.PERMPREFIX + "mod.info")) {
948 Util.sendMessage(asker, ChatColor.GREEN + plugin.myLocale(asker.getUniqueId()).levelCalculating);
949 setLevelWaitTime(asker);
950 new LevelCalcByChunk(plugin, plugin.getGrid().getIsland(targetPlayer), targetPlayer, asker, report);
951 } else {
952 Util.sendMessage(asker, ChatColor.YELLOW + plugin.myLocale(asker.getUniqueId()).islandresetWait.replace("[time]", String.valueOf(getLevelWaitTime(asker))));
953 }
954
955 } else {
956 // Asking for the level of another player
957 Util.sendMessage(asker, ChatColor.GREEN + plugin.myLocale(asker.getUniqueId()).islandislandLevelis.replace("[level]", String.valueOf(plugin.getPlayers().getIslandLevel(targetPlayer))));
958 }
959 } else {
960 // Console request
961 Util.sendMessage(sender, ChatColor.GREEN + plugin.myLocale().levelCalculating);
962 new LevelCalcByChunk(plugin, plugin.getGrid().getIsland(targetPlayer), targetPlayer, sender, report);
963 }
964 return true;
965 }
966
967 /**
968 * One-to-one relationship, you can return the first matched key
969 *
970 * @param map
971 * @param value
972 * @return key
973 */
974 public static <T, E> T getKeyByValue(Map<T, E> map, E value) {
975 for (Entry<T, E> entry : map.entrySet()) {
976 if (value.equals(entry.getValue())) {
977 return entry.getKey();
978 }
979 }
980 return null;
981 }
982
983 /*
984 * (non-Javadoc)
985 * @see
986 * org.bukkit.command.CommandExecutor#onCommand(org.bukkit.command.CommandSender
987 * , org.bukkit.command.Command, java.lang.String, java.lang.String[])
988 */
989 @Override
990 public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] split) {
991 if (!(sender instanceof Player)) {
992 Util.sendMessage(sender, plugin.myLocale().errorUseInGame);
993 return false;
994 }
995 final Player player = (Player) sender;
996 // Basic permissions check to even use /island
997 if (!VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.create")) {
998 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).islanderrorYouDoNotHavePermission);
999 return true;
1000 }
1001 /*
1002 * Grab data for this player - may be null or empty
1003 * playerUUID is the unique ID of the player who issued the command
1004 */
1005 final UUID playerUUID = player.getUniqueId();
1006 if (playerUUID == null) {
1007 plugin.getLogger().severe("Player " + sender.getName() + " has a null UUID - this should never happen!");
1008 Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorCommandNotReady + " (No UUID)");
1009 return true;
1010 }
1011 final UUID teamLeader = plugin.getPlayers().getTeamLeader(playerUUID);
1012 List<UUID> teamMembers = new ArrayList<UUID>();
1013 if (teamLeader != null) {
1014 teamMembers = plugin.getPlayers().getMembers(teamLeader);
1015 }
1016 // Island name (can have spaces)
1017 if (split.length > 1 && split[0].equalsIgnoreCase("name")) {
1018 // Naming of island
1019 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.name")
1020 && plugin.getPlayers().hasIsland(playerUUID)) {
1021 String name = split[1];
1022 for (int i = 2; i < split.length; i++) {
1023 name = name + " " + split[i];
1024 }
1025 if (name.length() < Settings.minNameLength) {
1026 Util.sendMessage(player, ChatColor.RED + (plugin.myLocale(player.getUniqueId()).errorTooShort).replace("[length]", String.valueOf(Settings.minNameLength)));
1027 return true;
1028 }
1029 if (name.length() > Settings.maxNameLength) {
1030 Util.sendMessage(player, ChatColor.RED + (plugin.myLocale(player.getUniqueId()).errorTooLong).replace("[length]", String.valueOf(Settings.maxNameLength)));
1031 return true;
1032 }
1033 plugin.getGrid().setIslandName(playerUUID, ChatColor.translateAlternateColorCodes('&', name));
1034 Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(player.getUniqueId()).generalSuccess);
1035 return true;
1036 } else {
1037 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoPermission);
1038 return true;
1039 }
1040 }
1041 // The target player's UUID
1042 UUID targetPlayer = null;
1043 // Check if a player has an island or is in a team
1044 switch (split.length) {
1045 // /island command by itself
1046 case 0:
1047 // New island
1048 if (plugin.getPlayers().getIslandLocation(playerUUID) == null && !plugin.getPlayers().inTeam(playerUUID)) {
1049 // Check if the max number of islands is made already
1050 if (Settings.maxIslands > 0 && plugin.getGrid().getIslandCount() > Settings.maxIslands) {
1051 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorMaxIslands);
1052 return true;
1053 }
1054 // Check if player has resets left
1055 if (plugin.getPlayers().getResetsLeft(playerUUID) == 0) {
1056 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).islandResetNoMore);
1057 return true;
1058 }
1059 // Create new island for player
1060 Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(player.getUniqueId()).islandnew);
1061 chooseIsland(player);
1062 return true;
1063 } else {
1064 // Island command
1065 // Check if this should open the Control Panel or not
1066 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.controlpanel") && plugin.getPlayers().getControlPanel(playerUUID)) {
1067 Util.runCommand(player, Settings.ISLANDCOMMAND + " cp");
1068 } else {
1069 // Check permission
1070 if (!VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.go")) {
1071 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoPermission);
1072 return true;
1073 }
1074 if (!player.getWorld().getName().equalsIgnoreCase(Settings.worldName) || Settings.allowTeleportWhenFalling
1075 || !PlayerEvents.isFalling(playerUUID) || (player.isOp() && !Settings.damageOps)) {
1076 // Teleport home
1077 plugin.getGrid().homeTeleport(player);
1078 if (Settings.islandRemoveMobs) {
1079 plugin.getGrid().removeMobs(player.getLocation());
1080 }
1081 } else {
1082 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorCommandNotReady);
1083 }
1084 }
1085 return true;
1086 }
1087 case 1:
1088 if (split[0].equalsIgnoreCase("value")) {
1089 if(valueLookup(player, split)) {
1090 return true;
1091 }
1092 } else if (split[0].equalsIgnoreCase("name")) {
1093 // Explain command
1094 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.name")
1095 && plugin.getPlayers().hasIsland(playerUUID)) {
1096 Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " name <name>: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandHelpName);
1097 return true;
1098 }
1099 } else if (split[0].equalsIgnoreCase("resetname")) {
1100 // Convert name to a UUID
1101 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.name")
1102 && plugin.getPlayers().hasIsland(playerUUID)) {
1103 // Has an island
1104 plugin.getGrid().setIslandName(playerUUID, null);
1105 Util.sendMessage(sender, plugin.myLocale().generalSuccess);
1106 }
1107 return true;
1108 }
1109 if (split[0].equalsIgnoreCase("trust")) {
1110 // Explain command
1111 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "coop")) {
1112 Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " coop <player>: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpCoop);
1113 return true;
1114 }
1115 } else if (split[0].equalsIgnoreCase("untrust")) {
1116 // Explain command
1117 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "coop")) {
1118 Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " uncoop <player>: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpUnCoop);
1119 return true;
1120 }
1121 } else if (split[0].equalsIgnoreCase("expel")) {
1122 // Explain command
1123 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.expel")) {
1124 Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " expel <player>: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpExpel);
1125 return true;
1126 }
1127 } else if (split[0].equalsIgnoreCase("inmatechat") || split[0].equalsIgnoreCase("ic")) {
1128 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "team.chat")) {
1129 // Check if this command is on or not
1130 if (!Settings.teamChat) {
1131 Util.sendMessage(player, ChatColor.RED + plugin.myLocale().errorUnknownCommand);
1132 return false;
1133 }
1134 // Check if in team
1135 if (plugin.getPlayers().inTeam(playerUUID)) {
1136 // Check if team members are online
1137 boolean online = false;
1138 for (UUID teamMember : plugin.getPlayers().getMembers(playerUUID)) {
1139 if (!teamMember.equals(playerUUID) && plugin.getServer().getPlayer(teamMember) != null) {
1140 online = true;
1141 }
1142 }
1143 if (!online) {
1144 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).teamChatNoTeamAround);
1145 Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(playerUUID).teamChatStatusOff);
1146 plugin.getChatListener().unSetPlayer(playerUUID);
1147 return true;
1148 }
1149 if (plugin.getChatListener().isTeamChat(playerUUID)) {
1150 // Toggle
1151 Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(playerUUID).teamChatStatusOff);
1152 plugin.getChatListener().unSetPlayer(playerUUID);
1153 } else {
1154 Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(playerUUID).teamChatStatusOn);
1155 plugin.getChatListener().setPlayer(playerUUID);
1156 }
1157 } else {
1158 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).teamChatNoTeam);
1159 }
1160 } else {
1161 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).errorNoPermission);
1162 }
1163 return true;
1164 }
1165 if (split[0].equalsIgnoreCase("banlist") || split[0].equalsIgnoreCase("suspended")) {
1166 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.ban")) {
1167 // Show banned players
1168 Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(playerUUID).adminInfoBannedPlayers + ":");
1169 List<UUID> bannedList = plugin.getPlayers().getBanList(playerUUID);
1170 if (bannedList.isEmpty()) {
1171 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).banNone);
1172 } else {
1173 for (UUID bannedPlayers: bannedList) {
1174 Util.sendMessage(player, plugin.myLocale(playerUUID).helpColor + plugin.getPlayers().getName(bannedPlayers));
1175 }
1176 }
1177 return true;
1178 } else {
1179 Util.sendMessage(player, plugin.myLocale(playerUUID).errorNoPermission);
1180 }
1181 return true;
1182 } else if (split[0].equalsIgnoreCase("ban") || split[0].equalsIgnoreCase("suspend")) {
1183 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.ban")) {
1184 // Just show ban help
1185 Util.sendMessage(player, plugin.myLocale(playerUUID).helpColor + "/" + label + " suspend <player>: " + ChatColor.WHITE + plugin.myLocale(playerUUID).islandhelpBan);
1186 } else {
1187 Util.sendMessage(player, plugin.myLocale(playerUUID).errorNoPermission);
1188 }
1189 return true;
1190 } else if (split[0].equalsIgnoreCase("unban") || split[0].equalsIgnoreCase("pardon") && VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.ban")) {
1191 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.ban")) {
1192 // Just show unban help
1193 Util.sendMessage(player, plugin.myLocale(playerUUID).helpColor + "/" + label + " pardon <player>: " + ChatColor.WHITE + plugin.myLocale(playerUUID).islandhelpUnban);
1194 } else {
1195 Util.sendMessage(player, plugin.myLocale(playerUUID).errorNoPermission);
1196 }
1197 return true;
1198 } else if (split[0].equalsIgnoreCase("make")) {
1199 //plugin.getLogger().info("DEBUG: /is make called");
1200 if (!pendingNewIslandSelection.contains(playerUUID)) {
1201 Util.sendMessage(player, ChatColor.RED + plugin.myLocale().errorUnknownCommand);
1202 return false;
1203 }
1204 pendingNewIslandSelection.remove(playerUUID);
1205 Island oldIsland = plugin.getGrid().getIsland(player.getUniqueId());
1206 newIsland(player);
1207 if (resettingIsland.contains(playerUUID)) {
1208 resettingIsland.remove(playerUUID);
1209 resetPlayer(player, oldIsland);
1210 }
1211 return true;
1212 } else
1213 if (split[0].equalsIgnoreCase("lang")) {
1214 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.lang")) {
1215 Util.sendMessage(player, "/" + label + " lang <#>");
1216 displayLocales(player);
1217 } else {
1218 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).errorNoPermission);
1219 }
1220 return true;
1221 } else if (split[0].equalsIgnoreCase("settings") || split[0].equalsIgnoreCase("configuration") || split[0].equalsIgnoreCase("config")) {
1222 // Show what the plugin settings are
1223 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.settings")) {
1224 try {
1225 player.openInventory(plugin.getSettingsPanel().islandGuardPanel(player));
1226 } catch (Exception e) {
1227 if (DEBUG)
1228 e.printStackTrace();
1229 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorCommandNotReady);
1230 }
1231 } else {
1232 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoPermission);
1233 }
1234 return true;
1235 } else if (split[0].equalsIgnoreCase("lock") || split[0].equalsIgnoreCase("lockdown")) {
1236 if (!VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.lock")) {
1237 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoPermission);
1238 return true;
1239 }
1240 // plugin.getLogger().info("DEBUG: perms ok");
1241 // Find out which island they want to lock
1242 Island island = plugin.getGrid().getIsland(playerUUID);
1243 if (island == null) {
1244 // plugin.getLogger().info("DEBUG: player has no island in grid");
1245 // Player has no island in the grid
1246 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoIsland);
1247 return true;
1248 } else {
1249 if (!island.isLocked()) {
1250 // Remove any visitors
1251 for (Player target : plugin.getServer().getOnlinePlayers()) {
1252 if (target == null || target.hasMetadata("NPC") || target.isOp() || player.equals(target) || VaultHelper.checkPerm(target, Settings.PERMPREFIX + "mod.bypassprotect"))
1253 continue;
1254 // See if target is on this player's island and not a coop player
1255 if (plugin.getGrid().isOnIsland(player, target)
1256 && !CoopPlay.getInstance().getCoopPlayers(island.getCenter()).contains(target.getUniqueId())) {
1257 // Send them home
1258 if (plugin.getPlayers().inTeam(target.getUniqueId()) || plugin.getPlayers().hasIsland(target.getUniqueId())) {
1259 plugin.getGrid().homeTeleport(target);
1260 } else {
1261 // Just move target to spawn
1262 if (!target.performCommand(Settings.SPAWNCOMMAND)) {
1263 target.teleport(player.getWorld().getSpawnLocation());
1264 }
1265 }
1266 Util.sendMessage(target, ChatColor.RED + plugin.myLocale(target.getUniqueId()).expelExpelled);
1267 plugin.getLogger().info(player.getName() + " expelled " + target.getName() + " from their island when locking.");
1268 // Yes they are
1269 Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(player.getUniqueId()).expelSuccess.replace("[name]", target.getName()));
1270 }
1271 }
1272 Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(playerUUID).lockLocking);
1273 plugin.getMessages().tellOfflineTeam(playerUUID, plugin.myLocale(playerUUID).lockPlayerLocked.replace("[name]", player.getName()));
1274 plugin.getMessages().tellTeam(playerUUID, plugin.myLocale(playerUUID).lockPlayerLocked.replace("[name]", player.getName()));
1275 island.setLocked(true);
1276 } else {
1277 Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(playerUUID).lockUnlocking);
1278 plugin.getMessages().tellOfflineTeam(playerUUID, plugin.myLocale(playerUUID).lockPlayerUnlocked.replace("[name]", player.getName()));
1279 plugin.getMessages().tellTeam(playerUUID, plugin.myLocale(playerUUID).lockPlayerUnlocked.replace("[name]", player.getName()));
1280 island.setLocked(false);
1281 }
1282 return true;
1283 }
1284 } else if (split[0].equalsIgnoreCase("go") || split[0].equalsIgnoreCase("tp")) {
1285 if (!VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.go")) {
1286 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoPermission);
1287 return true;
1288 }
1289 if (!plugin.getPlayers().hasIsland(playerUUID) && !plugin.getPlayers().inTeam(playerUUID)) {
1290 // Player has no island
1291 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).errorNoIsland);
1292 return true;
1293 }
1294 // Teleport home
1295 plugin.getGrid().homeTeleport(player);
1296 if (Settings.islandRemoveMobs) {
1297 plugin.getGrid().removeMobs(player.getLocation());
1298 }
1299 return true;
1300 }
1301
1302 if (split[0].equalsIgnoreCase("controlpanel") || split[0].equalsIgnoreCase("cp") || split[0].equalsIgnoreCase("station")) {
1303 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.controlpanel")) {
1304 if (ControlPanel.controlPanel.containsKey(ControlPanel.getDefaultPanelName())) {
1305 player.openInventory(ControlPanel.controlPanel.get(ControlPanel.getDefaultPanelName()));
1306 return true;
1307 } else {
1308 Util.sendMessage(player, plugin.myLocale(playerUUID).errorCommandNotReady);
1309 plugin.getLogger().severe("There is a problem with the controlpanel.yml file - it is probably corrupted. Delete it and let it be regenerated.");
1310 return true;
1311 }
1312 }
1313 }
1314
1315 if (split[0].equalsIgnoreCase("3054jt3094yjh3904jy0h0j5h2yhk") || split[0].equalsIgnoreCase("3054jt3094yjh3904jy0h02j5h2yhk")) {
1316 if (Settings.useEconomy && Settings.useMinishop) {
1317 // Check island
1318 if (plugin.getGrid().getIsland(player.getUniqueId()) == null) {
1319 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoIsland);
1320 return true;
1321 }
1322 if (player.getWorld().equals(ASkyBlock.getIslandWorld()) || player.getWorld().equals(ASkyBlock.getNetherWorld())) {
1323 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.minishop")) {
1324 if (ControlPanel.miniShop != null) {
1325 player.openInventory(ControlPanel.miniShop);
1326 } else {
1327 Util.sendMessage(player, plugin.myLocale(playerUUID).errorCommandNotReady);
1328 plugin.getLogger().severe("Player tried to open the minishop, but it does not exist. Look for errors in the console about the minishop loading.");
1329 }
1330 return true;
1331 }
1332 } else {
1333 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorWrongWorld);
1334 return true;
1335 }
1336 }
1337 else{
1338 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorMinishopDisabled);
1339 return true;
1340 }
1341 }
1342 // /island <command>
1343 if (split[0].equalsIgnoreCase("warp")) {
1344 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.warp")) {
1345 Util.sendMessage(player, ChatColor.YELLOW + "/island warp <player>: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpWarp);
1346 return true;
1347 }
1348 } else if (split[0].equalsIgnoreCase("warps")) {
1349 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.warp")) {
1350 // Step through warp table
1351 Collection<UUID> warpList = plugin.getWarpSignsListener().listWarps();
1352 if (warpList.isEmpty()) {
1353 Util.sendMessage(player, ChatColor.YELLOW + plugin.myLocale(player.getUniqueId()).warpserrorNoWarpsYet);
1354 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.addwarp") && plugin.getGrid().playerIsOnIsland(player)) {
1355 Util.sendMessage(player, ChatColor.YELLOW + plugin.myLocale().warpswarpTip);
1356 }
1357 return true;
1358 } else {
1359 if (Settings.useWarpPanel) {
1360 // Try the warp panel
1361 player.openInventory(plugin.getWarpPanel().getWarpPanel(0));
1362 } else {
1363 Boolean hasWarp = false;
1364 String wlist = "";
1365 for (UUID w : warpList) {
1366 if (w == null)
1367 continue;
1368 if (wlist.isEmpty()) {
1369 wlist = plugin.getPlayers().getName(w);
1370 } else {
1371 wlist += ", " + plugin.getPlayers().getName(w);
1372 }
1373 if (w.equals(playerUUID)) {
1374 hasWarp = true;
1375 }
1376 }
1377 Util.sendMessage(player, ChatColor.YELLOW + plugin.myLocale(player.getUniqueId()).warpswarpsAvailable + ": " + ChatColor.WHITE + wlist);
1378 if (!hasWarp && (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.addwarp"))) {
1379 Util.sendMessage(player, ChatColor.YELLOW + plugin.myLocale().warpswarpTip);
1380 }
1381 }
1382 return true;
1383 }
1384 }
1385 } else if (split[0].equalsIgnoreCase("restart") || split[0].equalsIgnoreCase("reset")) {
1386 if (!VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.reset")) {
1387 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoPermission);
1388 return true;
1389 }
1390 // Check this player has an island
1391 if (!plugin.getPlayers().hasIsland(playerUUID)) {
1392 // No so just start an island
1393 Util.runCommand(player, Settings.ISLANDCOMMAND);
1394 return true;
1395 }
1396 if (plugin.getPlayers().inTeam(playerUUID)) {
1397 if (!plugin.getPlayers().getTeamLeader(playerUUID).equals(playerUUID)) {
1398 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).islandresetOnlyOwner);
1399 } else {
1400 Util.sendMessage(player, ChatColor.YELLOW + plugin.myLocale(player.getUniqueId()).islandresetMustRemovePlayers);
1401 }
1402 return true;
1403 }
1404 // Check if the player has used up all their resets
1405 if (plugin.getPlayers().getResetsLeft(playerUUID) == 0) {
1406 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).islandResetNoMore);
1407 return true;
1408 }
1409 if (plugin.getPlayers().getResetsLeft(playerUUID) > 0) {
1410 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).resetYouHave.replace("[number]", String.valueOf(plugin.getPlayers().getResetsLeft(playerUUID))));
1411 }
1412 if (!onRestartWaitTime(player) || Settings.resetWait == 0 || player.isOp()) {
1413 // Kick off the confirmation
1414 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).islandresetConfirm.replace("[seconds]", String.valueOf(Settings.resetConfirmWait)));
1415 if (!confirm.containsKey(playerUUID) || !confirm.get(playerUUID)) {
1416 confirm.put(playerUUID, true);
1417 plugin.getServer().getScheduler().runTaskLater(plugin, new Runnable() {
1418 @Override
1419 public void run() {
1420 confirm.put(playerUUID, false);
1421 }
1422 }, (Settings.resetConfirmWait * 20));
1423 }
1424 return true;
1425 } else {
1426 Util.sendMessage(player, ChatColor.YELLOW + plugin.myLocale(player.getUniqueId()).islandresetWait.replace("[time]", String.valueOf(getResetWaitTime(player))));
1427 }
1428 return true;
1429 } else if (split[0].equalsIgnoreCase("confirm") || split[0].equalsIgnoreCase("confirmation")) {
1430 // This is where the actual reset is done
1431 if (confirm.containsKey(playerUUID) && confirm.get(playerUUID)) {
1432 confirm.remove(playerUUID);
1433 // Actually RESET the island
1434 Util.sendMessage(player, ChatColor.YELLOW + plugin.myLocale(player.getUniqueId()).islandresetPleaseWait);
1435 if (plugin.getPlayers().getResetsLeft(playerUUID) == 0) {
1436 Util.sendMessage(player, ChatColor.YELLOW + plugin.myLocale(player.getUniqueId()).islandResetNoMore);
1437 }
1438 if (plugin.getPlayers().getResetsLeft(playerUUID) > 0) {
1439 Util.sendMessage(player, ChatColor.YELLOW
1440 + plugin.myLocale(player.getUniqueId()).resetYouHave.replace("[number]", String.valueOf(plugin.getPlayers().getResetsLeft(playerUUID))));
1441 }
1442 // Show a schematic panel if the player has a choice
1443 // Get the schematics that this player is eligible to use
1444 List<Schematic> schems = getSchematics(player, false);
1445 //plugin.getLogger().info("DEBUG: size of schematics for this player = " + schems.size());
1446 Island oldIsland = plugin.getGrid().getIsland(player.getUniqueId());
1447 if (schems.isEmpty()) {
1448 // No schematics - use default island
1449 newIsland(player);
1450 resetPlayer(player,oldIsland);
1451 } else if (schems.size() == 1) {
1452 // Hobson's choice
1453 newIsland(player,schems.get(0));
1454 resetPlayer(player,oldIsland);
1455 } else {
1456 // A panel can only be shown if there is >1 viable schematic
1457 if (Settings.useSchematicPanel) {
1458 pendingNewIslandSelection.add(playerUUID);
1459 resettingIsland.add(playerUUID);
1460 player.openInventory(plugin.getSchematicsPanel().getPanel(player));
1461 } else {
1462 // No panel
1463 // Check schematics for specific permission
1464 schems = getSchematics(player,true);
1465 if (schems.isEmpty()) {
1466 newIsland(player);
1467 } else if (Settings.chooseIslandRandomly) {
1468 // Choose an island randomly from the list
1469 newIsland(player, schems.get(random.nextInt(schems.size())));
1470 } else {
1471 // Do the first one in the list
1472 newIsland(player, schems.get(0));
1473 }
1474 resetPlayer(player,oldIsland);
1475 }
1476 }
1477 return true;
1478 } else {
1479 Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/island restart: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpRestart);
1480 return true;
1481 }
1482 } else if (split[0].equalsIgnoreCase("sethome")) {
1483 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.sethome")) {
1484 // Check island
1485 if (plugin.getGrid().getIsland(player.getUniqueId()) == null) {
1486 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoIsland);
1487 return true;
1488 }
1489 plugin.getGrid().homeSet(player);
1490 return true;
1491 } else {
1492 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).errorNoPermission);
1493 return true;
1494 }
1495 } else if (split[0].equalsIgnoreCase("help")) {
1496 Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + plugin.myLocale(player.getUniqueId()).helpHeader.replace("[plugin]", plugin.getDescription().getName()).replace("[version]", plugin.getDescription().getVersion()));
1497 if (Settings.useControlPanel) {
1498 Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + ": " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpControlPanel);
1499 } else {
1500 Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + ": " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpIsland);
1501 }
1502 // Dynamic home sizes with permissions
1503 int maxHomes = Settings.maxHomes;
1504 for (PermissionAttachmentInfo perms : player.getEffectivePermissions()) {
1505 if (perms.getPermission().startsWith(Settings.PERMPREFIX + "island.maxhomes.")) {
1506 if (perms.getPermission().startsWith(Settings.PERMPREFIX + "island.maxhomes.*")) {
1507 maxHomes = Settings.maxHomes;
1508 break;
1509 } else {
1510 // Get the max value should there be more than one
1511 String[] spl = perms.getPermission().split(Settings.PERMPREFIX + "island.maxhomes.");
1512 if (spl.length > 1) {
1513 // Check that it is a number
1514 if (!NumberUtils.isDigits(spl[1])) {
1515 plugin.getLogger().severe("Player " + player.getName() + " has permission: " + perms.getPermission() + " <-- the last part MUST be a number! Ignoring...");
1516
1517 } else {
1518 maxHomes = Math.max(maxHomes, Integer.valueOf(spl[1]));
1519 }
1520 }
1521 }
1522 }
1523 // Do some sanity checking
1524 if (maxHomes < 1) {
1525 maxHomes = 1;
1526 }
1527 }
1528 if (maxHomes > 1 && VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.go")) {
1529 Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " go <1 - " + maxHomes + ">: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpTeleport);
1530 } else if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.go")) {
1531 Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " go: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpTeleport);
1532 }
1533 if (plugin.getGrid() != null && plugin.getGrid().getSpawn() != null && VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.spawn")) {
1534 Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " spawn: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpSpawn);
1535 }
1536 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.controlpanel")) {
1537 Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " controlpanel or cp [on/off]: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpControlPanel);
1538 }
1539 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.reset")) {
1540 Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " reset: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpRestart);
1541 }
1542 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.sethome")) {
1543 if (maxHomes > 1) {
1544 Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " sethome <1 - " + maxHomes + ">: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpSetHome);
1545 } else {
1546 Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " sethome: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpSetHome);
1547 }
1548 }
1549 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.info")) {
1550 Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " level: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpLevel);
1551 Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " level <player>: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpLevelPlayer);
1552 }
1553 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.name")
1554 && plugin.getPlayers().hasIsland(playerUUID)) {
1555 Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " name <name>: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandHelpName);
1556 }
1557 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.topten")) {
1558 Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " top: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpTop);
1559 }
1560 if (Settings.useEconomy && VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.minishop")) {
1561 Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " minishop or ms: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpMiniShop);
1562 }
1563 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.value")) {
1564 Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " value: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpValue);
1565 }
1566 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.warp")) {
1567 Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " warps: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpWarps);
1568 Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " warp <player>: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpWarp);
1569 }
1570 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "team.create")) {
1571 Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " team: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpTeam);
1572 Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " invite <player>: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpInvite);
1573 Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " leave: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpLeave);
1574 }
1575 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "team.kick")) {
1576 Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " kick/remove <player>: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpKick);
1577 }
1578 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "team.join")) {
1579 Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " <accept|yes/reject|no>: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpAcceptReject);
1580 }
1581 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "team.makeleader")) {
1582 Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " transfer/makeleader/ownership <player>: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpMakeLeader);
1583 }
1584 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "team.chat")
1585 && plugin.getPlayers().inTeam(playerUUID)) {
1586 Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " inmatechat/ic: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).teamChatHelp);
1587 }
1588 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.biomes")) {
1589 Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " biomes: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpBiome);
1590 }
1591 // if (!Settings.allowPvP) {
1592 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.expel")) {
1593 Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " expel <player>: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpExpel);
1594 }
1595 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.ban")) {
1596 Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " suspend/bam <player>: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpBan);
1597 Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " banlist: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpBanList);
1598 Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " pardon/unban <player>: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpUnban);
1599 }
1600 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "coop")) {
1601 Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " trust <player>: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpCoop);
1602 Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " untrust <player>: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpUnCoop);
1603 Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " listtrusted: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpListCoops);
1604
1605 }
1606 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.lock")) {
1607 Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " lock: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandHelpLock);
1608 }
1609 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.name")
1610 && plugin.getPlayers().hasIsland(playerUUID)) {
1611 Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " resetname: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpResetName);
1612 }
1613 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.settings")) {
1614 Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " settings: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandHelpSettings);
1615 }
1616 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.challenges")) {
1617 Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + plugin.myLocale(player.getUniqueId()).islandHelpChallenges);
1618 }
1619 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.lang")) {
1620 Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "/" + label + " lang <#>: "+ ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandHelpSelectLanguage);
1621 }
1622 // DEBUG - used to find meta tags
1623 /*
1624 if (player.getInventory().getItemInMainHand() != null) {
1625 net.minecraft.server.v1_11_R1.ItemStack stack = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand());
1626 NBTTagCompound tagCompound = stack.getTag();
1627 Bukkit.getLogger().info("DEBUG: tag = " + tagCompound);
1628 }
1629 */
1630 return true;
1631 } else if (split[0].equalsIgnoreCase("listtrusted")) {
1632 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "coop")) {
1633 if (!plugin.getPlayers().hasIsland(playerUUID)) {
1634 // Player has no island
1635 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoIsland);
1636 return true;
1637 }
1638 Island island = plugin.getGrid().getIsland(playerUUID);
1639 boolean none = true;
1640 for (UUID uuid: CoopPlay.getInstance().getCoopPlayers(island.getCenter())) {
1641 Util.sendMessage(player, ChatColor.GREEN + plugin.getPlayers().getName(uuid));
1642 none = false;
1643 }
1644 if (none) {
1645 Util.sendMessage(player, plugin.myLocale(playerUUID).helpColor + "/" + label + " coop <player>: " + ChatColor.WHITE + plugin.myLocale(player.getUniqueId()).islandhelpCoop);
1646 } else {
1647 Util.sendMessage(player, plugin.myLocale(playerUUID).helpColor + plugin.myLocale(playerUUID).coopUseExpel);
1648 }
1649 return true;
1650 }
1651 } else if (split[0].equalsIgnoreCase("biomes")) {
1652 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.biomes")) {
1653 // Only the team leader can do this
1654 if (teamLeader != null && !teamLeader.equals(playerUUID)) {
1655 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).levelerrornotYourIsland);
1656 return true;
1657 }
1658 if (!plugin.getPlayers().hasIsland(playerUUID)) {
1659 // Player has no island
1660 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoIsland);
1661 return true;
1662 }
1663 if (!plugin.getGrid().playerIsOnIsland(player)) {
1664 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).challengeserrorNotOnIsland);
1665 return true;
1666 }
1667 // Not allowed in the nether
1668 if (plugin.getPlayers().getIslandLocation(playerUUID).getWorld().getEnvironment().equals(Environment.NETHER)) {
1669 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorWrongWorld);
1670 return true;
1671 }
1672 // Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).helpColor + "[Biomes]");
1673 Inventory inv = plugin.getBiomes().getBiomePanel(player);
1674 if (inv != null) {
1675 player.openInventory(inv);
1676 }
1677 return true;
1678 } else {
1679 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoPermission);
1680 return true;
1681 }
1682 } else if (split[0].equalsIgnoreCase("spawn") && plugin.getGrid().getSpawn() != null) {
1683 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.spawn")) {
1684 // go to spawn
1685 Location l = ASkyBlock.getIslandWorld().getSpawnLocation();
1686 l.add(new Vector(0.5,0,0.5));
1687 Island spawn = plugin.getGrid().getSpawn();
1688 if (spawn != null && spawn.getSpawnPoint() != null) {
1689 l = spawn.getSpawnPoint();
1690 }
1691
1692 IslandPreTeleportEvent event = new IslandPreTeleportEvent(player, IslandPreTeleportEvent.Type.SPAWN, l);
1693 Bukkit.getPluginManager().callEvent(event);
1694 if (!event.isCancelled()) {
1695 player.teleport(event.getLocation());
1696 }
1697
1698 } else {
1699 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).errorNoPermission);
1700 }
1701 return true;
1702 } else if (split[0].equalsIgnoreCase("top")) {
1703 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.topten")) {
1704 if (creatingTopTen) {
1705 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorCommandNotReady);
1706 return true;
1707 }
1708 plugin.getTopTen().topTenShow(player);
1709 return true;
1710 } else {
1711 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).errorNoPermission);
1712 return true;
1713 }
1714 } else if (split[0].equalsIgnoreCase("level")) {
1715 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.info")) {
1716 if (!plugin.getPlayers().inTeam(playerUUID) && !plugin.getPlayers().hasIsland(playerUUID)) {
1717 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoIsland);
1718 return true;
1719 } else {
1720 if (!VaultHelper.checkPerm(player, Settings.PERMPREFIX + "intopten")) {
1721 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).topTenerrorExcluded.replace("[perm]", Settings.PERMPREFIX + "intopten"));
1722 }
1723 calculateIslandLevel(player, playerUUID);
1724 return true;
1725 }
1726 } else {
1727 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).errorNoPermission);
1728 return true;
1729 }
1730 } else if (split[0].equalsIgnoreCase("invite")) {
1731 // Invite label with no name, i.e., /island invite - tells the
1732 // player how many more people they can invite
1733 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "team.create")) {
1734 Util.sendMessage(player, plugin.myLocale(player.getUniqueId()).invitehelp);
1735 // If the player who is doing the inviting has a team
1736 if (plugin.getPlayers().inTeam(playerUUID)) {
1737 // Check to see if the player is the leader
1738 if (teamLeader.equals(playerUUID)) {
1739 // Check to see if the team is already full
1740 int maxSize = Settings.maxTeamSize;
1741 // Dynamic team sizes with permissions
1742 for (PermissionAttachmentInfo perms : player.getEffectivePermissions()) {
1743 if (perms.getPermission().startsWith(Settings.PERMPREFIX + "team.maxsize.")) {
1744 if (perms.getPermission().contains(Settings.PERMPREFIX + "team.maxsize.*")) {
1745 maxSize = Settings.maxTeamSize;
1746 break;
1747 } else {
1748 // Get the max value should there be more than one
1749 String[] spl = perms.getPermission().split(Settings.PERMPREFIX + "team.maxsize.");
1750 if (spl.length > 1) {
1751 if (!NumberUtils.isDigits(spl[1])) {
1752 plugin.getLogger().severe("Player " + player.getName() + " has permission: " + perms.getPermission() + " <-- the last part MUST be a number! Ignoring...");
1753
1754 } else {
1755 maxSize = Math.max(maxSize, Integer.valueOf(spl[1]));
1756 }
1757 }
1758 }
1759 }
1760 // Do some sanity checking
1761 if (maxSize < 1) {
1762 maxSize = 1;
1763 }
1764 }
1765 if (teamMembers.size() < maxSize) {
1766 Util.sendMessage(player, ChatColor.GREEN
1767 + plugin.myLocale(player.getUniqueId()).inviteyouCanInvite.replace("[number]", String.valueOf(maxSize - teamMembers.size())));
1768 } else {
1769 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).inviteerrorYourIslandIsFull);
1770 }
1771 return true;
1772 }
1773
1774 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).inviteerrorYouMustHaveIslandToInvite);
1775 return true;
1776 }
1777
1778 return true;
1779 } else {
1780 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).errorNoPermission);
1781 return true;
1782 }
1783 } else if (split[0].equalsIgnoreCase("trustaccept")) {
1784 // Accept an invite command
1785 if (coopInviteList.containsKey(playerUUID)) {
1786 // Check if inviter is online
1787 Player inviter = plugin.getServer().getPlayer(coopInviteList.get(playerUUID));
1788 if (inviter == null || !inviter.isOnline()) {
1789 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorOfflinePlayer);
1790 coopInviteList.remove(playerUUID);
1791 return true;
1792 }
1793 if (CoopPlay.getInstance().addCoopPlayer(inviter,player)) {
1794 // Tell everyone what happened
1795 Util.sendMessage(inviter, ChatColor.GREEN + plugin.myLocale(inviter.getUniqueId()).coopSuccess.replace("[name]", player.getName()));
1796 Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(playerUUID).coopMadeYouCoop.replace("[name]", inviter.getName()));
1797 // TODO: Give perms if the player is on the coop island
1798 }
1799 setResetWaitTime(player);
1800 // Remove the invite
1801 coopInviteList.remove(playerUUID);
1802 return true;
1803 }
1804 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorCommandNotReady);
1805 return true;
1806 } else if (split[0].equalsIgnoreCase("accept") || split[0].equalsIgnoreCase("yes")) {
1807 // Accept an invite command
1808 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "team.join")) {
1809 // If player is not in a team but has been invited to join
1810 // one
1811 if (!plugin.getPlayers().inTeam(playerUUID) && inviteList.containsKey(playerUUID)) {
1812 // If the invitee has an island of their own
1813 if (plugin.getPlayers().hasIsland(playerUUID)) {
1814 plugin.getLogger().info(player.getName() + "'s island will be deleted because they joined a party.");
1815 plugin.getPlayers().setInTeleport(playerUUID, true);
1816 plugin.deletePlayerIsland(playerUUID, true);
1817 plugin.getLogger().info("Island deleted.");
1818 }
1819 // Add the player to the team
1820 addPlayertoTeam(playerUUID, inviteList.get(playerUUID));
1821 // If the leader who did the invite does not yet have a
1822 // team (leader is not in a team yet)
1823 if (!plugin.getPlayers().inTeam(inviteList.get(playerUUID))) {
1824 // Add the leader to their own team
1825 addPlayertoTeam(inviteList.get(playerUUID), inviteList.get(playerUUID));
1826 }
1827 setResetWaitTime(player);
1828 if (Settings.teamJoinDeathReset) {
1829 plugin.getPlayers().setDeaths(player.getUniqueId(), 0);
1830 }
1831 plugin.getGrid().homeTeleport(player);
1832 plugin.resetPlayer(player);
1833 if (!player.hasPermission(Settings.PERMPREFIX + "command.newteamexempt")) {
1834 //plugin.getLogger().info("DEBUG: Executing new island commands");
1835 runCommands(Settings.teamStartCommands, player);
1836 }
1837 Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(playerUUID).inviteyouHaveJoinedAnIsland);
1838 if (plugin.getServer().getPlayer(inviteList.get(playerUUID)) != null) {
1839 Util.sendMessage(plugin.getServer().getPlayer(inviteList.get(playerUUID)),
1840 ChatColor.GREEN + plugin.myLocale(inviteList.get(playerUUID)).invitehasJoinedYourIsland.replace("[name]", player.getName()));
1841 }
1842 // Remove the invite
1843 inviteList.remove(player.getUniqueId());
1844 plugin.getGrid().saveGrid();
1845 return true;
1846 }
1847 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorCommandNotReady);
1848 return true;
1849 } else {
1850 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).errorNoPermission);
1851 return true;
1852 }
1853 } else if (split[0].equalsIgnoreCase("trustreject")) {
1854 // Reject /island coopreject
1855 if (coopInviteList.containsKey(playerUUID)) {
1856 Util.sendMessage(player, ChatColor.YELLOW + plugin.myLocale(playerUUID).rejectyouHaveRejectedInvitation);
1857 // If the player is online still then tell them directly
1858 // about the rejection
1859 if (Bukkit.getPlayer(inviteList.get(playerUUID)) != null) {
1860 Util.sendMessage(Bukkit.getPlayer(inviteList.get(playerUUID)),
1861 ChatColor.RED + plugin.myLocale(inviteList.get(playerUUID)).rejectnameHasRejectedInvite.replace("[name]", player.getName()));
1862 }
1863 // Remove this player from the global invite list
1864 coopInviteList.remove(playerUUID);
1865 } else {
1866 // Someone typed /island coopreject and had not been invited
1867 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).rejectyouHaveNotBeenInvited);
1868 }
1869 return true;
1870 } else if (split[0].equalsIgnoreCase("reject") ||(split[0].equalsIgnoreCase("no"))) {
1871 // Reject /island reject
1872 if (inviteList.containsKey(player.getUniqueId())) {
1873 Util.sendMessage(player, ChatColor.YELLOW + plugin.myLocale(playerUUID).rejectyouHaveRejectedInvitation);
1874 // If the player is online still then tell them directly
1875 // about the rejection
1876 if (Bukkit.getPlayer(inviteList.get(player.getUniqueId())) != null) {
1877 Util.sendMessage(Bukkit.getPlayer(inviteList.get(playerUUID)),
1878 ChatColor.RED + plugin.myLocale(inviteList.get(playerUUID)).rejectnameHasRejectedInvite.replace("[name]", player.getName()));
1879 }
1880 // Remove this player from the global invite list
1881 inviteList.remove(playerUUID);
1882 } else {
1883 // Someone typed /island reject and had not been invited
1884 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).rejectyouHaveNotBeenInvited);
1885 }
1886 return true;
1887 } else if (split[0].equalsIgnoreCase("leave")) {
1888 // Leave team command
1889 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "team.join")) {
1890 if (player.getWorld().equals(ASkyBlock.getIslandWorld()) ||
1891 (Settings.createNether && Settings.newNether &&
1892 ASkyBlock.getNetherWorld() != null && player.getWorld().equals(ASkyBlock.getNetherWorld()))) {
1893 if (plugin.getPlayers().inTeam(playerUUID)) {
1894 if (plugin.getPlayers().getTeamLeader(playerUUID) != null && plugin.getPlayers().getTeamLeader(playerUUID).equals(playerUUID)) {
1895 Util.sendMessage(player, ChatColor.YELLOW + plugin.myLocale(player.getUniqueId()).leaveerrorYouAreTheLeader);
1896 return true;
1897 }
1898 // Check for confirmation
1899 if (!leavingPlayers.contains(playerUUID)) {
1900 leavingPlayers.add(playerUUID);
1901 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).leaveWarning);
1902 new BukkitRunnable() {
1903
1904 @Override
1905 public void run() {
1906 // If the player is still on the list, remove them and cancel the leave
1907 if (leavingPlayers.contains(playerUUID)) {
1908 leavingPlayers.remove(playerUUID);
1909 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).leaveCanceled);
1910 }
1911 }
1912
1913 }.runTaskLater(plugin, Settings.resetConfirmWait * 20L);
1914 return true;
1915 }
1916 // Remove from confirmation list
1917 leavingPlayers.remove(playerUUID);
1918 // Remove from team
1919 if (!removePlayerFromTeam(playerUUID, teamLeader)) {
1920 //Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).leaveerrorYouCannotLeaveIsland);
1921 // If this is canceled, fail silently
1922 return true;
1923 }
1924 // Clear any coop inventories
1925 // CoopPlay.getInstance().returnAllInventories(player);
1926 // Remove any of the target's coop invitees and grab
1927 // their stuff
1928 CoopPlay.getInstance().clearMyInvitedCoops(player);
1929 CoopPlay.getInstance().clearMyCoops(player);
1930
1931 // Log the location that this player left so they
1932 // cannot join again before the cool down ends
1933 plugin.getPlayers().startInviteCoolDownTimer(playerUUID, plugin.getPlayers().getTeamIslandLocation(teamLeader));
1934
1935 // Remove any warps
1936 plugin.getWarpSignsListener().removeWarp(playerUUID);
1937 Util.sendMessage(player, ChatColor.YELLOW + plugin.myLocale(player.getUniqueId()).leaveyouHaveLeftTheIsland);
1938 // Tell the leader if they are online
1939 if (plugin.getServer().getPlayer(teamLeader) != null) {
1940 Player leader = plugin.getServer().getPlayer(teamLeader);
1941 Util.sendMessage(leader, ChatColor.RED + plugin.myLocale(teamLeader).leavenameHasLeftYourIsland.replace("[name]", player.getName()));
1942 } else {
1943 // Leave them a message
1944 plugin.getMessages().setMessage(teamLeader, ChatColor.RED + plugin.myLocale(teamLeader).leavenameHasLeftYourIsland.replace("[name]", player.getName()));
1945 }
1946 // Check if the size of the team is now 1
1947 // teamMembers.remove(playerUUID);
1948 if (teamMembers.size() < 2) {
1949 // plugin.getLogger().info("DEBUG: Party is less than 2 - removing leader from team");
1950 if (!removePlayerFromTeam(teamLeader, teamLeader)) {
1951 // If this is canceled, return silently.
1952 return true;
1953 }
1954 }
1955 // Clear all player variables and save
1956 plugin.resetPlayer(player);
1957 if (!player.performCommand(Settings.SPAWNCOMMAND)) {
1958 player.teleport(player.getWorld().getSpawnLocation());
1959 }
1960 return true;
1961 } else {
1962 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).leaveerrorYouCannotLeaveIsland);
1963 return true;
1964 }
1965 } else {
1966 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).leaveerrorYouMustBeInWorld);
1967 }
1968 return true;
1969 } else {
1970 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).errorNoPermission);
1971 return true;
1972 }
1973 } else if (split[0].equalsIgnoreCase("inmates")) {
1974 if (plugin.getPlayers().inTeam(playerUUID)) {
1975 if (teamLeader.equals(playerUUID)) {
1976 int maxSize = Settings.maxTeamSize;
1977 for (PermissionAttachmentInfo perms : player.getEffectivePermissions()) {
1978 if (perms.getPermission().startsWith(Settings.PERMPREFIX + "team.maxsize.")) {
1979 if (perms.getPermission().contains(Settings.PERMPREFIX + "team.maxsize.*")) {
1980 maxSize = Settings.maxTeamSize;
1981 break;
1982 } else {
1983 // Get the max value should there be more than one
1984 String[] spl = perms.getPermission().split(Settings.PERMPREFIX + "team.maxsize.");
1985 if (spl.length > 1) {
1986 if (!NumberUtils.isDigits(spl[1])) {
1987 plugin.getLogger().severe("Player " + player.getName() + " has permission: " + perms.getPermission() + " <-- the last part MUST be a number! Ignoring...");
1988
1989 } else {
1990 maxSize = Math.max(maxSize, Integer.valueOf(spl[1]));
1991 }
1992 }
1993 }
1994 }
1995 // Do some sanity checking
1996 if (maxSize < 1) {
1997 maxSize = 1;
1998 }
1999 }
2000 if (teamMembers.size() < maxSize) {
2001 Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(player.getUniqueId()).inviteyouCanInvite.replace("[number]", String.valueOf(maxSize - teamMembers.size())));
2002 } else {
2003 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).inviteerrorYourIslandIsFull);
2004 }
2005 }
2006 Util.sendMessage(player, ChatColor.YELLOW + plugin.myLocale(player.getUniqueId()).teamlistingMembers + ":");
2007 // Display members in the list
2008 for (UUID m : plugin.getPlayers().getMembers(teamLeader)) {
2009 Util.sendMessage(player, ChatColor.WHITE + plugin.getPlayers().getName(m));
2010 }
2011 } else if (inviteList.containsKey(playerUUID)) {
2012 Util.sendMessage(player, ChatColor.YELLOW
2013 + plugin.myLocale(player.getUniqueId()).invitenameHasInvitedYou.replace("[name]", plugin.getPlayers().getName(inviteList.get(playerUUID))));
2014 Util.sendMessage(player, ChatColor.WHITE + "/" + label + " [accept/reject]" + ChatColor.YELLOW + plugin.myLocale(player.getUniqueId()).invitetoAcceptOrReject);
2015 } else {
2016 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).kickerrorNoTeam);
2017 }
2018 return true;
2019 } else {
2020 // Incorrect syntax
2021 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).errorUnknownCommand);
2022 return true;
2023 }
2024 break;
2025 /*
2026 * Commands that have two parameters
2027 */
2028 case 2:
2029 if (split[0].equalsIgnoreCase("controlpanel") || split[0].equalsIgnoreCase("cp") || split[0].equalsIgnoreCase("station")) {
2030 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.controlpanelonoff")) {
2031 if (split[1].equalsIgnoreCase("on")) {
2032 plugin.getPlayers().setControlPanel(playerUUID, true);
2033 } else if (split[1].equalsIgnoreCase("off")) {
2034 plugin.getPlayers().setControlPanel(playerUUID, false);
2035 }
2036 Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(playerUUID).generalSuccess);
2037 return true;
2038 } else {
2039 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).errorNoPermission);
2040 return true;
2041 }
2042 } else if (split[0].equalsIgnoreCase("value")) {
2043 if(valueLookup(player, split)) {
2044 return true;
2045 }
2046 } else
2047 if (split[0].equalsIgnoreCase("warps")) {
2048 if (Settings.useWarpPanel) {
2049 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.warp")) {
2050 // Step through warp table
2051 Set<UUID> warpList = plugin.getWarpSignsListener().listWarps();
2052 if (warpList.isEmpty()) {
2053 Util.sendMessage(player, ChatColor.YELLOW + plugin.myLocale(player.getUniqueId()).warpserrorNoWarpsYet);
2054 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.addwarp") && plugin.getGrid().playerIsOnIsland(player)) {
2055 Util.sendMessage(player, ChatColor.YELLOW + plugin.myLocale().warpswarpTip);
2056 }
2057 return true;
2058 } else {
2059 // Try the warp panel
2060 int panelNum = 0;
2061 try {
2062 panelNum = Integer.valueOf(split[1]) - 1;
2063 } catch (Exception e) {
2064 panelNum = 0;
2065 }
2066 player.openInventory(plugin.getWarpPanel().getWarpPanel(panelNum));
2067 return true;
2068 }
2069 } else {
2070 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).errorNoPermission);
2071 }
2072 } else {
2073 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).errorUnknownCommand);
2074 return true;
2075 }
2076 } else
2077 if (split[0].equalsIgnoreCase("make")) {
2078 //plugin.getLogger().info("DEBUG: /is make '" + split[1] + "' called");
2079 if (!pendingNewIslandSelection.contains(playerUUID)) {
2080 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).errorUnknownCommand);
2081 return true;
2082 }
2083 pendingNewIslandSelection.remove(playerUUID);
2084 // Create a new island using schematic
2085 if (!schematics.containsKey(split[1])) {
2086 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).errorUnknownCommand);
2087 return true;
2088 } else {
2089 Schematic schematic = schematics.get(split[1]);
2090 // Check perm again
2091 if (schematic.getPerm().isEmpty() || VaultHelper.checkPerm(player, schematic.getPerm())) {
2092 Island oldIsland = plugin.getGrid().getIsland(player.getUniqueId());
2093 newIsland(player,schematic);
2094 if (resettingIsland.contains(playerUUID)) {
2095 resettingIsland.remove(playerUUID);
2096 resetPlayer(player, oldIsland);
2097 }
2098 return true;
2099 } else {
2100 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).errorNoPermission);
2101 return true;
2102 }
2103 }
2104 } else if (split[0].equalsIgnoreCase("lang")) {
2105 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.lang")) {
2106 if (!NumberUtils.isDigits(split[1])) {
2107 Util.sendMessage(player, ChatColor.RED + "/" + label + " lang <#>");
2108 displayLocales(player);
2109 return true;
2110 } else {
2111 try {
2112 int index = Integer.valueOf(split[1]);
2113 if (index < 1 || index > plugin.getAvailableLocales().size()) {
2114 Util.sendMessage(player, ChatColor.RED + "/" + label + " lang <#>");
2115 displayLocales(player);
2116 return true;
2117 }
2118 for (ASLocale locale : plugin.getAvailableLocales().values()) {
2119 if (locale.getIndex() == index) {
2120 plugin.getPlayers().setLocale(playerUUID, locale.getLocaleName());
2121 Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(playerUUID).generalSuccess);
2122 return true;
2123 }
2124 }
2125 // Not in the list
2126 Util.sendMessage(player, ChatColor.RED + "/" + label + " lang <#>");
2127 displayLocales(player);
2128 } catch (Exception e) {
2129 Util.sendMessage(player, ChatColor.RED + "/" + label + " lang <#>");
2130 displayLocales(player);
2131 }
2132 }
2133 return true;
2134 } else {
2135 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).errorNoPermission);
2136 return true;
2137 }
2138 } else
2139 // Multi home
2140 if (split[0].equalsIgnoreCase("go")) {
2141 if (!plugin.getPlayers().hasIsland(playerUUID) && !plugin.getPlayers().inTeam(playerUUID)) {
2142 // Player has no island
2143 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoIsland);
2144 return true;
2145 }
2146 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.sethome")) {
2147 int number = 1;
2148 try {
2149 number = Integer.valueOf(split[1]);
2150 //plugin.getLogger().info("DEBUG: number = " + number);
2151 if (number < 1) {
2152 plugin.getGrid().homeTeleport(player,1);
2153 } else {
2154 // Dynamic home sizes with permissions
2155 int maxHomes = Settings.maxHomes;
2156 for (PermissionAttachmentInfo perms : player.getEffectivePermissions()) {
2157 if (perms.getPermission().startsWith(Settings.PERMPREFIX + "island.maxhomes.")) {
2158 if (perms.getPermission().contains(Settings.PERMPREFIX + "island.maxhomes.*")) {
2159 maxHomes = Settings.maxHomes;
2160 break;
2161 } else {
2162 // Get the max value should there be more than one
2163 String[] spl = perms.getPermission().split(Settings.PERMPREFIX + "island.maxhomes.");
2164 if (spl.length > 1) {
2165 if (!NumberUtils.isDigits(spl[1])) {
2166 plugin.getLogger().severe("Player " + player.getName() + " has permission: " + perms.getPermission() + " <-- the last part MUST be a number! Ignoring...");
2167
2168 } else {
2169 maxHomes = Math.max(maxHomes, Integer.valueOf(spl[1]));
2170 }
2171 }
2172 }
2173 }
2174 // Do some sanity checking
2175 if (maxHomes < 1) {
2176 maxHomes = 1;
2177 }
2178 }
2179 if (number > maxHomes) {
2180 if (maxHomes > 1) {
2181 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).setHomeerrorNumHomes.replace("[max]",String.valueOf(maxHomes)));
2182 } else {
2183 plugin.getGrid().homeTeleport(player,1);
2184 }
2185 } else {
2186 // Teleport home
2187 plugin.getGrid().homeTeleport(player,number);
2188 }
2189 }
2190 } catch (Exception e) {
2191 // Teleport home
2192 plugin.getGrid().homeTeleport(player,1);
2193 }
2194 if (Settings.islandRemoveMobs) {
2195 plugin.getGrid().removeMobs(player.getLocation());
2196 }
2197 } else {
2198 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoPermission);
2199 }
2200 return true;
2201 } else if (split[0].equalsIgnoreCase("sethome")) {
2202 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.sethome")) {
2203 Island island = plugin.getGrid().getIsland(playerUUID);
2204 if (island == null) {
2205 // plugin.getLogger().info("DEBUG: player has no island in grid");
2206 // Player has no island in the grid
2207 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoIsland);
2208 return true;
2209 }
2210 // Dynamic home sizes with permissions
2211 int maxHomes = Settings.maxHomes;
2212 for (PermissionAttachmentInfo perms : player.getEffectivePermissions()) {
2213 if (perms.getPermission().startsWith(Settings.PERMPREFIX + "island.maxhomes.")) {
2214 // Get the max value should there be more than one
2215 if (perms.getPermission().contains(Settings.PERMPREFIX + "island.maxhomes.*")) {
2216 maxHomes = Settings.maxHomes;
2217 break;
2218 } else {
2219 String[] spl = perms.getPermission().split(Settings.PERMPREFIX + "island.maxhomes.");
2220 if (spl.length > 1) {
2221 if (!NumberUtils.isDigits(spl[1])) {
2222 plugin.getLogger().severe("Player " + player.getName() + " has permission: " + perms.getPermission() + " <-- the last part MUST be a number! Ignoring...");
2223
2224 } else {
2225 maxHomes = Math.max(maxHomes, Integer.valueOf(spl[1]));
2226 }
2227 }
2228 }
2229 }
2230 // Do some sanity checking
2231 if (maxHomes < 1) {
2232 maxHomes = 1;
2233 }
2234 }
2235 if (maxHomes > 1) {
2236 // Check the number given is a number
2237 int number = 0;
2238 try {
2239 number = Integer.valueOf(split[1]);
2240 if (number < 1 || number > maxHomes) {
2241 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).setHomeerrorNumHomes.replace("[max]",String.valueOf(maxHomes)));
2242 } else {
2243 plugin.getGrid().homeSet(player, number);
2244 }
2245 } catch (Exception e) {
2246 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).setHomeerrorNumHomes.replace("[max]",String.valueOf(maxHomes)));
2247 }
2248 } else {
2249 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoPermission);
2250 }
2251 return true;
2252 }
2253 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoPermission);
2254 return true;
2255 } else if (split[0].equalsIgnoreCase("warp")) {
2256 // Warp somewhere command
2257 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.warp")) {
2258 final Set<UUID> warpList = plugin.getWarpSignsListener().listWarps();
2259 if (warpList.isEmpty()) {
2260 Util.sendMessage(player, ChatColor.YELLOW + plugin.myLocale(player.getUniqueId()).warpserrorNoWarpsYet);
2261 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.addwarp")) {
2262 Util.sendMessage(player, ChatColor.YELLOW + plugin.myLocale().warpswarpTip);
2263 } else {
2264 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoPermission);
2265 }
2266 return true;
2267 } else {
2268 // Check if this is part of a name
2269 UUID foundWarp = null;
2270 for (UUID warp : warpList) {
2271 if (warp == null)
2272 continue;
2273 if (plugin.getPlayers().getName(warp) != null) {
2274 if (plugin.getPlayers().getName(warp).toLowerCase().equals(split[1].toLowerCase())) {
2275 foundWarp = warp;
2276 break;
2277 } else if (plugin.getPlayers().getName(warp).toLowerCase().startsWith(split[1].toLowerCase())) {
2278 foundWarp = warp;
2279 }
2280 }
2281 }
2282 if (foundWarp == null) {
2283 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).warpserrorDoesNotExist);
2284 return true;
2285 } else {
2286 // Warp exists!
2287 final Location warpSpot = plugin.getWarpSignsListener().getWarp(foundWarp);
2288 // Check if the warp spot is safe
2289 if (warpSpot == null) {
2290 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).warpserrorNotReadyYet);
2291 plugin.getLogger().warning("Null warp found, owned by " + plugin.getPlayers().getName(foundWarp));
2292 return true;
2293 }
2294 // Find out if island is locked
2295 Island island = plugin.getGrid().getIslandAt(warpSpot);
2296 // Check bans
2297 if (island != null && plugin.getPlayers().isBanned(island.getOwner(), playerUUID)) {
2298 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).banBanned.replace("[name]", plugin.getPlayers().getName(island.getOwner())));
2299 if (!VaultHelper.checkPerm(player, Settings.PERMPREFIX + "mod.bypassprotect")
2300 && !VaultHelper.checkPerm(player, Settings.PERMPREFIX + "mod.bypasslock")) {
2301 return true;
2302 }
2303 }
2304 if (island != null && island.isLocked() && !player.isOp() && !VaultHelper.checkPerm(player, Settings.PERMPREFIX + "mod.bypasslock")
2305 && !VaultHelper.checkPerm(player, Settings.PERMPREFIX + "mod.bypassprotect")) {
2306 // Always inform that the island is locked
2307 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).lockIslandLocked);
2308 // Check if this is the owner, team member or coop
2309 if (!plugin.getGrid().locationIsAtHome(player, true, warpSpot)) {
2310 //plugin.getLogger().info("DEBUG: not at home");
2311 return true;
2312 }
2313 }
2314 boolean pvp = false;
2315 if (island != null && ((warpSpot.getWorld().equals(ASkyBlock.getIslandWorld()) && island.getIgsFlag(SettingsFlag.PVP))
2316 || (warpSpot.getWorld().equals(ASkyBlock.getNetherWorld()) && island.getIgsFlag(SettingsFlag.NETHER_PVP)))) {
2317 pvp = true;
2318 }
2319 // Find out which direction the warp is facing
2320 Block b = warpSpot.getBlock();
2321 if (b.getType().equals(Material.SIGN_POST) || b.getType().equals(Material.WALL_SIGN)) {
2322 Sign sign = (Sign) b.getState();
2323 org.bukkit.material.Sign s = (org.bukkit.material.Sign) sign.getData();
2324 BlockFace directionFacing = s.getFacing();
2325 Location inFront = b.getRelative(directionFacing).getLocation();
2326 Location oneDown = b.getRelative(directionFacing).getRelative(BlockFace.DOWN).getLocation();
2327 if ((GridManager.isSafeLocation(inFront))) {
2328 warpPlayer(player, inFront, foundWarp, directionFacing, pvp);
2329 return true;
2330 } else if (b.getType().equals(Material.WALL_SIGN) && GridManager.isSafeLocation(oneDown)) {
2331 // Try one block down if this is a wall sign
2332 warpPlayer(player, oneDown, foundWarp, directionFacing, pvp);
2333 return true;
2334 }
2335 } else {
2336 // Warp has been removed
2337 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).warpserrorDoesNotExist);
2338 plugin.getWarpSignsListener().removeWarp(warpSpot);
2339 return true;
2340 }
2341 if (!(GridManager.isSafeLocation(warpSpot))) {
2342 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).warpserrorNotSafe);
2343 // WALL_SIGN's will always be unsafe if the place in front is obscured.
2344 if (b.getType().equals(Material.SIGN_POST)) {
2345 plugin.getLogger().warning(
2346 "Unsafe warp found at " + warpSpot.toString() + " owned by " + plugin.getPlayers().getName(foundWarp));
2347
2348 }
2349 return true;
2350 } else {
2351 final Location actualWarp = new Location(warpSpot.getWorld(), warpSpot.getBlockX() + 0.5D, warpSpot.getBlockY(),
2352 warpSpot.getBlockZ() + 0.5D);
2353 player.teleport(actualWarp);
2354 if (pvp) {
2355 Util.sendMessage(player, ChatColor.BOLD + "" + ChatColor.RED + plugin.myLocale(player.getUniqueId()).igs.get(SettingsFlag.PVP) + " " + plugin.myLocale(player.getUniqueId()).igsAllowed);
2356 if (plugin.getServer().getVersion().contains("(MC: 1.8") || plugin.getServer().getVersion().contains("(MC: 1.7")) {
2357 player.getWorld().playSound(player.getLocation(), Sound.valueOf("ARROW_HIT"), 1F, 1F);
2358 } else {
2359 player.getWorld().playSound(player.getLocation(), Sound.ENTITY_ARROW_HIT, 1F, 1F);
2360 }
2361 } else {
2362 if (plugin.getServer().getVersion().contains("(MC: 1.8") || plugin.getServer().getVersion().contains("(MC: 1.7")) {
2363 player.getWorld().playSound(player.getLocation(), Sound.valueOf("BAT_TAKEOFF"), 1F, 1F);
2364 } else {
2365 player.getWorld().playSound(player.getLocation(), Sound.ENTITY_BAT_TAKEOFF, 1F, 1F);
2366 }
2367 }
2368 return true;
2369 }
2370 }
2371 }
2372 } else {
2373 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoPermission);
2374 return true;
2375 }
2376 } else if (split[0].equalsIgnoreCase("worth")) {
2377 // island level <name> command
2378 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.info")) {
2379 // Find out if the target has an island
2380 final UUID targetPlayerUUID = plugin.getPlayers().getUUID(split[1]);
2381 // Invited player must be known
2382 if (targetPlayerUUID == null) {
2383 // plugin.getLogger().info("DEBUG: unknown player");
2384 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorUnknownPlayer);
2385 return true;
2386 }
2387 // Check if this player has an island or not
2388 if (plugin.getPlayers().hasIsland(targetPlayerUUID) || plugin.getPlayers().inTeam(targetPlayerUUID)) {
2389 calculateIslandLevel(player, targetPlayerUUID);
2390 } else {
2391 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoIslandOther);
2392 }
2393 return true;
2394 } else {
2395 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoPermission);
2396 return true;
2397 }
2398 } else if (split[0].equalsIgnoreCase("invite")) {
2399 // Team invite a player command
2400 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "team.create")) {
2401 // Only online players can be invited
2402 Player invitedPlayer = plugin.getServer().getPlayer(split[1]);
2403 if (invitedPlayer == null || !player.canSee(invitedPlayer)) {
2404 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorOfflinePlayer);
2405 return true;
2406 }
2407 final UUID invitedPlayerUUID = invitedPlayer.getUniqueId();
2408 // Player issuing the command must have an island
2409 if (!plugin.getPlayers().hasIsland(player.getUniqueId())) {
2410 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).inviteerrorYouMustHaveIslandToInvite);
2411 return true;
2412 }
2413 // Player cannot invite themselves
2414 if (player.getUniqueId().equals(invitedPlayer.getUniqueId())) {
2415 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).inviteerrorYouCannotInviteYourself);
2416 return true;
2417 }
2418 // Check if this player can be invited to this island, or
2419 // whether they are still on cooldown
2420 long time = plugin.getPlayers().getInviteCoolDownTime(invitedPlayerUUID, plugin.getPlayers().getIslandLocation(playerUUID));
2421 if (time > 0 && !player.isOp()) {
2422 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).inviteerrorCoolDown.replace("[time]", String.valueOf(time)));
2423 return true;
2424 }
2425 // If the player already has a team then check that they are
2426 // the leader, etc
2427 if (plugin.getPlayers().inTeam(player.getUniqueId())) {
2428 // Leader?
2429 if (teamLeader.equals(player.getUniqueId())) {
2430 // Invited player is free and not in a team
2431 if (!plugin.getPlayers().inTeam(invitedPlayerUUID)) {
2432 // Player has space in their team
2433 int maxSize = Settings.maxTeamSize;
2434 // Dynamic team sizes with permissions
2435 for (PermissionAttachmentInfo perms : player.getEffectivePermissions()) {
2436 if (perms.getPermission().startsWith(Settings.PERMPREFIX + "team.maxsize.")) {
2437 if (perms.getPermission().contains(Settings.PERMPREFIX + "team.maxsize.*")) {
2438 maxSize = Settings.maxTeamSize;
2439 break;
2440 } else {
2441 // Get the max value should there be more than one
2442 String[] spl = perms.getPermission().split(Settings.PERMPREFIX + "team.maxsize.");
2443 if (spl.length > 1) {
2444 if (!NumberUtils.isDigits(spl[1])) {
2445 plugin.getLogger().severe("Player " + player.getName() + " has permission: " + perms.getPermission() + " <-- the last part MUST be a number! Ignoring...");
2446
2447 } else {
2448 maxSize = Math.max(maxSize, Integer.valueOf(spl[1]));
2449 }
2450 }
2451 }
2452 }
2453 // Do some sanity checking
2454 if (maxSize < 1) {
2455 maxSize = 1;
2456 }
2457 }
2458 if (teamMembers.size() < maxSize) {
2459 // If that player already has an invite out
2460 // then retract it.
2461 // Players can only have one invite out at a
2462 // time - interesting
2463 if (inviteList.containsValue(playerUUID)) {
2464 inviteList.remove(getKeyByValue(inviteList, player.getUniqueId()));
2465 Util.sendMessage(player, ChatColor.YELLOW + plugin.myLocale(player.getUniqueId()).inviteremovingInvite);
2466 }
2467 // Put the invited player (key) onto the
2468 // list with inviter (value)
2469 // If someone else has invited a player,
2470 // then this invite will overwrite the
2471 // previous invite!
2472 inviteList.put(invitedPlayerUUID, player.getUniqueId());
2473 Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(player.getUniqueId()).inviteinviteSentTo.replace("[name]", invitedPlayer.getName()));
2474 // Send message to online player
2475 Util.sendMessage(Bukkit.getPlayer(invitedPlayerUUID), plugin.myLocale(invitedPlayerUUID).invitenameHasInvitedYou.replace("[name]", player.getName()));
2476 Util.sendMessage(Bukkit.getPlayer(invitedPlayerUUID),
2477 ChatColor.WHITE + "/" + label + " [accept/reject]" + ChatColor.YELLOW + " " + plugin.myLocale(invitedPlayerUUID).invitetoAcceptOrReject);
2478 if (plugin.getPlayers().hasIsland(invitedPlayerUUID)) {
2479 Util.sendMessage(Bukkit.getPlayer(invitedPlayerUUID), ChatColor.RED + plugin.myLocale(invitedPlayerUUID).invitewarningYouWillLoseIsland);
2480 }
2481 // Start timeout on invite
2482 if (Settings.inviteTimeout > 0) {
2483 plugin.getServer().getScheduler().runTaskLater(plugin, new Runnable() {
2484
2485 @Override
2486 public void run() {
2487 if (inviteList.containsKey(invitedPlayerUUID) && inviteList.get(invitedPlayerUUID).equals(playerUUID)) {
2488 inviteList.remove(invitedPlayerUUID);
2489 if (plugin.getServer().getPlayer(playerUUID) != null) {
2490 Util.sendMessage(plugin.getServer().getPlayer(playerUUID), ChatColor.YELLOW + plugin.myLocale(player.getUniqueId()).inviteremovingInvite);
2491 }
2492 if (plugin.getServer().getPlayer(invitedPlayerUUID) != null) {
2493 Util.sendMessage(plugin.getServer().getPlayer(invitedPlayerUUID), ChatColor.YELLOW + plugin.myLocale(player.getUniqueId()).inviteremovingInvite);
2494 }
2495 }
2496
2497 }}, Settings.inviteTimeout);
2498 }
2499 } else {
2500 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).inviteerrorYourIslandIsFull);
2501 }
2502 } else {
2503 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).inviteerrorThatPlayerIsAlreadyInATeam);
2504 }
2505 } else {
2506 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).inviteerrorYouMustHaveIslandToInvite);
2507 }
2508 } else {
2509 // First-time invite player does not have a team
2510 // Check if invitee is in a team or not
2511 if (!plugin.getPlayers().inTeam(invitedPlayerUUID)) {
2512 // If the inviter already has an invite out, remove
2513 // it
2514 if (inviteList.containsValue(playerUUID)) {
2515 inviteList.remove(getKeyByValue(inviteList, player.getUniqueId()));
2516 Util.sendMessage(player, ChatColor.YELLOW + plugin.myLocale(player.getUniqueId()).inviteremovingInvite);
2517 }
2518 // Place the player and invitee on the invite list
2519 inviteList.put(invitedPlayerUUID, player.getUniqueId());
2520 Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(player.getUniqueId()).inviteinviteSentTo.replace("[name]", invitedPlayer.getName()));
2521 Util.sendMessage(Bukkit.getPlayer(invitedPlayerUUID), plugin.myLocale(invitedPlayerUUID).invitenameHasInvitedYou.replace("[name]", player.getName()));
2522 Util.sendMessage(Bukkit.getPlayer(invitedPlayerUUID),
2523 ChatColor.WHITE + "/" + label + " [accept/reject]" + ChatColor.YELLOW + " " + plugin.myLocale(invitedPlayerUUID).invitetoAcceptOrReject);
2524 // Check if the player has an island and warn
2525 // accordingly
2526 // plugin.getLogger().info("DEBUG: invited player = "
2527 // + invitedPlayerUUID.toString());
2528 if (plugin.getPlayers().hasIsland(invitedPlayerUUID)) {
2529 // plugin.getLogger().info("DEBUG: invited player has island");
2530 Util.sendMessage(Bukkit.getPlayer(invitedPlayerUUID), ChatColor.RED + plugin.myLocale(invitedPlayerUUID).invitewarningYouWillLoseIsland);
2531 }
2532 // Start timeout on invite
2533 if (Settings.inviteTimeout > 0) {
2534 plugin.getServer().getScheduler().runTaskLater(plugin, new Runnable() {
2535
2536 @Override
2537 public void run() {
2538
2539 if (inviteList.containsKey(invitedPlayerUUID) && inviteList.get(invitedPlayerUUID).equals(playerUUID)) {
2540 inviteList.remove(invitedPlayerUUID);
2541 if (plugin.getServer().getPlayer(playerUUID) != null) {
2542 Util.sendMessage(plugin.getServer().getPlayer(playerUUID), ChatColor.YELLOW + plugin.myLocale(player.getUniqueId()).inviteremovingInvite);
2543 }
2544 if (plugin.getServer().getPlayer(invitedPlayerUUID) != null) {
2545 Util.sendMessage(plugin.getServer().getPlayer(invitedPlayerUUID), ChatColor.YELLOW + plugin.myLocale(player.getUniqueId()).inviteremovingInvite);
2546 }
2547 }
2548
2549 }}, Settings.inviteTimeout);
2550 }
2551 } else {
2552 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).inviteerrorThatPlayerIsAlreadyInATeam);
2553 }
2554 }
2555 return true;
2556 } else {
2557 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoPermission);
2558 return true;
2559 }
2560 } else if (split[0].equalsIgnoreCase("trust")) {
2561 // Give a player coop privileges
2562 if (!VaultHelper.checkPerm(player, Settings.PERMPREFIX + "coop")) {
2563 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoPermission);
2564 return true;
2565 }
2566 // Only online players can be cooped
2567 Player target = plugin.getServer().getPlayer(split[1]);
2568 if (target == null || !player.canSee(target)) {
2569 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorOfflinePlayer);
2570 return true;
2571 }
2572 final UUID targetPlayerUUID = target.getUniqueId();
2573 // Player issuing the command must have an island
2574 if (!plugin.getPlayers().hasIsland(playerUUID) && !plugin.getPlayers().inTeam(playerUUID)) {
2575 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).inviteerrorYouMustHaveIslandToInvite);
2576 return true;
2577 }
2578 // Player cannot invite themselves
2579 if (playerUUID.equals(targetPlayerUUID)) {
2580 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).inviteerrorYouCannotInviteYourself);
2581 return true;
2582 }
2583 // If target player is already on the team ignore
2584 if (plugin.getPlayers().getMembers(playerUUID).contains(targetPlayerUUID)) {
2585 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).coopOnYourTeam);
2586 return true;
2587 }
2588 // Target has to have an island
2589 if (!plugin.getPlayers().inTeam(targetPlayerUUID)) {
2590 if (!plugin.getPlayers().hasIsland(targetPlayerUUID)) {
2591 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoIslandOther);
2592 return true;
2593 }
2594 }
2595 // Check if this player can be invited to this island, or
2596 // whether they are still on cooldown
2597 long time = plugin.getPlayers().getInviteCoolDownTime(targetPlayerUUID, plugin.getPlayers().getIslandLocation(playerUUID));
2598 if (time > 0 && !player.isOp()) {
2599 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).inviteerrorCoolDown.replace("[time]", String.valueOf(time)));
2600 return true;
2601 }
2602
2603 if (Settings.coopIsRequest) {
2604 // Send out coop invite
2605 Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(player.getUniqueId()).inviteinviteSentTo.replace("[name]", target.getName()));
2606 Util.sendMessage(target, ChatColor.GREEN + plugin.myLocale(targetPlayerUUID).coopHasInvited.replace("[name]", player.getName()));
2607 Util.sendMessage(target, ChatColor.WHITE + "/" + label + " [trustaccept/trustreject] " + ChatColor.YELLOW + plugin.myLocale(targetPlayerUUID).invitetoAcceptOrReject);
2608 coopInviteList.put(targetPlayerUUID, playerUUID);
2609 if (Settings.inviteTimeout > 0) {
2610 plugin.getServer().getScheduler().runTaskLater(plugin, new Runnable() {
2611
2612 @Override
2613 public void run() {
2614
2615 if (coopInviteList.containsKey(targetPlayerUUID) && coopInviteList.get(targetPlayerUUID).equals(playerUUID)) {
2616 coopInviteList.remove(targetPlayerUUID);
2617 if (plugin.getServer().getPlayer(playerUUID) != null) {
2618 Util.sendMessage(plugin.getServer().getPlayer(playerUUID), ChatColor.YELLOW + plugin.myLocale(player.getUniqueId()).inviteremovingInvite);
2619 }
2620 if (plugin.getServer().getPlayer(targetPlayerUUID) != null) {
2621 Util.sendMessage(plugin.getServer().getPlayer(targetPlayerUUID), ChatColor.YELLOW + plugin.myLocale(player.getUniqueId()).inviteremovingInvite);
2622 }
2623 }
2624
2625 }
2626 }, Settings.inviteTimeout);
2627 }
2628 } else {
2629 // Add target to coop list
2630 if (CoopPlay.getInstance().addCoopPlayer(player, target)) {
2631 // Tell everyone what happened
2632 Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(player.getUniqueId()).coopSuccess.replace("[name]", target.getName()));
2633 Util.sendMessage(target, ChatColor.GREEN + plugin.myLocale(targetPlayerUUID).coopMadeYouCoop.replace("[name]", player.getName()));
2634 // TODO: Give perms if the player is on the coop island
2635 } // else fail silently
2636 }
2637 return true;
2638 } else if (split[0].equalsIgnoreCase("expel")) {
2639 if (!VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.expel")) {
2640 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoPermission);
2641 return true;
2642 }
2643 // Find out who they want to expel
2644 UUID targetPlayerUUID = plugin.getPlayers().getUUID(split[1]);
2645 if (targetPlayerUUID == null) {
2646 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorUnknownPlayer);
2647 return true;
2648 }
2649 // Target should not be themselves
2650 if (targetPlayerUUID.equals(playerUUID)) {
2651 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).expelNotYourself);
2652 return true;
2653 }
2654 // Target cannot be op
2655 Player target = plugin.getServer().getPlayer(targetPlayerUUID);
2656 if (target != null) {
2657 if (!player.canSee(target)) {
2658 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorUnknownPlayer);
2659 return true;
2660 }
2661 if (target.isOp() || VaultHelper.checkPerm(target, Settings.PERMPREFIX + "mod.bypassprotect")
2662 || VaultHelper.checkPerm(target, Settings.PERMPREFIX + "mod.bypassexpel")) {
2663 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).expelFail.replace("[name]", target.getName()));
2664 return true;
2665 }
2666 }
2667 // Remove them from the coop list
2668 boolean coop = CoopPlay.getInstance().removeCoopPlayer(player, targetPlayerUUID);
2669 if (coop) {
2670 if (target != null) {
2671 Util.sendMessage(target, ChatColor.RED + plugin.myLocale(target.getUniqueId()).coopRemoved.replace("[name]", player.getName()));
2672 } else {
2673 plugin.getMessages().setMessage(targetPlayerUUID, ChatColor.RED + plugin.myLocale(targetPlayerUUID).coopRemoved.replace("[name]", player.getName()));
2674 }
2675 Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(player.getUniqueId()).coopRemoveSuccess.replace("[name]", plugin.getPlayers().getName(targetPlayerUUID)));
2676 }
2677 // See if target is on this player's island
2678 if (target != null && plugin.getGrid().isOnIsland(player, target)) {
2679 // Check to see if this player has an island or is just
2680 // helping out
2681 if (plugin.getPlayers().inTeam(targetPlayerUUID) || plugin.getPlayers().hasIsland(targetPlayerUUID)) {
2682 plugin.getGrid().homeTeleport(target);
2683 } else {
2684 // Just move target to spawn
2685 if (!target.performCommand(Settings.SPAWNCOMMAND)) {
2686 target.teleport(player.getWorld().getSpawnLocation());
2687 /*
2688 * target.sendBlockChange(target.getWorld().
2689 * getSpawnLocation()
2690 * ,target.getWorld().getSpawnLocation().getBlock().
2691 * getType()
2692 * ,target.getWorld().getSpawnLocation().getBlock().
2693 * getData());
2694 */
2695 }
2696 }
2697 Util.sendMessage(target, ChatColor.RED + plugin.myLocale(target.getUniqueId()).expelExpelled);
2698 plugin.getLogger().info(player.getName() + " expelled " + target.getName() + " from their island.");
2699 // Yes they are
2700 Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(player.getUniqueId()).expelSuccess.replace("[name]", target.getName()));
2701 } else if (!coop) {
2702 // No they're not
2703 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).expelNotOnIsland);
2704 }
2705 return true;
2706 } else if (split[0].equalsIgnoreCase("untrust")) {
2707 if (!VaultHelper.checkPerm(player, Settings.PERMPREFIX + "coop")) {
2708 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoPermission);
2709 return true;
2710 }
2711 // Find out who they want to uncoop
2712 UUID targetPlayerUUID = plugin.getPlayers().getUUID(split[1]);
2713 if (targetPlayerUUID == null) {
2714 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorUnknownPlayer);
2715 return true;
2716 }
2717 // Target should not be themselves
2718 if (targetPlayerUUID.equals(playerUUID)) {
2719 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).expelNotYourself);
2720 return true;
2721 }
2722 OfflinePlayer target = plugin.getServer().getOfflinePlayer(targetPlayerUUID);
2723 // Remove them from the coop list
2724 boolean coop = CoopPlay.getInstance().removeCoopPlayer(player, targetPlayerUUID);
2725 if (coop) {
2726 if (target != null && target.isOnline()) {
2727 Util.sendMessage(target.getPlayer(), ChatColor.RED + plugin.myLocale(target.getUniqueId()).coopRemoved.replace("[name]", player.getName()));
2728 } else {
2729 plugin.getMessages().setMessage(targetPlayerUUID, ChatColor.RED + plugin.myLocale(targetPlayerUUID).coopRemoved.replace("[name]", player.getName()));
2730 }
2731 Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(player.getUniqueId()).coopRemoveSuccess.replace("[name]", plugin.getPlayers().getName(targetPlayerUUID)));
2732 } else {
2733 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).coopNotInCoop.replace("[name]", plugin.getPlayers().getName(targetPlayerUUID)));
2734 }
2735 return true;
2736 } else if (split[0].equalsIgnoreCase("ban") || split[0].equalsIgnoreCase("suspend")) {
2737 if (!VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.ban")) {
2738 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoPermission);
2739 return true;
2740 }
2741 // Find out who they want to ban
2742 final UUID targetPlayerUUID = plugin.getPlayers().getUUID(split[1]);
2743 // Player must be known
2744 if (targetPlayerUUID == null) {
2745 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorUnknownPlayer);
2746 return true;
2747 }
2748 // Target should not be themselves
2749 if (targetPlayerUUID.equals(playerUUID)) {
2750 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).banNotYourself);
2751 return true;
2752 }
2753 // Target cannot be on the same team
2754 if (plugin.getPlayers().inTeam(playerUUID) && plugin.getPlayers().inTeam(targetPlayerUUID)) {
2755 if (plugin.getPlayers().getTeamLeader(playerUUID).equals(plugin.getPlayers().getTeamLeader(targetPlayerUUID))) {
2756 // Same team!
2757 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).banNotTeamMember);
2758 return true;
2759 }
2760 }
2761 // Check that the player is not banned already
2762 if (plugin.getPlayers().isBanned(playerUUID, targetPlayerUUID)) {
2763 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).banAlreadyBanned.replace("[name]", split[1]));
2764 return true;
2765 }
2766 // Check online/offline status
2767 Player target = plugin.getServer().getPlayer(targetPlayerUUID);
2768 // Get offline player
2769 OfflinePlayer offlineTarget = plugin.getServer().getOfflinePlayer(targetPlayerUUID);
2770 // Target cannot be op
2771 if (offlineTarget.isOp() || (offlineTarget.isOnline() && !player.canSee(offlineTarget.getPlayer()))) {
2772 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).banFail.replace("[name]", split[1]));
2773 return true;
2774 }
2775 if (target != null) {
2776 // Do not ban players with the mod.noban permission
2777 if (VaultHelper.checkPerm(target, Settings.PERMPREFIX + "admin.noban")) {
2778 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).banFail.replace("[name]", split[1]));
2779 return true;
2780 }
2781 // Remove them from the coop list
2782 boolean coop = CoopPlay.getInstance().removeCoopPlayer(player, target);
2783 if (coop) {
2784 Util.sendMessage(target, ChatColor.RED + plugin.myLocale(target.getUniqueId()).coopRemoved.replace("[name]", player.getName()));
2785 Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(player.getUniqueId()).coopRemoveSuccess.replace("[name]", target.getName()));
2786 }
2787 // See if target is on this player's island and if so send them away
2788 if (plugin.getGrid().isOnIsland(player, target)) {
2789 // Check to see if this player has an island or is just
2790 // helping out
2791 if (plugin.getPlayers().inTeam(targetPlayerUUID) || plugin.getPlayers().hasIsland(targetPlayerUUID)) {
2792 plugin.getGrid().homeTeleport(target);
2793 } else {
2794 // Just move target to spawn
2795 if (!target.performCommand(Settings.SPAWNCOMMAND)) {
2796 target.teleport(player.getWorld().getSpawnLocation());
2797 }
2798 }
2799 }
2800 // Notifications
2801 // Target
2802 Util.sendMessage(target, ChatColor.RED + plugin.myLocale(targetPlayerUUID).banBanned.replace("[name]", player.getName()));
2803 } else {
2804 // Offline notification
2805 plugin.getMessages().setMessage(targetPlayerUUID, ChatColor.RED + plugin.myLocale(targetPlayerUUID).banBanned.replace("[name]", player.getName()));
2806 }
2807 // Console
2808 plugin.getLogger().info(player.getName() + " banned " + split[1] + " from their island.");
2809 // Player
2810 Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(player.getUniqueId()).banSuccess.replace("[name]", split[1]));
2811 // Tell team
2812 plugin.getMessages().tellTeam(playerUUID, ChatColor.GREEN + plugin.myLocale(player.getUniqueId()).banSuccess.replace("[name]", split[1]));
2813 plugin.getMessages().tellOfflineTeam(playerUUID, ChatColor.GREEN + plugin.myLocale(player.getUniqueId()).banSuccess.replace("[name]", split[1]));
2814 // Ban the sucker
2815 plugin.getPlayers().ban(playerUUID, targetPlayerUUID);
2816 plugin.getGrid().saveGrid();
2817 return true;
2818 } else if (split[0].equalsIgnoreCase("pardon") || split[0].equalsIgnoreCase("unban")) {
2819 if (!VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.ban")) {
2820 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoPermission);
2821 return true;
2822 }
2823 // Find out who they want to unban
2824 final UUID targetPlayerUUID = plugin.getPlayers().getUUID(split[1]);
2825 // Player must be known
2826 if (targetPlayerUUID == null) {
2827 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorUnknownPlayer);
2828 return true;
2829 }
2830 // Target should not be themselves
2831 if (targetPlayerUUID.equals(playerUUID)) {
2832 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).banNotYourself);
2833 return true;
2834 }
2835 // Check that the player is actually banned
2836 if (!plugin.getPlayers().isBanned(playerUUID, targetPlayerUUID)) {
2837 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).banNotBanned.replace("[name]", split[1]));
2838 return true;
2839 }
2840 // Notifications
2841 // Online check
2842 Player target = plugin.getServer().getPlayer(targetPlayerUUID);
2843 // Target
2844 if (target != null) {
2845 // Online
2846 Util.sendMessage(target, ChatColor.RED + plugin.myLocale(target.getUniqueId()).banLifted.replace("[name]", player.getName()));
2847 } else {
2848 plugin.getMessages().setMessage(targetPlayerUUID, ChatColor.GREEN + plugin.myLocale(targetPlayerUUID).banLifted.replace("[name]", player.getName()));
2849 }
2850 //OfflinePlayer offlineTarget = plugin.getServer().getOfflinePlayer(targetPlayerUUID);
2851 // Player
2852 Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(player.getUniqueId()).banLiftedSuccess.replace("[name]", split[1]));
2853 // Console
2854 plugin.getLogger().info(player.getName() + " unbanned " + split[1] + " from their island.");
2855 // Tell team
2856 plugin.getMessages().tellTeam(playerUUID, ChatColor.GREEN + plugin.myLocale(player.getUniqueId()).banLiftedSuccess.replace("[name]", split[1]));
2857 plugin.getMessages().tellOfflineTeam(playerUUID, ChatColor.GREEN + plugin.myLocale(player.getUniqueId()).banLiftedSuccess.replace("[name]", split[1]));
2858 // Unban the redeemed one
2859 plugin.getPlayers().unBan(playerUUID, targetPlayerUUID);
2860 plugin.getGrid().saveGrid();
2861 return true;
2862 } else if (split[0].equalsIgnoreCase("kick") || split[0].equalsIgnoreCase("remove")) {
2863 // PlayerIsland remove command with a player name, or island kick
2864 // command
2865 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "team.kick")) {
2866 if (!plugin.getPlayers().inTeam(playerUUID)) {
2867 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).kickerrorNoTeam);
2868 return true;
2869 }
2870 // Only leaders can kick
2871 if (teamLeader != null && !teamLeader.equals(playerUUID)) {
2872 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).kickerrorOnlyLeaderCan);
2873 return true;
2874 }
2875 // The main thing to do is check if the player name to kick
2876 // is in the list of players in the team.
2877 targetPlayer = null;
2878 for (UUID member : teamMembers) {
2879 if (plugin.getPlayers().getName(member).equalsIgnoreCase(split[1])) {
2880 targetPlayer = member;
2881 }
2882 }
2883 if (targetPlayer == null) {
2884 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).kickerrorNotPartOfTeam);
2885 return true;
2886 }
2887 if (teamMembers.contains(targetPlayer)) {
2888 // If the player leader tries to kick or remove
2889 // themselves
2890 if (player.getUniqueId().equals(targetPlayer)) {
2891 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).leaveerrorLeadersCannotLeave);
2892 return true;
2893 }
2894 // Try to kick player
2895 if (!removePlayerFromTeam(targetPlayer, teamLeader)) {
2896 //Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).leaveerrorYouCannotLeaveIsland);
2897 // If this is canceled, fail silently
2898 return true;
2899 }
2900 // Log the location that this player left so they
2901 // cannot join again before the cool down ends
2902 plugin.getPlayers().startInviteCoolDownTimer(targetPlayer, plugin.getPlayers().getIslandLocation(playerUUID));
2903 if (Settings.resetChallenges) {
2904 // Reset the player's challenge status
2905 plugin.getPlayers().resetAllChallenges(targetPlayer, false);
2906 }
2907 // Reset the island level
2908 plugin.getPlayers().setIslandLevel(targetPlayer, 0);
2909 plugin.getTopTen().topTenAddEntry(playerUUID, 0);
2910
2911 // If target is online
2912 Player target = plugin.getServer().getPlayer(targetPlayer);
2913 if (target != null) {
2914 // plugin.getLogger().info("DEBUG: player is online");
2915 Util.sendMessage(target, ChatColor.RED + plugin.myLocale(targetPlayer).kicknameRemovedYou.replace("[name]", player.getName()));
2916 // Clear any coop inventories
2917 // CoopPlay.getInstance().returnAllInventories(target);
2918 // Remove any of the target's coop invitees and
2919 // anyone they invited
2920 CoopPlay.getInstance().clearMyInvitedCoops(target);
2921 CoopPlay.getInstance().clearMyCoops(target);
2922 // Clear the player out and throw their stuff at the
2923 // leader
2924 if (target.getWorld().equals(ASkyBlock.getIslandWorld())) {
2925 if (!Settings.kickedKeepInv) {
2926 for (ItemStack i : target.getInventory().getContents()) {
2927 if (i != null) {
2928 try {
2929 // Fire an event to see if this item should be dropped or not
2930 // Some plugins may not want items to be dropped
2931 Item drop = player.getWorld().dropItemNaturally(player.getLocation(), i);
2932 PlayerDropItemEvent event = new PlayerDropItemEvent(target, drop);
2933 plugin.getServer().getPluginManager().callEvent(event);
2934 } catch (Exception e) {
2935 }
2936 }
2937 }
2938 // plugin.resetPlayer(target); <- no good if
2939 // reset inventory is false
2940 // Clear their inventory and equipment and set
2941 // them as survival
2942 target.getInventory().clear(); // Javadocs are
2943 // wrong - this
2944 // does not
2945 // clear armor slots! So...
2946 // plugin.getLogger().info("DEBUG: Clearing kicked player's inventory");
2947 target.getInventory().setArmorContents(null);
2948 target.getInventory().setHelmet(null);
2949 target.getInventory().setChestplate(null);
2950 target.getInventory().setLeggings(null);
2951 target.getInventory().setBoots(null);
2952 target.getEquipment().clear();
2953 // Update the inventory
2954 target.updateInventory();
2955 }
2956 }
2957 if (!target.performCommand(Settings.SPAWNCOMMAND)) {
2958 target.teleport(ASkyBlock.getIslandWorld().getSpawnLocation());
2959 }
2960 } else {
2961 // Offline
2962 if (DEBUG)
2963 plugin.getLogger().info("DEBUG: player is offline "+ targetPlayer.toString());
2964 // Tell offline player they were kicked
2965 plugin.getMessages().setMessage(targetPlayer, ChatColor.RED + plugin.myLocale(player.getUniqueId()).kicknameRemovedYou.replace("[name]", player.getName()));
2966 }
2967 // Remove any warps
2968 plugin.getWarpSignsListener().removeWarp(targetPlayer);
2969 // Tell leader they removed the player
2970 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).kicknameRemoved.replace("[name]", split[1]));
2971 //removePlayerFromTeam(targetPlayer, teamLeader);
2972 teamMembers.remove(targetPlayer);
2973 if (teamMembers.size() < 2) {
2974 if (!removePlayerFromTeam(player.getUniqueId(), teamLeader)) {
2975 // If cancelled, return silently
2976 return true;
2977 }
2978 }
2979 plugin.getPlayers().save(targetPlayer);
2980 } else {
2981 plugin.getLogger().warning("Player " + player.getName() + " failed to remove " + plugin.getPlayers().getName(targetPlayer));
2982 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).kickerrorNotPartOfTeam);
2983 }
2984 return true;
2985 } else {
2986 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoPermission);
2987 return true;
2988 }
2989 } else if (split[0].equalsIgnoreCase("makeleader") || split[0].equalsIgnoreCase("transfer") || split[0].equalsIgnoreCase("ownership")) {
2990 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "team.makeleader")) {
2991 targetPlayer = plugin.getPlayers().getUUID(split[1]);
2992 if (targetPlayer == null) {
2993 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorUnknownPlayer);
2994 return true;
2995 }
2996 if (targetPlayer.equals(playerUUID)) {
2997 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).makeLeadererrorGeneralError);
2998 return true;
2999 }
3000 if (!plugin.getPlayers().inTeam(player.getUniqueId())) {
3001 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).makeLeadererrorYouMustBeInTeam);
3002 return true;
3003 }
3004
3005 if (plugin.getPlayers().getMembers(player.getUniqueId()).size() > 2) {
3006 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).makeLeadererrorRemoveAllPlayersFirst);
3007 plugin.getLogger().info(player.getName() + " tried to transfer his island, but failed because >2 people in a team");
3008 return true;
3009 }
3010
3011 if (plugin.getPlayers().inTeam(player.getUniqueId())) {
3012 if (teamLeader.equals(player.getUniqueId())) {
3013 if (teamMembers.contains(targetPlayer)) {
3014 // targetPlayer is the new leader
3015 // plugin.getLogger().info("DEBUG: " +
3016 // plugin.getPlayers().getIslandLevel(teamLeader));
3017 // Remove the target player from the team
3018 if (!removePlayerFromTeam(targetPlayer, teamLeader, true)) {
3019 // If cancelled, return silently
3020 return true;
3021 }
3022 // Remove the leader from the team
3023 if (!removePlayerFromTeam(teamLeader, teamLeader, true)) {
3024 // If cancelled, return silently
3025 return true;
3026 }
3027 Util.sendMessage(player, ChatColor.GREEN
3028 + plugin.myLocale(player.getUniqueId()).makeLeadernameIsNowTheOwner.replace("[name]", plugin.getPlayers().getName(targetPlayer)));
3029
3030 // plugin.getLogger().info("DEBUG: " +
3031 // plugin.getPlayers().getIslandLevel(teamLeader));
3032 // Transfer the data from the old leader to the
3033 // new one
3034 plugin.getGrid().transferIsland(player.getUniqueId(), targetPlayer);
3035 // Create a new team with
3036 addPlayertoTeam(player.getUniqueId(), targetPlayer);
3037 addPlayertoTeam(targetPlayer, targetPlayer);
3038
3039 // Check if online
3040 Player target = plugin.getServer().getPlayer(targetPlayer);
3041 if (target == null) {
3042 plugin.getMessages().setMessage(targetPlayer, plugin.myLocale(player.getUniqueId()).makeLeaderyouAreNowTheOwner);
3043
3044 } else {
3045 // Online
3046 Util.sendMessage(plugin.getServer().getPlayer(targetPlayer), ChatColor.GREEN + plugin.myLocale(targetPlayer).makeLeaderyouAreNowTheOwner);
3047 // Check if new leader has a lower range permission than the island size
3048 boolean hasARangePerm = false;
3049 int range = Settings.islandProtectionRange;
3050 // Check for zero protection range
3051 Island islandByOwner = plugin.getGrid().getIsland(targetPlayer);
3052 if (islandByOwner.getProtectionSize() == 0) {
3053 plugin.getLogger().warning("Player " + player.getName() + "'s island had a protection range of 0. Setting to default " + range);
3054 islandByOwner.setProtectionSize(range);
3055 }
3056 for (PermissionAttachmentInfo perms : target.getEffectivePermissions()) {
3057 if (perms.getPermission().startsWith(Settings.PERMPREFIX + "island.range.")) {
3058 if (perms.getPermission().contains(Settings.PERMPREFIX + "island.range.*")) {
3059 // Ignore
3060 break;
3061 } else {
3062 String[] spl = perms.getPermission().split(Settings.PERMPREFIX + "island.range.");
3063 if (spl.length > 1) {
3064 if (!NumberUtils.isDigits(spl[1])) {
3065 plugin.getLogger().severe("Player " + player.getName() + " has permission: " + perms.getPermission() + " <-- the last part MUST be a number! Ignoring...");
3066
3067 } else {
3068 hasARangePerm = true;
3069 range = Math.max(range, Integer.valueOf(spl[1]));
3070 }
3071 }
3072 }
3073 }
3074 }
3075 // Only set the island range if the player has a perm to override the default
3076 if (hasARangePerm) {
3077 // Do some sanity checking
3078 if (range % 2 != 0) {
3079 range--;
3080 }
3081 // Get island range
3082
3083 // Range can go up or down
3084 if (range != islandByOwner.getProtectionSize()) {
3085 Util.sendMessage(player, ChatColor.GOLD + plugin.myLocale(targetPlayer).adminSetRangeUpdated.replace("[number]", String.valueOf(range)));
3086 Util.sendMessage(target, ChatColor.GOLD + plugin.myLocale(targetPlayer).adminSetRangeUpdated.replace("[number]", String.valueOf(range)));
3087 plugin.getLogger().info(
3088 "Makeleader: Island protection range changed from " + islandByOwner.getProtectionSize() + " to "
3089 + range + " for " + player.getName() + " due to permission.");
3090 }
3091 islandByOwner.setProtectionSize(range);
3092 }
3093 }
3094 plugin.getGrid().saveGrid();
3095 return true;
3096 }
3097 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).makeLeadererrorThatPlayerIsNotInTeam);
3098 } else {
3099 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).makeLeadererrorNotYourIsland);
3100 }
3101 } else {
3102 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).makeLeadererrorGeneralError);
3103 }
3104 return true;
3105 } else {
3106 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoPermission);
3107 return true;
3108 }
3109 } else {
3110 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).errorUnknownCommand);
3111 return true;
3112 }
3113 break;
3114 }
3115 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).errorUnknownCommand);
3116 return true;
3117 }
3118
3119
3120 /**
3121 * Shows available languages to the player
3122 * @param player
3123 */
3124 private void displayLocales(Player player) {
3125 TreeMap<Integer,String> langs = new TreeMap<Integer,String>();
3126 for (ASLocale locale : plugin.getAvailableLocales().values()) {
3127 if (!locale.getLocaleName().equalsIgnoreCase("locale")) {
3128 langs.put(locale.getIndex(), locale.getLanguageName() + " (" + locale.getCountryName() + ")");
3129 }
3130 }
3131 for (Entry<Integer, String> entry: langs.entrySet()) {
3132 Util.sendMessage(player, entry.getKey() + ": " + entry.getValue());
3133 }
3134 }
3135
3136 /**
3137 * Warps a player to a spot in front of a sign
3138 * @param player
3139 * @param inFront
3140 * @param foundWarp
3141 * @param directionFacing
3142 */
3143 private void warpPlayer(Player player, Location inFront, UUID foundWarp, BlockFace directionFacing, boolean pvp) {
3144 // convert blockface to angle
3145 float yaw = Util.blockFaceToFloat(directionFacing);
3146 final Location actualWarp = new Location(inFront.getWorld(), inFront.getBlockX() + 0.5D, inFront.getBlockY(),
3147 inFront.getBlockZ() + 0.5D, yaw, 30F);
3148 IslandPreTeleportEvent event = new IslandPreTeleportEvent(player, IslandPreTeleportEvent.Type.WARP, actualWarp);
3149 Bukkit.getPluginManager().callEvent(event);
3150 if (!event.isCancelled()) {
3151 player.teleport(event.getLocation());
3152 if (pvp) {
3153 Util.sendMessage(player, ChatColor.BOLD + "" + ChatColor.RED + plugin.myLocale(player.getUniqueId()).igs.get(SettingsFlag.PVP) + " " + plugin.myLocale(player.getUniqueId()).igsAllowed);
3154 if (plugin.getServer().getVersion().contains("(MC: 1.8") || plugin.getServer().getVersion().contains("(MC: 1.7")) {
3155 player.getWorld().playSound(player.getLocation(), Sound.valueOf("ARROW_HIT"), 1F, 1F);
3156 } else {
3157 player.getWorld().playSound(player.getLocation(), Sound.ENTITY_ARROW_HIT, 1F, 1F);
3158 }
3159 } else {
3160 if (plugin.getServer().getVersion().contains("(MC: 1.8") || plugin.getServer().getVersion().contains("(MC: 1.7")) {
3161 player.getWorld().playSound(player.getLocation(), Sound.valueOf("BAT_TAKEOFF"), 1F, 1F);
3162 } else {
3163 player.getWorld().playSound(player.getLocation(), Sound.ENTITY_BAT_TAKEOFF, 1F, 1F);
3164 }
3165 }
3166 Player warpOwner = plugin.getServer().getPlayer(foundWarp);
3167 if (warpOwner != null && !warpOwner.equals(player)) {
3168 Util.sendMessage(warpOwner, plugin.myLocale(foundWarp).warpsPlayerWarped.replace("[name]", player.getName()));
3169 }
3170 }
3171 }
3172
3173 /**
3174 * Only run when a new island is created for the first time
3175 * @param player
3176 */
3177 private void chooseIsland(Player player) {
3178 // Get the schematics that this player is eligible to use
3179 List<Schematic> schems = getSchematics(player, false);
3180 //plugin.getLogger().info("DEBUG: size of schematics for this player = " + schems.size());
3181 if (schems.isEmpty()) {
3182 // No schematics - use default island
3183 newIsland(player);
3184 } else if (schems.size() == 1) {
3185 // Hobson's choice
3186 newIsland(player,schems.get(0));
3187 } else {
3188 // A panel can only be shown if there is >1 viable schematic
3189 if (Settings.useSchematicPanel) {
3190 pendingNewIslandSelection.add(player.getUniqueId());
3191 Inventory inv = plugin.getSchematicsPanel().getPanel(player);
3192 if (inv != null) {
3193 player.openInventory(inv);
3194 } else {
3195 plugin.getLogger().severe("There are no valid schematics available for " + player.getName() + "! Check config.yml schematicsection.");
3196 }
3197 } else {
3198 // No panel
3199 // Check schematics for specific permission
3200 schems = getSchematics(player,true);
3201 if (schems.isEmpty()) {
3202 newIsland(player);
3203 } else if (Settings.chooseIslandRandomly) {
3204 // Choose an island randomly from the list
3205 newIsland(player, schems.get(random.nextInt(schems.size())));
3206 } else {
3207 // Do the first one in the list
3208 newIsland(player, schems.get(0));
3209 }
3210 }
3211 }
3212 }
3213
3214 private void resetPlayer(Player player, Island oldIsland) {
3215 // Deduct the reset
3216 plugin.getPlayers().setResetsLeft(player.getUniqueId(), plugin.getPlayers().getResetsLeft(player.getUniqueId()) - 1);
3217 // Reset deaths
3218 if (Settings.islandResetDeathReset) {
3219 plugin.getPlayers().setDeaths(player.getUniqueId(), 0);
3220 }
3221 // Clear any coop inventories
3222 // CoopPlay.getInstance().returnAllInventories(player);
3223 // Remove any coop invitees and grab their stuff
3224 CoopPlay.getInstance().clearMyInvitedCoops(player);
3225 CoopPlay.getInstance().clearMyCoops(player);
3226 //plugin.getLogger().info("DEBUG Reset command issued!");
3227 // Remove any warps
3228 plugin.getWarpSignsListener().removeWarp(player.getUniqueId());
3229 // Delete the old island, if it exists
3230 if (oldIsland != null) {
3231 plugin.getServer().getPluginManager().callEvent(new IslandPreDeleteEvent(player.getUniqueId(), oldIsland));
3232 // Remove any coops
3233 CoopPlay.getInstance().clearAllIslandCoops(oldIsland.getCenter());
3234 plugin.getGrid().removePlayersFromIsland(oldIsland, player.getUniqueId());
3235 //plugin.getLogger().info("DEBUG Deleting old island");
3236 new DeleteIslandChunk(plugin, oldIsland);
3237 //new DeleteIslandByBlock(plugin, oldIsland);
3238 // Fire event
3239 final IslandResetEvent event = new IslandResetEvent(player, oldIsland.getCenter());
3240 plugin.getServer().getPluginManager().callEvent(event);
3241 } else {
3242 //plugin.getLogger().info("DEBUG oldisland = null!");
3243 }
3244 plugin.getGrid().saveGrid();
3245 }
3246
3247 /**
3248 * Runs commands when a player resets or leaves a team, etc.
3249 * Can be run for offline players
3250 *
3251 * @param commands
3252 * @param offlinePlayer
3253 */
3254 public static void runCommands(List<String> commands, OfflinePlayer offlinePlayer) {
3255 // Run commands
3256 for (String cmd : commands) {
3257 if (cmd.startsWith("[SELF]")) {
3258 cmd = cmd.substring(6,cmd.length()).replace("[player]", offlinePlayer.getName()).trim();
3259 if (offlinePlayer.isOnline()) {
3260 try {
3261 Bukkit.getLogger().info("Running command '" + cmd + "' as " + offlinePlayer.getName());
3262 ((Player)offlinePlayer).performCommand(cmd);
3263 } catch (Exception e) {
3264 Bukkit.getLogger().severe("Problem executing island command executed by player - skipping!");
3265 Bukkit.getLogger().severe("Command was : " + cmd);
3266 Bukkit.getLogger().severe("Error was: " + e.getMessage());
3267 e.printStackTrace();
3268 }
3269 }
3270 continue;
3271 }
3272 // Substitute in any references to player
3273 try {
3274 //plugin.getLogger().info("Running command " + cmd + " as console.");
3275 if (!Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), cmd.replace("[player]", offlinePlayer.getName()))) {
3276 Bukkit.getLogger().severe("Problem executing island command - skipping!");
3277 Bukkit.getLogger().severe("Command was : " + cmd);
3278 }
3279 } catch (Exception e) {
3280 Bukkit.getLogger().severe("Problem executing island command - skipping!");
3281 Bukkit.getLogger().severe("Command was : " + cmd);
3282 Bukkit.getLogger().severe("Error was: " + e.getMessage());
3283 e.printStackTrace();
3284 }
3285 }
3286
3287 }
3288
3289 /**
3290 * Check time out for island restarting
3291 *
3292 * @param player
3293 * @return true if the timeout is over
3294 */
3295 public boolean onRestartWaitTime(final Player player) {
3296 if (resetWaitTime.containsKey(player.getUniqueId())) {
3297 if (resetWaitTime.get(player.getUniqueId()).longValue() > Calendar.getInstance().getTimeInMillis()) {
3298 return true;
3299 }
3300
3301 return false;
3302 }
3303
3304 return false;
3305 }
3306
3307 public boolean onLevelWaitTime(final Player player) {
3308 if (levelWaitTime.containsKey(player.getUniqueId())) {
3309 if (levelWaitTime.get(player.getUniqueId()).longValue() > Calendar.getInstance().getTimeInMillis()) {
3310 return true;
3311 }
3312
3313 return false;
3314 }
3315
3316 return false;
3317 }
3318
3319 /**
3320 * Sets a timeout for player into the Hashmap resetWaitTime
3321 *
3322 * @param player
3323 */
3324 private void setResetWaitTime(final Player player) {
3325 resetWaitTime.put(player.getUniqueId(), Long.valueOf(Calendar.getInstance().getTimeInMillis() + Settings.resetWait * 1000));
3326 }
3327
3328 /**
3329 * Sets cool down for the level command
3330 *
3331 * @param player
3332 */
3333 private void setLevelWaitTime(final Player player) {
3334 levelWaitTime.put(player.getUniqueId(), Long.valueOf(Calendar.getInstance().getTimeInMillis() + Settings.levelWait * 1000));
3335 }
3336
3337 /**
3338 * Returns how long the player must wait until they can restart their island
3339 * in seconds
3340 *
3341 * @param player
3342 * @return how long the player must wait
3343 */
3344 private long getResetWaitTime(final Player player) {
3345 if (resetWaitTime.containsKey(player.getUniqueId())) {
3346 if (resetWaitTime.get(player.getUniqueId()).longValue() > Calendar.getInstance().getTimeInMillis()) {
3347 return (resetWaitTime.get(player.getUniqueId()).longValue() - Calendar.getInstance().getTimeInMillis()) / 1000;
3348 }
3349
3350 return 0L;
3351 }
3352
3353 return 0L;
3354 }
3355
3356 private long getLevelWaitTime(final Player player) {
3357 if (levelWaitTime.containsKey(player.getUniqueId())) {
3358 if (levelWaitTime.get(player.getUniqueId()).longValue() > Calendar.getInstance().getTimeInMillis()) {
3359 return (levelWaitTime.get(player.getUniqueId()).longValue() - Calendar.getInstance().getTimeInMillis()) / 1000;
3360 }
3361
3362 return 0L;
3363 }
3364
3365 return 0L;
3366 }
3367
3368 /**
3369 * @return the creatingTopTen
3370 */
3371 public boolean isCreatingTopTen() {
3372 return creatingTopTen;
3373 }
3374
3375 /**
3376 * @param creatingTopTen the creatingTopTen to set
3377 */
3378 public void setCreatingTopTen(boolean creatingTopTen) {
3379 this.creatingTopTen = creatingTopTen;
3380 }
3381
3382 /**
3383 * Reserves a spot in the world for the player to have their island placed next time they make one
3384 * @param playerUUID - the player's UUID
3385 * @param location
3386 */
3387 public void reserveLocation(UUID playerUUID, Location location) {
3388 islandSpot.put(playerUUID, location);
3389 }
3390
3391 public boolean valueLookup(Player player, String[] split)
3392 {
3393 // Explain command
3394 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.value")) {
3395 // Check they are on their island
3396 if (!plugin.getGrid().playerIsOnIsland(player)) {
3397 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNotOnIsland);
3398 return true;
3399 }
3400 ItemStack item = player.getItemInHand();
3401 if(split.length > 1) {
3402 // Match Material for parsed input.
3403 Material material = Material.matchMaterial(split[1]);
3404 if(material != null) {
3405 item = new ItemStack(material);
3406 }
3407 }
3408 double multiplier = 1;
3409 if (item != null && item.getType().isBlock()) {
3410 // Get permission multiplier
3411 for (PermissionAttachmentInfo perms : player.getEffectivePermissions()) {
3412 if (perms.getPermission().startsWith(Settings.PERMPREFIX + "island.multiplier.")) {
3413 String[] spl = perms.getPermission().split(Settings.PERMPREFIX + "island.multiplier.");
3414 // Get the max value should there be more than one
3415 if (spl.length > 1) {
3416 if (!NumberUtils.isDigits(spl[1])) {
3417 plugin.getLogger().severe("Player " + player.getName() + " has permission: " + perms.getPermission() + " <-- the last part MUST be a number! Ignoring...");
3418
3419 } else {
3420 multiplier = Math.max(multiplier, Integer.valueOf(spl[1]));
3421 }
3422 }
3423 }
3424 // Do some sanity checking
3425 if (multiplier < 1) {
3426 multiplier = 1;
3427 }
3428 }
3429 // Player height
3430 if (player.getLocation().getBlockY() < Settings.seaHeight) {
3431 multiplier *= Settings.underWaterMultiplier;
3432 }
3433 // Get the value. Try the specific item
3434 int value = 0;
3435 if (Settings.blockValues.containsKey(item.getData())) {
3436 value = (int)((double)Settings.blockValues.get(item.getData()) * multiplier);
3437 } else if (Settings.blockValues.containsKey(new MaterialData(item.getType()))) {
3438 value = (int)((double)Settings.blockValues.get(new MaterialData(item.getType())) * multiplier);
3439 }
3440 if (value > 0) {
3441 // [name] placed here may be worth [value]
3442 Util.sendMessage(player, ChatColor.GREEN + (plugin.myLocale(player.getUniqueId()).islandblockValue.replace("[name]", Util.prettifyText(item.getType().name())).replace("[value]", String.valueOf(value))));
3443 } else {
3444 // [name] is worthless
3445 Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(player.getUniqueId()).islandblockWorthless.replace("[name]", Util.prettifyText(item.getType().name())));
3446 }
3447 } else {
3448 // That is not a block
3449 Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNotABlock);
3450 }
3451 return true;
3452 }
3453 return true;
3454 }
3455
3456 @Override
3457 public List<String> onTabComplete(final CommandSender sender, final Command command, final String label, final String[] args) {
3458 if (!(sender instanceof Player)) {
3459 return new ArrayList<String>();
3460 }
3461 final Player player = (Player) sender;
3462
3463 if (!VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.create")) {
3464 return new ArrayList<String>();
3465 }
3466
3467 final UUID playerUUID = player.getUniqueId();
3468 final UUID teamLeader = plugin.getPlayers().getTeamLeader(playerUUID);
3469 List<UUID> teamMembers = new ArrayList<UUID>();
3470 if (teamLeader != null) {
3471 teamMembers = plugin.getPlayers().getMembers(teamLeader);
3472 }
3473
3474 final List<String> options = new ArrayList<String>();
3475 String lastArg = (args.length != 0 ? args[args.length - 1] : "");
3476
3477 switch (args.length) {
3478 case 0:
3479 case 1:
3480 options.add("help"); //No permission needed.
3481 //options.add("make"); //Make is currently a private command never accessible to the player
3482 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.go")) {
3483 options.add("go");
3484 }
3485 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.name") && plugin.getPlayers().hasIsland(player.getUniqueId())) {
3486 options.add("name");
3487 }
3488 options.add("about"); //No permission needed. :-) Indeed.
3489 if (plugin.getGrid() != null && plugin.getGrid().getSpawn() != null) {
3490 options.add("spawn");
3491 }
3492 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.controlpanel")) {
3493 options.add("controlpanel");
3494 options.add("cp");
3495 }
3496 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.reset")) {
3497 options.add("reset");
3498 }
3499 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.sethome")) {
3500 options.add("sethome");
3501 }
3502 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.info")) {
3503 options.add("level");
3504 }
3505 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.topten")) {
3506 options.add("top");
3507 }
3508 if (Settings.useEconomy && VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.minishop")) {
3509 options.add("minishop");
3510 options.add("ms");
3511 }
3512 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.warp")) {
3513 options.add("warp");
3514 options.add("warps");
3515 }
3516 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "team.create")) {
3517 options.add("team");
3518 options.add("invite");
3519 options.add("leave");
3520 }
3521 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "team.kick")) {
3522 options.add("kick");
3523 }
3524 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "team.join")) {
3525 options.add("accept");
3526 options.add("reject");
3527 }
3528 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "team.makeleader")) {
3529 options.add("makeleader");
3530 }
3531 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "team.chat")) {
3532 options.add("teamchat");
3533 options.add("tc");
3534 }
3535 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.biomes")) {
3536 options.add("biomes");
3537 }
3538 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.expel")) {
3539 options.add("expel");
3540 }
3541 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "coop")) {
3542 options.add("coop");
3543 options.add("uncoop");
3544 options.add("listcoops");
3545 options.add("coopaccept");
3546 options.add("coopreject");
3547 }
3548 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.lock")) {
3549 options.add("lock");
3550 }
3551 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.settings")) {
3552 options.add("settings");
3553 }
3554 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.lang")) {
3555 options.add("lang");
3556 }
3557 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.ban")) {
3558 options.add("ban");
3559 options.add("unban");
3560 options.add("banlist");
3561 }
3562 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.value")) {
3563 options.add("value");
3564 }
3565 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.spawn")
3566 && plugin.getGrid() != null && plugin.getGrid().getSpawn() != null) {
3567 options.add("spawn");
3568 }
3569 break;
3570 case 2:
3571 if (args[0].equalsIgnoreCase("make")) {
3572 options.addAll(schematics.keySet());
3573 }
3574 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.sethome")) {
3575 if (args[0].equalsIgnoreCase("go") || args[0].equalsIgnoreCase("sethome")) {
3576 // Dynamic home sizes with permissions
3577 int maxHomes = Settings.maxHomes;
3578 for (PermissionAttachmentInfo perms : player.getEffectivePermissions()) {
3579 if (perms.getPermission().startsWith(Settings.PERMPREFIX + "island.maxhomes.")) {
3580 if (perms.getPermission().contains(Settings.PERMPREFIX + "island.maxhomes.*")) {
3581 maxHomes = Settings.maxHomes;
3582 break;
3583 } else {
3584 // Get the max value should there be more than one
3585 String[] spl = perms.getPermission().split(Settings.PERMPREFIX + "island.maxhomes.");
3586 if (spl.length > 1) {
3587 if (!NumberUtils.isDigits(spl[1])) {
3588 plugin.getLogger().severe("Player " + player.getName() + " has permission: " + perms.getPermission() + " <-- the last part MUST be a number! Ignoring...");
3589 } else {
3590 maxHomes = Math.max(maxHomes, Integer.valueOf(spl[1]));
3591 }
3592 }
3593 }
3594 }
3595 // Do some sanity checking
3596 if (maxHomes < 1) {
3597 maxHomes = 1;
3598 }
3599 }
3600 for (int i = 0; i < maxHomes; i++) {
3601 options.add(Integer.toString(i));
3602 }
3603 }
3604 }
3605 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.warp")
3606 && args[0].equalsIgnoreCase("warp")) {
3607 final Set<UUID> warpList = plugin.getWarpSignsListener().listWarps();
3608
3609 for (UUID warp : warpList) {
3610 options.add(plugin.getPlayers().getName(warp));
3611 }
3612 }
3613 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.info")
3614 && args[0].equalsIgnoreCase("worth")) {
3615 options.addAll(Util.getOnlinePlayerList(player));
3616 }
3617 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "team.create")
3618 && args[0].equalsIgnoreCase("invite")) {
3619 options.addAll(Util.getOnlinePlayerList(player));
3620 }
3621 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "coop")
3622 && args[0].equalsIgnoreCase("trust")) {
3623 options.addAll(Util.getOnlinePlayerList(player));
3624 }
3625 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "coop")
3626 && args[0].equalsIgnoreCase("untrust")) {
3627 options.addAll(Util.getOnlinePlayerList(player));
3628 }
3629 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.expel")
3630 && args[0].equalsIgnoreCase("expel")) {
3631 options.addAll(Util.getOnlinePlayerList(player));
3632 }
3633 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "team.kick")
3634 && (args[0].equalsIgnoreCase("kick") || args[0].equalsIgnoreCase("remove"))) {
3635 for (UUID member : teamMembers) {
3636 options.add(plugin.getPlayers().getName(member));
3637 }
3638 }
3639 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "team.makeleader")
3640 && args[0].equalsIgnoreCase("makeleader") || args[0].equalsIgnoreCase("ownership") || args[0].equalsIgnoreCase("transfer")) {
3641 for (UUID member : teamMembers) {
3642 options.add(plugin.getPlayers().getName(member));
3643 }
3644 }
3645 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.controlpanelonoff")
3646 && (args[0].equalsIgnoreCase("cp") || args[0].equalsIgnoreCase("controlpanel") || args[0].equalsIgnoreCase("station"))) {
3647 options.add("on");
3648 options.add("off");
3649 }
3650 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.ban")
3651 && (args[0].equalsIgnoreCase("ban") || args[0].equalsIgnoreCase("suspend"))) {
3652 for (Player banPlayer: plugin.getServer().getOnlinePlayers()) {
3653 if (!banPlayer.isOp() && !VaultHelper.checkPerm(banPlayer, Settings.PERMPREFIX + "admin.noban")
3654 && !banPlayer.equals(player)
3655 && !plugin.getPlayers().getMembers(playerUUID).contains(banPlayer.getUniqueId())) {
3656 options.add(banPlayer.getName());
3657 }
3658 }
3659 }
3660 if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "island.ban")
3661 && (args[0].equalsIgnoreCase("unban") || args[0].equalsIgnoreCase("pardon"))) {
3662 for (UUID banPlayer: plugin.getPlayers().getBanList(playerUUID)) {
3663 options.add(plugin.getPlayers().getName(banPlayer));
3664 }
3665 }
3666 break;
3667 }
3668
3669 return Util.tabLimit(options, lastArg);
3670 }
3671}