diff --git a/src/main/java/me/goodandevil/skyblock/listeners/Move.java b/src/main/java/me/goodandevil/skyblock/listeners/Move.java index eab52ce2..7e0ba76c 100644 --- a/src/main/java/me/goodandevil/skyblock/listeners/Move.java +++ b/src/main/java/me/goodandevil/skyblock/listeners/Move.java @@ -1,7 +1,17 @@ package me.goodandevil.skyblock.listeners; -import java.io.File; - +import me.goodandevil.skyblock.SkyBlock; +import me.goodandevil.skyblock.config.FileManager; +import me.goodandevil.skyblock.config.FileManager.Config; +import me.goodandevil.skyblock.island.*; +import me.goodandevil.skyblock.message.MessageManager; +import me.goodandevil.skyblock.playerdata.PlayerData; +import me.goodandevil.skyblock.playerdata.PlayerDataManager; +import me.goodandevil.skyblock.sound.SoundManager; +import me.goodandevil.skyblock.utils.version.NMSUtil; +import me.goodandevil.skyblock.utils.version.Sounds; +import me.goodandevil.skyblock.utils.world.LocationUtil; +import me.goodandevil.skyblock.world.WorldManager; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.attribute.Attribute; @@ -12,222 +22,207 @@ import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.potion.PotionEffect; -import me.goodandevil.skyblock.SkyBlock; -import me.goodandevil.skyblock.config.FileManager; -import me.goodandevil.skyblock.config.FileManager.Config; -import me.goodandevil.skyblock.island.Island; -import me.goodandevil.skyblock.island.IslandEnvironment; -import me.goodandevil.skyblock.island.IslandManager; -import me.goodandevil.skyblock.island.IslandRole; -import me.goodandevil.skyblock.island.IslandWorld; -import me.goodandevil.skyblock.message.MessageManager; -import me.goodandevil.skyblock.playerdata.PlayerData; -import me.goodandevil.skyblock.playerdata.PlayerDataManager; -import me.goodandevil.skyblock.sound.SoundManager; -import me.goodandevil.skyblock.utils.version.NMSUtil; -import me.goodandevil.skyblock.utils.version.Sounds; -import me.goodandevil.skyblock.utils.world.LocationUtil; -import me.goodandevil.skyblock.world.WorldManager; +import java.io.File; public class Move implements Listener { - private final SkyBlock skyblock; + private final SkyBlock skyblock; - public Move(SkyBlock skyblock) { - this.skyblock = skyblock; - } + public Move(SkyBlock skyblock) { + this.skyblock = skyblock; + } - @SuppressWarnings("deprecation") - @EventHandler - public void onPlayerMove(PlayerMoveEvent event) { - Player player = event.getPlayer(); + @SuppressWarnings("deprecation") + @EventHandler + public void onPlayerMove(PlayerMoveEvent event) { + Player player = event.getPlayer(); - Location from = event.getFrom(); - Location to = event.getTo(); + Location from = event.getFrom(); + Location to = event.getTo(); - if (from.getX() == to.getX() && from.getY() == to.getY() && from.getZ() == to.getZ()) { - return; - } + if (from.getX() == to.getX() && from.getY() == to.getY() && from.getZ() == to.getZ()) { + return; + } - PlayerDataManager playerDataManager = skyblock.getPlayerDataManager(); - MessageManager messageManager = skyblock.getMessageManager(); - IslandManager islandManager = skyblock.getIslandManager(); - SoundManager soundManager = skyblock.getSoundManager(); - WorldManager worldManager = skyblock.getWorldManager(); - FileManager fileManager = skyblock.getFileManager(); + PlayerDataManager playerDataManager = skyblock.getPlayerDataManager(); + MessageManager messageManager = skyblock.getMessageManager(); + IslandManager islandManager = skyblock.getIslandManager(); + SoundManager soundManager = skyblock.getSoundManager(); + WorldManager worldManager = skyblock.getWorldManager(); + FileManager fileManager = skyblock.getFileManager(); - if (worldManager.isIslandWorld(player.getWorld())) { - IslandWorld world = worldManager.getIslandWorld(player.getWorld()); + if (!worldManager.isIslandWorld(player.getWorld())) return; - if (world == IslandWorld.Nether || world == IslandWorld.End) { - if (!fileManager.getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration() - .getBoolean("Island.World." + world.name() + ".Enable")) { - Config config = fileManager.getConfig(new File(skyblock.getDataFolder(), "language.yml")); - FileConfiguration configLoad = config.getFileConfiguration(); + IslandWorld world = worldManager.getIslandWorld(player.getWorld()); - messageManager.sendMessage(player, configLoad.getString("Island.World.Message") - .replace(configLoad.getString("Island.World.Word." + world.name()), world.name())); + if (world == IslandWorld.Nether || world == IslandWorld.End) { + if (!fileManager.getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration() + .getBoolean("Island.World." + world.name() + ".Enable")) { + Config config = fileManager.getConfig(new File(skyblock.getDataFolder(), "language.yml")); + FileConfiguration configLoad = config.getFileConfiguration(); - if (playerDataManager.hasPlayerData(player)) { - PlayerData playerData = playerDataManager.getPlayerData(player); + messageManager.sendMessage(player, configLoad.getString("Island.World.Message") + .replace(configLoad.getString("Island.World.Word." + world.name()), world.name())); - if (playerData.getIsland() != null) { - Island island = islandManager - .getIsland(Bukkit.getServer().getOfflinePlayer(playerData.getIsland())); + if (playerDataManager.hasPlayerData(player)) { + PlayerData playerData = playerDataManager.getPlayerData(player); - if (island != null) { - if (island.hasRole(IslandRole.Member, player.getUniqueId()) - || island.hasRole(IslandRole.Operator, player.getUniqueId()) - || island.hasRole(IslandRole.Owner, player.getUniqueId())) { - player.teleport(island.getLocation(IslandWorld.Normal, IslandEnvironment.Main)); - } else { - player.teleport(island.getLocation(IslandWorld.Normal, IslandEnvironment.Visitor)); - } + if (playerData.getIsland() != null) { + Island island = islandManager + .getIsland(Bukkit.getServer().getOfflinePlayer(playerData.getIsland())); - player.setFallDistance(0.0F); - soundManager.playSound(player, Sounds.ENDERMAN_TELEPORT.bukkitSound(), 1.0F, 1.0F); + if (island != null) { + if (island.hasRole(IslandRole.Member, player.getUniqueId()) + || island.hasRole(IslandRole.Operator, player.getUniqueId()) + || island.hasRole(IslandRole.Owner, player.getUniqueId())) { + player.teleport(island.getLocation(IslandWorld.Normal, IslandEnvironment.Main)); + } else { + player.teleport(island.getLocation(IslandWorld.Normal, IslandEnvironment.Visitor)); + } - return; - } - } - } + player.setFallDistance(0.0F); + soundManager.playSound(player, Sounds.ENDERMAN_TELEPORT.bukkitSound(), 1.0F, 1.0F); - LocationUtil.teleportPlayerToSpawn(player); - soundManager.playSound(player, Sounds.ENDERMAN_TELEPORT.bukkitSound(), 1.0F, 1.0F); - } - } + return; + } + } + } - if (playerDataManager.hasPlayerData(player)) { - PlayerData playerData = playerDataManager.getPlayerData(player); + LocationUtil.teleportPlayerToSpawn(player); + soundManager.playSound(player, Sounds.ENDERMAN_TELEPORT.bukkitSound(), 1.0F, 1.0F); + } + } - if (playerData.getIsland() != null) { - Island island = islandManager - .getIsland(Bukkit.getServer().getOfflinePlayer(playerData.getIsland())); + if (playerDataManager.hasPlayerData(player)) { + PlayerData playerData = playerDataManager.getPlayerData(player); + + if (playerData.getIsland() != null) { + Island island = islandManager + .getIsland(Bukkit.getServer().getOfflinePlayer(playerData.getIsland())); - if (island != null) { - if (islandManager.isLocationAtIsland(island, to)) { - Config config = fileManager.getConfig(new File(skyblock.getDataFolder(), "config.yml")); - FileConfiguration configLoad = config.getFileConfiguration(); + if (island != null) { + if (islandManager.isLocationAtIsland(island, to)) { + Config config = fileManager.getConfig(new File(skyblock.getDataFolder(), "config.yml")); + FileConfiguration configLoad = config.getFileConfiguration(); - boolean keepItemsOnDeath; + boolean keepItemsOnDeath; - if (configLoad.getBoolean("Island.Settings.KeepItemsOnDeath.Enable")) { - if (island.getSetting(IslandRole.Owner, "KeepItemsOnDeath").getStatus()) { - keepItemsOnDeath = true; - } else { - keepItemsOnDeath = false; - } - } else if (configLoad.getBoolean("Island.KeepItemsOnDeath.Enable")) { - keepItemsOnDeath = true; - } else { - keepItemsOnDeath = false; - } + if (configLoad.getBoolean("Island.Settings.KeepItemsOnDeath.Enable")) { + if (island.getSetting(IslandRole.Owner, "KeepItemsOnDeath").getStatus()) { + keepItemsOnDeath = true; + } else { + keepItemsOnDeath = false; + } + } else if (configLoad.getBoolean("Island.KeepItemsOnDeath.Enable")) { + keepItemsOnDeath = true; + } else { + keepItemsOnDeath = false; + } - if (configLoad.getBoolean("Island.World." + world.name() + ".Liquid.Enable")) { - if (to.getY() <= configLoad.getInt("Island.World." + world.name() + ".Liquid.Height")) { - if (keepItemsOnDeath) { - player.setFallDistance(0.0F); + if (configLoad.getBoolean("Island.World." + world.name() + ".Liquid.Enable")) { + if (to.getY() <= configLoad.getInt("Island.World." + world.name() + ".Liquid.Height")) { + if (keepItemsOnDeath) { + player.setFallDistance(0.0F); - if (island.hasRole(IslandRole.Member, player.getUniqueId()) - || island.hasRole(IslandRole.Operator, player.getUniqueId()) - || island.hasRole(IslandRole.Owner, player.getUniqueId())) { - player.teleport( - island.getLocation(IslandWorld.Normal, IslandEnvironment.Main)); - } else { - player.teleport( - island.getLocation(IslandWorld.Normal, IslandEnvironment.Visitor)); - } + if (island.hasRole(IslandRole.Member, player.getUniqueId()) + || island.hasRole(IslandRole.Operator, player.getUniqueId()) + || island.hasRole(IslandRole.Owner, player.getUniqueId())) { + player.teleport( + island.getLocation(IslandWorld.Normal, IslandEnvironment.Main)); + } else { + player.teleport( + island.getLocation(IslandWorld.Normal, IslandEnvironment.Visitor)); + } - player.setFallDistance(0.0F); - soundManager.playSound(player, Sounds.ENDERMAN_TELEPORT.bukkitSound(), 1.0F, - 1.0F); - } + player.setFallDistance(0.0F); + soundManager.playSound(player, Sounds.ENDERMAN_TELEPORT.bukkitSound(), 1.0F, + 1.0F); + } - return; - } - } + return; + } + } - if (configLoad.getBoolean("Island.Void.Teleport.Enable")) { - if (to.getY() <= configLoad.getInt("Island.Void.Teleport.Offset")) { - if (!keepItemsOnDeath) { - player.getInventory().clear(); - player.setLevel(0); - player.setExp(0.0F); + if (configLoad.getBoolean("Island.Void.Teleport.Enable")) { + if (to.getY() <= configLoad.getInt("Island.Void.Teleport.Offset")) { + if (!keepItemsOnDeath) { + player.getInventory().clear(); + player.setLevel(0); + player.setExp(0.0F); - if (NMSUtil.getVersionNumber() > 8) { - player.setHealth( - player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()); - } else { - player.setHealth(player.getMaxHealth()); - } + if (NMSUtil.getVersionNumber() > 8) { + player.setHealth( + player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()); + } else { + player.setHealth(player.getMaxHealth()); + } - player.setFoodLevel(20); + player.setFoodLevel(20); - for (PotionEffect potionEffect : player.getActivePotionEffects()) { - player.removePotionEffect(potionEffect.getType()); - } - } + for (PotionEffect potionEffect : player.getActivePotionEffects()) { + player.removePotionEffect(potionEffect.getType()); + } + } - player.setFallDistance(0.0F); + player.setFallDistance(0.0F); - if (configLoad.getBoolean("Island.Void.Teleport.Island")) { - if (island.hasRole(IslandRole.Member, player.getUniqueId()) - || island.hasRole(IslandRole.Operator, player.getUniqueId()) - || island.hasRole(IslandRole.Owner, player.getUniqueId())) { - player.teleport( - island.getLocation(IslandWorld.Normal, IslandEnvironment.Main)); - } else { - player.teleport( - island.getLocation(IslandWorld.Normal, IslandEnvironment.Visitor)); - } - } else { - LocationUtil.teleportPlayerToSpawn(player); - } + if (configLoad.getBoolean("Island.Void.Teleport.Island")) { + if (island.hasRole(IslandRole.Member, player.getUniqueId()) + || island.hasRole(IslandRole.Operator, player.getUniqueId()) + || island.hasRole(IslandRole.Owner, player.getUniqueId())) { + player.teleport( + island.getLocation(IslandWorld.Normal, IslandEnvironment.Main)); + } else { + player.teleport( + island.getLocation(IslandWorld.Normal, IslandEnvironment.Visitor)); + } + } else { + LocationUtil.teleportPlayerToSpawn(player); + } - player.setFallDistance(0.0F); - soundManager.playSound(player, Sounds.ENDERMAN_TELEPORT.bukkitSound(), 1.0F, 1.0F); - } - } - } else { - Config config = skyblock.getFileManager() - .getConfig(new File(skyblock.getDataFolder(), "config.yml")); - FileConfiguration configLoad = config.getFileConfiguration(); + player.setFallDistance(0.0F); + soundManager.playSound(player, Sounds.ENDERMAN_TELEPORT.bukkitSound(), 1.0F, 1.0F); + } + } + } else { + Config config = skyblock.getFileManager() + .getConfig(new File(skyblock.getDataFolder(), "config.yml")); + FileConfiguration configLoad = config.getFileConfiguration(); - if (LocationUtil.isLocationAtLocationRadius(to, - island.getLocation(world, IslandEnvironment.Island), island.getRadius() + 2)) { - if(!configLoad.getBoolean("Island.WorldBorder.Enable")){ - player.teleport(player.getLocation() - .add(from.toVector().subtract(to.toVector()).normalize().multiply(2.0D))); - player.setFallDistance(0.0F); - soundManager.playSound(player, Sounds.ENDERMAN_TELEPORT.bukkitSound(), 1.0F, 1.0F); - } - } else { - if (island.getVisit().isVisitor(player.getUniqueId())) { - player.teleport(island.getLocation(world, IslandEnvironment.Visitor)); - } else { - player.teleport(island.getLocation(world, IslandEnvironment.Main)); - } + if (LocationUtil.isLocationAtLocationRadius(to, + island.getLocation(world, IslandEnvironment.Island), island.getRadius() + 2)) { + if (!configLoad.getBoolean("Island.WorldBorder.Enable")) { + player.teleport(player.getLocation() + .add(from.toVector().subtract(to.toVector()).normalize().multiply(2.0D))); + player.setFallDistance(0.0F); + soundManager.playSound(player, Sounds.ENDERMAN_TELEPORT.bukkitSound(), 1.0F, 1.0F); + } + } else { + if (island.getVisit().isVisitor(player.getUniqueId())) { + player.teleport(island.getLocation(world, IslandEnvironment.Visitor)); + } else { + player.teleport(island.getLocation(world, IslandEnvironment.Main)); + } - player.setFallDistance(0.0F); - messageManager.sendMessage(player, skyblock.getFileManager() - .getConfig(new File(skyblock.getDataFolder(), "language.yml")) - .getFileConfiguration().getString("Island.WorldBorder.Outside.Message")); - soundManager.playSound(player, Sounds.ENDERMAN_TELEPORT.bukkitSound(), 1.0F, 1.0F); - } - } + player.setFallDistance(0.0F); + messageManager.sendMessage(player, skyblock.getFileManager() + .getConfig(new File(skyblock.getDataFolder(), "language.yml")) + .getFileConfiguration().getString("Island.WorldBorder.Outside.Message")); + soundManager.playSound(player, Sounds.ENDERMAN_TELEPORT.bukkitSound(), 1.0F, 1.0F); + } + } - return; - } - } + return; + } + } - LocationUtil.teleportPlayerToSpawn(player); + LocationUtil.teleportPlayerToSpawn(player); - messageManager.sendMessage(player, - skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")) - .getFileConfiguration().getString("Island.WorldBorder.Disappeared.Message")); - soundManager.playSound(player, Sounds.ENDERMAN_TELEPORT.bukkitSound(), 1.0F, 1.0F); - } - } - } + messageManager.sendMessage(player, + skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")) + .getFileConfiguration().getString("Island.WorldBorder.Disappeared.Message")); + soundManager.playSound(player, Sounds.ENDERMAN_TELEPORT.bukkitSound(), 1.0F, 1.0F); + } + } }