Fixes a bug with EntityTeleportListener (#2222)

There was incorrect teleportation type detection, as target world were set to NORMAL. This prevented to detect that portal in opposite side exists, and should be linked to the correct position.
This commit is contained in:
BONNe 2023-11-10 17:23:38 +02:00 committed by GitHub
parent 5503ce0d90
commit 285205fe3f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 28 deletions

View File

@ -7,6 +7,7 @@
package world.bentobox.bentobox.listeners.teleports;
import java.util.Objects;
import java.util.UUID;
import org.bukkit.Bukkit;
@ -77,9 +78,30 @@ public class EntityTeleportListener extends AbstractTeleportListener implements
event.setCancelled(true);
return;
}
// Trigger event processor.
// Check which teleportation is happening.
World.Environment source = fromWorld.getEnvironment();
World.Environment destination = event.getTo().getWorld().getEnvironment();
if (World.Environment.NETHER == source && World.Environment.NORMAL == destination ||
World.Environment.NORMAL == source && World.Environment.NETHER == destination)
{
// Nether to overworld or opposite
this.portalProcess(event, World.Environment.NETHER);
}
else if (World.Environment.THE_END == source && World.Environment.NORMAL == destination ||
World.Environment.NORMAL == source && World.Environment.THE_END == destination)
{
// end to overworld or opposite
this.portalProcess(event, World.Environment.THE_END);
}
else
{
// unknown teleportation
this.portalProcess(event, event.getTo().getWorld().getEnvironment());
}
}
/**
@ -224,33 +246,25 @@ public class EntityTeleportListener extends AbstractTeleportListener implements
}
this.inTeleport.add(event.getEntity().getUniqueId());
// Get target world.
World toWorld;
if (environment.equals(World.Environment.NORMAL))
{
toWorld = overWorld;
}
else
{
toWorld = this.getNetherEndWorld(overWorld, environment);
}
if (!overWorld.equals(toWorld) && !this.isIslandWorld(overWorld, environment))
if (fromWorld.equals(overWorld) && !this.isIslandWorld(overWorld, environment))
{
// This is not island world. Use standard nether or end world teleportation.
this.handleToStandardNetherOrEnd(event, overWorld, toWorld);
this.handleToStandardNetherOrEnd(event, overWorld, environment);
return;
}
if (!overWorld.equals(fromWorld) && !this.isIslandWorld(overWorld, environment))
if (!fromWorld.equals(overWorld) && !this.isIslandWorld(overWorld, environment))
{
// If entering a portal in the other world, teleport to a portal in overworld if
// there is one
this.handleFromStandardNetherOrEnd(event, overWorld, toWorld.getEnvironment());
this.handleFromStandardNetherOrEnd(event, overWorld, environment);
return;
}
// To the nether/end or overworld.
World toWorld = !fromWorld.getEnvironment().equals(environment) ?
this.getNetherEndWorld(overWorld, environment) : overWorld;
// Set the destination location
// If portals cannot be created, then destination is the spawn point, otherwise it's the vector
event.setTo(this.calculateLocation(event.getFrom(),
@ -324,10 +338,11 @@ public class EntityTeleportListener extends AbstractTeleportListener implements
* Handle teleport to standard nether or end
* @param event - EntityPortalEvent
* @param overWorld - over world
* @param toWorld - to world
* @param environment - to target environment
*/
private void handleToStandardNetherOrEnd(EntityPortalEvent event, World overWorld, World toWorld)
private void handleToStandardNetherOrEnd(EntityPortalEvent event, World overWorld, World.Environment environment)
{
World toWorld = Objects.requireNonNull(this.getNetherEndWorld(overWorld, environment));
Location spawnPoint = toWorld.getSpawnLocation();
// If going to the nether and nether portals are active then just teleport to approx location
@ -345,7 +360,7 @@ public class EntityTeleportListener extends AbstractTeleportListener implements
toWorld.setSpawnLocation(100, 50, 0);
}
if (this.isAllowedOnServer(toWorld.getEnvironment()))
if (this.isAllowedOnServer(environment))
{
// To Standard Nether or end
event.setTo(spawnPoint);

View File

@ -327,7 +327,7 @@ public class PlayerTeleportListener extends AbstractTeleportListener implements
return;
}
if (environment.equals(World.Environment.THE_END))
if (World.Environment.THE_END.equals(environment))
{
// Prevent death from hitting the ground while calculating location.
event.getPlayer().setVelocity(new Vector(0,0,0));
@ -374,14 +374,14 @@ public class PlayerTeleportListener extends AbstractTeleportListener implements
Location spawnPoint = toWorld.getSpawnLocation();
// If going to the nether and nether portals are active then just teleport to approx location
if (environment.equals(World.Environment.NETHER) &&
if (World.Environment.NETHER.equals(environment) &&
this.plugin.getIWM().getWorldSettings(overWorld).isMakeNetherPortals())
{
spawnPoint = event.getFrom().toVector().toLocation(toWorld);
}
// If spawn is set as 0,63,0 in the End then move it to 100, 50 ,0.
if (environment.equals(World.Environment.THE_END) && spawnPoint.getBlockX() == 0 && spawnPoint.getBlockZ() == 0)
if (World.Environment.THE_END.equals(environment) && spawnPoint.getBlockX() == 0 && spawnPoint.getBlockZ() == 0)
{
// Set to the default end spawn
spawnPoint = new Location(toWorld, 100, 50, 0);
@ -413,7 +413,7 @@ public class PlayerTeleportListener extends AbstractTeleportListener implements
*/
private void handleFromStandardNetherOrEnd(PlayerPortalEvent event, World overWorld, World.Environment environment)
{
if (environment.equals(World.Environment.NETHER) &&
if (World.Environment.NETHER.equals(environment) &&
this.plugin.getIWM().getWorldSettings(overWorld).isMakeNetherPortals())
{
// Set to location directly to the from location.