public void changeDimension(EntityPlayer entityplayer, int i, TeleportCause cause) {
WorldServer exitWorld = null;
if (entityplayer.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 : this.server.worlds) {
if (world.dimension == i) {
exitWorld = world;
}
}
}
Location enter = entityplayer.getBukkitEntity().getLocation();
Location exit = null;
boolean useTravelAgent = false; // don't use agent for custom worlds or return from THE_END
if (exitWorld != null) {
if ((cause == TeleportCause.END_PORTAL) && (i == 0)) {
// THE_END -> NORMAL; use bed if available, otherwise default spawn
exit = ((org.bukkit.craftbukkit.entity.CraftPlayer) entityplayer.getBukkitEntity()).getBedSpawnLocation();
if (exit == null || ((CraftWorld) exit.getWorld()).getHandle().dimension != 0) {
exit = exitWorld.getWorld().getSpawnLocation();
}
} else {
// NORMAL <-> NETHER or NORMAL -> THE_END
exit = this.calculateTarget(enter, exitWorld);
useTravelAgent = true;
}
}
TravelAgent agent = exit != null ? (TravelAgent) ((CraftWorld) exit.getWorld()).getHandle().getTravelAgent() : 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);
if (event.isCancelled() || event.getTo() == null) {
return;
}
exit = event.useTravelAgent() ? event.getPortalTravelAgent().findOrCreate(event.getTo()) : event.getTo();
if (exit == null) {
return;
}
exitWorld = ((CraftWorld) exit.getWorld()).getHandle();
Vector velocity = entityplayer.getBukkitEntity().getVelocity();
boolean before = exitWorld.chunkProviderServer.forceChunkLoad;
exitWorld.chunkProviderServer.forceChunkLoad = true;
exitWorld.getTravelAgent().adjustExit(entityplayer, exit, velocity);
exitWorld.chunkProviderServer.forceChunkLoad = before;
this.moveToWorld(entityplayer, exitWorld.dimension, true, exit, false); // Vanilla doesn't check for suffocation when handling portals, so neither should we
if (entityplayer.motX != velocity.getX() || entityplayer.motY != velocity.getY() || entityplayer.motZ != velocity.getZ()) {
entityplayer.getBukkitEntity().setVelocity(velocity);
}
// CraftBukkit end
}
PlayerList.java 文件源码
java
阅读 27
收藏 0
点赞 0
评论 0
项目:CraftBukkit
作者:
评论列表
文章目录