From 172238258ce9010910ee03af8f539987820283f1 Mon Sep 17 00:00:00 2001 From: tastybento Date: Sun, 1 Oct 2017 15:53:59 -0700 Subject: [PATCH] Added debug to nether portals and fixed chunk loading for levels. --- .../askyblock/LevelCalcByChunk.java | 15 +++++++++++---- .../askyblock/listeners/NetherPortals.java | 17 ++++++++++++++++- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/com/wasteofplastic/askyblock/LevelCalcByChunk.java b/src/com/wasteofplastic/askyblock/LevelCalcByChunk.java index 72de035fb..7d2aa23cb 100644 --- a/src/com/wasteofplastic/askyblock/LevelCalcByChunk.java +++ b/src/com/wasteofplastic/askyblock/LevelCalcByChunk.java @@ -32,6 +32,7 @@ import org.apache.commons.lang.math.NumberUtils; import org.bukkit.ChatColor; +import org.bukkit.Chunk; import org.bukkit.ChunkSnapshot; import org.bukkit.World; import org.bukkit.command.CommandSender; @@ -125,11 +126,17 @@ public LevelCalcByChunk(final ASkyBlock plugin, final UUID targetPlayer, final C Set chunkSnapshot = new HashSet(); for (int x = island.getMinProtectedX(); x < (island.getMinProtectedX() + island.getProtectionSize() + 16); x += 16) { for (int z = island.getMinProtectedZ(); z < (island.getMinProtectedZ() + island.getProtectionSize() + 16); z += 16) { - if (!world.getBlockAt(x, 0, z).getChunk().isLoaded()) { - world.getBlockAt(x, 0, z).getChunk().load(); - chunkSnapshot.add(world.getBlockAt(x, 0, z).getChunk().getChunkSnapshot()); - world.getBlockAt(x, 0, z).getChunk().unload(); + if (!world.isChunkLoaded((int)((double)x/16), (int)((double)z/16))) { + //plugin.getLogger().info("DEBUG: chunk is not loaded"); + // If the chunk isn't already generated, don't try and generate it + if (world.loadChunk((int)((double)x/16), (int)((double)z/16), false)) { + //plugin.getLogger().info("DEBUG: chunk loaded"); + Chunk chunk = world.getChunkAt((int)((double)x/16), (int)((double)z/16)); + chunkSnapshot.add(chunk.getChunkSnapshot()); + //plugin.getLogger().info("DEBUG: unload = " + chunk.unload(false)); + } } else { + //plugin.getLogger().info("DEBUG: chunk is loaded"); chunkSnapshot.add(world.getBlockAt(x, 0, z).getChunk().getChunkSnapshot()); } //plugin.getLogger().info("DEBUG: getting chunk at " + x + ", " + z); diff --git a/src/com/wasteofplastic/askyblock/listeners/NetherPortals.java b/src/com/wasteofplastic/askyblock/listeners/NetherPortals.java index eb0c0bf77..f6578dfe0 100644 --- a/src/com/wasteofplastic/askyblock/listeners/NetherPortals.java +++ b/src/com/wasteofplastic/askyblock/listeners/NetherPortals.java @@ -121,7 +121,7 @@ public void onEntityPortal(EntityPortalEvent event) { @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onPlayerPortal(PlayerPortalEvent event) { if (DEBUG) - plugin.getLogger().info("Player portal event - reason =" + event.getCause()); + plugin.getLogger().info("DEBUG: Player portal event - reason = " + event.getCause()); UUID playerUUID = event.getPlayer().getUniqueId(); // If the nether is disabled then quit immediately if (!Settings.createNether || ASkyBlock.getNetherWorld() == null) { @@ -138,12 +138,27 @@ public void onPlayerPortal(PlayerPortalEvent event) { if ((island == null && !Settings.defaultWorldSettings.get(SettingsFlag.PORTAL)) || (island != null && !(island.getIgsFlag(SettingsFlag.PORTAL) || island.getMembers().contains(event.getPlayer().getUniqueId())))) { // Portals use is not allowed + if (DEBUG) + plugin.getLogger().info("DEBUG: portal use not allowed"); if (!event.getPlayer().isOp() && !VaultHelper.checkPerm(event.getPlayer(), Settings.PERMPREFIX + "mod.bypassprotect")) { Util.sendMessage(event.getPlayer(), ChatColor.RED + plugin.myLocale(event.getPlayer().getUniqueId()).islandProtected); event.setCancelled(true); return; } } + if (DEBUG) { + plugin.getLogger().info("DEBUG: portal use allowed"); + if (island != null) { + plugin.getLogger().info("DEBUG: island is not null, portal flag is " + island.getIgsFlag(SettingsFlag.PORTAL)); + plugin.getLogger().info("DEBUG: player is a member? " + island.getMembers().contains(event.getPlayer().getUniqueId())); + plugin.getLogger().info("DEBUG: player is op? " + event.getPlayer().isOp()); + plugin.getLogger().info("DEBUG: player has bypass perm? " + VaultHelper.checkPerm(event.getPlayer(), Settings.PERMPREFIX + "mod.bypassprotect")); + } else { + plugin.getLogger().info("DEBUG: island is null, default portal flag is " + Settings.defaultWorldSettings.get(SettingsFlag.PORTAL)); + plugin.getLogger().info("DEBUG: player is op? " + event.getPlayer().isOp()); + plugin.getLogger().info("DEBUG: player has bypass perm? " + VaultHelper.checkPerm(event.getPlayer(), Settings.PERMPREFIX + "mod.bypassprotect")); + } + } // Determine what portal it is switch (event.getCause()) { case END_PORTAL: