Fix loop in nether portals (#1686)

* Fix loop in nether portals

Close #1685

* Forgot to import
This commit is contained in:
Huynh Tien 2021-02-18 02:53:22 +07:00 committed by GitHub
parent 969b413588
commit 2bc5e59e9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -12,6 +12,7 @@ import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.World.Environment; import org.bukkit.World.Environment;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -65,8 +66,9 @@ public class PortalTeleportationListener implements Listener {
if (!(e.getEntity() instanceof Player)) { if (!(e.getEntity() instanceof Player)) {
return; return;
} }
Entity entity = e.getEntity();
Material type = e.getLocation().getBlock().getType(); Material type = e.getLocation().getBlock().getType();
UUID uuid = e.getEntity().getUniqueId(); UUID uuid = entity.getUniqueId();
if (inPortal.contains(uuid) || !plugin.getIWM().inWorld(Util.getWorld(e.getLocation().getWorld()))) { if (inPortal.contains(uuid) || !plugin.getIWM().inWorld(Util.getWorld(e.getLocation().getWorld()))) {
return; return;
} }
@ -75,8 +77,8 @@ public class PortalTeleportationListener implements Listener {
// Schedule a time // Schedule a time
Bukkit.getScheduler().runTaskLater(plugin, () -> { Bukkit.getScheduler().runTaskLater(plugin, () -> {
// Check again if still in portal // Check again if still in portal
if (type.equals(Material.NETHER_PORTAL)) { if (entity.getLocation().getBlock().getType().equals(Material.NETHER_PORTAL)) {
PlayerPortalEvent en = new PlayerPortalEvent((Player)e.getEntity(), e.getLocation(), null, TeleportCause.NETHER_PORTAL, 0, false, 0); PlayerPortalEvent en = new PlayerPortalEvent((Player)entity, e.getLocation(), null, TeleportCause.NETHER_PORTAL, 0, false, 0);
if (!this.onIslandPortal(en)) { if (!this.onIslandPortal(en)) {
// Failed // Failed
inPortal.remove(uuid); inPortal.remove(uuid);
@ -89,7 +91,7 @@ public class PortalTeleportationListener implements Listener {
} }
// End portals are instant transfer // End portals are instant transfer
if (!Bukkit.getAllowEnd() && (type.equals(Material.END_PORTAL) || type.equals(Material.END_GATEWAY))) { if (!Bukkit.getAllowEnd() && (type.equals(Material.END_PORTAL) || type.equals(Material.END_GATEWAY))) {
PlayerPortalEvent en = new PlayerPortalEvent((Player)e.getEntity(), PlayerPortalEvent en = new PlayerPortalEvent((Player)entity,
e.getLocation(), e.getLocation(),
null, null,
type.equals(Material.END_PORTAL) ? TeleportCause.END_PORTAL : TeleportCause.END_GATEWAY, type.equals(Material.END_PORTAL) ? TeleportCause.END_PORTAL : TeleportCause.END_GATEWAY,