diff --git a/src/main/java/com/onarandombox/MultiverseNetherPortals/listeners/MVNPEntityListener.java b/src/main/java/com/onarandombox/MultiverseNetherPortals/listeners/MVNPEntityListener.java index 8db94c4..af1f6df 100644 --- a/src/main/java/com/onarandombox/MultiverseNetherPortals/listeners/MVNPEntityListener.java +++ b/src/main/java/com/onarandombox/MultiverseNetherPortals/listeners/MVNPEntityListener.java @@ -316,11 +316,10 @@ public void onEntityPortal(EntityPortalEvent event) { return; } - // Some shortcuts for later Entity entity = event.getEntity(); - Location fromLocation = this.locationManipulation.getBlockLocation(event.getFrom()); - Location originalToLocation = this.locationManipulation.getBlockLocation(event.getTo()); + Location fromLocation = event.getFrom(); + Location originalToLocation = event.getTo(); World fromWorld = fromLocation.getWorld(); World originalToWorld = originalToLocation.getWorld(); @@ -388,7 +387,7 @@ else if (fromWorld.getEnvironment() == World.Environment.NETHER && type == Porta } // If we are going to the end from anywhere else if (newToWorld.getEnvironment() == World.Environment.THE_END && type == PortalType.ENDER) { - Location spawnLocation = EndPlatformCreator.getVanillaLocation(newToWorld); + Location spawnLocation = EndPlatformCreator.getVanillaLocation(entity, newToWorld); event.setTo(spawnLocation); EndPlatformCreator.createEndPlatform(spawnLocation, plugin.isEndPlatformDropBlocks()); } diff --git a/src/main/java/com/onarandombox/MultiverseNetherPortals/listeners/MVNPPlayerListener.java b/src/main/java/com/onarandombox/MultiverseNetherPortals/listeners/MVNPPlayerListener.java index 9c04e70..c63433e 100644 --- a/src/main/java/com/onarandombox/MultiverseNetherPortals/listeners/MVNPPlayerListener.java +++ b/src/main/java/com/onarandombox/MultiverseNetherPortals/listeners/MVNPPlayerListener.java @@ -64,12 +64,14 @@ public void onPlayerPortal(PlayerPortalEvent event) { return; } + Player player = event.getPlayer(); + if (type == PortalType.NETHER) { try { Class.forName("org.bukkit.TravelAgent"); event.useTravelAgent(true); } catch (ClassNotFoundException ignore) { - Logging.fine("TravelAgent not available for PlayerPortalEvent for " + event.getPlayer().getName()); + Logging.fine("TravelAgent not available for PlayerPortalEvent for " + player.getName()); } } @@ -79,24 +81,24 @@ public void onPlayerPortal(PlayerPortalEvent event) { if (currentWorld.equalsIgnoreCase(linkedWorld)) { newTo = null; } else if (linkedWorld != null) { - newTo = this.linkChecker.findNewTeleportLocation(currentLocation, linkedWorld, event.getPlayer()); + newTo = this.linkChecker.findNewTeleportLocation(currentLocation, linkedWorld, player); } else if (this.nameChecker.isValidNetherName(currentWorld)) { if (type == PortalType.NETHER) { - newTo = this.linkChecker.findNewTeleportLocation(currentLocation, this.nameChecker.getNormalName(currentWorld, PortalType.NETHER), event.getPlayer()); + newTo = this.linkChecker.findNewTeleportLocation(currentLocation, this.nameChecker.getNormalName(currentWorld, PortalType.NETHER), player); } else { - newTo = this.linkChecker.findNewTeleportLocation(currentLocation, this.nameChecker.getEndName(this.nameChecker.getNormalName(currentWorld, PortalType.NETHER)), event.getPlayer()); + newTo = this.linkChecker.findNewTeleportLocation(currentLocation, this.nameChecker.getEndName(this.nameChecker.getNormalName(currentWorld, PortalType.NETHER)), player); } } else if (this.nameChecker.isValidEndName(currentWorld)) { if (type == PortalType.NETHER) { - newTo = this.linkChecker.findNewTeleportLocation(currentLocation, this.nameChecker.getNetherName(this.nameChecker.getNormalName(currentWorld, PortalType.ENDER)), event.getPlayer()); + newTo = this.linkChecker.findNewTeleportLocation(currentLocation, this.nameChecker.getNetherName(this.nameChecker.getNormalName(currentWorld, PortalType.ENDER)), player); } else { - newTo = this.linkChecker.findNewTeleportLocation(currentLocation, this.nameChecker.getNormalName(currentWorld, PortalType.ENDER), event.getPlayer()); + newTo = this.linkChecker.findNewTeleportLocation(currentLocation, this.nameChecker.getNormalName(currentWorld, PortalType.ENDER), player); } } else { if (type == PortalType.ENDER) { - newTo = this.linkChecker.findNewTeleportLocation(currentLocation, this.nameChecker.getEndName(currentWorld), event.getPlayer()); + newTo = this.linkChecker.findNewTeleportLocation(currentLocation, this.nameChecker.getEndName(currentWorld), player); } else { - newTo = this.linkChecker.findNewTeleportLocation(currentLocation, this.nameChecker.getNetherName(currentWorld), event.getPlayer()); + newTo = this.linkChecker.findNewTeleportLocation(currentLocation, this.nameChecker.getNetherName(currentWorld), player); } } @@ -112,17 +114,17 @@ public void onPlayerPortal(PlayerPortalEvent event) { if (!event.isCancelled()) { if (fromWorld.getEnvironment() == World.Environment.THE_END && type == PortalType.ENDER) { - Logging.fine("Player '" + event.getPlayer().getName() + "' will be teleported to the spawn of '" + toWorld.getName() + "' since they used an end exit portal."); + Logging.fine("Player '" + player.getName() + "' will be teleported to the spawn of '" + toWorld.getName() + "' since they used an end exit portal."); try { Class.forName("org.bukkit.TravelAgent"); event.getPortalTravelAgent().setCanCreatePortal(false); } catch (ClassNotFoundException ignore) { - Logging.fine("TravelAgent not available for PlayerPortalEvent for " + event.getPlayer().getName() + ". There may be a portal created at spawn."); + Logging.fine("TravelAgent not available for PlayerPortalEvent for " + player.getName() + ". There may be a portal created at spawn."); } if (toWorld.getBedRespawn() - && event.getPlayer().getBedSpawnLocation() != null - && event.getPlayer().getBedSpawnLocation().getWorld().getUID() == toWorld.getCBWorld().getUID()) { - event.setTo(event.getPlayer().getBedSpawnLocation()); + && player.getBedSpawnLocation() != null + && player.getBedSpawnLocation().getWorld().getUID() == toWorld.getCBWorld().getUID()) { + event.setTo(player.getBedSpawnLocation()); } else { event.setTo(toWorld.getSpawnLocation()); } @@ -132,20 +134,20 @@ public void onPlayerPortal(PlayerPortalEvent event) { event.getPortalTravelAgent().setCanCreatePortal(true); event.setTo(event.getPortalTravelAgent().findOrCreate(event.getTo())); } catch (ClassNotFoundException ignore) { - Logging.fine("TravelAgent not available for PlayerPortalEvent for " + event.getPlayer().getName() + ". Their destination may not be correct."); + Logging.fine("TravelAgent not available for PlayerPortalEvent for " + player.getName() + ". Their destination may not be correct."); event.setTo(event.getTo()); } } else if (toWorld.getEnvironment() == World.Environment.THE_END && type == PortalType.ENDER) { - Location spawnLocation = EndPlatformCreator.getVanillaLocation(event.getTo().getWorld()); + Location spawnLocation = EndPlatformCreator.getVanillaLocation(player, event.getTo().getWorld()); event.setTo(spawnLocation); EndPlatformCreator.createEndPlatform(spawnLocation, plugin.isEndPlatformDropBlocks()); } // Advancements need to be triggered manually if (type == PortalType.NETHER && event.getTo().getWorld().getEnvironment() == World.Environment.NETHER) { - awardAdvancement(event.getPlayer(), enterNetherAdvancement, ENTER_NETHER_CRITERIA); + awardAdvancement(player, enterNetherAdvancement, ENTER_NETHER_CRITERIA); } else if (type == PortalType.ENDER && event.getTo().getWorld().getEnvironment() == World.Environment.THE_END) { - awardAdvancement(event.getPlayer(), enterEndAdvancement, ENTER_END_CRITERIA); + awardAdvancement(player, enterEndAdvancement, ENTER_END_CRITERIA); } } } diff --git a/src/main/java/com/onarandombox/MultiverseNetherPortals/utils/EndPlatformCreator.java b/src/main/java/com/onarandombox/MultiverseNetherPortals/utils/EndPlatformCreator.java index face112..1ea9854 100644 --- a/src/main/java/com/onarandombox/MultiverseNetherPortals/utils/EndPlatformCreator.java +++ b/src/main/java/com/onarandombox/MultiverseNetherPortals/utils/EndPlatformCreator.java @@ -2,12 +2,13 @@ import com.dumptruckman.minecraft.util.Logging; import com.onarandombox.MultiverseCore.api.MultiverseWorld; -import com.onarandombox.MultiverseNetherPortals.MultiverseNetherPortals; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; public class EndPlatformCreator { @@ -60,14 +61,16 @@ public static void createEndPlatform(Location spawnLocation, boolean dropEndBloc /** * The default vanilla location for the end platform */ - public static Location getVanillaLocation(World world) { - return new Location(world, 100, 49, 0, 90, 0); + public static Location getVanillaLocation(Entity entity, World world) { + return entity instanceof Player + ? new Location(world, 100, 49, 0, 90, 0) + : new Location(world, 100.5, 50, 0.5, 90, 0); } /** * The default vanilla location for the end platform */ - public static Location getVanillaLocation(MultiverseWorld world) { - return getVanillaLocation(world.getCBWorld()); + public static Location getVanillaLocation(Entity entity, MultiverseWorld world) { + return getVanillaLocation(entity, world.getCBWorld()); } }