Compensate for allow-nether/allow-end as false; Fixes BUKKIT-3466

When either of those settings are false, the worlds are not loaded and
therefore will not be targeted for portal exits.  Existing worlds are
iterated directly to avoid defaulting to the first world if a direct
dimension match is not found.

Plugins must also specify exit from custom Bukkit worlds to comply with
original commit: https://github.com/Bukkit/CraftBukkit/commit/2dc2af0

This commit introduces a constant to clarify the dependency on the
CraftBukkit implementation of custom worlds having a dimension offset.
Dieser Commit ist enthalten in:
EdGruberman 2013-01-22 18:36:03 -07:00 committet von feildmaster
Ursprung 488e45b4ff
Commit 9df87d3399
4 geänderte Dateien mit 38 neuen und 14 gelöschten Zeilen

Datei anzeigen

@ -1750,10 +1750,20 @@ public abstract class Entity {
MinecraftServer minecraftserver = MinecraftServer.getServer(); MinecraftServer minecraftserver = MinecraftServer.getServer();
// CraftBukkit start - move logic into new function "teleportToLocation" // CraftBukkit start - move logic into new function "teleportToLocation"
// int j = this.dimension; // int j = this.dimension;
Location enter = this.getBukkitEntity().getLocation(); WorldServer exitWorld = null;
Location exit = minecraftserver.getPlayerList().calculateTarget(enter, minecraftserver.getWorldServer(i)); if (this.dimension < CraftWorld.CUSTOM_DIMENSION_OFFSET) { // plugins must specify exit from custom Bukkit worlds
// only target existing worlds (compensate for allow-nether/allow-end as false)
for (WorldServer world : minecraftserver.worlds) {
if (world.dimension == i) {
exitWorld = world;
}
}
}
TravelAgent agent = (TravelAgent) ((CraftWorld) exit.getWorld()).getHandle().s(); Location enter = this.getBukkitEntity().getLocation();
Location exit = exitWorld != null ? minecraftserver.getPlayerList().calculateTarget(enter, minecraftserver.getWorldServer(i)) : null;
TravelAgent agent = exit != null ? (TravelAgent) ((CraftWorld) exit.getWorld()).getHandle().s() : null;
EntityPortalEvent event = new EntityPortalEvent(this.getBukkitEntity(), enter, exit, agent); EntityPortalEvent event = new EntityPortalEvent(this.getBukkitEntity(), enter, exit, agent);
event.getEntity().getServer().getPluginManager().callEvent(event); event.getEntity().getServer().getPluginManager().callEvent(event);
if (event.isCancelled() || event.getTo() == null || !this.isAlive()) { if (event.isCancelled() || event.getTo() == null || !this.isAlive()) {

Datei anzeigen

@ -424,23 +424,35 @@ public abstract class PlayerList {
// CraftBukkit start - Replaced the standard handling of portals with a more customised method. // CraftBukkit start - Replaced the standard handling of portals with a more customised method.
public void changeDimension(EntityPlayer entityplayer, int i, TeleportCause cause) { public void changeDimension(EntityPlayer entityplayer, int i, TeleportCause cause) {
WorldServer exitWorld = this.server.getWorldServer(i); WorldServer exitWorld = null;
Location enter = entityplayer.getBukkitEntity().getLocation(); if (entityplayer.dimension < CraftWorld.CUSTOM_DIMENSION_OFFSET) { // plugins must specify exit from custom Bukkit worlds
Location exit = null; // only target existing worlds (compensate for allow-nether/allow-end as false)
if ((cause == TeleportCause.END_PORTAL) && (i == 0)) { for (WorldServer world : this.server.worlds) {
// THE_END -> NORMAL; use bed if available if (world.dimension == i) {
exit = ((CraftPlayer) entityplayer.getBukkitEntity()).getBedSpawnLocation(); exitWorld = world;
} }
if (exit == null) { }
exit = this.calculateTarget(enter, exitWorld);
} }
TravelAgent agent = (TravelAgent) ((CraftWorld) exit.getWorld()).getHandle().s(); Location enter = entityplayer.getBukkitEntity().getLocation();
Location exit = null;
if (exitWorld != null) {
if ((cause == TeleportCause.END_PORTAL) && (i == 0)) {
// THE_END -> NORMAL; use bed if available
exit = ((CraftPlayer) entityplayer.getBukkitEntity()).getBedSpawnLocation();
}
if (exit == null) {
exit = this.calculateTarget(enter, exitWorld);
}
}
TravelAgent agent = exit != null ? (TravelAgent) ((CraftWorld) exit.getWorld()).getHandle().s() : null;
PlayerPortalEvent event = new PlayerPortalEvent(entityplayer.getBukkitEntity(), enter, exit, agent, cause); PlayerPortalEvent event = new PlayerPortalEvent(entityplayer.getBukkitEntity(), enter, exit, agent, cause);
Bukkit.getServer().getPluginManager().callEvent(event); Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled() || event.getTo() == null) { if (event.isCancelled() || event.getTo() == null) {
return; return;
} }
exit = event.useTravelAgent() ? event.getPortalTravelAgent().findOrCreate(exit) : event.getTo(); exit = event.useTravelAgent() ? event.getPortalTravelAgent().findOrCreate(exit) : event.getTo();
exitWorld = ((CraftWorld) exit.getWorld()).getHandle(); exitWorld = ((CraftWorld) exit.getWorld()).getHandle();

Datei anzeigen

@ -694,7 +694,7 @@ public final class CraftServer implements Server {
converter.convert(name, new ConvertProgressUpdater(console)); converter.convert(name, new ConvertProgressUpdater(console));
} }
int dimension = 10 + console.worlds.size(); int dimension = CraftWorld.CUSTOM_DIMENSION_OFFSET + console.worlds.size();
boolean used = false; boolean used = false;
do { do {
for (WorldServer server : console.worlds) { for (WorldServer server : console.worlds) {

Datei anzeigen

@ -49,6 +49,8 @@ import org.bukkit.plugin.messaging.StandardMessenger;
import org.bukkit.craftbukkit.util.LongHash; import org.bukkit.craftbukkit.util.LongHash;
public class CraftWorld implements World { public class CraftWorld implements World {
public static final int CUSTOM_DIMENSION_OFFSET = 10;
private final WorldServer world; private final WorldServer world;
private Environment environment; private Environment environment;
private final CraftServer server = (CraftServer) Bukkit.getServer(); private final CraftServer server = (CraftServer) Bukkit.getServer();