Skip to content

Commit

Permalink
add teleportation cause to teleports
Browse files Browse the repository at this point in the history
  • Loading branch information
NonSwag committed Apr 27, 2024
1 parent 192e542 commit c7d6386
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import java.util.stream.IntStream;

import static org.bukkit.event.player.PlayerTeleportEvent.TeleportCause.END_PORTAL;

@RequiredArgsConstructor
public class PortalListener implements Listener {
private final PortalCooldown cooldown = new PortalCooldown();
Expand All @@ -42,19 +44,20 @@ public void onEntityPortalEnter(EntityPortalEnterEvent event) {
if (!readyEvent.callEvent() || readyEvent.getTargetWorld() == null) return;
if (readyEvent.getTargetWorld().getEnvironment().equals(World.Environment.THE_END)) {
generateEndPlatform(readyEvent.getTargetWorld());
event.getEntity().teleportAsync(new Location(readyEvent.getTargetWorld(), 100.5, 50, 0.5, 90, 0));
var spawn = new Location(readyEvent.getTargetWorld(), 100.5, 50, 0.5, 90, 0);
event.getEntity().teleportAsync(spawn, END_PORTAL);
} else if (readyEvent.getTargetWorld().getEnvironment().equals(World.Environment.NETHER)) {
var spawn = event.getLocation().clone();
spawn.setWorld(readyEvent.getTargetWorld());
spawn.setX(spawn.getX() * readyEvent.getTargetWorld().getCoordinateScale());
spawn.setZ(spawn.getZ() * readyEvent.getTargetWorld().getCoordinateScale());
event.getEntity().teleportAsync(spawn);
event.getEntity().teleportAsync(spawn, END_PORTAL);
} else if (event.getEntity() instanceof Player player) {
var location = player.getRespawnLocation();
if (location == null || !location.getWorld().equals(readyEvent.getTargetWorld()))
player.teleportAsync(readyEvent.getTargetWorld().getSpawnLocation());
else player.teleportAsync(location);
} else event.getEntity().teleportAsync(readyEvent.getTargetWorld().getSpawnLocation());
player.teleportAsync(readyEvent.getTargetWorld().getSpawnLocation(), END_PORTAL);
else player.teleportAsync(location, END_PORTAL);
} else event.getEntity().teleportAsync(readyEvent.getTargetWorld().getSpawnLocation(), END_PORTAL);
}

private void generateEndPlatform(World world) {
Expand Down

0 comments on commit c7d6386

Please sign in to comment.