From 6d0e8bb44c6c2ffdece5c27adb171d762065cd31 Mon Sep 17 00:00:00 2001 From: Genre Mamanao <41022228+Faun471@users.noreply.github.com> Date: Sat, 21 Oct 2023 19:33:20 +0800 Subject: [PATCH] Handle end portal (#750) --- .../configs/Configuration.java | 1 + .../iridiumskyblock/configs/Messages.java | 2 ++ .../listeners/PlayerPortalListener.java | 20 ++++++++++++++++++- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/iridium/iridiumskyblock/configs/Configuration.java b/src/main/java/com/iridium/iridiumskyblock/configs/Configuration.java index 98194f612..e0e66d5a3 100644 --- a/src/main/java/com/iridium/iridiumskyblock/configs/Configuration.java +++ b/src/main/java/com/iridium/iridiumskyblock/configs/Configuration.java @@ -56,6 +56,7 @@ public Configuration() { public boolean allowPvPOnIslands = false; public int distance = 151; public int netherUnlockLevel = 10; + public int endUnlockLevel = 20; public int pasterDelayInTick = 1; public int pasterLimitPerTick = 10; diff --git a/src/main/java/com/iridium/iridiumskyblock/configs/Messages.java b/src/main/java/com/iridium/iridiumskyblock/configs/Messages.java index 128b07c0d..e8e514862 100644 --- a/src/main/java/com/iridium/iridiumskyblock/configs/Messages.java +++ b/src/main/java/com/iridium/iridiumskyblock/configs/Messages.java @@ -13,6 +13,8 @@ public Messages() { public String voidLostItems = "%prefix% &7You've lost %items%!"; public String netherIslandsDisabled = "%prefix% &7Nether islands have been disabled."; public String netherLocked = "%prefix% &7Reach Island level %level% to unlock the Nether."; + public String endIslandsDisabled = "%prefix% &7End islands have been disabled."; + public String endLocked = "%prefix% &7Reach Island level %level% to unlock the End."; public String islandBorderChanged = "%prefix% &7%player% has changed your Island border to %color%."; public String borderColorDisabled = "%prefix% &7That border color has been disabled."; public String notAColor = "%prefix% &7That is not a valid color."; diff --git a/src/main/java/com/iridium/iridiumskyblock/listeners/PlayerPortalListener.java b/src/main/java/com/iridium/iridiumskyblock/listeners/PlayerPortalListener.java index 4e579a7d5..c2e7ec379 100644 --- a/src/main/java/com/iridium/iridiumskyblock/listeners/PlayerPortalListener.java +++ b/src/main/java/com/iridium/iridiumskyblock/listeners/PlayerPortalListener.java @@ -34,8 +34,26 @@ public void onPlayerPortal(PlayerPortalEvent event) { } World world = Objects.equals(event.getFrom().getWorld(), nether) ? IridiumSkyblock.getInstance().getTeamManager().getWorld(World.Environment.NORMAL) : nether; event.setTo(island.getCenter(world)); + } else if (event.getCause() == PlayerTeleportEvent.TeleportCause.END_PORTAL) { + if (island.getLevel() < IridiumSkyblock.getInstance().getConfiguration().endUnlockLevel) { + event.getPlayer().sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().endLocked + .replace("%level%", String.valueOf(IridiumSkyblock.getInstance().getConfiguration().endUnlockLevel)) + .replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix) + )); + event.setCancelled(true); + return; + } + World end = IridiumSkyblock.getInstance().getIslandManager().getWorld(World.Environment.THE_END); + if (end == null) { + event.getPlayer().sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().endIslandsDisabled + .replace("%prefix%", IridiumSkyblock.getInstance().getConfiguration().prefix) + )); + event.setCancelled(true); + return; + } + World world = Objects.equals(event.getFrom().getWorld(), end) ? IridiumSkyblock.getInstance().getTeamManager().getWorld(World.Environment.NORMAL) : end; + event.setTo(island.getCenter(world)); } }); } - }