diff --git a/src/main/java/us/talabrek/ultimateskyblock/IslandCommand.java b/src/main/java/us/talabrek/ultimateskyblock/IslandCommand.java index cadeced2a..237b2bb93 100644 --- a/src/main/java/us/talabrek/ultimateskyblock/IslandCommand.java +++ b/src/main/java/us/talabrek/ultimateskyblock/IslandCommand.java @@ -52,9 +52,7 @@ public boolean onCommand(final CommandSender sender, final Command command, fina return true; } if (!uSkyBlock.getInstance().onRestartCooldown(player) || Settings.general_cooldownRestart == 0) { - uSkyBlock.getInstance().restartPlayerIsland(player, pi.getIslandLocation()); - uSkyBlock.getInstance().setRestartCooldown(player); - return true; + return uSkyBlock.getInstance().restartPlayerIsland(player, pi.getIslandLocation()); } player.sendMessage(ChatColor.YELLOW + "You can restart your island in " + uSkyBlock.getInstance().getRestartCooldownTime(player) / 1000L + " seconds."); return true; diff --git a/src/main/java/us/talabrek/ultimateskyblock/PlayerJoin.java b/src/main/java/us/talabrek/ultimateskyblock/PlayerJoin.java index 9c57e3230..67644707a 100644 --- a/src/main/java/us/talabrek/ultimateskyblock/PlayerJoin.java +++ b/src/main/java/us/talabrek/ultimateskyblock/PlayerJoin.java @@ -40,12 +40,12 @@ public void onPlayerJoin(final PlayerJoinEvent event) { uSkyBlock.getInstance().createIslandConfig(pi.locationForParty(), event.getPlayer().getName()); } uSkyBlock.getInstance().clearIslandConfig(pi.locationForParty(), event.getPlayer().getName()); - if (Settings.island_protectWithWorldGuard && Bukkit.getServer().getPluginManager().isPluginEnabled("WorldGuard")) { - WorldGuardHandler.protectIsland(event.getPlayer(), event.getPlayer().getName(), pi); - } } f.delete(); } + if (Settings.island_protectWithWorldGuard && Bukkit.getServer().getPluginManager().isPluginEnabled("WorldGuard")) { + WorldGuardHandler.protectIsland(event.getPlayer(), event.getPlayer().getName(), pi); + } uSkyBlock.getInstance().addActivePlayer(event.getPlayer().getName(), pi); if (pi.getHasIsland() && !uSkyBlock.getInstance().getTempIslandConfig(pi.locationForParty()).contains("general.level")) { uSkyBlock.getInstance().createIslandConfig(pi.locationForParty(), event.getPlayer().getName()); diff --git a/src/main/java/us/talabrek/ultimateskyblock/SkyBlockMenu.java b/src/main/java/us/talabrek/ultimateskyblock/SkyBlockMenu.java index 8dc80a5bb..0be386944 100644 --- a/src/main/java/us/talabrek/ultimateskyblock/SkyBlockMenu.java +++ b/src/main/java/us/talabrek/ultimateskyblock/SkyBlockMenu.java @@ -15,6 +15,8 @@ import java.util.List; import java.util.Set; import java.util.logging.Level; +import java.util.regex.Matcher; +import java.util.regex.Pattern; // TODO: Move all the texts to resource-files (translatable). /** @@ -880,53 +882,7 @@ public void populateChallengeRank(Inventory menu, final Player player, final int meta4 = currentChallengeItem.getItemMeta(); meta4.setDisplayName(challenge); } - lores.add("\u00a77" + config.getString("options.challenges.challengeList." + challengeName + ".description")); - lores.add("\u00a7eThis challenge requires the following:"); - final String[] reqList = config.getString("options.challenges.challengeList." + challengeName + ".requiredItems").split(" "); - int reqItem = 0; - int reqAmount = 0; - int reqMod = -1; - String[] array; - for (int length = (array = reqList).length, j = 0; j < length; ++j) { - final String s = array[j]; - final String[] sPart = s.split(":"); - if (sPart.length == 2) { - reqItem = Integer.parseInt(sPart[0]); - final String[] sScale = sPart[1].split(";"); - if (sScale.length == 1) { - reqAmount = Integer.parseInt(sPart[1]); - } else if (sScale.length == 2) { - if (sScale[1].charAt(0) == '+') { - reqAmount = Integer.parseInt(sScale[0]) + Integer.parseInt(sScale[1].substring(1)) * skyBlock.getActivePlayers().get(player.getName()).checkChallengeSinceTimer(challengeName); - } else if (sScale[1].charAt(0) == '*') { - reqAmount = Integer.parseInt(sScale[0]) * (Integer.parseInt(sScale[1].substring(1)) * skyBlock.getActivePlayers().get(player.getName()).checkChallengeSinceTimer(challengeName)); - } else if (sScale[1].charAt(0) == '-') { - reqAmount = Integer.parseInt(sScale[0]) - Integer.parseInt(sScale[1].substring(1)) * skyBlock.getActivePlayers().get(player.getName()).checkChallengeSinceTimer(challengeName); - } else if (sScale[1].charAt(0) == '/') { - reqAmount = Integer.parseInt(sScale[0]) / (Integer.parseInt(sScale[1].substring(1)) * skyBlock.getActivePlayers().get(player.getName()).checkChallengeSinceTimer(challengeName)); - } - } - } else if (sPart.length == 3) { - reqItem = Integer.parseInt(sPart[0]); - final String[] sScale = sPart[2].split(";"); - if (sScale.length == 1) { - reqAmount = Integer.parseInt(sPart[2]); - } else if (sScale.length == 2) { - if (sScale[1].charAt(0) == '+') { - reqAmount = Integer.parseInt(sScale[0]) + Integer.parseInt(sScale[1].substring(1)) * skyBlock.getActivePlayers().get(player.getName()).checkChallengeSinceTimer(challengeName); - } else if (sScale[1].charAt(0) == '*') { - reqAmount = Integer.parseInt(sScale[0]) * (Integer.parseInt(sScale[1].substring(1)) * skyBlock.getActivePlayers().get(player.getName()).checkChallengeSinceTimer(challengeName)); - } else if (sScale[1].charAt(0) == '-') { - reqAmount = Integer.parseInt(sScale[0]) - Integer.parseInt(sScale[1].substring(1)) * skyBlock.getActivePlayers().get(player.getName()).checkChallengeSinceTimer(challengeName); - } else if (sScale[1].charAt(0) == '/') { - reqAmount = Integer.parseInt(sScale[0]) / (Integer.parseInt(sScale[1].substring(1)) * skyBlock.getActivePlayers().get(player.getName()).checkChallengeSinceTimer(challengeName)); - } - } - reqMod = Integer.parseInt(sPart[1]); - } - final ItemStack newItem = new ItemStack(reqItem, reqAmount, (short) reqMod); - lores.add("\u00a7f" + newItem.getAmount() + " " + newItem.getType().toString()); - } + addRequiredItems(player, lores, challengeName, config); if (pi.checkChallenge(challengeName) > 0 && config.getBoolean("options.challenges.challengeList." + challengeName + ".repeatable")) { if (pi.onChallengeCooldown(challengeName)) { if (pi.getChallengeCooldownTime(challengeName) / 86400000L >= 1L) { @@ -957,11 +913,44 @@ public void populateChallengeRank(Inventory menu, final Player player, final int menu.setItem(++location, currentChallengeItem); lores.clear(); } catch (NullPointerException e) { - skyBlock.getLogger().log(Level.SEVERE, "Mis-configured challenge " + challenge, e); + skyBlock.getLogger().log(Level.SEVERE, "Misconfigured challenge " + challenge, e); + } + } + } + + private void addRequiredItems(Player player, List lores, String challengeName, FileConfiguration config) { + lores.add("\u00a77" + config.getString("options.challenges.challengeList." + challengeName + ".description")); + lores.add("\u00a7eThis challenge requires the following:"); + String reqItems = config.getString("options.challenges.challengeList." + challengeName + ".requiredItems"); + int timesCompleted = skyBlock.getPlayerInfo(player).checkChallengeSinceTimer(challengeName); + if (reqItems != null) { + Pattern reqPattern = Pattern.compile("(?[0-9]+)(:(?[0-9]+))?:(?[0-9]+)(;(?[+\\-*])(?[0-9]+))?"); + for (String item : reqItems.split(" ")) { + Matcher m = reqPattern.matcher(item); + if (m.matches()) { + int reqItem = Integer.parseInt(m.group("type")); + int subType = m.group("subtype") != null ? Integer.parseInt(m.group("subtype")) : 0; + int amount = Integer.parseInt(m.group("amount")); + char op = m.group("op") != null ? m.group("op").charAt(0) : 0; + int inc = m.group("inc") != null ? Integer.parseInt(m.group("inc")) : 0; + amount = calcAmount(amount, op, inc, timesCompleted); + Material mat = Material.getMaterial(reqItem); // Deprecated my ass + lores.add("\u00a7f" + amount + " " + mat.name()); + } } } } + private int calcAmount(int amount, char op, int inc, int timesCompleted) { + switch (op) { + case '+': return amount + inc*timesCompleted; + case '-': return amount - inc*timesCompleted; // Why? + case '*': return amount * inc * timesCompleted; // Oh, my god! Just do the time m8! + case '/': return amount / (inc * timesCompleted); // Yay! Free stuff!!! + } + return amount; + } + private boolean isCompletedChallenge(String challengeName) { return challengeName.charAt(1) == '2'; } diff --git a/src/main/java/us/talabrek/ultimateskyblock/WorldGuardHandler.java b/src/main/java/us/talabrek/ultimateskyblock/WorldGuardHandler.java index 1c2ffa53e..264488b78 100644 --- a/src/main/java/us/talabrek/ultimateskyblock/WorldGuardHandler.java +++ b/src/main/java/us/talabrek/ultimateskyblock/WorldGuardHandler.java @@ -1,7 +1,10 @@ package us.talabrek.ultimateskyblock; import com.sk89q.worldguard.bukkit.*; +import com.sk89q.worldguard.protection.managers.RegionManager; import org.bukkit.Location; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.plugin.*; import org.bukkit.entity.*; import com.sk89q.worldguard.domains.*; @@ -24,50 +27,92 @@ public static WorldGuardPlugin getWorldGuard() { return (WorldGuardPlugin) plugin; } - public static void protectIsland(final Player sender, final String player, final PlayerInfo pi) { + public static boolean protectIsland(final Player sender, final String player, final PlayerInfo pi) { try { if (Settings.island_protectWithWorldGuard) { - if (pi.getIslandLocation() != null && !getWorldGuard().getRegionManager(uSkyBlock.getSkyBlockWorld()).hasRegion(player + "Island")) { - ProtectedRegion region = null; + WorldGuardPlugin worldGuard = getWorldGuard(); + RegionManager regionManager = worldGuard.getRegionManager(uSkyBlock.getSkyBlockWorld()); + String regionName = player + "Island"; + if (pi.getIslandLocation() != null && noOrOldRegion(regionName, regionManager)) { + ProtectedCuboidRegion region = new ProtectedCuboidRegion(player + "Island", getProtectionVectorLeft(pi.getIslandLocation()), getProtectionVectorRight(pi.getIslandLocation())); final DefaultDomain owners = new DefaultDomain(); - region = new ProtectedCuboidRegion(player + "Island", getProtectionVectorLeft(pi.getIslandLocation()), getProtectionVectorRight(pi.getIslandLocation())); owners.addPlayer(player); region.setOwners(owners); - region.setParent(getWorldGuard().getRegionManager(uSkyBlock.getSkyBlockWorld()).getRegion("__Global__")); + region.setParent(regionManager.getRegion("__Global__")); region.setPriority(100); - region.setFlag((Flag) DefaultFlag.GREET_MESSAGE, DefaultFlag.GREET_MESSAGE.parseInput(getWorldGuard(), sender, "\u00a7d** You are entering a protected island area. (" + player + ")")); - region.setFlag((Flag) DefaultFlag.FAREWELL_MESSAGE, DefaultFlag.FAREWELL_MESSAGE.parseInput(getWorldGuard(), sender, "\u00a7d** You are leaving a protected island area. (" + player + ")")); - region.setFlag((Flag) DefaultFlag.PVP, DefaultFlag.PVP.parseInput(getWorldGuard(), sender, Settings.island_allowPvP)); - region.setFlag((Flag) DefaultFlag.CHEST_ACCESS, DefaultFlag.CHEST_ACCESS.parseInput(getWorldGuard(), sender, "deny")); - region.setFlag((Flag) DefaultFlag.USE, DefaultFlag.USE.parseInput(getWorldGuard(), sender, "deny")); - region.setFlag((Flag) DefaultFlag.DESTROY_VEHICLE, DefaultFlag.DESTROY_VEHICLE.parseInput(getWorldGuard(), sender, "deny")); - region.setFlag((Flag) DefaultFlag.ENTITY_ITEM_FRAME_DESTROY, DefaultFlag.ENTITY_ITEM_FRAME_DESTROY.parseInput(getWorldGuard(), sender, "deny")); - region.setFlag((Flag) DefaultFlag.ENTITY_PAINTING_DESTROY, DefaultFlag.ENTITY_PAINTING_DESTROY.parseInput(getWorldGuard(), sender, "deny")); - final ApplicableRegionSet set = getWorldGuard().getRegionManager(uSkyBlock.getSkyBlockWorld()).getApplicableRegions(pi.getIslandLocation()); + region.setFlag(DefaultFlag.GREET_MESSAGE, DefaultFlag.GREET_MESSAGE.parseInput(worldGuard, sender, "\u00a7d** You are entering a protected island area. (" + player + ")")); + region.setFlag(DefaultFlag.FAREWELL_MESSAGE, DefaultFlag.FAREWELL_MESSAGE.parseInput(worldGuard, sender, "\u00a7d** You are leaving a protected island area. (" + player + ")")); + setRegionFlags(sender, region, worldGuard); + final ApplicableRegionSet set = regionManager.getApplicableRegions(pi.getIslandLocation()); if (set.size() > 0) { for (final ProtectedRegion regions : set) { if (!regions.getId().equalsIgnoreCase("__global__")) { - getWorldGuard().getRegionManager(uSkyBlock.getSkyBlockWorld()).removeRegion(regions.getId()); + regionManager.removeRegion(regions.getId()); } } } - getWorldGuard().getRegionManager(uSkyBlock.getSkyBlockWorld()).addRegion(region); + regionManager.addRegion(region); System.out.print("New protected region created for " + player + "'s Island by " + sender.getName()); - getWorldGuard().getRegionManager(uSkyBlock.getSkyBlockWorld()).save(); - } else { - sender.sendMessage("Player doesn't have an island or it's already protected!"); + regionManager.save(); + return true; } } } catch (Exception ex) { System.out.print("ERROR: Failed to protect " + player + "'s Island (" + sender.getName() + ")"); ex.printStackTrace(); } + return false; + } + + private static void setRegionFlags(Player sender, ProtectedCuboidRegion region, WorldGuardPlugin worldGuard) throws InvalidFlagFormat { + FileConfiguration config = uSkyBlock.getInstance().getConfig(); + ConfigurationSection configurationSection = config.getConfigurationSection("options.island.worldGuardFlags"); + if (configurationSection != null) { + for (String group : configurationSection.getKeys(false)) { + ConfigurationSection groupSection = configurationSection.getConfigurationSection(group); + RegionGroup regionGroup = RegionGroup.valueOf(group.toUpperCase()); + if (regionGroup == null) { + System.out.println("&4[uSkyBlock]&r Unknown group " + group + " in config.yml"); + continue; + } + for (String flag : groupSection.getKeys(false)) { + String stateString = groupSection.getString(flag); + StateFlag.State state = StateFlag.State.valueOf(stateString.toUpperCase()); + if (state == null) { + System.out.println("&4[uSkyBlock]&r Unknown state " + stateString + " only allow/deny supported"); + continue; + } + region.setFlag(new StateFlag(flag, false, regionGroup), state); + System.out.println("\u00a9[uSkyBlock]&r Setting flag " + flag + " to " + state + " for " + regionGroup); + } + } + } else { + region.setFlag(DefaultFlag.PVP, DefaultFlag.PVP.parseInput(worldGuard, sender, Settings.island_allowPvP)); + region.setFlag(DefaultFlag.CHEST_ACCESS, StateFlag.State.DENY); + region.setFlag(DefaultFlag.USE, StateFlag.State.DENY); + region.setFlag(DefaultFlag.DESTROY_VEHICLE, StateFlag.State.DENY); + region.setFlag(DefaultFlag.ENTITY_ITEM_FRAME_DESTROY, StateFlag.State.DENY); + region.setFlag(DefaultFlag.ENTITY_PAINTING_DESTROY, StateFlag.State.DENY); + + region.setFlag(new StateFlag("chest-access", true, RegionGroup.OWNERS), StateFlag.State.ALLOW); + region.setFlag(new StateFlag("use", true, RegionGroup.OWNERS), StateFlag.State.ALLOW); + } + } + + private static boolean noOrOldRegion(String regionId, RegionManager regionManager) { + if (regionManager.hasRegion(regionId)) { + ProtectedRegion region = regionManager.getRegion(regionId); + StateFlag use = new StateFlag("use", true, RegionGroup.OWNERS); + StateFlag.State useFlag = region.getFlag(use); + return useFlag == null; // We need to set it + } + return true; } public static void islandLock(final CommandSender sender, final String player) { try { if (getWorldGuard().getRegionManager(uSkyBlock.getSkyBlockWorld()).hasRegion(player + "Island")) { - getWorldGuard().getRegionManager(uSkyBlock.getSkyBlockWorld()).getRegion(player + "Island").setFlag((Flag) DefaultFlag.ENTRY, DefaultFlag.ENTRY.parseInput(getWorldGuard(), sender, "deny")); + getWorldGuard().getRegionManager(uSkyBlock.getSkyBlockWorld()).getRegion(player + "Island").setFlag(DefaultFlag.ENTRY, DefaultFlag.ENTRY.parseInput(getWorldGuard(), sender, "deny")); sender.sendMessage(ChatColor.YELLOW + "Your island is now locked. Only your party members may enter."); getWorldGuard().getRegionManager(uSkyBlock.getSkyBlockWorld()).save(); } else { @@ -82,7 +127,7 @@ public static void islandLock(final CommandSender sender, final String player) { public static void islandUnlock(final CommandSender sender, final String player) { try { if (getWorldGuard().getRegionManager(uSkyBlock.getSkyBlockWorld()).hasRegion(player + "Island")) { - getWorldGuard().getRegionManager(uSkyBlock.getSkyBlockWorld()).getRegion(player + "Island").setFlag((Flag) DefaultFlag.ENTRY, DefaultFlag.ENTRY.parseInput(getWorldGuard(), sender, "allow")); + getWorldGuard().getRegionManager(uSkyBlock.getSkyBlockWorld()).getRegion(player + "Island").setFlag(DefaultFlag.ENTRY, DefaultFlag.ENTRY.parseInput(getWorldGuard(), sender, "allow")); sender.sendMessage(ChatColor.YELLOW + "Your island is unlocked and anyone may enter, however only you and your party members may build or remove blocks."); getWorldGuard().getRegionManager(uSkyBlock.getSkyBlockWorld()).save(); } else { @@ -132,12 +177,12 @@ public static void transferRegion(final String owner, final String player, final region2 = new ProtectedCuboidRegion(player + "Island", getWorldGuard().getRegionManager(Bukkit.getWorld("skyworld")).getRegion(owner + "Island").getMinimumPoint(), getWorldGuard().getRegionManager(Bukkit.getWorld(Settings.general_worldName)).getRegion(owner + "Island").getMaximumPoint()); region2.setOwners(getWorldGuard().getRegionManager(uSkyBlock.getSkyBlockWorld()).getRegion(owner + "Island").getOwners()); region2.setParent(getWorldGuard().getRegionManager(uSkyBlock.getSkyBlockWorld()).getRegion("__Global__")); - region2.setFlag((Flag) DefaultFlag.GREET_MESSAGE, DefaultFlag.GREET_MESSAGE.parseInput(getWorldGuard(), sender, "\u00a7d** You are entering a protected island area. (" + player + ")")); - region2.setFlag((Flag) DefaultFlag.FAREWELL_MESSAGE, DefaultFlag.FAREWELL_MESSAGE.parseInput(getWorldGuard(), sender, "\u00a7d** You are leaving a protected island area. (" + player + ")")); - region2.setFlag((Flag) DefaultFlag.PVP, DefaultFlag.PVP.parseInput(getWorldGuard(), sender, "deny")); - region2.setFlag((Flag) DefaultFlag.DESTROY_VEHICLE, DefaultFlag.DESTROY_VEHICLE.parseInput(getWorldGuard(), sender, "deny")); - region2.setFlag((Flag) DefaultFlag.ENTITY_ITEM_FRAME_DESTROY, DefaultFlag.ENTITY_ITEM_FRAME_DESTROY.parseInput(getWorldGuard(), sender, "deny")); - region2.setFlag((Flag) DefaultFlag.ENTITY_PAINTING_DESTROY, DefaultFlag.ENTITY_PAINTING_DESTROY.parseInput(getWorldGuard(), sender, "deny")); + region2.setFlag(DefaultFlag.GREET_MESSAGE, DefaultFlag.GREET_MESSAGE.parseInput(getWorldGuard(), sender, "\u00a7d** You are entering a protected island area. (" + player + ")")); + region2.setFlag(DefaultFlag.FAREWELL_MESSAGE, DefaultFlag.FAREWELL_MESSAGE.parseInput(getWorldGuard(), sender, "\u00a7d** You are leaving a protected island area. (" + player + ")")); + region2.setFlag(DefaultFlag.PVP, DefaultFlag.PVP.parseInput(getWorldGuard(), sender, "deny")); + region2.setFlag(DefaultFlag.DESTROY_VEHICLE, DefaultFlag.DESTROY_VEHICLE.parseInput(getWorldGuard(), sender, "deny")); + region2.setFlag(DefaultFlag.ENTITY_ITEM_FRAME_DESTROY, DefaultFlag.ENTITY_ITEM_FRAME_DESTROY.parseInput(getWorldGuard(), sender, "deny")); + region2.setFlag(DefaultFlag.ENTITY_PAINTING_DESTROY, DefaultFlag.ENTITY_PAINTING_DESTROY.parseInput(getWorldGuard(), sender, "deny")); getWorldGuard().getRegionManager(uSkyBlock.getSkyBlockWorld()).removeRegion(owner + "Island"); getWorldGuard().getRegionManager(uSkyBlock.getSkyBlockWorld()).addRegion(region2); } catch (Exception e) { diff --git a/src/main/java/us/talabrek/ultimateskyblock/uSkyBlock.java b/src/main/java/us/talabrek/ultimateskyblock/uSkyBlock.java index dc71a4950..05cc7d319 100644 --- a/src/main/java/us/talabrek/ultimateskyblock/uSkyBlock.java +++ b/src/main/java/us/talabrek/ultimateskyblock/uSkyBlock.java @@ -17,8 +17,11 @@ import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; +import org.yaml.snakeyaml.Yaml; import java.io.*; +import java.nio.file.Files; +import java.nio.file.Paths; import java.text.DateFormat; import java.text.DecimalFormat; import java.util.*; @@ -41,8 +44,6 @@ public class uSkyBlock extends JavaPlugin { private static uSkyBlock instance; public List removeList; List rankDisplay; - public FileConfiguration configPlugin; - public File filePlugin; private Location lastIsland; private Stack orphaned; private Stack tempOrphaned; @@ -71,11 +72,11 @@ public class uSkyBlock extends JavaPlugin { public uSkyBlock() { super(); this.df = new DecimalFormat(".#"); + // TODO: 08/12/2014 - R4zorax: Most of these should be converted to local variables this.levelConfig = null; this.lastIslandConfig = null; this.orphans = null; this.islands = new HashMap<>(); - this.levelConfigFile = null; this.orphanFile = null; this.lastIslandConfigFile = null; this.removeList = new ArrayList<>(); @@ -119,8 +120,6 @@ public void onEnable() { if (!this.getDataFolder().exists()) { this.getDataFolder().mkdir(); } - this.configPlugin = super.getConfig(); - this.filePlugin = new File(this.getDataFolder(), "config.yml"); if (Settings.loadPluginConfig(getConfig())) { saveConfig(); } @@ -240,7 +239,7 @@ public void registerEvents() { manager.registerEvents(new PlayerJoin(), this); if (!Settings.island_protectWithWorldGuard) { System.out.print("[uSkyBlock] Using built in protection."); - manager.registerEvents(new ProtectionEvents(), getInstance()); + manager.registerEvents(new ProtectionEvents(), this); } else { System.out.print("[uSkyBlock] Using WorldGuard protection."); } @@ -521,79 +520,38 @@ public void deletePlayerIsland(final String player) { } } - public void restartPlayerIsland(final Player player, final Location next) { - boolean hasIslandNow = false; + public boolean restartPlayerIsland(final Player player, final Location next) { if (next.getBlockX() == 0 && next.getBlockZ() == 0) { - return; - } - this.removeIsland(next); - if (getInstance().getSchemFile().length > 0 && Bukkit.getServer().getPluginManager().isPluginEnabled("WorldEdit")) { - String cSchem = ""; - for (int i = 0; i < getInstance().getSchemFile().length; ++i) { - if (!hasIslandNow) { - if (getInstance().getSchemFile()[i].getName().lastIndexOf(46) > 0) { - cSchem = getInstance().getSchemFile()[i].getName().substring(0, getInstance().getSchemFile()[i].getName().lastIndexOf(46)); - } else { - cSchem = getInstance().getSchemFile()[i].getName(); - } - if (VaultHandler.checkPerk(player.getName(), "usb.schematic." + cSchem, getSkyBlockWorld())) { - try { - if (WorldEditHandler.loadIslandSchematic(getSkyBlockWorld(), getInstance().getSchemFile()[i], next)) { - this.setChest(next, player); - hasIslandNow = true; - } - } catch (MaxChangedBlocksException e) { - e.printStackTrace(); - } catch (DataException e2) { - e2.printStackTrace(); - } catch (IOException e3) { - e3.printStackTrace(); - } - } - } - } - if (!hasIslandNow) { - for (int i = 0; i < getInstance().getSchemFile().length; ++i) { - if (getInstance().getSchemFile()[i].getName().lastIndexOf(46) > 0) { - cSchem = getInstance().getSchemFile()[i].getName().substring(0, getInstance().getSchemFile()[i].getName().lastIndexOf(46)); - } else { - cSchem = getInstance().getSchemFile()[i].getName(); - } - if (cSchem.equalsIgnoreCase(Settings.island_schematicName)) { - try { - if (WorldEditHandler.loadIslandSchematic(getSkyBlockWorld(), getInstance().getSchemFile()[i], next)) { - this.setChest(next, player); - hasIslandNow = true; - } - } catch (MaxChangedBlocksException e) { - e.printStackTrace(); - } catch (DataException e2) { - e2.printStackTrace(); - } catch (IOException e3) { - e3.printStackTrace(); - } - } - } - } + return false; } - if (!hasIslandNow) { - if (!Settings.island_useOldIslands) { - this.generateIslandBlocks(next.getBlockX(), next.getBlockZ(), player, getSkyBlockWorld()); - } else { - this.oldGenerateIslandBlocks(next.getBlockX(), next.getBlockZ(), player, getSkyBlockWorld()); - } + try { + removeIsland(next); + createIsland(player, next); + next.setY((double) Settings.island_height); + this.setNewPlayerIsland(player, next); + player.getInventory().clear(); + player.getEquipment().clear(); + changePlayerBiome(player, "OCEAN"); + refreshIslandChunks(next); + clearEntitiesNearPlayer(player); + setRestartCooldown(player); + return true; + } catch (Exception e) { + player.sendMessage("Could not create your Island. Please contact a server moderator."); + e.printStackTrace(); + return false; } - next.setY((double) Settings.island_height); - System.out.println(next.getBlockY()); - this.setNewPlayerIsland(player, next); - player.getInventory().clear(); - player.getEquipment().clear(); - getInstance().changePlayerBiome(player, "OCEAN"); + } + + private void refreshIslandChunks(Location next) { for (int x = Settings.island_protectionRange / 2 * -1 - 16; x <= Settings.island_protectionRange / 2 + 16; x += 16) { for (int z = Settings.island_protectionRange / 2 * -1 - 16; z <= Settings.island_protectionRange / 2 + 16; z += 16) { getSkyBlockWorld().refreshChunk((next.getBlockX() + x) / 16, (next.getBlockZ() + z) / 16); } } + } + + private void clearEntitiesNearPlayer(Player player) { for (final Entity tempent : player.getNearbyEntities((double) (Settings.island_protectionRange / 2), 250.0, (double) (Settings.island_protectionRange / 2))) { if (!(tempent instanceof Player)) { tempent.remove(); @@ -637,7 +595,9 @@ public boolean devSetPlayerIsland(final Player sender, final Location l, final S getInstance().createIslandConfig(pi.locationForParty(), player); getInstance().clearIslandConfig(pi.locationForParty(), player); if (Settings.island_protectWithWorldGuard && Bukkit.getServer().getPluginManager().isPluginEnabled("WorldGuard")) { - WorldGuardHandler.protectIsland(sender, player, pi); + if (!WorldGuardHandler.protectIsland(sender, player, pi)) { + sender.sendMessage("Player doesn't have an island or it's already protected!"); + } } getIslandConfig(pi.locationForParty()); return true; @@ -1314,7 +1274,7 @@ public boolean checkIfCanCompleteChallenge(final Player player, final String cha if (!this.getConfig().getString("options.challenges.challengeList." + challenge + ".type").equalsIgnoreCase("islandLevel")) { return false; } - if (getIslandConfig(getInstance().getActivePlayers().get(player.getName()).locationForParty()).getInt("general.level") >= this.getConfig().getInt("options.challenges.challengeList." + challenge + ".requiredItems")) { + if (getIslandConfig(getPlayerInfo(player).locationForParty()).getInt("general.level") >= this.getConfig().getInt("options.challenges.challengeList." + challenge + ".requiredItems")) { return true; } player.sendMessage(ChatColor.RED + "Your island must be level " + this.getConfig().getInt("options.challenges.challengeList." + challenge + ".requiredItems") + " to complete this challenge!"); @@ -1339,13 +1299,13 @@ public boolean takeRequired(final Player player, final String challenge, final S reqAmount = Integer.parseInt(sPart[1]); } else if (sScale.length == 2) { if (sScale[1].charAt(0) == '+') { - reqAmount = Integer.parseInt(sScale[0]) + Integer.parseInt(sScale[1].substring(1)) * getInstance().getActivePlayers().get(player.getName()).checkChallengeSinceTimer(challenge); + reqAmount = Integer.parseInt(sScale[0]) + Integer.parseInt(sScale[1].substring(1)) * getPlayerInfo(player).checkChallengeSinceTimer(challenge); } else if (sScale[1].charAt(0) == '*') { - reqAmount = Integer.parseInt(sScale[0]) * (Integer.parseInt(sScale[1].substring(1)) * getInstance().getActivePlayers().get(player.getName()).checkChallengeSinceTimer(challenge)); + reqAmount = Integer.parseInt(sScale[0]) * (Integer.parseInt(sScale[1].substring(1)) * getPlayerInfo(player).checkChallengeSinceTimer(challenge)); } else if (sScale[1].charAt(0) == '-') { - reqAmount = Integer.parseInt(sScale[0]) - Integer.parseInt(sScale[1].substring(1)) * getInstance().getActivePlayers().get(player.getName()).checkChallengeSinceTimer(challenge); + reqAmount = Integer.parseInt(sScale[0]) - Integer.parseInt(sScale[1].substring(1)) * getPlayerInfo(player).checkChallengeSinceTimer(challenge); } else if (sScale[1].charAt(0) == '/') { - reqAmount = Integer.parseInt(sScale[0]) / (Integer.parseInt(sScale[1].substring(1)) * getInstance().getActivePlayers().get(player.getName()).checkChallengeSinceTimer(challenge)); + reqAmount = Integer.parseInt(sScale[0]) / (Integer.parseInt(sScale[1].substring(1)) * getPlayerInfo(player).checkChallengeSinceTimer(challenge)); } } if (!player.getInventory().contains(reqItem, reqAmount)) { @@ -1359,13 +1319,13 @@ public boolean takeRequired(final Player player, final String challenge, final S reqAmount = Integer.parseInt(sPart[2]); } else if (sScale.length == 2) { if (sScale[1].charAt(0) == '+') { - reqAmount = Integer.parseInt(sScale[0]) + Integer.parseInt(sScale[1].substring(1)) * getInstance().getActivePlayers().get(player.getName()).checkChallengeSinceTimer(challenge); + reqAmount = Integer.parseInt(sScale[0]) + Integer.parseInt(sScale[1].substring(1)) * getPlayerInfo(player).checkChallengeSinceTimer(challenge); } else if (sScale[1].charAt(0) == '*') { - reqAmount = Integer.parseInt(sScale[0]) * (Integer.parseInt(sScale[1].substring(1)) * getInstance().getActivePlayers().get(player.getName()).checkChallengeSinceTimer(challenge)); + reqAmount = Integer.parseInt(sScale[0]) * (Integer.parseInt(sScale[1].substring(1)) * getPlayerInfo(player).checkChallengeSinceTimer(challenge)); } else if (sScale[1].charAt(0) == '-') { - reqAmount = Integer.parseInt(sScale[0]) - Integer.parseInt(sScale[1].substring(1)) * getInstance().getActivePlayers().get(player.getName()).checkChallengeSinceTimer(challenge); + reqAmount = Integer.parseInt(sScale[0]) - Integer.parseInt(sScale[1].substring(1)) * getPlayerInfo(player).checkChallengeSinceTimer(challenge); } else if (sScale[1].charAt(0) == '/') { - reqAmount = Integer.parseInt(sScale[0]) / (Integer.parseInt(sScale[1].substring(1)) * getInstance().getActivePlayers().get(player.getName()).checkChallengeSinceTimer(challenge)); + reqAmount = Integer.parseInt(sScale[0]) / (Integer.parseInt(sScale[1].substring(1)) * getPlayerInfo(player).checkChallengeSinceTimer(challenge)); } } reqMod = Integer.parseInt(sPart[1]); @@ -1397,13 +1357,13 @@ public boolean hasRequired(final Player player, final String challenge, final St reqAmount = Integer.parseInt(sPart[1]); } else if (sScale.length == 2) { if (sScale[1].charAt(0) == '+') { - reqAmount = Integer.parseInt(sScale[0]) + Integer.parseInt(sScale[1].substring(1)) * getInstance().getActivePlayers().get(player.getName()).checkChallengeSinceTimer(challenge); + reqAmount = Integer.parseInt(sScale[0]) + Integer.parseInt(sScale[1].substring(1)) * getPlayerInfo(player).checkChallengeSinceTimer(challenge); } else if (sScale[1].charAt(0) == '*') { - reqAmount = Integer.parseInt(sScale[0]) * (Integer.parseInt(sScale[1].substring(1)) * getInstance().getActivePlayers().get(player.getName()).checkChallengeSinceTimer(challenge)); + reqAmount = Integer.parseInt(sScale[0]) * (Integer.parseInt(sScale[1].substring(1)) * getPlayerInfo(player).checkChallengeSinceTimer(challenge)); } else if (sScale[1].charAt(0) == '-') { - reqAmount = Integer.parseInt(sScale[0]) - Integer.parseInt(sScale[1].substring(1)) * getInstance().getActivePlayers().get(player.getName()).checkChallengeSinceTimer(challenge); + reqAmount = Integer.parseInt(sScale[0]) - Integer.parseInt(sScale[1].substring(1)) * getPlayerInfo(player).checkChallengeSinceTimer(challenge); } else if (sScale[1].charAt(0) == '/') { - reqAmount = Integer.parseInt(sScale[0]) / (Integer.parseInt(sScale[1].substring(1)) * getInstance().getActivePlayers().get(player.getName()).checkChallengeSinceTimer(challenge)); + reqAmount = Integer.parseInt(sScale[0]) / (Integer.parseInt(sScale[1].substring(1)) * getPlayerInfo(player).checkChallengeSinceTimer(challenge)); } } if (!player.getInventory().containsAtLeast(new ItemStack(reqItem, reqAmount, (short) 0), reqAmount)) { @@ -1416,13 +1376,13 @@ public boolean hasRequired(final Player player, final String challenge, final St reqAmount = Integer.parseInt(sPart[2]); } else if (sScale.length == 2) { if (sScale[1].charAt(0) == '+') { - reqAmount = Integer.parseInt(sScale[0]) + Integer.parseInt(sScale[1].substring(1)) * getInstance().getActivePlayers().get(player.getName()).checkChallengeSinceTimer(challenge); + reqAmount = Integer.parseInt(sScale[0]) + Integer.parseInt(sScale[1].substring(1)) * getPlayerInfo(player).checkChallengeSinceTimer(challenge); } else if (sScale[1].charAt(0) == '*') { - reqAmount = Integer.parseInt(sScale[0]) * (Integer.parseInt(sScale[1].substring(1)) * getInstance().getActivePlayers().get(player.getName()).checkChallengeSinceTimer(challenge)); + reqAmount = Integer.parseInt(sScale[0]) * (Integer.parseInt(sScale[1].substring(1)) * getPlayerInfo(player).checkChallengeSinceTimer(challenge)); } else if (sScale[1].charAt(0) == '-') { - reqAmount = Integer.parseInt(sScale[0]) - Integer.parseInt(sScale[1].substring(1)) * getInstance().getActivePlayers().get(player.getName()).checkChallengeSinceTimer(challenge); + reqAmount = Integer.parseInt(sScale[0]) - Integer.parseInt(sScale[1].substring(1)) * getPlayerInfo(player).checkChallengeSinceTimer(challenge); } else if (sScale[1].charAt(0) == '/') { - reqAmount = Integer.parseInt(sScale[0]) / (Integer.parseInt(sScale[1].substring(1)) * getInstance().getActivePlayers().get(player.getName()).checkChallengeSinceTimer(challenge)); + reqAmount = Integer.parseInt(sScale[0]) / (Integer.parseInt(sScale[1].substring(1)) * getPlayerInfo(player).checkChallengeSinceTimer(challenge)); } } reqMod = Integer.parseInt(sPart[1]); @@ -1476,7 +1436,7 @@ public boolean giveReward(final Player player, final String challenge) { double rewCurrency = 0.0; player.sendMessage(ChatColor.GREEN + "You have completed the " + challenge + " challenge!"); String[] rewList; - if (getInstance().getActivePlayers().get(player.getName()).checkChallenge(challenge) == 0) { + if (getPlayerInfo(player).checkChallenge(challenge) == 0) { rewList = this.getConfig().getString("options.challenges.challengeList." + challenge.toLowerCase() + ".itemReward").split(" "); if (Settings.challenges_enableEconomyPlugin && VaultHandler.hasEcon()) { rewCurrency = this.getConfig().getInt("options.challenges.challengeList." + challenge.toLowerCase() + ".currencyReward"); @@ -1511,7 +1471,7 @@ public boolean giveReward(final Player player, final String challenge) { rewBonus += 0.2; } VaultHandler.depositPlayer(player.getName(), rewCurrency * rewBonus); - if (getInstance().getActivePlayers().get(player.getName()).checkChallenge(challenge) > 0) { + if (getPlayerInfo(player).checkChallenge(challenge) > 0) { player.giveExp(getInstance().getConfig().getInt("options.challenges.challengeList." + challenge + ".repeatXpReward")); player.sendMessage(ChatColor.YELLOW + "Repeat reward(s): " + ChatColor.WHITE + getInstance().getConfig().getString("options.challenges.challengeList." + challenge + ".repeatRewardText")); player.sendMessage(ChatColor.YELLOW + "Repeat exp reward: " + ChatColor.WHITE + getInstance().getConfig().getInt("options.challenges.challengeList." + challenge + ".repeatXpReward")); @@ -1525,7 +1485,7 @@ public boolean giveReward(final Player player, final String challenge) { player.sendMessage(ChatColor.YELLOW + "Exp reward: " + ChatColor.WHITE + getInstance().getConfig().getInt("options.challenges.challengeList." + challenge + ".xpReward")); player.sendMessage(ChatColor.YELLOW + "Currency reward: " + ChatColor.WHITE + this.df.format(getInstance().getConfig().getInt("options.challenges.challengeList." + challenge + ".currencyReward") * rewBonus) + " " + VaultHandler.getEcon().currencyNamePlural() + "\u00a7a(+" + this.df.format((rewBonus - 1.0) * 100.0) + "%)"); } - } else if (getInstance().getActivePlayers().get(player.getName()).checkChallenge(challenge) > 0) { + } else if (getPlayerInfo(player).checkChallenge(challenge) > 0) { player.giveExp(getInstance().getConfig().getInt("options.challenges.challengeList." + challenge + ".repeatXpReward")); player.sendMessage(ChatColor.YELLOW + "Repeat reward(s): " + ChatColor.WHITE + getInstance().getConfig().getString("options.challenges.challengeList." + challenge + ".repeatRewardText")); player.sendMessage(ChatColor.YELLOW + "Repeat exp reward: " + ChatColor.WHITE + getInstance().getConfig().getInt("options.challenges.challengeList." + challenge + ".repeatXpReward")); @@ -1559,7 +1519,7 @@ public boolean giveReward(final Player player, final String challenge) { player.getInventory().addItem(new ItemStack[]{new ItemStack(rewItem, rewAmount, (short) rewMod)}); } } - getInstance().getActivePlayers().get(player.getName()).completeChallenge(challenge); + getPlayerInfo(player).completeChallenge(challenge); return true; } @@ -1906,8 +1866,8 @@ public boolean changePlayerBiome(final Player player, final String bName) { if (!VaultHandler.checkPerk(player.getName(), "usb.biome." + bName, player.getWorld())) { return false; } - if (getIslandConfig(getInstance().getActivePlayers().get(player.getName()).locationForParty()).getBoolean("party.members." + player.getName() + ".canChangeBiome")) { - this.setBiome(getInstance().getActivePlayers().get(player.getName()).getIslandLocation(), bName); + if (getIslandConfig(getPlayerInfo(player).locationForParty()).getBoolean("party.members." + player.getName() + ".canChangeBiome")) { + this.setBiome(getPlayerInfo(player).getIslandLocation(), bName); this.setConfigBiome(player, bName); return true; } @@ -1954,97 +1914,99 @@ public boolean createIsland(final CommandSender sender, final PlayerInfo pi) { final Location last = getInstance().getLastIsland(); last.setY((double) Settings.island_height); try { - while (getInstance().hasOrphanedIsland()) { - if (!getInstance().islandAtLocation(getInstance().checkOrphan())) { - break; - } - getInstance().removeNextOrphan(); - } - while (getInstance().hasOrphanedIsland() && !getInstance().checkOrphan().getWorld().getName().equalsIgnoreCase(Settings.general_worldName)) { - getInstance().removeNextOrphan(); + Location next = getNextIslandLocation(last); + createIsland(player, next); + setNewPlayerIsland(player, next); + player.getInventory().clear(); + player.getEquipment().clear(); + getInstance().changePlayerBiome(player, "OCEAN"); + refreshIslandChunks(next); + clearEntitiesNearPlayer(player); + protectWithWorldGuard(sender, player, pi); + } catch (Exception ex) { + player.sendMessage("Could not create your Island. Please contact a server moderator."); + ex.printStackTrace(); + return false; + } + System.out.println("Finished creating player island."); + return true; + } + + private void protectWithWorldGuard(CommandSender sender, Player player, PlayerInfo pi) { + if (Settings.island_protectWithWorldGuard && Bukkit.getServer().getPluginManager().isPluginEnabled("WorldGuard")) { + if (!WorldGuardHandler.protectIsland(player, sender.getName(), pi)) { + sender.sendMessage("Player doesn't have an island or it's already protected!"); } - Location next; - if (getInstance().hasOrphanedIsland() && !getInstance().islandAtLocation(getInstance().checkOrphan())) { - next = getInstance().getOrphanedIsland(); - getInstance().saveOrphans(); - } else { - next = this.nextIslandLocation(last); - getInstance().setLastIsland(next); - while (getInstance().islandAtLocation(next)) { - next = this.nextIslandLocation(next); - } - while (getInstance().islandInSpawn(next)) { - next = this.nextIslandLocation(next); + } + } + + private void createIsland(Player player, Location next) throws DataException, IOException, MaxChangedBlocksException { + boolean hasIslandNow = false; + if (getInstance().getSchemFile().length > 0 && Bukkit.getServer().getPluginManager().isPluginEnabled("WorldEdit")) { + String cSchem = ""; + for (int i = 0; i < getInstance().getSchemFile().length; ++i) { + if (!hasIslandNow) { + if (getInstance().getSchemFile()[i].getName().lastIndexOf(46) > 0) { + cSchem = getInstance().getSchemFile()[i].getName().substring(0, getInstance().getSchemFile()[i].getName().lastIndexOf(46)); + } else { + cSchem = getInstance().getSchemFile()[i].getName(); + } + if (VaultHandler.checkPerk(player.getName(), "usb.schematic." + cSchem, getSkyBlockWorld()) && WorldEditHandler.loadIslandSchematic(getSkyBlockWorld(), getInstance().getSchemFile()[i], next)) { + this.setChest(next, player); + hasIslandNow = true; + } } - getInstance().setLastIsland(next); } - boolean hasIslandNow = false; - if (getInstance().getSchemFile().length > 0 && Bukkit.getServer().getPluginManager().isPluginEnabled("WorldEdit")) { - String cSchem = ""; + if (!hasIslandNow) { for (int i = 0; i < getInstance().getSchemFile().length; ++i) { - if (!hasIslandNow) { - if (getInstance().getSchemFile()[i].getName().lastIndexOf(46) > 0) { - cSchem = getInstance().getSchemFile()[i].getName().substring(0, getInstance().getSchemFile()[i].getName().lastIndexOf(46)); - } else { - cSchem = getInstance().getSchemFile()[i].getName(); - } - if (VaultHandler.checkPerk(player.getName(), "usb.schematic." + cSchem, getSkyBlockWorld()) && WorldEditHandler.loadIslandSchematic(getSkyBlockWorld(), getInstance().getSchemFile()[i], next)) { - this.setChest(next, player); - hasIslandNow = true; - } + if (getInstance().getSchemFile()[i].getName().lastIndexOf(46) > 0) { + cSchem = getInstance().getSchemFile()[i].getName().substring(0, getInstance().getSchemFile()[i].getName().lastIndexOf(46)); + } else { + cSchem = getInstance().getSchemFile()[i].getName(); } - } - if (!hasIslandNow) { - for (int i = 0; i < getInstance().getSchemFile().length; ++i) { - if (getInstance().getSchemFile()[i].getName().lastIndexOf(46) > 0) { - cSchem = getInstance().getSchemFile()[i].getName().substring(0, getInstance().getSchemFile()[i].getName().lastIndexOf(46)); - } else { - cSchem = getInstance().getSchemFile()[i].getName(); - } - if (cSchem.equalsIgnoreCase(Settings.island_schematicName) && WorldEditHandler.loadIslandSchematic(getSkyBlockWorld(), getInstance().getSchemFile()[i], next)) { - this.setChest(next, player); - hasIslandNow = true; - } + if (cSchem.equalsIgnoreCase(Settings.island_schematicName) && WorldEditHandler.loadIslandSchematic(getSkyBlockWorld(), getInstance().getSchemFile()[i], next)) { + this.setChest(next, player); + hasIslandNow = true; } } } - if (!hasIslandNow) { - if (!Settings.island_useOldIslands) { - this.generateIslandBlocks(next.getBlockX(), next.getBlockZ(), player, getSkyBlockWorld()); - } else { - this.oldGenerateIslandBlocks(next.getBlockX(), next.getBlockZ(), player, getSkyBlockWorld()); - } + } + if (!hasIslandNow) { + if (!Settings.island_useOldIslands) { + this.generateIslandBlocks(next.getBlockX(), next.getBlockZ(), player, getSkyBlockWorld()); + } else { + this.oldGenerateIslandBlocks(next.getBlockX(), next.getBlockZ(), player, getSkyBlockWorld()); } - next.setY((double) Settings.island_height); - System.out.println(next.getBlockY()); - System.out.println("Preparing to set new player information..."); - this.setNewPlayerIsland(player, next); - System.out.println("Finished setting new player information."); - player.getInventory().clear(); - player.getEquipment().clear(); - System.out.println("Preparing to set initial player biome..."); - getInstance().changePlayerBiome(player, "OCEAN"); - System.out.println("Finished setting initial player biome."); - for (int x = Settings.island_protectionRange / 2 * -1 - 16; x <= Settings.island_protectionRange / 2 + 16; x += 16) { - for (int z = Settings.island_protectionRange / 2 * -1 - 16; z <= Settings.island_protectionRange / 2 + 16; z += 16) { - getSkyBlockWorld().refreshChunk((next.getBlockX() + x) / 16, (next.getBlockZ() + z) / 16); - } + } + next.setY((double) Settings.island_height); + } + + private Location getNextIslandLocation(Location last) { + while (getInstance().hasOrphanedIsland()) { + if (!getInstance().islandAtLocation(getInstance().checkOrphan())) { + break; } - for (final Entity tempent : player.getNearbyEntities(50.0, 250.0, 50.0)) { - if (!(tempent instanceof Player)) { - tempent.remove(); - } + getInstance().removeNextOrphan(); + } + while (getInstance().hasOrphanedIsland() && !getInstance().checkOrphan().getWorld().getName().equalsIgnoreCase(Settings.general_worldName)) { + getInstance().removeNextOrphan(); + } + Location next; + if (getInstance().hasOrphanedIsland() && !getInstance().islandAtLocation(getInstance().checkOrphan())) { + next = getInstance().getOrphanedIsland(); + getInstance().saveOrphans(); + } else { + next = this.nextIslandLocation(last); + getInstance().setLastIsland(next); + while (getInstance().islandAtLocation(next)) { + next = this.nextIslandLocation(next); } - if (Settings.island_protectWithWorldGuard && Bukkit.getServer().getPluginManager().isPluginEnabled("WorldGuard")) { - WorldGuardHandler.protectIsland(player, sender.getName(), pi); + while (getInstance().islandInSpawn(next)) { + next = this.nextIslandLocation(next); } - } catch (Exception ex) { - player.sendMessage("Could not create your Island. Pleace contact a server moderator."); - ex.printStackTrace(); - return false; + getInstance().setLastIsland(next); } - System.out.println("Finished creating player island."); - return true; + return next; } public void generateIslandBlocks(final int x, final int z, final Player player, final World world) { @@ -2278,6 +2240,7 @@ private void islandExtras(final int x, final int z, final Player player, final W blockToChange.setTypeId(18); blockToChange = world.getBlockAt(x, Settings.island_height + 5, z + 1); blockToChange.setTypeId(54); + blockToChange.setData((byte) 3); final Chest chest = (Chest) blockToChange.getState(); final Inventory inventory = chest.getInventory(); inventory.clear(); @@ -2358,15 +2321,15 @@ public Location getChestSpawnLoc(final Location loc, final Player player) { } private void setNewPlayerIsland(final Player player, final Location loc) { - getInstance().getActivePlayers().get(player.getName()).startNewIsland(loc); + getPlayerInfo(player).startNewIsland(loc); player.teleport(this.getChestSpawnLoc(loc, player)); - if (this.getIslandConfig(getInstance().getActivePlayers().get(player.getName()).locationForParty()) == null) { - this.createIslandConfig(getInstance().getActivePlayers().get(player.getName()).locationForParty(), player.getName()); + if (this.getIslandConfig(getPlayerInfo(player).locationForParty()) == null) { + this.createIslandConfig(getPlayerInfo(player).locationForParty(), player.getName()); } - this.clearIslandConfig(getInstance().getActivePlayers().get(player.getName()).locationForParty(), player.getName()); + this.clearIslandConfig(getPlayerInfo(player).locationForParty(), player.getName()); getInstance().updatePartyNumber(player); getInstance().homeSet(player); - getInstance().getActivePlayers().get(player.getName()).savePlayerConfig(player.getName()); + getPlayerInfo(player).savePlayerConfig(player.getName()); } public void setWarpLocation(final String location, final Location loc) { @@ -2411,37 +2374,37 @@ public void displayIslandConfigs() { } public void updatePartyNumber(final Player player) { - if (getIslandConfig(getInstance().getActivePlayers().get(player.getName()).locationForParty()).getInt("party.maxSize") < 8 && VaultHandler.checkPerk(player.getName(), "usb.extra.partysize", player.getWorld())) { - getIslandConfig(getInstance().getActivePlayers().get(player.getName()).locationForParty()).set("party.maxSize", 8); - getInstance().saveIslandConfig(getInstance().getActivePlayers().get(player.getName()).locationForParty()); + if (getIslandConfig(getPlayerInfo(player).locationForParty()).getInt("party.maxSize") < 8 && VaultHandler.checkPerk(player.getName(), "usb.extra.partysize", player.getWorld())) { + getIslandConfig(getPlayerInfo(player).locationForParty()).set("party.maxSize", 8); + getInstance().saveIslandConfig(getPlayerInfo(player).locationForParty()); return; } - if (getIslandConfig(getInstance().getActivePlayers().get(player.getName()).locationForParty()).getInt("party.maxSize") < 7 && VaultHandler.checkPerk(player.getName(), "usb.extra.party3", player.getWorld())) { - getIslandConfig(getInstance().getActivePlayers().get(player.getName()).locationForParty()).set("party.maxSize", 7); - getInstance().saveIslandConfig(getInstance().getActivePlayers().get(player.getName()).locationForParty()); + if (getIslandConfig(getPlayerInfo(player).locationForParty()).getInt("party.maxSize") < 7 && VaultHandler.checkPerk(player.getName(), "usb.extra.party3", player.getWorld())) { + getIslandConfig(getPlayerInfo(player).locationForParty()).set("party.maxSize", 7); + getInstance().saveIslandConfig(getPlayerInfo(player).locationForParty()); return; } - if (getIslandConfig(getInstance().getActivePlayers().get(player.getName()).locationForParty()).getInt("party.maxSize") < 6 && VaultHandler.checkPerk(player.getName(), "usb.extra.party2", player.getWorld())) { - getIslandConfig(getInstance().getActivePlayers().get(player.getName()).locationForParty()).set("party.maxSize", 6); - getInstance().saveIslandConfig(getInstance().getActivePlayers().get(player.getName()).locationForParty()); + if (getIslandConfig(getPlayerInfo(player).locationForParty()).getInt("party.maxSize") < 6 && VaultHandler.checkPerk(player.getName(), "usb.extra.party2", player.getWorld())) { + getIslandConfig(getPlayerInfo(player).locationForParty()).set("party.maxSize", 6); + getInstance().saveIslandConfig(getPlayerInfo(player).locationForParty()); return; } - if (getIslandConfig(getInstance().getActivePlayers().get(player.getName()).locationForParty()).getInt("party.maxSize") < 5 && VaultHandler.checkPerk(player.getName(), "usb.extra.party1", player.getWorld())) { - getIslandConfig(getInstance().getActivePlayers().get(player.getName()).locationForParty()).set("party.maxSize", 5); - getInstance().saveIslandConfig(getInstance().getActivePlayers().get(player.getName()).locationForParty()); + if (getIslandConfig(getPlayerInfo(player).locationForParty()).getInt("party.maxSize") < 5 && VaultHandler.checkPerk(player.getName(), "usb.extra.party1", player.getWorld())) { + getIslandConfig(getPlayerInfo(player).locationForParty()).set("party.maxSize", 5); + getInstance().saveIslandConfig(getPlayerInfo(player).locationForParty()); } } public void changePlayerPermission(final Player player, final String playername, final String perm) { - if (!getIslandConfig(getInstance().getActivePlayers().get(player.getName()).locationForParty()).contains("party.members." + playername + "." + perm)) { + if (!getIslandConfig(getPlayerInfo(player).locationForParty()).contains("party.members." + playername + "." + perm)) { return; } - if (getIslandConfig(getInstance().getActivePlayers().get(player.getName()).locationForParty()).getBoolean("party.members." + playername + "." + perm)) { - getIslandConfig(getInstance().getActivePlayers().get(player.getName()).locationForParty()).set("party.members." + playername + "." + perm, false); + if (getIslandConfig(getPlayerInfo(player).locationForParty()).getBoolean("party.members." + playername + "." + perm)) { + getIslandConfig(getPlayerInfo(player).locationForParty()).set("party.members." + playername + "." + perm, false); } else { - getIslandConfig(getInstance().getActivePlayers().get(player.getName()).locationForParty()).set("party.members." + playername + "." + perm, true); + getIslandConfig(getPlayerInfo(player).locationForParty()).set("party.members." + playername + "." + perm, true); } - getInstance().saveIslandConfig(getInstance().getActivePlayers().get(player.getName()).locationForParty()); + getInstance().saveIslandConfig(getPlayerInfo(player).locationForParty()); } public boolean checkForOnlineMembers(final Player p) { diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index b299500ca..e36277ed1 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -22,6 +22,17 @@ options: extremebonus: 352:8 263:4 donorbonus: 261:1 262:32 272:1 protectWithWorldGuard: false + worldGuardFlags: + ALL: + pvp: 'deny' + chest-access: 'deny' + use: 'deny' + destroy-vehicle: 'deny' + entity-item-frame-destroy: 'deny' + entity-painting-destroy: 'deny' + OWNERS: + use: 'allow' + chest-access: 'allow' protectionRange: 105 allowPvP: deny allowIslandLock: true