Skip to content

Commit 285205f

Browse files
authored
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.
1 parent 5503ce0 commit 285205f

File tree

2 files changed

+43
-28
lines changed

2 files changed

+43
-28
lines changed

src/main/java/world/bentobox/bentobox/listeners/teleports/EntityTeleportListener.java

+38-23
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
package world.bentobox.bentobox.listeners.teleports;
88

99

10+
import java.util.Objects;
1011
import java.util.UUID;
1112

1213
import org.bukkit.Bukkit;
@@ -77,8 +78,29 @@ public void onEntityPortal(EntityPortalEvent event)
7778
event.setCancelled(true);
7879
return;
7980
}
80-
// Trigger event processor.
81-
this.portalProcess(event, event.getTo().getWorld().getEnvironment());
81+
82+
// Check which teleportation is happening.
83+
84+
World.Environment source = fromWorld.getEnvironment();
85+
World.Environment destination = event.getTo().getWorld().getEnvironment();
86+
87+
if (World.Environment.NETHER == source && World.Environment.NORMAL == destination ||
88+
World.Environment.NORMAL == source && World.Environment.NETHER == destination)
89+
{
90+
// Nether to overworld or opposite
91+
this.portalProcess(event, World.Environment.NETHER);
92+
}
93+
else if (World.Environment.THE_END == source && World.Environment.NORMAL == destination ||
94+
World.Environment.NORMAL == source && World.Environment.THE_END == destination)
95+
{
96+
// end to overworld or opposite
97+
this.portalProcess(event, World.Environment.THE_END);
98+
}
99+
else
100+
{
101+
// unknown teleportation
102+
this.portalProcess(event, event.getTo().getWorld().getEnvironment());
103+
}
82104
}
83105

84106

@@ -224,32 +246,24 @@ private void portalProcess(EntityPortalEvent event, World.Environment environmen
224246
}
225247
this.inTeleport.add(event.getEntity().getUniqueId());
226248

227-
// Get target world.
228-
World toWorld;
229-
230-
if (environment.equals(World.Environment.NORMAL))
231-
{
232-
toWorld = overWorld;
233-
}
234-
else
235-
{
236-
toWorld = this.getNetherEndWorld(overWorld, environment);
237-
}
238-
239-
if (!overWorld.equals(toWorld) && !this.isIslandWorld(overWorld, environment))
249+
if (fromWorld.equals(overWorld) && !this.isIslandWorld(overWorld, environment))
240250
{
241251
// This is not island world. Use standard nether or end world teleportation.
242-
this.handleToStandardNetherOrEnd(event, overWorld, toWorld);
252+
this.handleToStandardNetherOrEnd(event, overWorld, environment);
243253
return;
244254
}
245-
246-
if (!overWorld.equals(fromWorld) && !this.isIslandWorld(overWorld, environment))
255+
256+
if (!fromWorld.equals(overWorld) && !this.isIslandWorld(overWorld, environment))
247257
{
248258
// If entering a portal in the other world, teleport to a portal in overworld if
249259
// there is one
250-
this.handleFromStandardNetherOrEnd(event, overWorld, toWorld.getEnvironment());
260+
this.handleFromStandardNetherOrEnd(event, overWorld, environment);
251261
return;
252262
}
263+
264+
// To the nether/end or overworld.
265+
World toWorld = !fromWorld.getEnvironment().equals(environment) ?
266+
this.getNetherEndWorld(overWorld, environment) : overWorld;
253267

254268
// Set the destination location
255269
// If portals cannot be created, then destination is the spawn point, otherwise it's the vector
@@ -286,7 +300,7 @@ private void portalProcess(EntityPortalEvent event, World.Environment environmen
286300
// Let the server teleport
287301
return;
288302
}
289-
303+
290304
if (environment.equals(World.Environment.THE_END))
291305
{
292306
// Prevent death from hitting the ground while calculating location.
@@ -324,10 +338,11 @@ private void portalProcess(EntityPortalEvent event, World.Environment environmen
324338
* Handle teleport to standard nether or end
325339
* @param event - EntityPortalEvent
326340
* @param overWorld - over world
327-
* @param toWorld - to world
341+
* @param environment - to target environment
328342
*/
329-
private void handleToStandardNetherOrEnd(EntityPortalEvent event, World overWorld, World toWorld)
343+
private void handleToStandardNetherOrEnd(EntityPortalEvent event, World overWorld, World.Environment environment)
330344
{
345+
World toWorld = Objects.requireNonNull(this.getNetherEndWorld(overWorld, environment));
331346
Location spawnPoint = toWorld.getSpawnLocation();
332347

333348
// If going to the nether and nether portals are active then just teleport to approx location
@@ -345,7 +360,7 @@ private void handleToStandardNetherOrEnd(EntityPortalEvent event, World overWorl
345360
toWorld.setSpawnLocation(100, 50, 0);
346361
}
347362

348-
if (this.isAllowedOnServer(toWorld.getEnvironment()))
363+
if (this.isAllowedOnServer(environment))
349364
{
350365
// To Standard Nether or end
351366
event.setTo(spawnPoint);

src/main/java/world/bentobox/bentobox/listeners/teleports/PlayerTeleportListener.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ private void portalProcess(PlayerPortalEvent event, World.Environment environmen
301301

302302
// Find the distance from edge of island's protection and set the search radius
303303
this.getIsland(event.getTo()).ifPresent(island ->
304-
event.setSearchRadius(this.calculateSearchRadius(event.getTo(), island)));
304+
event.setSearchRadius(this.calculateSearchRadius(event.getTo(), island)));
305305

306306
// Check if there is an island there or not
307307
if (this.isPastingMissingIslands(overWorld) &&
@@ -327,7 +327,7 @@ private void portalProcess(PlayerPortalEvent event, World.Environment environmen
327327
return;
328328
}
329329

330-
if (environment.equals(World.Environment.THE_END))
330+
if (World.Environment.THE_END.equals(environment))
331331
{
332332
// Prevent death from hitting the ground while calculating location.
333333
event.getPlayer().setVelocity(new Vector(0,0,0));
@@ -374,14 +374,14 @@ private void handleToStandardNetherOrEnd(PlayerPortalEvent event,
374374
Location spawnPoint = toWorld.getSpawnLocation();
375375

376376
// If going to the nether and nether portals are active then just teleport to approx location
377-
if (environment.equals(World.Environment.NETHER) &&
377+
if (World.Environment.NETHER.equals(environment) &&
378378
this.plugin.getIWM().getWorldSettings(overWorld).isMakeNetherPortals())
379379
{
380380
spawnPoint = event.getFrom().toVector().toLocation(toWorld);
381381
}
382382

383383
// If spawn is set as 0,63,0 in the End then move it to 100, 50 ,0.
384-
if (environment.equals(World.Environment.THE_END) && spawnPoint.getBlockX() == 0 && spawnPoint.getBlockZ() == 0)
384+
if (World.Environment.THE_END.equals(environment) && spawnPoint.getBlockX() == 0 && spawnPoint.getBlockZ() == 0)
385385
{
386386
// Set to the default end spawn
387387
spawnPoint = new Location(toWorld, 100, 50, 0);
@@ -413,7 +413,7 @@ private void handleToStandardNetherOrEnd(PlayerPortalEvent event,
413413
*/
414414
private void handleFromStandardNetherOrEnd(PlayerPortalEvent event, World overWorld, World.Environment environment)
415415
{
416-
if (environment.equals(World.Environment.NETHER) &&
416+
if (World.Environment.NETHER.equals(environment) &&
417417
this.plugin.getIWM().getWorldSettings(overWorld).isMakeNetherPortals())
418418
{
419419
// Set to location directly to the from location.

0 commit comments

Comments
 (0)