Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the 'Illegal Entity Teleport' issue #70

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,9 @@ private boolean setDefaultGameMode(@NotNull final Player player, @NotNull final
return;
}

final Long lastTeleportion =
final Long lastTeleportation =
this.teleportationTimeout.getIfPresent(event.getPlayer().getUniqueId());
if (lastTeleportion != null && (System.currentTimeMillis() - lastTeleportion) < 5000L) {
if (lastTeleportation != null && (System.currentTimeMillis() - lastTeleportation) < 5000L) {
event.setCancelled(true);
return;
}
Expand Down Expand Up @@ -398,9 +398,9 @@ private boolean setDefaultGameMode(@NotNull final Player player, @NotNull final
return;
}

final Long lastTeleportion =
final Long lastTeleportation =
this.teleportationTimeout.getIfPresent(event.getEntity().getUniqueId());
if (lastTeleportion != null && (System.currentTimeMillis() - lastTeleportion) < 5000L) {
if (lastTeleportation != null && (System.currentTimeMillis() - lastTeleportation) < 5000L) {
return;
}

Expand All @@ -416,8 +416,22 @@ private boolean setDefaultGameMode(@NotNull final Player player, @NotNull final
if (location != null) {
this.teleportationTimeout
.put(event.getEntity().getUniqueId(), System.currentTimeMillis());
PaperLib.teleportAsync(event.getEntity(), location,
PlayerTeleportEvent.TeleportCause.COMMAND);

// Prevents the default EntityPortalEvent call
event.getEntity().setPortalCooldown(100);

// Calls our own EntityPortalEvent
EntityPortalEvent portalEvent = new EntityPortalEvent(event.getEntity(),
event.getLocation(), location);
Bukkit.getServer().getPluginManager().callEvent(portalEvent);
if (portalEvent.isCancelled() || portalEvent.getTo() == null
|| portalEvent.getTo().getWorld() == null || portalEvent.getEntity()
.isDead()) {
return;
}

PaperLib.teleportAsync(event.getEntity(), portalEvent.getTo(),
PlayerTeleportEvent.TeleportCause.NETHER_PORTAL);
} else {
hyperverse.getLogger().warning(String
.format("Failed to find/create a portal surrounding %s",
Expand All @@ -438,29 +452,25 @@ private boolean setDefaultGameMode(@NotNull final Player player, @NotNull final
final Location destination =
hyperWorld.getTeleportationManager().endDestination(event.getEntity());
if (destination != null) {
PaperLib.teleportAsync(event.getEntity(), destination,
PlayerTeleportEvent.TeleportCause.COMMAND);
}
}
}

@EventHandler public void onEntityPortalEvent(final EntityPortalEvent event) {
if (event.getEntityType() == EntityType.PLAYER) {
return;
}

final HyperWorld hyperWorld =
this.worldManager.getWorld(Objects.requireNonNull(event.getFrom().getWorld()));
if (hyperWorld == null) {
return;
}
this.teleportationTimeout
.put(event.getEntity().getUniqueId(), System.currentTimeMillis());

// Prevents the default EntityPortalEvent call
event.getEntity().setPortalCooldown(100);

// Calls our own EntityPortalEvent
EntityPortalEvent portalEvent = new EntityPortalEvent(event.getEntity(),
event.getLocation(), destination);
Bukkit.getServer().getPluginManager().callEvent(portalEvent);
if (portalEvent.isCancelled() || portalEvent.getTo() == null
|| portalEvent.getTo().getWorld() == null || portalEvent.getEntity()
.isDead()) {
return;
}

if (event.getFrom().getBlock().getType() == Material.NETHER_PORTAL && !hyperWorld
.getFlag(NetherFlag.class).isEmpty()) {
event.setCancelled(true);
} else if (event.getFrom().getBlock().getType() == Material.END_PORTAL && !hyperWorld
.getFlag(EndFlag.class).isEmpty()) {
event.setCancelled(true);
PaperLib.teleportAsync(event.getEntity(), portalEvent.getTo(),
PlayerTeleportEvent.TeleportCause.END_PORTAL);
}
}
}

Expand Down