3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-18 20:40:08 +01:00

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.
Dieser Commit ist enthalten in:
EdGruberman 2013-02-03 12:55:51 -07:00 committet von feildmaster
Ursprung 4d3865a036
Commit efe8e9a7f5
3 geänderte Dateien mit 7 neuen und 2 gelöschten Zeilen

Datei anzeigen

@ -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);

Datei anzeigen

@ -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);

Datei anzeigen

@ -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) {