use of org.bukkit.Material in project acidisland by tastybento.
the class ASkyBlock method registerEvents.
/**
* Registers events
*/
public void registerEvents() {
final PluginManager manager = getServer().getPluginManager();
// Nether portal events
manager.registerEvents(new NetherPortals(this), this);
// Nether spawning events
manager.registerEvents(new NetherSpawning(this), this);
// Island Protection events
manager.registerEvents(new IslandGuard(this), this);
// Island Entity Limits
manager.registerEvents(new EntityLimits(this), this);
// Player events
playerEvents = new PlayerEvents(this);
manager.registerEvents(playerEvents, this);
try {
Class<?> clazz = Class.forName("org.bukkit.event.entity.EntityPickupItemEvent", false, getClassLoader());
if (clazz != null) {
manager.registerEvents(new PlayerEvents3(this), this);
}
} catch (ClassNotFoundException e) {
manager.registerEvents(new PlayerEvents2(this), this);
}
// New V1.8 events
if (onePointEight) {
manager.registerEvents(new IslandGuard1_8(this), this);
}
// Check for 1.9 material
for (Material m : Material.values()) {
if (m.name().equalsIgnoreCase("END_CRYSTAL")) {
manager.registerEvents(new IslandGuard1_9(this), this);
break;
}
}
// Events for when a player joins or leaves the server
manager.registerEvents(new JoinLeaveEvents(this), this);
// Ensures Lava flows correctly in ASkyBlock world
lavaListener = new LavaCheck(this);
manager.registerEvents(lavaListener, this);
// Ensures that water is acid
manager.registerEvents(new AcidEffect(this), this);
// Ensures that boats are safe in ASkyBlock
if (Settings.acidDamage > 0D) {
manager.registerEvents(new SafeBoat(this), this);
}
// Enables warp signs in ASkyBlock
warpSignsListener = new WarpSigns(this);
manager.registerEvents(warpSignsListener, this);
// Control panel - for future use
// manager.registerEvents(new ControlPanel(), this);
// Change names of inventory items
// manager.registerEvents(new AcidInventory(this), this);
// Schematics panel
schematicsPanel = new SchematicsPanel(this);
manager.registerEvents(schematicsPanel, this);
// Track incoming world teleports
manager.registerEvents(new WorldEnter(this), this);
// Team chat
chatListener = new ChatListener(this);
manager.registerEvents(chatListener, this);
// Wither
if (Settings.restrictWither) {
manager.registerEvents(new FlyingMobEvents(this), this);
}
if (Settings.recoverSuperFlat) {
manager.registerEvents(new CleanSuperFlat(), this);
}
}
use of org.bukkit.Material in project acidisland by tastybento.
the class IslandBlock method setChest.
@SuppressWarnings("deprecation")
public void setChest(NMSAbstraction nms, Map<String, Tag> tileData) {
try {
ListTag chestItems = (ListTag) tileData.get("Items");
if (chestItems != null) {
// int number = 0;
for (Tag item : chestItems.getValue()) {
if (item instanceof CompoundTag) {
try {
// Id is a number
short itemType = (Short) ((CompoundTag) item).getValue().get("id").getValue();
short itemDamage = (Short) ((CompoundTag) item).getValue().get("Damage").getValue();
byte itemAmount = (Byte) ((CompoundTag) item).getValue().get("Count").getValue();
byte itemSlot = (Byte) ((CompoundTag) item).getValue().get("Slot").getValue();
ItemStack chestItem = new ItemStack(itemType, itemAmount, itemDamage);
chestContents.put(itemSlot, chestItem);
} catch (ClassCastException ex) {
// Id is a material
String itemType = (String) ((CompoundTag) item).getValue().get("id").getValue();
try {
// Get the material
if (itemType.startsWith("minecraft:")) {
String material = itemType.substring(10).toUpperCase();
// Special case for non-standard material names
Material itemMaterial;
if (WEtoM.containsKey(material)) {
// Bukkit.getLogger().info("DEBUG: Found in hashmap");
itemMaterial = WEtoM.get(material);
} else {
// Bukkit.getLogger().info("DEBUG: Not in hashmap");
itemMaterial = Material.valueOf(material);
}
short itemDamage = (Short) ((CompoundTag) item).getValue().get("Damage").getValue();
byte itemAmount = (Byte) ((CompoundTag) item).getValue().get("Count").getValue();
byte itemSlot = (Byte) ((CompoundTag) item).getValue().get("Slot").getValue();
ItemStack chestItem = new ItemStack(itemMaterial, itemAmount, itemDamage);
if (itemMaterial.equals(Material.WRITTEN_BOOK)) {
chestItem = nms.setBook(item);
}
// Check for potions
if (itemMaterial.toString().contains("POTION")) {
chestItem = nms.setPotion(itemMaterial, item, chestItem);
}
chestContents.put(itemSlot, chestItem);
}
} catch (Exception exx) {
// Bukkit.getLogger().info(item.toString());
// Bukkit.getLogger().info(((CompoundTag)item).getValue().get("id").getName());
Bukkit.getLogger().severe("Could not parse item [" + itemType.substring(10).toUpperCase() + "] in schematic - skipping!");
// Bukkit.getLogger().severe(item.toString());
exx.printStackTrace();
}
}
// Bukkit.getLogger().info("Set chest inventory slot "
// + itemSlot + " to " +
// chestItem.toString());
}
}
// Bukkit.getLogger().info("Added " + number + " items to chest");
}
} catch (Exception e) {
Bukkit.getLogger().severe("Could not parse schematic file item, skipping!");
// e.printStackTrace();
}
}
use of org.bukkit.Material in project acidisland by tastybento.
the class LevelCalcByChunk method scanChunk.
@SuppressWarnings("deprecation")
private void scanChunk(ChunkSnapshot chunk) {
for (int x = 0; x < 16; x++) {
// Check if the block coord is inside the protection zone and if not, don't count it
if (chunk.getX() * 16 + x < island.getMinProtectedX() || chunk.getX() * 16 + x >= island.getMinProtectedX() + (island.getProtectionSize() * 2)) {
continue;
}
for (int z = 0; z < 16; z++) {
// Check if the block coord is inside the protection zone and if not, don't count it
if (chunk.getZ() * 16 + z < island.getMinProtectedZ() || chunk.getZ() * 16 + z >= island.getMinProtectedZ() + (island.getProtectionSize() * 2)) {
continue;
}
for (int y = 0; y < island.getCenter().getWorld().getMaxHeight(); y++) {
Material blockType = Material.getMaterial(chunk.getBlockTypeId(x, y, z));
boolean belowSeaLevel = (Settings.seaHeight > 0 && y <= Settings.seaHeight) ? true : false;
// Air is free
if (!blockType.equals(Material.AIR)) {
checkBlock(blockType, chunk.getBlockData(x, y, z), belowSeaLevel);
}
}
}
}
}
use of org.bukkit.Material in project acidisland by tastybento.
the class PluginConfig method loadPluginConfig.
/**
* Loads the various settings from the config.yml file into the plugin
* @param plugin - ASkyBlock plugin object - askyblock
* @return true if plugin config is loaded correctly
*/
public static boolean loadPluginConfig(ASkyBlock plugin) {
try {
plugin.getConfig();
} catch (final Exception e) {
e.printStackTrace();
}
// The order in this file should match the order in config.yml so that it is easy to check that everything is covered
// ********************** Island settings **************************
Settings.islandDistance = plugin.getConfig().getInt("island.distance", 200);
if (Settings.islandDistance < 50) {
Settings.islandDistance = 50;
plugin.getLogger().info("Setting minimum island distance to 50");
}
if (Settings.islandDistance % 2 != 0) {
plugin.getLogger().warning("Island distance should be even!");
}
Settings.islandProtectionRange = plugin.getConfig().getInt("island.protectionRange", 100);
if (Settings.islandProtectionRange > Settings.islandDistance) {
plugin.getLogger().warning("Protection range cannot be > island distance. Setting them to be equal.");
Settings.islandProtectionRange = Settings.islandDistance;
}
if (Settings.islandProtectionRange <= 0) {
plugin.getLogger().warning("Protection range of 0 in config.yml: To disable protection, the range should");
plugin.getLogger().warning("equal the island distance and then you should allow all island protection flags");
plugin.getLogger().warning("in config.yml. Protection range will be set to island distance (" + Settings.islandDistance + ")");
Settings.islandProtectionRange = Settings.islandDistance;
}
if (Settings.islandProtectionRange % 2 != 0) {
Settings.islandProtectionRange--;
plugin.getLogger().warning("Protection range must be even, using " + Settings.islandProtectionRange);
}
// xoffset and zoffset are not public and only used for IslandWorld compatibility
Settings.islandXOffset = plugin.getConfig().getInt("island.xoffset", 0);
if (Settings.islandXOffset < 0) {
Settings.islandXOffset = 0;
plugin.getLogger().info("Setting minimum island X Offset to 0");
} else if (Settings.islandXOffset > Settings.islandDistance) {
Settings.islandXOffset = Settings.islandDistance;
plugin.getLogger().info("Setting maximum island X Offset to " + Settings.islandDistance);
}
Settings.islandZOffset = plugin.getConfig().getInt("island.zoffset", 0);
if (Settings.islandZOffset < 0) {
Settings.islandZOffset = 0;
plugin.getLogger().info("Setting minimum island Z Offset to 0");
} else if (Settings.islandZOffset > Settings.islandDistance) {
Settings.islandZOffset = Settings.islandDistance;
plugin.getLogger().info("Setting maximum island Z Offset to " + Settings.islandDistance);
}
// This is the origin of new islands
long x = plugin.getConfig().getLong("island.startx", 0);
// Check this is a multiple of island distance
long z = plugin.getConfig().getLong("island.startz", 0);
Settings.islandStartX = Math.round((double) x / Settings.islandDistance) * Settings.islandDistance + Settings.islandXOffset;
Settings.islandStartZ = Math.round((double) z / Settings.islandDistance) * Settings.islandDistance + Settings.islandZOffset;
// ASkyBlock and AcidIsland difference
if (Settings.GAMETYPE.equals(Settings.GameType.ACIDISLAND)) {
Settings.islandHeight = plugin.getConfig().getInt("island.islandlevel", 50) - 5;
// The island's center is actually 5 below sea level
Settings.seaHeight = plugin.getConfig().getInt("island.sealevel", 50);
} else {
// ASkyBlock
Settings.islandHeight = plugin.getConfig().getInt("island.islandlevel", 120) - 5;
// The island's center is actually 5 below sea level
Settings.seaHeight = plugin.getConfig().getInt("island.sealevel", 0);
}
if (Settings.islandHeight < 0) {
Settings.islandHeight = 0;
}
if (Settings.seaHeight < 0) {
Settings.seaHeight = 0;
}
// Island reset settings
Settings.resetLimit = plugin.getConfig().getInt("island.resetlimit", 2);
if (Settings.resetWait < 0) {
Settings.resetWait = -1;
}
Settings.resetWait = plugin.getConfig().getInt("island.resetwait", 300);
if (Settings.resetWait < 0) {
Settings.resetWait = 0;
}
// Seconds to wait for a confirmation of reset
Settings.resetConfirmWait = plugin.getConfig().getInt("island.resetconfirmwait", 10);
if (Settings.resetConfirmWait < 0) {
Settings.resetConfirmWait = 0;
}
// Timeout required between duplicate team join/leaves
Settings.inviteWait = plugin.getConfig().getInt("island.invitewait", 60);
if (Settings.inviteWait < 0) {
Settings.inviteWait = 0;
}
// Invite timeout before accept/reject timesout
Settings.inviteTimeout = plugin.getConfig().getInt("island.invitetimeout", 60);
// Convert to ticks
Settings.inviteTimeout *= 20;
// Max team size
Settings.maxTeamSize = plugin.getConfig().getInt("island.maxteamsize", 4);
// Deprecated settings - use permission askyblock.team.maxsize.<number> instead
/*
Settings.maxTeamSizeVIP = plugin.getConfig().getInt("island.vipteamsize", 0);
Settings.maxTeamSizeVIP2 = plugin.getConfig().getInt("island.vip2teamsize", 0);
if (Settings.maxTeamSizeVIP > 0 || Settings.maxTeamSizeVIP2 > 0) {
plugin.getLogger().warning(Settings.PERMPREFIX + "team.vip and " + Settings.PERMPREFIX + "team.vip2 are deprecated!");
plugin.getLogger().warning("Use permission " + Settings.PERMPREFIX + "team.maxsize.<number> instead.");
}
*/
// Island level cool down time
Settings.levelWait = plugin.getConfig().getInt("island.levelwait", 60);
if (Settings.levelWait < 0) {
Settings.levelWait = 0;
}
// Get chest items
String chestItems = plugin.getConfig().getString("island.chestItems", "");
if (!chestItems.isEmpty()) {
final String[] chestItemString = chestItems.split(" ");
// plugin.getLogger().info("DEBUG: chest items = " + chestItemString);
final ItemStack[] tempChest = new ItemStack[chestItemString.length];
for (int i = 0; i < tempChest.length; i++) {
String[] amountdata = chestItemString[i].split(":");
try {
if (amountdata.length == 3 && amountdata[0].equalsIgnoreCase("MONSTER_EGG")) {
try {
EntityType type = EntityType.valueOf(amountdata[1].toUpperCase());
if (Bukkit.getServer().getVersion().contains("(MC: 1.8") || Bukkit.getServer().getVersion().contains("(MC: 1.7")) {
tempChest[i] = new SpawnEgg(type).toItemStack(Integer.parseInt(amountdata[2]));
} else {
try {
tempChest[i] = new SpawnEgg1_9(type).toItemStack(Integer.parseInt(amountdata[2]));
} catch (Exception ex) {
tempChest[i] = new ItemStack(Material.MONSTER_EGG);
plugin.getLogger().severe("Monster eggs not supported with this server version.");
}
}
} catch (Exception e) {
plugin.getLogger().severe("Spawn eggs must be described by name. Try one of these (not all are possible):");
for (EntityType type : EntityType.values()) {
if (type.isSpawnable() && type.isAlive()) {
plugin.getLogger().severe(type.toString());
}
}
}
} else if (amountdata[0].equals("POTION")) {
// amountdata.length);
if (amountdata.length == 6) {
tempChest[i] = Challenges.getPotion(amountdata, Integer.parseInt(amountdata[5]), "config.yml");
} else {
plugin.getLogger().severe("Problem loading chest item from config.yml so skipping it: " + chestItemString[i]);
plugin.getLogger().severe("Potions for the chest must be fully defined as POTION:NAME:<LEVEL>:<EXTENDED>:<SPLASH/LINGER>:QTY");
}
} else {
Material mat;
if (StringUtils.isNumeric(amountdata[0])) {
mat = Material.getMaterial(Integer.parseInt(amountdata[0]));
} else {
mat = Material.getMaterial(amountdata[0].toUpperCase());
}
if (amountdata.length == 2) {
tempChest[i] = new ItemStack(mat, Integer.parseInt(amountdata[1]));
} else if (amountdata.length == 3) {
tempChest[i] = new ItemStack(mat, Integer.parseInt(amountdata[2]), Short.parseShort(amountdata[1]));
}
}
} catch (java.lang.IllegalArgumentException ex) {
ex.printStackTrace();
plugin.getLogger().severe("Problem loading chest item from config.yml so skipping it: " + chestItemString[i]);
plugin.getLogger().severe("Error is : " + ex.getMessage());
plugin.getLogger().info("Potential potion types are: ");
for (PotionType c : PotionType.values()) plugin.getLogger().info(c.name());
} catch (Exception e) {
e.printStackTrace();
plugin.getLogger().severe("Problem loading chest item from config.yml so skipping it: " + chestItemString[i]);
plugin.getLogger().info("Potential material types are: ");
for (Material c : Material.values()) plugin.getLogger().info(c.name());
// e.printStackTrace();
}
}
Settings.chestItems = tempChest;
} else {
// Nothing in the chest
Settings.chestItems = new ItemStack[0];
}
// Defaul companion
String companion = plugin.getConfig().getString("island.companion", "COW").toUpperCase();
Settings.islandCompanion = null;
if (!companion.equalsIgnoreCase("NOTHING")) {
String commaList = "NOTHING, ";
for (EntityType type : EntityType.values()) {
if (companion.equalsIgnoreCase(type.toString())) {
Settings.islandCompanion = type;
break;
}
commaList += ", " + type.toString();
}
if (Settings.islandCompanion == null) {
plugin.getLogger().warning("Island companion is not recognized. Pick from " + commaList);
}
}
// Companion names
List<String> companionNames = plugin.getConfig().getStringList("island.companionnames");
Settings.companionNames = new ArrayList<String>();
for (String name : companionNames) {
Settings.companionNames.add(ChatColor.translateAlternateColorCodes('&', name));
}
// Island name length
Settings.minNameLength = plugin.getConfig().getInt("island.minnamelength", 1);
Settings.maxNameLength = plugin.getConfig().getInt("island.maxnamelength", 20);
if (Settings.minNameLength < 0) {
Settings.minNameLength = 0;
}
if (Settings.maxNameLength < 1) {
Settings.maxNameLength = 1;
}
if (Settings.minNameLength > Settings.maxNameLength) {
Settings.minNameLength = Settings.maxNameLength;
}
// Flymode expiration while flying oustide island boundaries
Settings.flyTimeOutside = plugin.getConfig().getInt("island.flytimeoutside", 0);
if (Settings.flyTimeOutside < 0) {
Settings.flyTimeOutside = 0;
}
// Temporary Permissions while inside island
Settings.temporaryPermissions = plugin.getConfig().getStringList("island.islandtemporaryperms");
// System settings
Settings.allowEndermanGriefing = plugin.getConfig().getBoolean("island.allowendermangriefing", true);
Settings.endermanDeathDrop = plugin.getConfig().getBoolean("island.endermandeathdrop", true);
Settings.allowCreeperDamage = plugin.getConfig().getBoolean("island.allowcreeperdamage", true);
Settings.allowCreeperGriefing = plugin.getConfig().getBoolean("island.allowcreepergriefing", false);
Settings.allowTNTDamage = plugin.getConfig().getBoolean("island.allowtntdamage", false);
Settings.allowFireExtinguish = plugin.getConfig().getBoolean("island.allowfireextinguish", false);
Settings.allowChestDamage = plugin.getConfig().getBoolean("island.allowchestdamage", false);
Settings.allowVisitorKeepInvOnDeath = plugin.getConfig().getBoolean("island.allowvisitorkeepinvondeath", false);
Settings.allowPistonPush = plugin.getConfig().getBoolean("island.allowpistonpush", true);
Settings.allowMobDamageToItemFrames = plugin.getConfig().getBoolean("island.allowitemframedamage", false);
// Clean up blocks around edges when deleting islands - this is a hidden setting not in the config.yml
// Add if admins complain about slow cleaning.
Settings.cleanRate = plugin.getConfig().getInt("island.cleanrate", 2);
if (Settings.cleanRate < 1) {
Settings.cleanRate = 1;
}
// ******** General Settings **********
// Load world name
Settings.worldName = plugin.getConfig().getString("general.worldName");
// Check if the world name matches island.yml info
File islandFile = new File(plugin.getDataFolder(), "islands.yml");
if (islandFile.exists()) {
YamlConfiguration islandYaml = new YamlConfiguration();
try {
islandYaml.load(islandFile);
if (!islandYaml.contains(Settings.worldName)) {
// Bad news, stop everything and tell the admin
plugin.getLogger().severe("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+");
plugin.getLogger().severe("More set up is required. Go to config.yml and edit it.");
plugin.getLogger().severe("");
plugin.getLogger().severe("Check island world name is same as world in islands.yml.");
plugin.getLogger().severe("If you are resetting and changing world, delete island.yml and restart.");
plugin.getLogger().severe("");
plugin.getLogger().severe("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+");
return false;
}
} catch (Exception e) {
}
}
// Get the default language
Settings.defaultLanguage = plugin.getConfig().getString("general.defaultlanguage", "en-US");
// Load languages
HashMap<String, ASLocale> availableLocales = new HashMap<String, ASLocale>();
FileLister fl = new FileLister(plugin);
try {
int index = 1;
for (String code : fl.list()) {
// plugin.getLogger().info("DEBUG: lang file = " + code);
availableLocales.put(code, new ASLocale(plugin, code, index++));
}
} catch (IOException e1) {
plugin.getLogger().severe("Could not add locales!");
}
if (!availableLocales.containsKey(Settings.defaultLanguage)) {
plugin.getLogger().severe("'" + Settings.defaultLanguage + ".yml' not found in /locale folder. Using /locale/en-US.yml");
Settings.defaultLanguage = "en-US";
availableLocales.put(Settings.defaultLanguage, new ASLocale(plugin, Settings.defaultLanguage, 0));
}
plugin.setAvailableLocales(availableLocales);
// Check for updates
Settings.updateCheck = plugin.getConfig().getBoolean("general.checkupdates", true);
// Silence command feedback
Settings.silenceCommandFeedback = plugin.getConfig().getBoolean("general.silencecommandfeedback", true);
// Action bar settings
Settings.showInActionBar = plugin.getConfig().getBoolean("general.showinactionbar", true);
// Max Islands
Settings.maxIslands = plugin.getConfig().getInt("general.maxIslands", 0);
// Use control panel
Settings.useControlPanel = plugin.getConfig().getBoolean("general.usecontrolpanel", false);
// Create nether or not
Settings.createNether = plugin.getConfig().getBoolean("general.createnether", true);
if (!Settings.createNether) {
plugin.getLogger().info("The Nether is disabled");
}
// Use the island nether
Settings.newNether = plugin.getConfig().getBoolean("general.newnether", true);
// Nether trees
Settings.netherTrees = plugin.getConfig().getBoolean("general.nethertrees", true);
// Nether roof option
Settings.netherRoof = plugin.getConfig().getBoolean("general.netherroof", true);
// Nether spawn protection radius
Settings.netherSpawnRadius = plugin.getConfig().getInt("general.netherspawnradius", 25);
if (Settings.netherSpawnRadius < 0) {
Settings.netherSpawnRadius = 0;
} else if (Settings.netherSpawnRadius > 100) {
Settings.netherSpawnRadius = 100;
}
// Nether roof option
Settings.netherRoof = plugin.getConfig().getBoolean("general.netherroof", true);
// Run level calc at login
Settings.loginLevel = plugin.getConfig().getBoolean("general.loginlevel", false);
// Island reset commands
Settings.resetCommands = plugin.getConfig().getStringList("general.resetcommands");
Settings.leaveCommands = plugin.getConfig().getStringList("general.leavecommands");
Settings.startCommands = plugin.getConfig().getStringList("general.startcommands");
Settings.teamStartCommands = plugin.getConfig().getStringList("general.teamstartcommands");
Settings.visitorCommandBlockList = plugin.getConfig().getStringList("general.visitorbannedcommands");
// How long a player has to wait after deactivating PVP until they can activate PVP again
Settings.pvpRestartCooldown = plugin.getConfig().getLong("general.pvpcooldown", 60);
// Invincible visitors
Settings.invincibleVisitors = plugin.getConfig().getBoolean("general.invinciblevisitors", false);
if (Settings.invincibleVisitors) {
Settings.visitorDamagePrevention = new HashSet<DamageCause>();
List<String> damageSettings = plugin.getConfig().getStringList("general.invinciblevisitorsoptions");
for (DamageCause cause : DamageCause.values()) {
if (damageSettings.contains(cause.toString())) {
Settings.visitorDamagePrevention.add(cause);
}
}
}
// ASkyBlock and AcidIsland difference
if (Settings.GAMETYPE.equals(Settings.GameType.ACIDISLAND)) {
Settings.acidDamage = plugin.getConfig().getDouble("general.aciddamage", 5D);
if (Settings.acidDamage > 100D) {
Settings.acidDamage = 100D;
} else if (Settings.acidDamage < 0D) {
Settings.acidDamage = 0D;
}
Settings.mobAcidDamage = plugin.getConfig().getDouble("general.mobaciddamage", 10D);
if (Settings.mobAcidDamage > 100D) {
Settings.mobAcidDamage = 100D;
} else if (Settings.mobAcidDamage < 0D) {
Settings.mobAcidDamage = 0D;
}
Settings.rainDamage = plugin.getConfig().getDouble("general.raindamage", 0.5D);
if (Settings.rainDamage > 100D) {
Settings.rainDamage = 100D;
} else if (Settings.rainDamage < 0D) {
Settings.rainDamage = 0D;
}
} else {
Settings.acidDamage = plugin.getConfig().getDouble("general.aciddamage", 0D);
if (Settings.acidDamage > 100D) {
Settings.acidDamage = 100D;
} else if (Settings.acidDamage < 0D) {
Settings.acidDamage = 0D;
}
Settings.mobAcidDamage = plugin.getConfig().getDouble("general.mobaciddamage", 0D);
if (Settings.mobAcidDamage > 100D) {
Settings.mobAcidDamage = 100D;
} else if (Settings.mobAcidDamage < 0D) {
Settings.mobAcidDamage = 0D;
}
Settings.rainDamage = plugin.getConfig().getDouble("general.raindamage", 0D);
if (Settings.rainDamage > 100D) {
Settings.rainDamage = 100D;
} else if (Settings.rainDamage < 0D) {
Settings.rainDamage = 0D;
}
}
Settings.animalAcidDamage = plugin.getConfig().getDouble("general.animaldamage", 0D);
if (Settings.animalAcidDamage > 100D) {
Settings.animalAcidDamage = 100D;
} else if (Settings.animalAcidDamage < 0D) {
Settings.animalAcidDamage = 0D;
}
Settings.damageChickens = plugin.getConfig().getBoolean("general.damagechickens", false);
// Destroy items in acid timer
Settings.acidItemDestroyTime = plugin.getConfig().getLong("general.itemdestroyafter", 0L) * 20L;
Settings.damageOps = plugin.getConfig().getBoolean("general.damageops", false);
// Helmet and full armor acid protection options
Settings.helmetProtection = plugin.getConfig().getBoolean("general.helmetprotection", true);
Settings.fullArmorProtection = plugin.getConfig().getBoolean("general.fullarmorprotection", false);
// Damage Type
List<String> acidDamageType = plugin.getConfig().getStringList("general.damagetype");
Settings.acidDamageType.clear();
if (acidDamageType != null) {
for (String effect : acidDamageType) {
PotionEffectType newPotionType = PotionEffectType.getByName(effect);
if (newPotionType != null) {
// Check if it is a valid addition
if (newPotionType.equals(PotionEffectType.BLINDNESS) || newPotionType.equals(PotionEffectType.CONFUSION) || newPotionType.equals(PotionEffectType.HUNGER) || newPotionType.equals(PotionEffectType.POISON) || newPotionType.equals(PotionEffectType.SLOW) || newPotionType.equals(PotionEffectType.SLOW_DIGGING) || newPotionType.equals(PotionEffectType.WEAKNESS)) {
Settings.acidDamageType.add(newPotionType);
}
} else {
plugin.getLogger().warning("Could not interpret acid damage modifier: " + effect + " - skipping");
plugin.getLogger().warning("Types can be : SLOW, SLOW_DIGGING, CONFUSION,");
plugin.getLogger().warning("BLINDNESS, HUNGER, WEAKNESS and POISON");
}
}
}
Settings.logInRemoveMobs = plugin.getConfig().getBoolean("general.loginremovemobs", true);
Settings.islandRemoveMobs = plugin.getConfig().getBoolean("general.islandremovemobs", false);
List<String> mobWhiteList = plugin.getConfig().getStringList("general.mobwhitelist");
Settings.mobWhiteList.clear();
for (String mobName : mobWhiteList) {
boolean mobFound = false;
for (EntityType type : EntityType.values()) {
if (mobName.toUpperCase().equals(type.toString())) {
try {
Settings.mobWhiteList.add(EntityType.valueOf(mobName.toUpperCase()));
} catch (Exception e) {
plugin.getLogger().severe("Error in config.yml, mobwhitelist value '" + mobName + "' is invalid.");
}
mobFound = true;
break;
}
}
if (!mobFound) {
plugin.getLogger().severe("Error in config.yml, mobwhitelist value '" + mobName + "' is invalid.");
plugin.getLogger().severe("Possible values are : ");
for (EntityType e : EntityType.values()) {
if (e.isAlive()) {
plugin.getLogger().severe(e.name());
}
}
}
}
Settings.monsterSpawnLimit = plugin.getConfig().getInt("general.monsterspawnlimit", 100);
if (Settings.monsterSpawnLimit < -1) {
Settings.monsterSpawnLimit = -1;
}
Settings.animalSpawnLimit = plugin.getConfig().getInt("general.animalspawnlimit", 15);
if (Settings.animalSpawnLimit < -1) {
Settings.animalSpawnLimit = -1;
}
Settings.breedingLimit = plugin.getConfig().getInt("general.breedinglimit", 0);
Settings.waterAnimalSpawnLimit = plugin.getConfig().getInt("general.wateranimalspawnlimit", 15);
if (Settings.waterAnimalSpawnLimit < -1) {
Settings.waterAnimalSpawnLimit = -1;
}
Settings.villagerLimit = plugin.getConfig().getInt("general.villagerlimit", 0);
Settings.limitedBlocks = new HashMap<String, Integer>();
Settings.entityLimits = new HashMap<EntityType, Integer>();
plugin.getLogger().info("Loading entity limits");
ConfigurationSection entityLimits = plugin.getConfig().getConfigurationSection("general.entitylimits");
if (entityLimits != null) {
for (String entity : entityLimits.getKeys(false)) {
int limit = entityLimits.getInt(entity.toUpperCase(), -1);
// Check if this is an entity
for (EntityType type : EntityType.values()) {
// plugin.getLogger().info("DEBUG: is " + entity + " = " + type.name() + "?");
if (type.name().equals(entity.toUpperCase())) {
// plugin.getLogger().info("DEBUG: yes");
Settings.entityLimits.put(type, limit);
if (limit > 0) {
plugin.getLogger().info(entity.toUpperCase() + " will be limited to " + limit);
}
break;
}
}
if (Material.getMaterial(entity.toUpperCase()) != null && limit > -1) {
Settings.limitedBlocks.put(entity.toUpperCase(), limit);
plugin.getLogger().info(entity.toUpperCase() + " will be limited to " + limit);
if (entity.equalsIgnoreCase("REDSTONE_COMPARATOR")) {
// Player can only ever place a redstone comparator in the OFF state
Settings.limitedBlocks.put("REDSTONE_COMPARATOR_OFF", limit);
} else if (entity.equalsIgnoreCase("BANNER")) {
// To simplify banners, the banner is allowed and automatically made wall and standing banner
Settings.limitedBlocks.put("WALL_BANNER", limit);
Settings.limitedBlocks.put("STANDING_BANNER", limit);
} else if (entity.equalsIgnoreCase("SIGN")) {
// To simplify signs, the sign is allowed and automatically made wall and standing signs
Settings.limitedBlocks.put("WALL_SIGN", limit);
Settings.limitedBlocks.put("SIGN_POST", limit);
}
}
}
}
// Level to purge
Settings.abandonedIslandLevel = plugin.getConfig().getInt("general.abandonedislandlevel", 10);
if (Settings.abandonedIslandLevel < 0) {
Settings.abandonedIslandLevel = 0;
}
Settings.maxPurge = plugin.getConfig().getInt("general.maxpurge", 500);
if (Settings.maxPurge < 0) {
Settings.maxPurge = 0;
}
// Use economy or not
// In future expand to include internal economy
Settings.useEconomy = plugin.getConfig().getBoolean("general.useeconomy", true);
// Reset money when an island is started
Settings.resetMoney = plugin.getConfig().getBoolean("general.resetmoney", true);
// Use the minishop or not
Settings.useMinishop = plugin.getConfig().getBoolean("general.useminishop", true);
// Starting money - default $0
Settings.startingMoney = plugin.getConfig().getDouble("general.startingmoney", 0D);
// Things to reset when an island is reset
Settings.resetChallenges = plugin.getConfig().getBoolean("general.resetchallenges", true);
Settings.clearInventory = plugin.getConfig().getBoolean("general.resetinventory", true);
// Kicked players keep inventory
Settings.kickedKeepInv = plugin.getConfig().getBoolean("general.kickedkeepinv", false);
// Leavers lose resets
Settings.leaversLoseReset = plugin.getConfig().getBoolean("general.leaversloseresets", true);
// Reset the ender chest
Settings.resetEnderChest = plugin.getConfig().getBoolean("general.resetenderchest", false);
// Check if /island command is allowed when falling
Settings.allowTeleportWhenFalling = plugin.getConfig().getBoolean("general.allowfallingteleport", true);
Settings.fallingCommandBlockList = plugin.getConfig().getStringList("general.blockingcommands");
// Challenges
Settings.broadcastMessages = plugin.getConfig().getBoolean("general.broadcastmessages", true);
Settings.removeCompleteOntimeChallenges = plugin.getConfig().getBoolean("general.removecompleteonetimechallenges", false);
Settings.addCompletedGlow = plugin.getConfig().getBoolean("general.addcompletedglow", true);
// Max home number
Settings.maxHomes = plugin.getConfig().getInt("general.maxhomes", 1);
if (Settings.maxHomes < 1) {
Settings.maxHomes = 1;
}
// Make island automatically
Settings.makeIslandIfNone = plugin.getConfig().getBoolean("general.makeislandifnone", false);
// Immediate teleport
Settings.immediateTeleport = plugin.getConfig().getBoolean("general.immediateteleport", false);
// Respawn on island
Settings.respawnOnIsland = plugin.getConfig().getBoolean("general.respawnonisland", false);
// Team chat
Settings.teamChat = plugin.getConfig().getBoolean("general.teamchat", true);
Settings.logTeamChat = plugin.getConfig().getBoolean("general.logteamchat", true);
// Chat prefixes
Settings.chatLevelPrefix = plugin.getConfig().getString("general.chatlevelprefix", "{ISLAND_LEVEL}");
Settings.chatChallengeLevelPrefix = plugin.getConfig().getString("general.chatchallanegelevelprefix", "{ISLAND_CHALLENGE_LEVEL}");
Settings.chatIslandPlayer = plugin.getConfig().getString("general.chatislandplayer", "{ISLAND_PLAYER}");
// Chat team suffixes - Not public right now
Settings.setTeamName = plugin.getConfig().getBoolean("general.setteamsuffix", false);
Settings.teamSuffix = plugin.getConfig().getString("general.teamsuffix", "([level])");
// Restrict wither
Settings.restrictWither = plugin.getConfig().getBoolean("general.restrictwither", true);
// Warp Restriction
Settings.warpLevelsRestriction = plugin.getConfig().getInt("general.warplevelrestriction", 10);
// Warp panel
Settings.useWarpPanel = plugin.getConfig().getBoolean("general.usewarppanel", true);
// Mute death messages
Settings.muteDeathMessages = plugin.getConfig().getBoolean("general.mutedeathmessages", false);
// How often the grid will be saved to file. Default is 5 minutes
Settings.backupDuration = (plugin.getConfig().getLong("general.backupduration", 5) * 20 * 60);
// Allow pushing
Settings.allowPushing = plugin.getConfig().getBoolean("general.allowpushing", true);
// try to remove the team from the scoreboard
if (Settings.allowPushing) {
try {
ScoreboardManager manager = plugin.getServer().getScoreboardManager();
if (manager != null) {
Scoreboard scoreboard = manager.getMainScoreboard();
if (scoreboard != null) {
Team pTeam = scoreboard.getTeam(NO_PUSH_TEAM_NAME);
if (pTeam != null) {
pTeam.unregister();
}
}
}
} catch (Exception e) {
plugin.getLogger().warning("Problem removing no push from scoreboard.");
}
}
// Recover superflat
Settings.recoverSuperFlat = plugin.getConfig().getBoolean("general.recoversuperflat");
if (Settings.recoverSuperFlat) {
plugin.getLogger().warning("*********************************************************");
plugin.getLogger().warning("WARNING: Recover super flat mode is enabled");
plugin.getLogger().warning("This will regenerate any chunks with bedrock at y=0 when they are loaded");
plugin.getLogger().warning("Switch off when superflat chunks are cleared");
plugin.getLogger().warning("You should back up your world before running this");
plugin.getLogger().warning("*********************************************************");
}
// Persistent coops
Settings.persistantCoops = plugin.getConfig().getBoolean("general.persistentcoops");
// Only leader can coop
Settings.onlyLeaderCanCoop = plugin.getConfig().getBoolean("general.onlyleadercancoop", false);
// Fake players
Settings.allowedFakePlayers = plugin.getConfig().getStringList("general.fakeplayers");
// Allow Obsidian Scooping
Settings.allowObsidianScooping = plugin.getConfig().getBoolean("general.allowobsidianscooping", true);
// Use old display (chat instead of GUI) for Island top ten
Settings.displayIslandTopTenInChat = plugin.getConfig().getBoolean("general.islandtopteninchat", false);
// Magic Cobble Generator
Settings.useMagicCobbleGen = plugin.getConfig().getBoolean("general.usemagiccobblegen", false);
if (Settings.useMagicCobbleGen) {
Settings.magicCobbleGenOnlyAtSpawn = plugin.getConfig().getBoolean("general.magiccobblegenonlyatspawn", false);
if (plugin.getConfig().isSet("general.magiccobblegenchances")) {
// plugin.getLogger().info("DEBUG: magic cobble gen enabled and chances section found");
// Clear the cobble gen chances so they can be reloaded
LavaCheck.clearChances();
Settings.magicCobbleGenChances = new TreeMap<Long, TreeMap<Double, Material>>();
for (String level : plugin.getConfig().getConfigurationSection("general.magiccobblegenchances").getKeys(false)) {
long levelLong = 0;
try {
if (level.equals("default")) {
levelLong = Long.MIN_VALUE;
} else {
levelLong = Long.parseLong(level);
}
TreeMap<Double, Material> blockMapTree = new TreeMap<Double, Material>();
double chanceTotal = 0;
for (String block : plugin.getConfig().getConfigurationSection("general.magiccobblegenchances." + level).getKeys(false)) {
double chance = plugin.getConfig().getDouble("general.magiccobblegenchances." + level + "." + block, 0D);
if (chance > 0 && Material.getMaterial(block) != null && Material.getMaterial(block).isBlock()) {
// Store the cumulative chance in the treemap. It does not need to add up to 100%
chanceTotal += chance;
blockMapTree.put(chanceTotal, Material.getMaterial(block));
}
}
if (!blockMapTree.isEmpty() && chanceTotal > 0) {
Settings.magicCobbleGenChances.put(levelLong, blockMapTree);
// Store the requested values as a % chance
Map<Material, Double> chances = new HashMap<Material, Double>();
for (Entry<Double, Material> en : blockMapTree.entrySet()) {
double chance = plugin.getConfig().getDouble("general.magiccobblegenchances." + level + "." + en.getValue(), 0D);
chances.put(en.getValue(), (chance / chanceTotal) * 100);
}
LavaCheck.storeChances(levelLong, chances);
}
} catch (NumberFormatException e) {
// Putting the catch here means that an invalid level is skipped completely
plugin.getLogger().severe("Unknown level '" + level + "' listed in magiccobblegenchances section! Must be an integer or 'default'. Skipping...");
}
}
}
}
// Disable offline redstone
Settings.disableOfflineRedstone = plugin.getConfig().getBoolean("general.disableofflineredstone", false);
// Allow/disallow TNT pusing
Settings.allowTNTPushing = plugin.getConfig().getBoolean("general.allowTNTpushing", true);
// Fancy island level display
Settings.fancyIslandLevelDisplay = plugin.getConfig().getBoolean("general.fancylevelinchat", false);
// Check config.yml version
String configVersion = plugin.getConfig().getString("general.version", "");
// Ignore last digit if it is 4 digits long
if (configVersion.split("\\.").length == 4) {
configVersion = configVersion.substring(0, configVersion.lastIndexOf('.'));
}
// Save for plugin version
String version = plugin.getDescription().getVersion();
// plugin.getLogger().info("DEBUG: version length " + version.split("\\.").length);
if (version.split("\\.").length == 4) {
version = version.substring(0, version.lastIndexOf('.'));
}
if (configVersion.isEmpty() || !configVersion.equalsIgnoreCase(version)) {
// Check to see if this has already been shared
File newConfig = new File(plugin.getDataFolder(), "config.new.yml");
plugin.getLogger().warning("***********************************************************");
plugin.getLogger().warning("Config file is out of date. See config.new.yml for updates!");
plugin.getLogger().warning("config.yml version is '" + configVersion + "'");
plugin.getLogger().warning("Latest config version is '" + version + "'");
plugin.getLogger().warning("***********************************************************");
if (!newConfig.exists()) {
File oldConfig = new File(plugin.getDataFolder(), "config.yml");
File bakConfig = new File(plugin.getDataFolder(), "config.bak");
if (oldConfig.renameTo(bakConfig)) {
plugin.saveResource("config.yml", false);
oldConfig.renameTo(newConfig);
bakConfig.renameTo(oldConfig);
}
}
}
// *** Non-Public Settings - these are "secret" settings that may not be used anymore
// Level logging
Settings.levelLogging = plugin.getConfig().getBoolean("general.levellogging");
// Custom generator
Settings.useOwnGenerator = plugin.getConfig().getBoolean("general.useowngenerator", false);
// Use physics when pasting island block schematics
Settings.usePhysics = plugin.getConfig().getBoolean("general.usephysics", false);
// Legacy setting support for hopper limiting
if (Settings.limitedBlocks.isEmpty()) {
Settings.hopperLimit = plugin.getConfig().getInt("general.hopperlimit", -1);
if (Settings.hopperLimit > 0) {
Settings.limitedBlocks.put("HOPPER", Settings.hopperLimit);
}
}
// No acid bottles or buckets
Settings.acidBottle = plugin.getConfig().getBoolean("general.acidbottles", true);
// ************ Protection Settings ****************
// Default settings hashmaps - make sure this is kept up to date with new settings
// If a setting is not listed, the world default is used
Settings.defaultWorldSettings.clear();
Settings.defaultIslandSettings.clear();
Settings.defaultSpawnSettings.clear();
Settings.visitorSettings.clear();
ConfigurationSection protectionWorld = plugin.getConfig().getConfigurationSection("protection.world");
for (String setting : protectionWorld.getKeys(false)) {
try {
SettingsFlag flag = SettingsFlag.valueOf(setting.toUpperCase());
boolean value = plugin.getConfig().getBoolean("protection.world." + flag.name());
Settings.defaultWorldSettings.put(flag, value);
Settings.defaultSpawnSettings.put(flag, value);
Settings.defaultIslandSettings.put(flag, value);
} catch (Exception e) {
plugin.getLogger().severe("Unknown setting in config.yml:protection.world " + setting.toUpperCase() + " skipping...");
}
}
// Establish defaults if they are missing in the config file.
for (SettingsFlag flag : SettingsFlag.values()) {
if (!Settings.defaultWorldSettings.containsKey(flag)) {
plugin.getLogger().warning("config.yml:protection.world." + flag.name() + " is missing. You should add it to the config file. Setting to false by default");
Settings.defaultWorldSettings.put(flag, false);
}
if (!Settings.defaultIslandSettings.containsKey(flag)) {
Settings.defaultIslandSettings.put(flag, false);
}
if (!Settings.defaultSpawnSettings.containsKey(flag)) {
Settings.defaultSpawnSettings.put(flag, false);
}
}
ConfigurationSection protectionIsland = plugin.getConfig().getConfigurationSection("protection.island");
for (String setting : protectionIsland.getKeys(false)) {
try {
SettingsFlag flag = SettingsFlag.valueOf(setting.toUpperCase());
// Only items in the config.yml can be per island customized
Settings.visitorSettings.put(flag, protectionIsland.getBoolean(setting));
// plugin.getLogger().info("DEBUG: visitor flag added " + flag);
Settings.defaultIslandSettings.put(flag, Settings.visitorSettings.get(flag));
} catch (Exception e) {
plugin.getLogger().severe("Unknown setting in config.yml:island.world " + setting.toUpperCase() + " skipping...");
}
}
// ******************** Biome Settings *********************
Settings.biomeCost = plugin.getConfig().getDouble("biomesettings.defaultcost", 100D);
if (Settings.biomeCost < 0D) {
Settings.biomeCost = 0D;
plugin.getLogger().warning("Biome default cost is < $0, so set to zero.");
}
String defaultBiome = plugin.getConfig().getString("biomesettings.defaultbiome", "PLAINS");
try {
Settings.defaultBiome = Biome.valueOf(defaultBiome);
} catch (Exception e) {
plugin.getLogger().severe("Could not parse biome " + defaultBiome + " using PLAINS instead.");
Settings.defaultBiome = Biome.PLAINS;
}
// ******************** Schematic Section *******************
// Hack skeleton spawners for 1.11
Settings.hackSkeletonSpawners = plugin.getConfig().getBoolean("schematicsection.hackskeletonspawners", true);
// ****************** Levels blockvalues.yml ****************
// Get the blockvalues.yml file
YamlConfiguration blockValuesConfig = Util.loadYamlFile("blockvalues.yml");
// Get the under water multiplier
Settings.deathpenalty = blockValuesConfig.getInt("deathpenalty", 0);
Settings.sumTeamDeaths = blockValuesConfig.getBoolean("sumteamdeaths");
Settings.maxDeaths = blockValuesConfig.getInt("maxdeaths", 10);
Settings.islandResetDeathReset = blockValuesConfig.getBoolean("islandresetdeathreset", true);
Settings.teamJoinDeathReset = blockValuesConfig.getBoolean("teamjoindeathreset", true);
Settings.underWaterMultiplier = blockValuesConfig.getDouble("underwater", 1D);
Settings.levelCost = blockValuesConfig.getInt("levelcost", 100);
if (Settings.levelCost < 1) {
Settings.levelCost = 1;
plugin.getLogger().warning("levelcost in blockvalues.yml cannot be less than 1. Setting to 1.");
}
Settings.blockLimits = new HashMap<MaterialData, Integer>();
if (blockValuesConfig.isSet("limits")) {
for (String material : blockValuesConfig.getConfigurationSection("limits").getKeys(false)) {
try {
String[] split = material.split(":");
byte data = 0;
if (split.length > 1) {
data = Byte.valueOf(split[1]);
}
Material mat;
if (StringUtils.isNumeric(split[0])) {
mat = Material.getMaterial(Integer.parseInt(split[0]));
} else {
mat = Material.valueOf(split[0].toUpperCase());
}
MaterialData materialData = new MaterialData(mat);
materialData.setData(data);
Settings.blockLimits.put(materialData, blockValuesConfig.getInt("limits." + material, 0));
if (DEBUG) {
plugin.getLogger().info("Maximum number of " + materialData + " will be " + Settings.blockLimits.get(materialData));
}
} catch (Exception e) {
plugin.getLogger().warning("Unknown material (" + material + ") in blockvalues.yml Limits section. Skipping...");
}
}
}
Settings.blockValues = new HashMap<MaterialData, Integer>();
if (blockValuesConfig.isSet("blocks")) {
for (String material : blockValuesConfig.getConfigurationSection("blocks").getKeys(false)) {
try {
String[] split = material.split(":");
byte data = 0;
if (split.length > 1) {
data = Byte.valueOf(split[1]);
}
MaterialData materialData = null;
if (StringUtils.isNumeric(split[0])) {
materialData = new MaterialData(Integer.parseInt(split[0]));
} else {
materialData = new MaterialData(Material.valueOf(split[0].toUpperCase()));
}
materialData.setData(data);
Settings.blockValues.put(materialData, blockValuesConfig.getInt("blocks." + material, 0));
if (DEBUG) {
plugin.getLogger().info(materialData.toString());
}
} catch (Exception e) {
// e.printStackTrace();
plugin.getLogger().warning("Unknown material (" + material + ") in blockvalues.yml blocks section. Skipping...");
}
}
} else {
plugin.getLogger().severe("No block values in blockvalues.yml! All island levels will be zero!");
}
// All done
return true;
}
use of org.bukkit.Material in project acidisland by tastybento.
the class AdminCmd method onCommand.
/*
* (non-Javadoc)
* @see
* org.bukkit.command.CommandExecutor#onCommand(org.bukkit.command.CommandSender
* , org.bukkit.command.Command, java.lang.String, java.lang.String[])
*/
@Override
public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] split) {
// Console commands
Player player;
if (sender instanceof Player) {
player = (Player) sender;
if (player.getUniqueId() == null) {
return false;
}
if (split.length > 0) {
// Admin-only commands : reload, register, delete and purge
if (split[0].equalsIgnoreCase("reload") || split[0].equalsIgnoreCase("register") || split[0].equalsIgnoreCase("delete") || split[0].equalsIgnoreCase("purge") || split[0].equalsIgnoreCase("confirm") || split[0].equalsIgnoreCase("setspawn") || split[0].equalsIgnoreCase("deleteisland") || split[0].equalsIgnoreCase("setrange") || split[0].equalsIgnoreCase("reserve") || split[0].equalsIgnoreCase("addrange") || split[0].equalsIgnoreCase("unregister") || split[0].equalsIgnoreCase("clearresetall") || split[0].equalsIgnoreCase("settingsreset") || split[0].equalsIgnoreCase("cobblestats") || split[0].equalsIgnoreCase("setlanguage")) {
if (!checkAdminPerms(player, split)) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoPermission);
return true;
}
} else {
// Mod commands
if (!checkModPerms(player, split)) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoPermission);
return true;
}
}
}
}
// Island name (can have spaces)
if (split.length > 1 && split[0].equalsIgnoreCase("name")) {
final UUID playerUUID = plugin.getPlayers().getUUID(split[1], true);
// + playerUUID);
if (!plugin.getPlayers().isAKnownPlayer(playerUUID)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorUnknownPlayer);
return true;
} else {
if (split.length == 2) {
// Say the island name
Util.sendMessage(sender, plugin.getGrid().getIslandName(playerUUID));
} else {
String name = split[2];
for (int i = 3; i < split.length; i++) {
name = name + " " + split[i];
}
if (name.length() < Settings.minNameLength) {
Util.sendMessage(sender, ChatColor.RED + (plugin.myLocale().errorTooShort).replace("[length]", String.valueOf(Settings.minNameLength)));
return true;
}
if (name.length() > Settings.maxNameLength) {
Util.sendMessage(sender, ChatColor.RED + (plugin.myLocale().errorTooLong).replace("[length]", String.valueOf(Settings.maxNameLength)));
return true;
}
plugin.getGrid().setIslandName(playerUUID, ChatColor.translateAlternateColorCodes('&', name));
Util.sendMessage(sender, ChatColor.GREEN + plugin.myLocale().generalSuccess);
}
return true;
}
}
// Check for zero parameters e.g., /asadmin
switch(split.length) {
case 0:
help(sender, label);
return true;
case 1:
if (split[0].equalsIgnoreCase("setlanguage")) {
Util.sendMessage(sender, plugin.myLocale().helpColor + plugin.myLocale().adminHelpsetLanguage);
return true;
}
if (split[0].equalsIgnoreCase("listchallengeresets")) {
// Reset the challenge now
for (String challenge : plugin.getChallenges().getRepeatingChallengeResets()) {
Util.sendMessage(sender, ChatColor.GREEN + challenge);
}
return true;
} else if (split[0].equalsIgnoreCase("cobblestats")) {
if (LavaCheck.getStats().size() == 0) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().banNone);
return true;
}
// Display by level
for (Long level : LavaCheck.getStats().keySet()) {
if (level == Long.MIN_VALUE) {
Util.sendMessage(sender, plugin.myLocale().challengeslevel + ": Default");
} else {
Util.sendMessage(sender, plugin.myLocale().challengeslevel + ": " + level);
}
// Collect and sort
Collection<String> result = new TreeSet<String>(Collator.getInstance());
for (Material mat : LavaCheck.getStats().get(level).elementSet()) {
result.add(" " + Util.prettifyText(mat.toString()) + ": " + LavaCheck.getStats().get(level).count(mat) + "/" + LavaCheck.getStats().get(level).size() + " or " + ((long) ((double) LavaCheck.getStats().get(level).count(mat) / LavaCheck.getStats().get(level).size() * 100)) + "% (config = " + String.valueOf(LavaCheck.getConfigChances(level, mat)) + "%)");
}
// Send to player
for (String r : result) {
Util.sendMessage(sender, r);
}
}
return true;
}
if (split[0].equalsIgnoreCase("setdeaths")) {
Util.sendMessage(sender, plugin.myLocale().helpColor + label + " setdeaths <player> <number>:" + ChatColor.WHITE + " " + plugin.myLocale().adminHelpsetDeaths);
return true;
} else if (split[0].equalsIgnoreCase("settingsreset")) {
Util.sendMessage(sender, plugin.myLocale().helpColor + label + " settingsreset help");
return true;
} else if (Settings.teamChat && split[0].equalsIgnoreCase("spy")) {
if (!(sender instanceof Player)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().adminLockerrorInGame);
return true;
}
player = (Player) sender;
if (VaultHelper.checkPerm(player, Settings.PERMPREFIX + "mod.spy") || player.isOp()) {
if (plugin.getChatListener().toggleSpy(player.getUniqueId())) {
Util.sendMessage(sender, ChatColor.GREEN + plugin.myLocale().teamChatSpyStatusOn);
} else {
Util.sendMessage(sender, ChatColor.GREEN + plugin.myLocale().teamChatSpyStatusOff);
}
return true;
}
} else if (split[0].equalsIgnoreCase("lock")) {
// Just /asadmin lock
if (!(sender instanceof Player)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().adminLockerrorInGame);
return true;
}
player = (Player) sender;
Island island = plugin.getGrid().getIslandAt(player.getLocation());
// Check if island exists
if (island == null) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNotOnIsland);
return true;
} else {
Player owner = plugin.getServer().getPlayer(island.getOwner());
if (island.isLocked()) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().lockUnlocking);
island.setLocked(false);
if (owner != null) {
Util.sendMessage(owner, plugin.myLocale(owner.getUniqueId()).adminLockadminUnlockedIsland);
} else {
plugin.getMessages().setMessage(island.getOwner(), plugin.myLocale(island.getOwner()).adminLockadminUnlockedIsland);
}
} else {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().lockLocking);
island.setLocked(true);
if (owner != null) {
Util.sendMessage(owner, plugin.myLocale(owner.getUniqueId()).adminLockadminLockedIsland);
} else {
plugin.getMessages().setMessage(island.getOwner(), plugin.myLocale(island.getOwner()).adminLockadminLockedIsland);
}
}
return true;
}
} else // Find farms
if (split[0].equalsIgnoreCase("topbreeders")) {
// Go through each island and find how many farms there are
Util.sendMessage(sender, plugin.myLocale().adminTopBreedersFinding);
// TreeMap<Integer, List<UUID>> topEntityIslands = new TreeMap<Integer, List<UUID>>();
// Generate the stats
Util.sendMessage(sender, plugin.myLocale().adminTopBreedersChecking.replace("[number]", String.valueOf(plugin.getGrid().getOwnershipMap().size())));
// Try just finding every entity
final List<Entity> allEntities = ASkyBlock.getIslandWorld().getEntities();
final World islandWorld = ASkyBlock.getIslandWorld();
final World netherWorld = ASkyBlock.getNetherWorld();
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
@Override
public void run() {
Map<UUID, Multiset<EntityType>> result = new HashMap<UUID, Multiset<EntityType>>();
// Find out where the entities are
for (Entity entity : allEntities) {
// System.out.println("DEBUG " + entity.getType().toString());
if (entity.getLocation().getWorld().equals(islandWorld) || entity.getLocation().getWorld().equals(netherWorld)) {
// System.out.println("DEBUG in world");
if (entity instanceof Creature && !(entity instanceof Player)) {
// System.out.println("DEBUG creature");
// Find out where it is
Island island = plugin.getGrid().getIslandAt(entity.getLocation());
if (island != null && !island.isSpawn()) {
// System.out.println("DEBUG on island");
// Add to result
UUID owner = island.getOwner();
Multiset<EntityType> count = result.get(owner);
if (count == null) {
// New entry for owner
// System.out.println("DEBUG new entry for owner");
count = HashMultiset.create();
}
count.add(entity.getType());
result.put(owner, count);
}
}
}
}
// Sort by the number of entities on each island
TreeMap<Integer, List<UUID>> topEntityIslands = new TreeMap<Integer, List<UUID>>();
for (Entry<UUID, Multiset<EntityType>> entry : result.entrySet()) {
int numOfEntities = entry.getValue().size();
List<UUID> players = topEntityIslands.get(numOfEntities);
if (players == null) {
players = new ArrayList<UUID>();
}
players.add(entry.getKey());
topEntityIslands.put(numOfEntities, players);
}
final TreeMap<Integer, List<UUID>> topBreeders = topEntityIslands;
final Map<UUID, Multiset<EntityType>> finalResult = result;
// Now display results in sync thread
plugin.getServer().getScheduler().runTask(plugin, new Runnable() {
@Override
public void run() {
if (topBreeders.isEmpty()) {
Util.sendMessage(sender, plugin.myLocale().adminTopBreedersNothing);
return;
}
int rank = 1;
// Display, largest first
for (int numOfEntities : topBreeders.descendingKeySet()) {
// Only bother if there's more that 5 animals
if (numOfEntities > 5) {
// There can be multiple owners in the same position
List<UUID> owners = topBreeders.get(numOfEntities);
// Go through the owners one by one
for (UUID owner : owners) {
Util.sendMessage(sender, "#" + rank + " " + plugin.getPlayers().getName(owner) + " = " + numOfEntities);
String content = "";
Multiset<EntityType> entityCount = finalResult.get(owner);
for (EntityType entity : entityCount.elementSet()) {
int num = entityCount.count(entity);
String color = ChatColor.GREEN.toString();
if (num > 10 && num <= 20) {
color = ChatColor.YELLOW.toString();
} else if (num > 20 && num <= 40) {
color = ChatColor.GOLD.toString();
} else if (num > 40) {
color = ChatColor.RED.toString();
}
content += Util.prettifyText(entity.toString()) + " x " + color + num + ChatColor.WHITE + ", ";
}
int lastComma = content.lastIndexOf(",");
// lastComma);
if (lastComma > 0) {
content = content.substring(0, lastComma);
}
Util.sendMessage(sender, " " + content);
}
rank++;
if (rank > 10) {
break;
}
}
}
// If we didn't show anything say so
if (rank == 1) {
Util.sendMessage(sender, plugin.myLocale().adminTopBreedersNothing);
}
}
});
}
});
return true;
}
// Delete island
if (split[0].equalsIgnoreCase("deleteisland")) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().adminDeleteIslandError);
return true;
}
// Set spawn
if (split[0].equalsIgnoreCase("setspawn")) {
// Find the closest island
if (!(sender instanceof Player)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorUseInGame);
return true;
}
player = (Player) sender;
// Island spawn must be in the island world
if (!player.getLocation().getWorld().getName().equals(Settings.worldName)) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorWrongWorld);
return true;
}
// The island location is calculated based on the grid
Location closestIsland = getClosestIsland(player.getLocation());
Island oldSpawn = plugin.getGrid().getSpawn();
Island newSpawn = plugin.getGrid().getIslandAt(closestIsland);
if (newSpawn != null && newSpawn.isSpawn()) {
// Already spawn, so just set the world spawn coords
plugin.getGrid().setSpawnPoint(player.getLocation());
// ASkyBlock.getIslandWorld().setSpawnLocation(player.getLocation().getBlockX(), player.getLocation().getBlockY(), player.getLocation().getBlockZ());
Util.sendMessage(sender, ChatColor.GREEN + plugin.myLocale().adminSetSpawnset);
return true;
}
// Space otherwise occupied - find if anyone owns it
if (newSpawn != null && newSpawn.getOwner() != null) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().adminSetSpawnownedBy.replace("[name]", plugin.getPlayers().getName(newSpawn.getOwner())));
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().adminSetSpawnmove);
return true;
}
if (oldSpawn != null) {
Util.sendMessage(sender, ChatColor.GOLD + "Changing spawn island location. Warning: old spawn island location at " + oldSpawn.getCenter().getBlockX() + "," + oldSpawn.getCenter().getBlockZ() + " will be at risk of being overwritten with new islands. Recommend to clear that old area.");
plugin.getGrid().deleteSpawn();
}
// New spawn site is free, so make it official
if (newSpawn == null) {
// Make the new spawn
newSpawn = plugin.getGrid().addIsland(closestIsland.getBlockX(), closestIsland.getBlockZ());
// Set the default spawn island settings
newSpawn.setSpawnDefaults();
}
plugin.getGrid().setSpawn(newSpawn);
plugin.getGrid().setSpawnPoint(player.getLocation());
// ASkyBlock.getIslandWorld().setSpawnLocation(player.getLocation().getBlockX(), player.getLocation().getBlockY(), player.getLocation().getBlockZ());
Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale().adminSetSpawnsetting.replace("[location]", player.getLocation().getBlockX() + "," + player.getLocation().getBlockZ()));
Util.sendMessage(player, ChatColor.YELLOW + plugin.myLocale().adminSetSpawncenter.replace("[location]", newSpawn.getCenter().getBlockX() + "," + newSpawn.getCenter().getBlockZ()));
Util.sendMessage(player, ChatColor.YELLOW + (plugin.myLocale().adminSetSpawnlimits.replace("[min]", newSpawn.getMinX() + "," + newSpawn.getMinZ())).replace("[max]", (newSpawn.getMinX() + newSpawn.getIslandDistance() - 1) + "," + (newSpawn.getMinZ() + newSpawn.getIslandDistance() - 1)));
Util.sendMessage(player, ChatColor.YELLOW + plugin.myLocale().adminSetSpawnrange.replace("[number]", String.valueOf(newSpawn.getProtectionSize())));
Util.sendMessage(player, ChatColor.YELLOW + (plugin.myLocale().adminSetSpawncoords.replace("[min]", newSpawn.getMinProtectedX() + ", " + newSpawn.getMinProtectedZ())).replace("[max]", +(newSpawn.getMinProtectedX() + newSpawn.getProtectionSize() - 1) + ", " + (newSpawn.getMinProtectedZ() + newSpawn.getProtectionSize() - 1)));
if (newSpawn.isLocked()) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale().adminSetSpawnlocked);
}
// Save grid async
plugin.getGrid().saveGrid(true);
return true;
} else if (split[0].equalsIgnoreCase("info") || split[0].equalsIgnoreCase("setrange")) {
// Find the closest island
if (!(sender instanceof Player)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorUseInGame);
return true;
}
Location closestIsland = getClosestIsland(((Player) sender).getLocation());
if (closestIsland == null) {
Util.sendMessage(sender, ChatColor.RED + "Sorry, could not find an island. Move closer?");
return true;
}
Island island = plugin.getGrid().getIslandAt(closestIsland);
if (island != null && island.isSpawn()) {
Util.sendMessage(sender, ChatColor.GREEN + plugin.myLocale().adminInfotitle);
Util.sendMessage(sender, ChatColor.YELLOW + plugin.myLocale().adminSetSpawncenter.replace("[location]", island.getCenter().getBlockX() + "," + island.getCenter().getBlockZ()));
Util.sendMessage(sender, ChatColor.YELLOW + (plugin.myLocale().adminSetSpawnlimits.replace("[min]", island.getMinX() + "," + island.getMinZ())).replace("[max]", (island.getMinX() + island.getIslandDistance() - 1) + "," + (island.getMinZ() + island.getIslandDistance() - 1)));
Util.sendMessage(sender, ChatColor.YELLOW + plugin.myLocale().adminSetSpawnrange.replace("[number]", String.valueOf(island.getProtectionSize())));
Util.sendMessage(sender, ChatColor.YELLOW + (plugin.myLocale().adminSetSpawncoords.replace("[min]", island.getMinProtectedX() + ", " + island.getMinProtectedZ())).replace("[max]", +(island.getMinProtectedX() + island.getProtectionSize() - 1) + ", " + (island.getMinProtectedZ() + island.getProtectionSize() - 1)));
if (island.isLocked()) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().adminSetSpawnlocked);
}
return true;
}
if (island == null) {
plugin.getLogger().info("Get island at was null" + closestIsland);
}
UUID target = plugin.getPlayers().getPlayerFromIslandLocation(closestIsland);
if (target == null) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().adminInfounowned);
return true;
}
showInfo(target, sender);
return true;
} else if (split[0].equalsIgnoreCase("resetsign")) {
// Find the closest island
if (!(sender instanceof Player)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorUseInGame);
return true;
}
player = (Player) sender;
if (!VaultHelper.checkPerm(player, Settings.PERMPREFIX + "mod.signadmin") && !player.isOp()) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoPermission);
return true;
}
// Find out whether the player is looking at a warp sign
// Look at what the player was looking at
BlockIterator iter = new BlockIterator(player, 10);
Block lastBlock = iter.next();
while (iter.hasNext()) {
lastBlock = iter.next();
if (lastBlock.getType() == Material.AIR)
continue;
break;
}
if (!lastBlock.getType().equals(Material.SIGN_POST)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale(player.getUniqueId()).adminResetSignNoSign);
return true;
}
// Check if it is a warp sign
Sign sign = (Sign) lastBlock.getState();
Util.sendMessage(sender, ChatColor.GREEN + plugin.myLocale(player.getUniqueId()).adminResetSignFound);
// Find out whose island this is
// plugin.getLogger().info("DEBUG: closest bedrock: " +
// closestBedRock.toString());
UUID target = plugin.getPlayers().getPlayerFromIslandLocation(player.getLocation());
if (target == null) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale(player.getUniqueId()).adminInfounowned);
return true;
}
if (plugin.getWarpSignsListener().addWarp(target, lastBlock.getLocation())) {
// Change sign color to green
sign.setLine(0, ChatColor.GREEN + plugin.myLocale().warpswelcomeLine);
sign.update(true, false);
Util.sendMessage(sender, ChatColor.GREEN + plugin.myLocale(player.getUniqueId()).adminResetSignRescued.replace("[name]", plugin.getPlayers().getName(target)));
return true;
}
// Warp already exists
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale(player.getUniqueId()).adminResetSignErrorExists.replace("[name]", plugin.getWarpSignsListener().getWarpOwner(lastBlock.getLocation())));
return true;
} else if (split[0].equalsIgnoreCase("reload")) {
// Remove temp permissions
plugin.getPlayerEvents().removeAllTempPerms();
plugin.reloadConfig();
PluginConfig.loadPluginConfig(plugin);
plugin.getChallenges().reloadChallengeConfig();
if (Settings.useEconomy && VaultHelper.setupEconomy()) {
ControlPanel.loadShop();
} else {
Settings.useEconomy = false;
}
ControlPanel.loadControlPanel();
if (Settings.updateCheck) {
plugin.checkUpdates();
} else {
plugin.setUpdateCheck(null);
}
plugin.getIslandCmd().loadSchematics();
if (plugin.getAcidTask() != null)
plugin.getAcidTask().runAcidItemRemovalTask();
// Give back any temporary permissions
plugin.getPlayerEvents().giveAllTempPerms();
// Reset resets if the admin changes it to or from unlimited
for (Player players : plugin.getServer().getOnlinePlayers()) {
UUID playerUUID = players.getUniqueId();
if (plugin.getPlayers().hasIsland(playerUUID) || plugin.getPlayers().inTeam(playerUUID)) {
if (Settings.resetLimit < plugin.getPlayers().getResetsLeft(playerUUID) || (Settings.resetLimit >= 0 && plugin.getPlayers().getResetsLeft(playerUUID) < 0)) {
plugin.getPlayers().setResetsLeft(playerUUID, Settings.resetLimit);
}
}
}
Util.sendMessage(sender, ChatColor.YELLOW + plugin.myLocale().reloadconfigReloaded);
return true;
} else if (split[0].equalsIgnoreCase("topten")) {
Util.sendMessage(sender, ChatColor.YELLOW + plugin.myLocale().adminTopTengenerating);
TopTen.topTenCreate(sender);
return true;
} else if (split[0].equalsIgnoreCase("purge")) {
if (purgeFlag) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().purgealreadyRunning);
return true;
}
Util.sendMessage(sender, ChatColor.YELLOW + plugin.myLocale().purgeusage.replace("[label]", label));
return true;
} else if (split[0].equalsIgnoreCase("confirm")) {
if (!confirmReq) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().confirmerrorTimeLimitExpired);
return true;
} else {
// Tell purge routine to go
confirmOK = true;
confirmReq = false;
}
return true;
} else // clearesetall - clears all player resets
if (split[0].equalsIgnoreCase("clearresetall")) {
if (asyncPending) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorCommandNotReady);
return true;
}
// Do online players first
plugin.getPlayers().clearResets(Settings.resetLimit);
// Do offline players
final File playerFolder = plugin.getPlayersFolder();
// Set the pending flag
asyncPending = true;
// Check against player files
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
@Override
public void run() {
// System.out.println("DEBUG: Running async task");
int done = 0;
// Check files against potentialUnowned
FilenameFilter ymlFilter = new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
String lowercaseName = name.toLowerCase();
if (lowercaseName.endsWith(".yml")) {
return true;
} else {
return false;
}
}
};
for (File file : playerFolder.listFiles(ymlFilter)) {
List<String> playerFileContents = new ArrayList<String>();
done++;
try {
Scanner scanner = new Scanner(file);
while (scanner.hasNextLine()) {
final String lineFromFile = scanner.nextLine();
if (lineFromFile.contains("resetsLeft:")) {
playerFileContents.add("resetsLeft: " + Settings.resetLimit);
} else {
playerFileContents.add(lineFromFile);
}
}
scanner.close();
// Write file
try (FileWriter writer = new FileWriter(file)) {
for (String str : playerFileContents) {
writer.write(str + "\n");
}
}
if (done % 500 == 0) {
final int update = done;
plugin.getServer().getScheduler().runTask(plugin, new Runnable() {
@Override
public void run() {
// Tell player
Util.sendMessage(sender, ChatColor.GREEN + plugin.myLocale().clearedResetLimit + " [" + update + " players]...");
}
});
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// System.out.println("DEBUG: scanning done");
asyncPending = false;
Util.sendMessage(sender, ChatColor.YELLOW + plugin.myLocale().clearedResetLimit + " [" + done + " players] completed.");
}
});
return true;
} else {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorUnknownCommand);
return false;
}
case 2:
if (split[0].equalsIgnoreCase("setlanguage")) {
if (asyncPending) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorCommandNotReady);
return true;
}
if (plugin.getAvailableLocales().keySet().contains(split[1])) {
// Change the config.yml setting without removing comments
try {
Util.setConfig("defaultlanguage", Settings.defaultLanguage, split[1]);
} catch (IOException e) {
Util.sendMessage(sender, ChatColor.RED + e.getMessage());
return true;
// e.printStackTrace();
}
plugin.getConfig().set("general.defaultlanguage", split[1]);
Settings.defaultLanguage = split[1];
// Load languages
HashMap<String, ASLocale> availableLocales = new HashMap<String, ASLocale>();
FileLister fl = new FileLister(plugin);
try {
int index = 1;
for (String code : fl.list()) {
// plugin.getLogger().info("DEBUG: lang file = " + code);
availableLocales.put(code, new ASLocale(plugin, code, index++));
}
} catch (IOException e1) {
plugin.getLogger().severe("Could not add locales!");
}
if (!availableLocales.containsKey(Settings.defaultLanguage)) {
plugin.getLogger().severe("'" + Settings.defaultLanguage + ".yml' not found in /locale folder. Using /locale/en-US.yml");
Settings.defaultLanguage = "en-US";
availableLocales.put(Settings.defaultLanguage, new ASLocale(plugin, Settings.defaultLanguage, 0));
}
plugin.setAvailableLocales(availableLocales);
// Run through all the players and set their languages
for (UUID onlinePlayer : plugin.getPlayers().getOnlineCachedPlayers()) {
plugin.getPlayers().setLocale(onlinePlayer, Settings.defaultLanguage);
}
// Prepare for the async check - make final
final File playerFolder = plugin.getPlayersFolder();
// Set the pending flag
asyncPending = true;
// Change player files
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
@Override
public void run() {
try {
Util.setPlayerYamlConfig(playerFolder, "locale", Settings.defaultLanguage);
// Run sync task
plugin.getServer().getScheduler().runTask(plugin, new Runnable() {
@Override
public void run() {
Util.sendMessage(sender, ChatColor.GREEN + plugin.myLocale().generalSuccess);
asyncPending = false;
}
});
} catch (final IOException e) {
// Run sync task
plugin.getServer().getScheduler().runTask(plugin, new Runnable() {
@Override
public void run() {
Util.sendMessage(sender, ChatColor.RED + e.getMessage());
asyncPending = false;
}
});
}
// System.out.println("DEBUG: scanning done");
}
});
Util.sendMessage(sender, ChatColor.RED + plugin.getAvailableLocales().keySet().toString());
}
return true;
} else if (split[0].equalsIgnoreCase("level")) {
// Convert name to a UUID
final UUID playerUUID = plugin.getPlayers().getUUID(split[1], true);
// + playerUUID);
if (playerUUID == null) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorUnknownPlayer);
return true;
} else {
if (sender instanceof Player) {
plugin.getIslandCmd().calculateIslandLevel(sender, playerUUID, false);
} else {
plugin.getIslandCmd().calculateIslandLevel(sender, playerUUID, true);
}
return true;
}
}
if (split[0].equalsIgnoreCase("clearchallengereset")) {
split[1] = split[1].toLowerCase();
if (!Settings.challengeList.contains(split[1])) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().resetChallengeerrorChallengeDoesNotExist);
return true;
}
// Clear challenge reset
plugin.getChallenges().clearChallengeReset(split[1]);
Util.sendMessage(sender, ChatColor.GREEN + plugin.myLocale().generalSuccess);
return true;
} else if (split[0].equalsIgnoreCase("resetchallengeforall")) {
if (!Settings.challengeList.contains(split[1].toLowerCase())) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().resetChallengeerrorChallengeDoesNotExist);
return true;
}
// Reset the challenge now
plugin.getChallenges().resetChallengeForAll(split[1].toLowerCase(), 0L, "");
Util.sendMessage(sender, ChatColor.GREEN + plugin.myLocale().generalSuccess);
return true;
} else if (split[0].equalsIgnoreCase("settingsreset")) {
plugin.reloadConfig();
PluginConfig.loadPluginConfig(plugin);
if (split[1].equalsIgnoreCase("all")) {
Util.sendMessage(sender, ChatColor.GREEN + plugin.myLocale().settingsResetInProgress);
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
@Override
public void run() {
for (Island island : plugin.getGrid().getOwnedIslands().values()) {
island.setIgsDefaults();
}
for (Island island : plugin.getGrid().getUnownedIslands().values()) {
island.setIgsDefaults();
}
plugin.getGrid().saveGrid();
// Go back to non-async world
plugin.getServer().getScheduler().runTask(plugin, new Runnable() {
@Override
public void run() {
// Reset any warp signs
plugin.getWarpPanel().updateAllWarpText();
Util.sendMessage(sender, ChatColor.GREEN + plugin.myLocale().settingsResetDone);
}
});
}
});
return true;
} else {
// Check if there is a flag here
for (SettingsFlag flag : SettingsFlag.values()) {
if (split[1].equalsIgnoreCase(flag.toString())) {
Util.sendMessage(sender, ChatColor.GREEN + plugin.myLocale().settingsResetInProgress);
final SettingsFlag flagToSet = flag;
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
@Override
public void run() {
for (Island island : plugin.getGrid().getOwnedIslands().values()) {
island.setIgsFlag(flagToSet, Settings.defaultIslandSettings.get(flagToSet));
}
for (Island island : plugin.getGrid().getUnownedIslands().values()) {
island.setIgsFlag(flagToSet, Settings.defaultIslandSettings.get(flagToSet));
}
plugin.getGrid().saveGrid();
// Go back to non-async world
plugin.getServer().getScheduler().runTask(plugin, new Runnable() {
@Override
public void run() {
if (flagToSet.equals(SettingsFlag.PVP) || flagToSet.equals(SettingsFlag.NETHER_PVP)) {
// Reset any warp signs
plugin.getWarpPanel().updateAllWarpText();
}
Util.sendMessage(sender, ChatColor.GREEN + plugin.myLocale().settingsResetDone);
}
});
}
});
return true;
}
}
// Show help
Util.sendMessage(sender, plugin.myLocale().helpColor + "/" + label + " settingsreset [help | all | flag]:" + ChatColor.WHITE + " " + plugin.myLocale().adminHelpSettingsReset);
Util.sendMessage(sender, ChatColor.GREEN + "flag options: ");
String commaList = "all";
for (SettingsFlag flag : SettingsFlag.values()) {
commaList += ", " + flag.toString();
}
Util.sendMessage(sender, commaList);
return true;
}
}
// Resetsign <player> - makes a warp sign for player
if (split[0].equalsIgnoreCase("resetsign")) {
// Find the closest island
if (!(sender instanceof Player)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorUseInGame);
return true;
}
Player p = (Player) sender;
if (!VaultHelper.checkPerm(p, Settings.PERMPREFIX + "mod.signadmin") && !p.isOp()) {
Util.sendMessage(p, ChatColor.RED + plugin.myLocale(p.getUniqueId()).errorNoPermission);
return true;
}
// Convert target name to a UUID
final UUID playerUUID = plugin.getPlayers().getUUID(split[1], true);
if (!plugin.getPlayers().isAKnownPlayer(playerUUID)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorUnknownPlayer);
} else {
// Check if this player has an island
if (!plugin.getPlayers().hasIsland(playerUUID) && !plugin.getPlayers().inTeam(playerUUID)) {
// No island
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorNoIslandOther);
return true;
}
// Has an island
// Find out whether the player is looking at a warp sign
// Look at what the player was looking at
BlockIterator iter = new BlockIterator(p, 10);
Block lastBlock = iter.next();
while (iter.hasNext()) {
lastBlock = iter.next();
if (lastBlock.getType() == Material.AIR)
continue;
break;
}
// Check if it is a sign
if (!lastBlock.getType().equals(Material.SIGN_POST)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale(p.getUniqueId()).adminResetSignNoSign);
return true;
}
Sign sign = (Sign) lastBlock.getState();
// Check if the sign is within the right island boundary
Location islandLoc = plugin.getPlayers().getIslandLocation(playerUUID);
Island island = plugin.getGrid().getIslandAt(islandLoc);
if (island == null) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale(p.getUniqueId()).errorNoIsland);
return true;
}
if (!island.inIslandSpace(sign.getLocation())) {
Util.sendMessage(p, ChatColor.RED + plugin.myLocale(p.getUniqueId()).adminSetHomeNotOnPlayersIsland);
} else {
Util.sendMessage(sender, ChatColor.GREEN + plugin.myLocale(p.getUniqueId()).adminResetSignFound);
// Find out if this player is allowed to have a sign on this island
if (plugin.getWarpSignsListener().addWarp(playerUUID, lastBlock.getLocation())) {
// Change sign color to green
sign.setLine(0, ChatColor.GREEN + plugin.myLocale().warpswelcomeLine);
sign.update();
Util.sendMessage(p, ChatColor.GREEN + plugin.myLocale(p.getUniqueId()).adminResetSignRescued.replace("[name]", plugin.getPlayers().getName(playerUUID)));
return true;
}
// Warp already exists
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale(p.getUniqueId()).adminResetSignErrorExists.replace("[name]", plugin.getWarpSignsListener().getWarpOwner(lastBlock.getLocation())));
}
}
return true;
} else // Delete the island you are on
if (split[0].equalsIgnoreCase("deleteisland")) {
if (!split[1].equalsIgnoreCase("confirm")) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().adminDeleteIslandError);
return true;
}
// Get the island I am on
Island island = plugin.getGrid().getIslandAt(((Player) sender).getLocation());
if (island == null) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().adminDeleteIslandnoid);
return true;
}
// Try to get the owner of this island
UUID owner = island.getOwner();
String name = "unknown";
if (owner != null) {
name = plugin.getPlayers().getName(owner);
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().adminSetSpawnownedBy.replace("[name]", name));
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().adminDeleteIslanduse.replace("[name]", name));
return true;
} else {
Util.sendMessage(sender, ChatColor.YELLOW + plugin.myLocale().deleteremoving.replace("[name]", name));
deleteIslands(island, sender);
return true;
}
} else if (split[0].equalsIgnoreCase("resetname")) {
// Convert name to a UUID
final UUID playerUUID = plugin.getPlayers().getUUID(split[1], true);
if (!plugin.getPlayers().isAKnownPlayer(playerUUID)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorUnknownPlayer);
} else {
// Check if this player has an island
if (!plugin.getPlayers().hasIsland(playerUUID) && !plugin.getPlayers().inTeam(playerUUID)) {
// No island
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorNoIslandOther);
return true;
}
// Has an island
plugin.getGrid().setIslandName(playerUUID, null);
Util.sendMessage(sender, plugin.myLocale().generalSuccess);
}
return true;
} else if (split[0].equalsIgnoreCase("resethome")) {
// Convert name to a UUID
final UUID playerUUID = plugin.getPlayers().getUUID(split[1], true);
if (!plugin.getPlayers().isAKnownPlayer(playerUUID)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorUnknownPlayer);
} else {
// Check if this player has an island
if (!plugin.getPlayers().hasIsland(playerUUID) && !plugin.getPlayers().inTeam(playerUUID)) {
// No island
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorNoIslandOther);
return true;
}
// Has an island
Location safeHome = plugin.getGrid().getSafeHomeLocation(playerUUID, 1);
if (safeHome == null) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().adminSetHomeNoneFound);
} else {
plugin.getPlayers().setHomeLocation(playerUUID, safeHome);
Util.sendMessage(sender, ChatColor.GREEN + plugin.myLocale().adminSetHomeHomeSet.replace("[location]", safeHome.getBlockX() + ", " + safeHome.getBlockY() + "," + safeHome.getBlockZ()));
}
}
return true;
} else if (split[0].equalsIgnoreCase("sethome")) {
if (!(sender instanceof Player)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().adminLockerrorInGame);
return true;
}
player = (Player) sender;
// Convert name to a UUID
final UUID playerUUID = plugin.getPlayers().getUUID(split[1], true);
if (!plugin.getPlayers().isAKnownPlayer(playerUUID)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorUnknownPlayer);
} else {
// Check if this player has an island
if (!plugin.getPlayers().hasIsland(playerUUID) && !plugin.getPlayers().inTeam(playerUUID)) {
// No island
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorNoIslandOther);
return true;
}
// Has an island
Location islandLoc = plugin.getPlayers().getIslandLocation(playerUUID);
Island island = plugin.getGrid().getIslandAt(islandLoc);
// Check the player is within the island boundaries
if (island == null || !island.inIslandSpace(player.getLocation())) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).adminSetHomeNotOnPlayersIsland);
} else {
// Check that the location is safe
if (!GridManager.isSafeLocation(player.getLocation())) {
// Not safe
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).adminSetHomeNoneFound);
} else {
// Success
plugin.getPlayers().setHomeLocation(playerUUID, player.getLocation());
Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(player.getUniqueId()).adminSetHomeHomeSet.replace("[location]", player.getLocation().getBlockX() + ", " + player.getLocation().getBlockY() + "," + player.getLocation().getBlockZ()));
}
}
}
return true;
} else // Set protection for the island the player is on
if (split[0].equalsIgnoreCase("setrange")) {
if (!(sender instanceof Player)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().adminLockerrorInGame);
return true;
}
player = (Player) sender;
UUID playerUUID = player.getUniqueId();
Island island = plugin.getGrid().getIslandAt(player.getLocation());
// Check if island exists
if (island == null) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale().errorNotOnIsland);
return true;
} else {
int newRange = 10;
int maxRange = Settings.islandDistance;
// If spawn do something different
if (island.isSpawn()) {
try {
newRange = Integer.valueOf(split[1]);
} catch (Exception e) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).adminSetRangeInvalid);
return true;
}
Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(playerUUID).adminSetRangeSet.replace("[number]", String.valueOf(newRange)));
if (newRange > maxRange) {
Util.sendMessage(player, ChatColor.RED + "" + ChatColor.BOLD + plugin.myLocale(playerUUID).adminSetRangeWarning.replace("[max]", String.valueOf(maxRange)));
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).adminSetRangeWarning2);
}
island.setProtectionSize(newRange);
Util.sendMessage(player, ChatColor.YELLOW + plugin.myLocale().adminSetSpawncenter.replace("[location]", island.getCenter().getBlockX() + "," + island.getCenter().getBlockZ()));
Util.sendMessage(player, ChatColor.YELLOW + plugin.myLocale().adminSetSpawnlimits.replace("[min]", island.getMinX() + "," + island.getMinZ()).replace("[max]", (island.getMinX() + island.getIslandDistance() - 1) + "," + (island.getMinZ() + island.getIslandDistance() - 1)));
Util.sendMessage(player, ChatColor.YELLOW + plugin.myLocale().adminSetSpawnrange.replace("[number]", String.valueOf(island.getProtectionSize())));
Util.sendMessage(player, ChatColor.YELLOW + plugin.myLocale().adminSetSpawncoords.replace("[min]", island.getMinProtectedX() + ", " + island.getMinProtectedZ()).replace("[max]", +(island.getMinProtectedX() + island.getProtectionSize() - 1) + ", " + (island.getMinProtectedZ() + island.getProtectionSize() - 1)));
if (island.isLocked()) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale().adminSetSpawnlocked);
}
} else {
try {
newRange = Integer.valueOf(split[1]);
} catch (Exception e) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).adminSetRangeInvalid + " " + plugin.myLocale(playerUUID).adminSetRangeTip.replace("[max]", String.valueOf(maxRange)));
return true;
}
if (newRange < 10 || newRange > maxRange) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).adminSetRangeInvalid + " " + plugin.myLocale(playerUUID).adminSetRangeTip.replace("[max]", String.valueOf(maxRange)));
return true;
}
island.setProtectionSize(newRange);
Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(playerUUID).adminSetRangeSet.replace("[number]", String.valueOf(newRange)));
showInfo(island.getOwner(), sender);
}
return true;
}
} else // Add/remove protection for the island the player is on
if (split[0].equalsIgnoreCase("addrange")) {
if (!(sender instanceof Player)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().adminLockerrorInGame);
return true;
}
player = (Player) sender;
UUID playerUUID = player.getUniqueId();
Island island = plugin.getGrid().getIslandAt(player.getLocation());
// Check if island exists
if (island == null) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale().errorNotOnIsland);
return true;
} else {
int newRange = island.getProtectionSize();
int maxRange = Settings.islandDistance;
// If spawn do something different
if (island.isSpawn()) {
try {
newRange = Integer.valueOf(split[1]) + island.getProtectionSize();
} catch (Exception e) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).adminSetRangeInvalid);
return true;
}
Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(playerUUID).adminSetRangeSet.replace("[number]", String.valueOf(newRange)));
if (newRange > maxRange) {
Util.sendMessage(player, ChatColor.RED + "" + ChatColor.BOLD + plugin.myLocale(playerUUID).adminSetRangeWarning.replace("[max]", String.valueOf(maxRange)));
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).adminSetRangeWarning2);
}
island.setProtectionSize(newRange);
Util.sendMessage(player, ChatColor.YELLOW + plugin.myLocale().adminSetSpawncenter.replace("[location]", island.getCenter().getBlockX() + "," + island.getCenter().getBlockZ()));
Util.sendMessage(player, ChatColor.YELLOW + plugin.myLocale().adminSetSpawnlimits.replace("[min]", island.getMinX() + "," + island.getMinZ()).replace("[max]", (island.getMinX() + island.getIslandDistance() - 1) + "," + (island.getMinZ() + island.getIslandDistance() - 1)));
Util.sendMessage(player, ChatColor.YELLOW + plugin.myLocale().adminSetSpawnrange.replace("[number]", String.valueOf(island.getProtectionSize())));
Util.sendMessage(player, ChatColor.YELLOW + plugin.myLocale().adminSetSpawncoords.replace("[min]", island.getMinProtectedX() + ", " + island.getMinProtectedZ()).replace("[max]", +(island.getMinProtectedX() + island.getProtectionSize() - 1) + ", " + (island.getMinProtectedZ() + island.getProtectionSize() - 1)));
if (island.isLocked()) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale().adminSetSpawnlocked);
}
} else {
try {
newRange = Integer.valueOf(split[1]) + island.getProtectionSize();
} catch (Exception e) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).adminSetRangeInvalid + " " + plugin.myLocale(playerUUID).adminSetRangeTip.replace("[max]", String.valueOf(maxRange)));
return true;
}
if (newRange < 10 || newRange > maxRange) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(playerUUID).adminSetRangeInvalid + " " + plugin.myLocale(playerUUID).adminSetRangeTip.replace("[max]", String.valueOf(maxRange)));
return true;
}
island.setProtectionSize(newRange);
Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(playerUUID).adminSetRangeSet.replace("[number]", String.valueOf(newRange)));
showInfo(island.getOwner(), sender);
}
return true;
}
}
if (split[0].equalsIgnoreCase("purge")) {
// Protect island from purging
if (split[1].equalsIgnoreCase("allow") || split[1].equalsIgnoreCase("disallow")) {
// Find the closest island
if (!(sender instanceof Player)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().adminLockerrorInGame);
return true;
}
Player p = (Player) sender;
// Island spawn must be in the island world
if (!p.getLocation().getWorld().equals(ASkyBlock.getIslandWorld()) && !p.getLocation().getWorld().equals(ASkyBlock.getNetherWorld())) {
Util.sendMessage(p, ChatColor.RED + plugin.myLocale(p.getUniqueId()).errorWrongWorld);
return true;
}
Island island = plugin.getGrid().getIslandAt(p.getLocation());
if (island == null) {
Util.sendMessage(p, ChatColor.RED + plugin.myLocale(p.getUniqueId()).errorNoIslandOther);
return true;
}
if (split[1].equalsIgnoreCase("disallow")) {
island.setPurgeProtected(true);
} else {
island.setPurgeProtected(false);
}
if (island.isPurgeProtected()) {
Util.sendMessage(p, ChatColor.GREEN + plugin.myLocale(p.getUniqueId()).adminPreventPurge);
} else {
Util.sendMessage(p, ChatColor.GREEN + plugin.myLocale(p.getUniqueId()).adminAllowPurge);
}
return true;
}
// this flag stops a repeat
if (purgeFlag) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().purgealreadyRunning);
return true;
}
if (split[1].equalsIgnoreCase("unowned")) {
countUnowned(sender);
return true;
}
// Set the flag
purgeFlag = true;
// See if this purge unowned
// Convert days to hours - no other limit checking?
final int time;
try {
time = Integer.parseInt(split[1]) * 24;
} catch (Exception e) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().purgeusage.replace("[label]", label));
purgeFlag = false;
return true;
}
Util.sendMessage(sender, ChatColor.YELLOW + plugin.myLocale().purgecalculating.replace("[time]", split[1]));
// Check who has not been online since the time
for (Entry<UUID, Island> entry : plugin.getGrid().getOwnershipMap().entrySet()) {
// Only do this if it isn't protected
if (entry.getKey() != null && !entry.getValue().isPurgeProtected()) {
if (Bukkit.getOfflinePlayer(entry.getKey()).hasPlayedBefore()) {
long offlineTime = Bukkit.getOfflinePlayer(entry.getKey()).getLastPlayed();
offlineTime = (System.currentTimeMillis() - offlineTime) / 3600000L;
if (offlineTime > time && plugin.getPlayers().getIslandLevel(entry.getKey()) < Settings.abandonedIslandLevel) {
removeList.add(entry.getKey());
}
} else {
removeList.add(entry.getKey());
}
}
}
if (removeList.isEmpty()) {
Util.sendMessage(sender, ChatColor.YELLOW + plugin.myLocale().purgenoneFound);
purgeFlag = false;
return true;
}
Util.sendMessage(sender, ChatColor.YELLOW + plugin.myLocale().purgethisWillRemove.replace("[number]", String.valueOf(removeList.size())).replace("[level]", String.valueOf(Settings.abandonedIslandLevel)));
long runtime = removeList.size() * 2L;
Util.sendMessage(sender, ChatColor.YELLOW + plugin.myLocale().purgeEstimatedRunTime.replace("[time]", String.format("%d h %02d m %02d s", runtime / 3600, (runtime % 3600) / 60, (runtime % 60))));
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().purgewarning);
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().purgetypeConfirm.replace("[label]", label));
if (removeList.size() > Settings.maxPurge) {
Util.sendMessage(sender, plugin.myLocale().purgeLimit.replace("[number]", String.valueOf(Settings.maxPurge)));
Iterator<UUID> it = removeList.iterator();
int count = 1;
while (it.hasNext()) {
it.next();
if (count++ > Settings.maxPurge) {
it.remove();
}
}
}
confirmReq = true;
confirmOK = false;
confirmTimer = 0;
new BukkitRunnable() {
@Override
public void run() {
// cancels
if (confirmTimer++ > 10) {
// Ten seconds is up!
confirmReq = false;
confirmOK = false;
purgeFlag = false;
removeList.clear();
Util.sendMessage(sender, ChatColor.YELLOW + plugin.myLocale().purgepurgeCancelled);
this.cancel();
} else if (confirmOK) {
// Set up a repeating task to run every 2
// seconds to remove
// islands one by one and then cancel when
// done
final int total = removeList.size();
new BukkitRunnable() {
@Override
public void run() {
if (removeList.isEmpty() && purgeFlag) {
purgeFlag = false;
Util.sendMessage(sender, ChatColor.YELLOW + plugin.myLocale().purgefinished);
this.cancel();
}
if (removeList.size() > 0 && purgeFlag) {
// Check if the player is online
if (plugin.getServer().getPlayer(removeList.get(0)) == null) {
// Check the level
if (plugin.getPlayers().getIslandLevel(removeList.get(0)) < Settings.abandonedIslandLevel) {
Util.sendMessage(sender, ChatColor.YELLOW + "[" + (total - removeList.size() + 1) + "/" + total + "] " + plugin.myLocale().purgeremovingName.replace("[name]", plugin.getPlayers().getName(removeList.get(0))));
plugin.deletePlayerIsland(removeList.get(0), true);
}
} else {
Util.sendMessage(sender, ChatColor.YELLOW + "[" + (total - removeList.size() + 1) + "/" + total + "] " + "Skipping online player...");
}
removeList.remove(0);
}
// Util.sendMessage(sender, "Now waiting...");
}
}.runTaskTimer(plugin, 0L, 20L);
confirmReq = false;
confirmOK = false;
this.cancel();
}
}
}.runTaskTimer(plugin, 0L, 40L);
return true;
} else if (split[0].equalsIgnoreCase("lock")) {
// Convert name to a UUID
final UUID playerUUID = plugin.getPlayers().getUUID(split[1], true);
if (!plugin.getPlayers().isAKnownPlayer(playerUUID)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorUnknownPlayer);
return true;
} else {
Island island = plugin.getGrid().getIsland(playerUUID);
if (island != null) {
Player owner = plugin.getServer().getPlayer(island.getOwner());
if (island.isLocked()) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().lockUnlocking);
island.setLocked(false);
if (owner != null) {
owner.sendMessage(plugin.myLocale(owner.getUniqueId()).adminLockadminUnlockedIsland);
} else {
plugin.getMessages().setMessage(island.getOwner(), plugin.myLocale(island.getOwner()).adminLockadminUnlockedIsland);
}
} else {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().lockLocking);
island.setLocked(true);
if (owner != null) {
Util.sendMessage(owner, plugin.myLocale(owner.getUniqueId()).adminLockadminLockedIsland);
} else {
plugin.getMessages().setMessage(island.getOwner(), plugin.myLocale(island.getOwner()).adminLockadminLockedIsland);
}
}
} else {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorNoIslandOther);
}
return true;
}
} else if (split[0].equalsIgnoreCase("setdeaths")) {
// Convert name to a UUID
final UUID playerUUID = plugin.getPlayers().getUUID(split[1], true);
if (!plugin.getPlayers().isAKnownPlayer(playerUUID)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorUnknownPlayer);
return true;
} else {
Util.sendMessage(sender, ChatColor.GREEN + plugin.getPlayers().getName(playerUUID) + " " + plugin.getPlayers().getDeaths(playerUUID) + " " + plugin.myLocale().deaths);
Util.sendMessage(sender, plugin.myLocale().helpColor + label + " setdeaths <player> <number>:" + ChatColor.WHITE + " " + plugin.myLocale().adminHelpsetDeaths);
return true;
}
} else if (split[0].equalsIgnoreCase("clearreset")) {
// Convert name to a UUID
final UUID playerUUID = plugin.getPlayers().getUUID(split[1], true);
if (!plugin.getPlayers().isAKnownPlayer(playerUUID)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorUnknownPlayer);
return true;
} else {
plugin.getPlayers().setResetsLeft(playerUUID, Settings.resetLimit);
Util.sendMessage(sender, ChatColor.YELLOW + plugin.myLocale().clearedResetLimit + " [" + Settings.resetLimit + "]");
return true;
}
} else if (split[0].equalsIgnoreCase("tp")) {
if (!(sender instanceof Player)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorUnknownCommand);
return true;
}
player = (Player) sender;
// Convert name to a UUID
final UUID targetUUID = plugin.getPlayers().getUUID(split[1], true);
if (!plugin.getPlayers().isAKnownPlayer(targetUUID)) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorUnknownPlayer);
return true;
} else {
if (plugin.getPlayers().hasIsland(targetUUID) || plugin.getPlayers().inTeam(targetUUID)) {
// Teleport to the over world
Location warpSpot = plugin.getPlayers().getIslandLocation(targetUUID).toVector().toLocation(ASkyBlock.getIslandWorld());
String failureMessage = ChatColor.RED + plugin.myLocale(player.getUniqueId()).adminTpManualWarp.replace("[location]", warpSpot.getBlockX() + " " + warpSpot.getBlockY() + " " + warpSpot.getBlockZ());
// Try the player's home first
Location home = plugin.getPlayers().getHomeLocation(targetUUID);
plugin.getGrid();
if (home != null && home.getWorld().equals(ASkyBlock.getIslandWorld()) && GridManager.isSafeLocation(home)) {
player.teleport(home);
return true;
}
// Other wise, go to a safe spot
new SafeTeleportBuilder(plugin).entity(player).location(warpSpot).failureMessage(failureMessage).build();
return true;
}
Util.sendMessage(sender, plugin.myLocale().errorNoIslandOther);
return true;
}
} else if (split[0].equalsIgnoreCase("tpnether")) {
if (!Settings.createNether || !Settings.newNether || ASkyBlock.getNetherWorld() == null) {
return false;
}
if (!(sender instanceof Player)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorUnknownCommand);
return true;
}
player = (Player) sender;
// Convert name to a UUID
final UUID targetUUID = plugin.getPlayers().getUUID(split[1], true);
if (!plugin.getPlayers().isAKnownPlayer(targetUUID)) {
Util.sendMessage(player, ChatColor.RED + plugin.myLocale(player.getUniqueId()).errorUnknownPlayer);
return true;
} else {
if (plugin.getPlayers().hasIsland(targetUUID) || plugin.getPlayers().inTeam(targetUUID)) {
// Teleport to the nether
Location warpSpot = plugin.getPlayers().getIslandLocation(targetUUID).toVector().toLocation(ASkyBlock.getNetherWorld());
String failureMessage = ChatColor.RED + plugin.myLocale(player.getUniqueId()).adminTpManualWarp.replace("[location]", warpSpot.getBlockX() + " " + warpSpot.getBlockY() + " " + warpSpot.getBlockZ());
// Try the player's home first
Location home = plugin.getPlayers().getHomeLocation(targetUUID);
plugin.getGrid();
if (home != null && home.getWorld().equals(ASkyBlock.getNetherWorld()) && GridManager.isSafeLocation(home)) {
player.teleport(home);
return true;
}
new SafeTeleportBuilder(plugin).entity(player).location(warpSpot).failureMessage(failureMessage).build();
return true;
}
Util.sendMessage(sender, plugin.myLocale().errorNoIslandOther);
return true;
}
} else if (split[0].equalsIgnoreCase("delete")) {
// Convert name to a UUID
final UUID playerUUID = plugin.getPlayers().getUUID(split[1], true);
if (!plugin.getPlayers().isAKnownPlayer(playerUUID)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorUnknownPlayer);
return true;
} else {
// This now deletes the player and cleans them up even if
// they don't have an island
Util.sendMessage(sender, ChatColor.YELLOW + plugin.myLocale().deleteremoving.replace("[name]", split[1]));
// If they are online and in ASkyBlock then delete their
// stuff too
Player target = plugin.getServer().getPlayer(playerUUID);
if (target != null) {
// Clear any coop inventories
// CoopPlay.getInstance().returnAllInventories(target);
// Remove any of the target's coop invitees and grab
// their stuff
CoopPlay.getInstance().clearMyInvitedCoops(target);
CoopPlay.getInstance().clearMyCoops(target);
plugin.resetPlayer(target);
}
// plugin.getLogger().info("DEBUG: deleting player");
plugin.deletePlayerIsland(playerUUID, true);
return true;
}
} else if (split[0].equalsIgnoreCase("reserve")) {
// Reserves a spot for the player's next island
if (sender instanceof Player) {
player = (Player) sender;
// Convert name to a UUID
final UUID playerUUID = plugin.getPlayers().getUUID(split[1], true);
if (!plugin.getPlayers().isAKnownPlayer(playerUUID)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorUnknownPlayer);
return true;
} else {
// Check the spot
Location islandLoc = plugin.getGrid().getClosestIsland(player.getLocation());
Island island = plugin.getGrid().getIslandAt(islandLoc);
if (island == null) {
// Empty spot, reserve it!
plugin.getIslandCmd().reserveLocation(playerUUID, islandLoc);
Util.sendMessage(sender, ChatColor.GREEN + " [" + islandLoc.getBlockX() + ", " + islandLoc.getBlockZ() + "] " + plugin.myLocale().generalSuccess);
} else {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().adminReserveIslandExists);
}
return true;
}
} else {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorUnknownCommand);
}
return true;
} else if (split[0].equalsIgnoreCase("register")) {
if (sender instanceof Player) {
// Convert name to a UUID
final UUID playerUUID = plugin.getPlayers().getUUID(split[1], true);
// plugin.getLogger().info("DEBUG: UUID is " + playerUUID);
if (!plugin.getPlayers().isAKnownPlayer(playerUUID)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorUnknownPlayer);
return true;
} else {
if (adminSetPlayerIsland(sender, ((Player) sender).getLocation(), playerUUID)) {
Util.sendMessage(sender, ChatColor.GREEN + plugin.myLocale().registersettingIsland.replace("[name]", split[1]));
plugin.getGrid().saveGrid();
} else {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().registererrorBedrockNotFound);
}
return true;
}
} else {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorUnknownCommand);
}
return true;
} else if (split[0].equalsIgnoreCase("unregister")) {
// Convert name to a UUID
final UUID playerUUID = plugin.getPlayers().getUUID(split[1], true);
if (!plugin.getPlayers().isAKnownPlayer(playerUUID)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorUnknownPlayer);
return true;
} else {
if (plugin.getPlayers().inTeam(playerUUID)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().adminUnregisterOnTeam);
return true;
}
Location island = plugin.getPlayers().getIslandLocation(playerUUID);
if (island == null) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorNoIslandOther);
return true;
}
// Delete player, but keep blocks
Util.sendMessage(sender, ChatColor.GREEN + plugin.myLocale().adminUnregisterKeepBlocks.replace("[location]", +plugin.getPlayers().getIslandLocation(playerUUID).getBlockX() + "," + plugin.getPlayers().getIslandLocation(playerUUID).getBlockZ()));
plugin.deletePlayerIsland(playerUUID, false);
plugin.getGrid().saveGrid();
return true;
}
} else if (split[0].equalsIgnoreCase("info")) {
// Convert name to a UUID
final UUID playerUUID = plugin.getPlayers().getUUID(split[1], true);
// + playerUUID);
if (!plugin.getPlayers().isAKnownPlayer(playerUUID)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorUnknownPlayer);
return true;
} else {
showInfo(playerUUID, sender);
return true;
}
} else if (split[0].equalsIgnoreCase("resetallchallenges")) {
// Convert name to a UUID
final UUID playerUUID = plugin.getPlayers().getUUID(split[1], true);
if (!plugin.getPlayers().isAKnownPlayer(playerUUID)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorUnknownPlayer);
return true;
}
plugin.getPlayers().resetAllChallenges(playerUUID, true);
Util.sendMessage(sender, ChatColor.YELLOW + plugin.myLocale().resetChallengessuccess.replace("[name]", split[1]));
return true;
} else {
return false;
}
case 3:
if (split[0].equalsIgnoreCase("resetchallengeforall")) {
if (!Settings.challengeList.contains(split[1].toLowerCase())) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().resetChallengeerrorChallengeDoesNotExist);
return true;
}
// Convert repeat to time in millis
split[2] = split[2].trim();
// plugin.getLogger().info("DEBUG: " + split[2]);
if (split[2].length() > 1 && (split[2].toLowerCase().endsWith("m") || split[2].toLowerCase().endsWith("h") || split[2].toLowerCase().endsWith("d"))) {
char unit = split[2].charAt(split[2].length() - 1);
String value = split[2].substring(0, split[2].length() - 1);
try {
long repeat = 0;
int number = Integer.valueOf(value);
switch(unit) {
case 'm':
// Minutes
repeat = 60000L * number;
break;
case 'h':
repeat = 60000L * 60 * number;
break;
case 'd':
repeat = 60000L * 60 * 24 * number;
break;
}
// Reset all the players online
plugin.getChallenges().resetChallengeForAll(split[1].toLowerCase(), repeat, split[2]);
Util.sendMessage(sender, ChatColor.GREEN + plugin.myLocale().generalSuccess);
} catch (Exception e) {
e.printStackTrace();
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().adminResetChallengeForAllError);
return true;
}
} else {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().adminResetChallengeForAllError);
return true;
}
return true;
} else // Confirm purge unowned
if (split[0].equalsIgnoreCase("purge")) {
if (purgeFlag) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().purgealreadyRunning);
return true;
}
// Check if this is purge unowned
if (split[1].equalsIgnoreCase("unowned") && split[2].equalsIgnoreCase("confirm")) {
if (!purgeUnownedConfirm) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().confirmerrorTimeLimitExpired);
return true;
} else {
purgeUnownedConfirm = false;
// Purge the unowned islands
purgeUnownedIslands(sender);
return true;
}
}
}
// Add or remove protection range
if (split[0].equalsIgnoreCase("addrange")) {
// Convert name to a UUID
UUID playerUUID = plugin.getPlayers().getUUID(split[1], true);
// Check if player exists
if (!plugin.getPlayers().isAKnownPlayer(playerUUID)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorUnknownPlayer);
return true;
}
// Check if the target is in a team and if so, the leader needs to be adjusted
if (plugin.getPlayers().inTeam(playerUUID)) {
playerUUID = plugin.getPlayers().getTeamLeader(playerUUID);
}
// Get the range that this player has now
Island island = plugin.getGrid().getIsland(playerUUID);
if (island == null) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorNoIslandOther);
return true;
} else {
int newRange = 0;
int maxRange = Settings.islandDistance;
try {
newRange = Integer.valueOf(split[2]) + island.getProtectionSize();
} catch (Exception e) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().adminSetRangeInvalid + " " + plugin.myLocale().adminSetRangeTip.replace("[max]", String.valueOf(maxRange)));
return true;
}
if (newRange < 10 || newRange > maxRange) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().adminSetRangeInvalid + " " + plugin.myLocale().adminSetRangeTip.replace("[max]", String.valueOf(maxRange)));
return true;
}
island.setProtectionSize(newRange);
Util.sendMessage(sender, ChatColor.GREEN + plugin.myLocale().adminSetRangeSet.replace("[number]", String.valueOf(newRange)));
showInfo(playerUUID, sender);
plugin.getGrid().saveGrid();
return true;
}
} else if (split[0].equalsIgnoreCase("setrange")) {
// Convert name to a UUID
UUID playerUUID = plugin.getPlayers().getUUID(split[1], true);
// Check if player exists
if (!plugin.getPlayers().isAKnownPlayer(playerUUID)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorUnknownPlayer);
return true;
}
// Check if the target is in a team and if so, the leader needs to be adjusted
if (plugin.getPlayers().inTeam(playerUUID)) {
playerUUID = plugin.getPlayers().getTeamLeader(playerUUID);
}
// Get the range that this player has now
Island island = plugin.getGrid().getIsland(playerUUID);
if (island == null) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorNoIslandOther);
return true;
} else {
int newRange = 0;
int maxRange = Settings.islandDistance;
try {
newRange = Integer.valueOf(split[2]);
} catch (Exception e) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().adminSetRangeInvalid + " " + plugin.myLocale().adminSetRangeTip.replace("[max]", String.valueOf(maxRange)));
return true;
}
if (newRange < 10 || newRange > maxRange) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().adminSetRangeInvalid + " " + plugin.myLocale().adminSetRangeTip.replace("[max]", String.valueOf(maxRange)));
return true;
}
island.setProtectionSize(newRange);
Util.sendMessage(sender, ChatColor.GREEN + plugin.myLocale().adminSetRangeSet.replace("[number]", String.valueOf(newRange)));
showInfo(playerUUID, sender);
plugin.getGrid().saveGrid();
return true;
}
} else if (split[0].equalsIgnoreCase("setdeaths")) {
// Convert name to a UUID
final UUID playerUUID = plugin.getPlayers().getUUID(split[1], true);
if (!plugin.getPlayers().isAKnownPlayer(playerUUID)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorUnknownPlayer);
return true;
} else {
try {
int newDeaths = Integer.valueOf(split[2]);
int oldDeaths = plugin.getPlayers().getDeaths(playerUUID);
plugin.getPlayers().setDeaths(playerUUID, newDeaths);
Util.sendMessage(sender, ChatColor.GREEN + plugin.getPlayers().getName(playerUUID) + " " + oldDeaths + " >>> " + newDeaths + " " + plugin.myLocale().deaths);
} catch (Exception e) {
Util.sendMessage(sender, ChatColor.GREEN + plugin.getPlayers().getName(playerUUID) + " " + plugin.getPlayers().getDeaths(playerUUID) + " " + plugin.myLocale().deaths);
Util.sendMessage(sender, plugin.myLocale().helpColor + label + " setdeaths <player> <number>:" + ChatColor.WHITE + " " + plugin.myLocale().adminHelpsetDeaths);
return true;
}
return true;
}
}
// Change biomes
if (split[0].equalsIgnoreCase("setbiome")) {
// Convert name to a UUID
UUID playerUUID = plugin.getPlayers().getUUID(split[1], true);
// Check if player exists
if (!plugin.getPlayers().isAKnownPlayer(playerUUID)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorUnknownPlayer);
return true;
}
// Check if the target is in a team and if so, the leader
if (plugin.getPlayers().inTeam(playerUUID)) {
playerUUID = plugin.getPlayers().getTeamLeader(playerUUID);
}
Island island = plugin.getGrid().getIsland(playerUUID);
if (island == null) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorNoIsland);
return true;
}
// Check if biome is valid
Biome biome = null;
String biomeName = split[2].toUpperCase();
try {
biome = Biome.valueOf(biomeName);
biomeName = biome.name();
if (!plugin.getConfig().contains("biomes." + biomeName)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().biomeUnknown);
// shown
for (Biome b : Biome.values()) {
if (plugin.getConfig().contains("biomes." + b.name())) {
Util.sendMessage(sender, b.name());
}
}
return true;
}
// Get friendly name
biomeName = plugin.getConfig().getString("biomes." + biomeName + ".friendlyname", Util.prettifyText(biomeName));
} catch (Exception e) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().biomeUnknown);
for (Biome b : Biome.values()) {
if (plugin.getConfig().contains("biomes." + b.name())) {
Util.sendMessage(sender, b.name());
}
}
return true;
}
// Okay clear to set biome
// Actually set the biome
new SetBiome(plugin, island, biome, sender);
Util.sendMessage(sender, ChatColor.GREEN + plugin.myLocale().biomeSet.replace("[biome]", biomeName));
Player targetPlayer = plugin.getServer().getPlayer(playerUUID);
if (targetPlayer != null) {
// Online
Util.sendMessage(targetPlayer, "[Admin] " + ChatColor.GREEN + plugin.myLocale(playerUUID).biomeSet.replace("[biome]", biomeName));
} else {
plugin.getMessages().setMessage(playerUUID, "[Admin] " + ChatColor.GREEN + plugin.myLocale(playerUUID).biomeSet.replace("[biome]", biomeName));
}
return true;
} else // team kick <player> and team delete <leader>
if (split[0].equalsIgnoreCase("team")) {
// Convert name to a UUID
final UUID playerUUID = plugin.getPlayers().getUUID(split[2], true);
if (!plugin.getPlayers().isAKnownPlayer(playerUUID)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorUnknownPlayer);
return true;
}
if (split[1].equalsIgnoreCase("kick")) {
// Remove player from team
if (!plugin.getPlayers().inTeam(playerUUID)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorNoTeam);
return true;
}
UUID teamLeader = plugin.getPlayers().getTeamLeader(playerUUID);
if (teamLeader == null) {
// Clear the player of all team-related items
if (!plugin.getPlayers().setLeaveTeam(playerUUID)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorBlockedByAPI);
return true;
}
plugin.getPlayers().setHomeLocation(playerUUID, null);
plugin.getPlayers().setIslandLocation(playerUUID, null);
// Remove any warps
plugin.getWarpSignsListener().removeWarp(playerUUID);
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().kicknameRemoved.replace("[name]", split[2]));
plugin.getPlayers().save(playerUUID);
return true;
}
// Payer is not a team leader
if (!teamLeader.equals(playerUUID)) {
// Clear the player of all team-related items
if (!plugin.getPlayers().setLeaveTeam(playerUUID)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorBlockedByAPI);
return true;
}
plugin.getPlayers().setHomeLocation(playerUUID, null);
plugin.getPlayers().setIslandLocation(playerUUID, null);
// Clear the leader of this player and if they now have
// no team, remove the team
plugin.getPlayers().removeMember(teamLeader, playerUUID);
if (plugin.getPlayers().getMembers(teamLeader).size() < 2) {
if (!plugin.getPlayers().setLeaveTeam(teamLeader)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorBlockedByAPI);
return true;
}
}
// Remove any warps
plugin.getWarpSignsListener().removeWarp(playerUUID);
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().kicknameRemoved.replace("[name]", split[2]));
plugin.getPlayers().save(playerUUID);
return true;
} else {
Util.sendMessage(sender, ChatColor.RED + (plugin.myLocale().adminTeamKickLeader.replace("[label]", label)).replace("[name]", split[2]));
return true;
}
} else {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorUnknownCommand);
return false;
}
} else if (split[0].equalsIgnoreCase("completechallenge")) {
// Convert name to a UUID
final UUID playerUUID = plugin.getPlayers().getUUID(split[1], true);
if (!plugin.getPlayers().isAKnownPlayer(playerUUID)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorUnknownPlayer);
return true;
}
if (plugin.getPlayers().checkChallenge(playerUUID, split[2].toLowerCase()) || !plugin.getPlayers().get(playerUUID).challengeExists(split[2].toLowerCase())) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().completeChallengeerrorChallengeDoesNotExist);
return true;
}
plugin.getPlayers().get(playerUUID).completeChallenge(split[2].toLowerCase());
plugin.getPlayers().save(playerUUID);
Util.sendMessage(sender, ChatColor.YELLOW + plugin.myLocale().completeChallengechallangeCompleted.replace("[challengename]", split[2].toLowerCase()).replace("[name]", split[1]));
return true;
} else if (split[0].equalsIgnoreCase("resetchallenge")) {
// Convert name to a UUID
final UUID playerUUID = plugin.getPlayers().getUUID(split[1], true);
if (!plugin.getPlayers().isAKnownPlayer(playerUUID)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorUnknownPlayer);
return true;
}
if (!plugin.getPlayers().checkChallenge(playerUUID, split[2].toLowerCase()) || !plugin.getPlayers().get(playerUUID).challengeExists(split[2].toLowerCase())) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().resetChallengeerrorChallengeDoesNotExist);
return true;
}
plugin.getPlayers().resetChallenge(playerUUID, split[2].toLowerCase());
plugin.getPlayers().save(playerUUID);
Util.sendMessage(sender, ChatColor.YELLOW + plugin.myLocale().resetChallengechallengeReset.replace("[challengename]", split[2].toLowerCase()).replace("[name]", split[1]));
return true;
} else if (split[0].equalsIgnoreCase("info") && split[1].equalsIgnoreCase("challenges")) {
// Convert name to a UUID
final UUID playerUUID = plugin.getPlayers().getUUID(split[2], true);
// + playerUUID);
if (!plugin.getPlayers().isAKnownPlayer(playerUUID)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorUnknownPlayer);
return true;
} else {
showInfoChallenges(playerUUID, sender);
return true;
}
}
return false;
case 4:
// Team add <player> <leader>
if (split[0].equalsIgnoreCase("team") && split[1].equalsIgnoreCase("add")) {
// Convert names to UUIDs
final UUID playerUUID = plugin.getPlayers().getUUID(split[2], true);
final Player targetPlayer = plugin.getServer().getPlayer(playerUUID);
final UUID teamLeader = plugin.getPlayers().getUUID(split[3], true);
if (!plugin.getPlayers().isAKnownPlayer(playerUUID) || !plugin.getPlayers().isAKnownPlayer(teamLeader)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorUnknownPlayer);
return true;
}
if (playerUUID.equals(teamLeader)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().adminTeamAddLeaderToOwn);
return true;
}
// See if leader has an island
if (!plugin.getPlayers().hasIsland(teamLeader)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().adminTeamAddLeaderNoIsland);
return true;
}
// Check to see if this player is already in a team
if (plugin.getPlayers().inTeam(playerUUID)) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().inviteerrorThatPlayerIsAlreadyInATeam);
return true;
}
// then add it
if (!plugin.getPlayers().getMembers(teamLeader).contains(teamLeader)) {
// Set up the team leader
if (!plugin.getPlayers().setJoinTeam(teamLeader, teamLeader, plugin.getPlayers().getIslandLocation(teamLeader))) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorBlockedByAPI);
return true;
}
plugin.getPlayers().addTeamMember(teamLeader, teamLeader);
Util.sendMessage(sender, ChatColor.GOLD + plugin.myLocale().adminTeamAddedLeader);
}
// This is a hack to clear any pending invitations
if (targetPlayer != null) {
Util.runCommand(targetPlayer, Settings.ISLANDCOMMAND + " decline");
}
// If the invitee has an island of their own
if (plugin.getPlayers().hasIsland(playerUUID)) {
Location islandLoc = plugin.getPlayers().getIslandLocation(playerUUID);
if (islandLoc != null) {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().adminTeamNowUnowned.replace("[name]", plugin.getPlayers().getName(playerUUID)).replace("[location]", islandLoc.getBlockX() + " " + islandLoc.getBlockZ()));
}
}
// Remove their old island affiliation - do not delete the
// island just in case
plugin.deletePlayerIsland(playerUUID, false);
// Join the team and set the team island location and leader
plugin.getPlayers().setJoinTeam(playerUUID, teamLeader, plugin.getPlayers().getIslandLocation(teamLeader));
// Configure the best home location for this player
if (plugin.getPlayers().getHomeLocation(teamLeader) != null) {
plugin.getPlayers().setHomeLocation(playerUUID, plugin.getPlayers().getHomeLocation(teamLeader));
Util.sendMessage(sender, ChatColor.GREEN + plugin.myLocale().adminTeamSettingHome);
} else {
plugin.getPlayers().setHomeLocation(playerUUID, plugin.getPlayers().getIslandLocation(teamLeader));
Util.sendMessage(sender, ChatColor.GREEN + plugin.myLocale().adminTeamSettingHome);
}
// it
if (!plugin.getPlayers().getMembers(teamLeader).contains(playerUUID)) {
plugin.getPlayers().addTeamMember(teamLeader, playerUUID);
Util.sendMessage(sender, ChatColor.GREEN + plugin.myLocale().adminTeamAddingPlayer);
} else {
Util.sendMessage(sender, ChatColor.GOLD + plugin.myLocale().adminTeamAlreadyOnTeam);
}
// Teleport the player if they are online
if (targetPlayer != null) {
plugin.getGrid().homeTeleport(targetPlayer);
}
plugin.getGrid().saveGrid();
return true;
} else {
Util.sendMessage(sender, ChatColor.RED + plugin.myLocale().errorUnknownCommand);
return false;
}
default:
return false;
}
}
Aggregations