From efe8e9a7f504aed2d187e4aeb3bc55460ddf8eca Mon Sep 17 00:00:00 2001 From: EdGruberman Date: Sun, 3 Feb 2013 12:55:51 -0700 Subject: [PATCH] Always return a TravelAgent; Fixes BUKKIT-3541 Recent changes caused PlayerPortalEvent to suddenly return null unexpectedly and could end up in NPEs resulting that did not before. This commit addresses that situation by always ensuring a TravelAgent instance is returned. The TravelAgent for world 0 is returned arbitrarily in an effort to compensate for plugins that are implementation dependent and expect some form of a TravelAgent to be accessible in the event at all times. --- src/main/java/net/minecraft/server/Entity.java | 2 +- src/main/java/net/minecraft/server/PlayerList.java | 2 +- src/main/java/org/bukkit/craftbukkit/CraftTravelAgent.java | 5 +++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java index 87efe2cb1f..71707ed197 100644 --- a/src/main/java/net/minecraft/server/Entity.java +++ b/src/main/java/net/minecraft/server/Entity.java @@ -1764,7 +1764,7 @@ public abstract class Entity { Location exit = exitWorld != null ? minecraftserver.getPlayerList().calculateTarget(enter, minecraftserver.getWorldServer(i)) : null; boolean useTravelAgent = exitWorld != null && !(this.dimension == 1 && exitWorld.dimension == 1); // don't use agent for custom worlds or return from THE_END - TravelAgent agent = exit != null ? (TravelAgent) ((CraftWorld) exit.getWorld()).getHandle().s() : null; + TravelAgent agent = exit != null ? (TravelAgent) ((CraftWorld) exit.getWorld()).getHandle().s() : org.bukkit.craftbukkit.CraftTravelAgent.DEFAULT; // return arbitrary TA to compensate for implementation dependent plugins EntityPortalEvent event = new EntityPortalEvent(this.getBukkitEntity(), enter, exit, agent); event.useTravelAgent(useTravelAgent); event.getEntity().getServer().getPluginManager().callEvent(event); diff --git a/src/main/java/net/minecraft/server/PlayerList.java b/src/main/java/net/minecraft/server/PlayerList.java index c9810b4b3b..b0bb672e3c 100644 --- a/src/main/java/net/minecraft/server/PlayerList.java +++ b/src/main/java/net/minecraft/server/PlayerList.java @@ -451,7 +451,7 @@ public abstract class PlayerList { } } - TravelAgent agent = exit != null ? (TravelAgent) ((CraftWorld) exit.getWorld()).getHandle().s() : null; + TravelAgent agent = exit != null ? (TravelAgent) ((CraftWorld) exit.getWorld()).getHandle().s() : org.bukkit.craftbukkit.CraftTravelAgent.DEFAULT; // return arbitrary TA to compensate for implementation dependent plugins PlayerPortalEvent event = new PlayerPortalEvent(entityplayer.getBukkitEntity(), enter, exit, agent, cause); event.useTravelAgent(useTravelAgent); Bukkit.getServer().getPluginManager().callEvent(event); diff --git a/src/main/java/org/bukkit/craftbukkit/CraftTravelAgent.java b/src/main/java/org/bukkit/craftbukkit/CraftTravelAgent.java index b21714e5f2..3a313e5349 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftTravelAgent.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftTravelAgent.java @@ -9,12 +9,17 @@ import org.bukkit.TravelAgent; public class CraftTravelAgent extends PortalTravelAgent implements TravelAgent { + public static TravelAgent DEFAULT = null; + private int searchRadius = 128; private int creationRadius = 16; private boolean canCreatePortal = true; public CraftTravelAgent(WorldServer worldserver) { super(worldserver); + if (DEFAULT == null && worldserver.dimension == 0) { + DEFAULT = (TravelAgent) worldserver.s(); + } } public Location findOrCreate(Location target) {