From c193d2d7c532adf3206228c2b276244d8991d381 Mon Sep 17 00:00:00 2001 From: Esophose Date: Mon, 27 May 2019 10:28:42 -0600 Subject: [PATCH] Teleporting to island by coordinates, change some event priorities --- build.gradle | 2 +- .../skyblock/island/IslandManager.java | 10 ++++++---- .../goodandevil/skyblock/listeners/Block.java | 4 ++-- .../skyblock/listeners/Interact.java | 2 +- .../me/goodandevil/skyblock/listeners/Move.java | 17 ++++++++++++++--- 5 files changed, 24 insertions(+), 11 deletions(-) diff --git a/build.gradle b/build.gradle index 2a51ed97..3f79d2cc 100644 --- a/build.gradle +++ b/build.gradle @@ -2,7 +2,7 @@ import org.apache.tools.ant.filters.ReplaceTokens apply plugin: 'java' group 'com.songoda.fabledskyblock' -version 'Build-75' +version 'Build-76' sourceCompatibility = 1.8 diff --git a/src/main/java/me/goodandevil/skyblock/island/IslandManager.java b/src/main/java/me/goodandevil/skyblock/island/IslandManager.java index 2fe4b2d7..4a35c27e 100644 --- a/src/main/java/me/goodandevil/skyblock/island/IslandManager.java +++ b/src/main/java/me/goodandevil/skyblock/island/IslandManager.java @@ -555,11 +555,12 @@ public class IslandManager { return null; } - public void loadIslandAtLocation(Location location) { + public Island loadIslandAtLocation(Location location) { FileManager fileManager = skyblock.getFileManager(); File configFile = new File(skyblock.getDataFolder().toString() + "/island-data"); - if (!configFile.exists()) return; + if (!configFile.exists()) + return null; for (File fileList : configFile.listFiles()) { if (fileList != null && fileList.getName().contains(".yml") && fileList.getName().length() > 35) { @@ -576,14 +577,15 @@ public class IslandManager { if (LocationUtil.isLocationAtLocationRadius(location, islandLocation, size)) { UUID islandOwnerUUID = UUID.fromString(fileList.getName().replace(".yml", "")); - this.loadIsland(Bukkit.getOfflinePlayer(islandOwnerUUID)); - return; + return this.loadIsland(Bukkit.getOfflinePlayer(islandOwnerUUID)); } } catch (Exception e) { e.printStackTrace(); } } } + + return null; } public void unloadIsland(Island island, org.bukkit.OfflinePlayer player) { diff --git a/src/main/java/me/goodandevil/skyblock/listeners/Block.java b/src/main/java/me/goodandevil/skyblock/listeners/Block.java index b9be762b..5e155f01 100644 --- a/src/main/java/me/goodandevil/skyblock/listeners/Block.java +++ b/src/main/java/me/goodandevil/skyblock/listeners/Block.java @@ -45,7 +45,7 @@ public class Block implements Listener { } @SuppressWarnings("deprecation") - @EventHandler + @EventHandler(priority = EventPriority.LOW) public void onBlockBreak(BlockBreakEvent event) { Player player = event.getPlayer(); org.bukkit.block.Block block = event.getBlock(); @@ -159,7 +159,7 @@ public class Block implements Listener { } } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + @EventHandler(priority = EventPriority.LOW) public void onBlockPlace(BlockPlaceEvent event) { Player player = event.getPlayer(); org.bukkit.block.Block block = event.getBlock(); diff --git a/src/main/java/me/goodandevil/skyblock/listeners/Interact.java b/src/main/java/me/goodandevil/skyblock/listeners/Interact.java index 8ae11a21..19e7f0c5 100644 --- a/src/main/java/me/goodandevil/skyblock/listeners/Interact.java +++ b/src/main/java/me/goodandevil/skyblock/listeners/Interact.java @@ -49,7 +49,7 @@ public class Interact implements Listener { } @SuppressWarnings("deprecation") - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onPlayerInteract(PlayerInteractEvent event) { Player player = event.getPlayer(); org.bukkit.block.Block block = event.getClickedBlock(); diff --git a/src/main/java/me/goodandevil/skyblock/listeners/Move.java b/src/main/java/me/goodandevil/skyblock/listeners/Move.java index e88dd1b8..d78b5269 100644 --- a/src/main/java/me/goodandevil/skyblock/listeners/Move.java +++ b/src/main/java/me/goodandevil/skyblock/listeners/Move.java @@ -40,7 +40,7 @@ public class Move implements Listener { Location from = event.getFrom(); Location to = event.getTo(); - if (from.getX() == to.getX() && from.getY() == to.getY() && from.getZ() == to.getZ()) { + if (to == null || (from.getBlockX() == to.getBlockX() && from.getBlockY() == to.getBlockY() && from.getBlockZ() == to.getBlockZ())) { return; } @@ -51,7 +51,8 @@ public class Move implements Listener { WorldManager worldManager = skyblock.getWorldManager(); FileManager fileManager = skyblock.getFileManager(); - if (!worldManager.isIslandWorld(player.getWorld())) return; + if (!worldManager.isIslandWorld(player.getWorld())) + return; IslandWorld world = worldManager.getIslandWorld(player.getWorld()); @@ -187,7 +188,7 @@ public class Move implements Listener { if (LocationUtil.isLocationAtLocationRadius(to, island.getLocation(world, IslandEnvironment.Island), island.getRadius() + 2)) { - if (!configLoad.getBoolean("Island.WorldBorder.Enable")) { + if (!configLoad.getBoolean("Island.WorldBorder.Enable") || !island.isBorder()) { player.teleport(player.getLocation() .add(from.toVector().subtract(to.toVector()).normalize().multiply(2.0D))); player.setFallDistance(0.0F); @@ -212,6 +213,16 @@ public class Move implements Listener { } } + // Load the island they are now on if one exists + if (player.hasPermission("fabledskyblock.bypass")) { + Island loadedIsland = islandManager.loadIslandAtLocation(player.getLocation()); + if (loadedIsland != null) { + Bukkit.broadcastMessage("Sidestepped normal rules for bypass user"); + playerData.setIsland(loadedIsland.getOwnerUUID()); + return; + } + } + LocationUtil.teleportPlayerToSpawn(player); messageManager.sendMessage(player,