From d0566348919456f94245944aefe831524f04fb4e Mon Sep 17 00:00:00 2001 From: SuperRonanCraft Date: Thu, 28 Dec 2023 19:25:48 -0500 Subject: [PATCH] cooldown ignore fix + essentials try/catch --- .../addons/portals/PortalsEvents.java | 8 +++---- pom.xml | 2 +- .../BetterRTP/player/rtp/RTPPlayer.java | 6 +++++ .../BetterRTP/player/rtp/RTP_PlayerInfo.java | 6 ++++- .../customEvents/RTP_FailedEvent.java | 23 +++++++++++++++++++ .../references/depends/DepEssentials.java | 16 +++++++++---- .../references/helpers/HelperRTP.java | 2 +- 7 files changed, 51 insertions(+), 12 deletions(-) create mode 100644 src/main/java/me/SuperRonanCraft/BetterRTP/references/customEvents/RTP_FailedEvent.java diff --git a/BetterRTPAddons/src/main/java/me/SuperRonanCraft/BetterRTPAddons/addons/portals/PortalsEvents.java b/BetterRTPAddons/src/main/java/me/SuperRonanCraft/BetterRTPAddons/addons/portals/PortalsEvents.java index 260ad23c..56695a6d 100644 --- a/BetterRTPAddons/src/main/java/me/SuperRonanCraft/BetterRTPAddons/addons/portals/PortalsEvents.java +++ b/BetterRTPAddons/src/main/java/me/SuperRonanCraft/BetterRTPAddons/addons/portals/PortalsEvents.java @@ -54,10 +54,10 @@ void move(PlayerMoveEvent e) { if (ploc.getBlockX() <= Math.max(loc1.getBlockX(), loc2.getBlockX()) && ploc.getBlockX() >= Math.min(loc1.getBlockX(), loc2.getBlockX())) - if (ploc.getBlockZ() <= Math.max(loc1.getBlockZ(), loc2.getBlockZ()) - && ploc.getBlockZ() >= Math.min(loc1.getBlockZ(), loc2.getBlockZ())) - if (ploc.getBlockY() <= Math.max(loc1.getBlockY(), loc2.getBlockY()) - && ploc.getBlockY() >= Math.min(loc1.getBlockY(), loc2.getBlockY())) { + if (ploc.getBlockZ() <= Math.max(loc1.getBlockZ(), loc2.getBlockZ()) + && ploc.getBlockZ() >= Math.min(loc1.getBlockZ(), loc2.getBlockZ())) + if (ploc.getBlockY() <= Math.max(loc1.getBlockY(), loc2.getBlockY()) + && ploc.getBlockY() >= Math.min(loc1.getBlockY(), loc2.getBlockY())) { playerPortaling.put(e.getPlayer(), portal); World world = portal.getWorld() != null ? Bukkit.getWorld(portal.getWorld()) : null; HelperRTP.tp(e.getPlayer(), e.getPlayer(), world, null, RTP_TYPE.ADDON_PORTAL, ignoreCooldown, ignoreDelay); diff --git a/pom.xml b/pom.xml index 80dc56e3..d9285c26 100644 --- a/pom.xml +++ b/pom.xml @@ -297,7 +297,7 @@ net.essentialsx EssentialsX - 2.19.7 + 2.20.1 provided diff --git a/src/main/java/me/SuperRonanCraft/BetterRTP/player/rtp/RTPPlayer.java b/src/main/java/me/SuperRonanCraft/BetterRTP/player/rtp/RTPPlayer.java index c7985747..62d3c357 100644 --- a/src/main/java/me/SuperRonanCraft/BetterRTP/player/rtp/RTPPlayer.java +++ b/src/main/java/me/SuperRonanCraft/BetterRTP/player/rtp/RTPPlayer.java @@ -2,14 +2,18 @@ import io.papermc.lib.PaperLib; import lombok.Getter; +import me.RonanCraft.Pueblos.resources.tools.HelperEvent; import me.SuperRonanCraft.BetterRTP.BetterRTP; +import me.SuperRonanCraft.BetterRTP.references.customEvents.RTP_FailedEvent; import me.SuperRonanCraft.BetterRTP.references.customEvents.RTP_FindLocationEvent; +import me.SuperRonanCraft.BetterRTP.references.customEvents.RTP_SettingUpEvent; import me.SuperRonanCraft.BetterRTP.references.helpers.HelperRTP_Check; import me.SuperRonanCraft.BetterRTP.references.rtpinfo.QueueData; import me.SuperRonanCraft.BetterRTP.references.rtpinfo.QueueHandler; import me.SuperRonanCraft.BetterRTP.references.rtpinfo.RandomLocation; import me.SuperRonanCraft.BetterRTP.references.rtpinfo.worlds.WorldPlayer; import me.SuperRonanCraft.BetterRTP.versions.AsyncHandler; +import me.SuperRonanCraft.BetterRTP.versions.FoliaHandler; import org.bukkit.Bukkit; import org.bukkit.Chunk; import org.bukkit.Location; @@ -111,6 +115,8 @@ private void metMax(CommandSender sendi, Player p) { settings.teleport.failedTeleport(p, sendi); getPl().getCooldowns().removeCooldown(p, worldPlayer.getWorld()); getPl().getPInfo().getRtping().remove(p); + //RTP Failed Event + Bukkit.getServer().getPluginManager().callEvent(new RTP_FailedEvent(this)); } /** diff --git a/src/main/java/me/SuperRonanCraft/BetterRTP/player/rtp/RTP_PlayerInfo.java b/src/main/java/me/SuperRonanCraft/BetterRTP/player/rtp/RTP_PlayerInfo.java index d369d088..50c2b463 100644 --- a/src/main/java/me/SuperRonanCraft/BetterRTP/player/rtp/RTP_PlayerInfo.java +++ b/src/main/java/me/SuperRonanCraft/BetterRTP/player/rtp/RTP_PlayerInfo.java @@ -17,7 +17,11 @@ public RTP_PlayerInfo() { } public RTP_PlayerInfo(boolean applyDelay, boolean applyCooldown) { - this(applyDelay, applyCooldown, true, true, true); + this(applyDelay, applyCooldown, true); + } + + public RTP_PlayerInfo(boolean applyDelay, boolean applyCooldown, boolean checkCooldown) { + this(applyDelay, applyCooldown, checkCooldown, true, true); } public RTP_PlayerInfo(boolean applyDelay, diff --git a/src/main/java/me/SuperRonanCraft/BetterRTP/references/customEvents/RTP_FailedEvent.java b/src/main/java/me/SuperRonanCraft/BetterRTP/references/customEvents/RTP_FailedEvent.java new file mode 100644 index 00000000..8e91e916 --- /dev/null +++ b/src/main/java/me/SuperRonanCraft/BetterRTP/references/customEvents/RTP_FailedEvent.java @@ -0,0 +1,23 @@ +package me.SuperRonanCraft.BetterRTP.references.customEvents; + +import lombok.Getter; +import me.SuperRonanCraft.BetterRTP.player.rtp.RTPPlayer; +import me.SuperRonanCraft.BetterRTP.references.rtpinfo.worlds.RTPWorld; +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.jetbrains.annotations.Nullable; + +//Called when an rtp is finding a valid location +@Getter public class RTP_FailedEvent extends RTPEvent { + + Player p; + RTPWorld world; + int attempts; + + public RTP_FailedEvent(RTPPlayer rtpPlayer) { + this.p = rtpPlayer.getPlayer(); + this.world = rtpPlayer.getWorldPlayer(); + this.attempts = rtpPlayer.getAttempts(); + } +} diff --git a/src/main/java/me/SuperRonanCraft/BetterRTP/references/depends/DepEssentials.java b/src/main/java/me/SuperRonanCraft/BetterRTP/references/depends/DepEssentials.java index 48b12be7..8bde641b 100644 --- a/src/main/java/me/SuperRonanCraft/BetterRTP/references/depends/DepEssentials.java +++ b/src/main/java/me/SuperRonanCraft/BetterRTP/references/depends/DepEssentials.java @@ -9,11 +9,17 @@ public class DepEssentials { public static void setBackLocation(Player player, Location location) { - Essentials ess = (Essentials) Bukkit.getServer().getPluginManager().getPlugin("Essentials"); - if (ess == null) return; - User user = ess.getUser(player.getUniqueId()); - if (user == null) return; - user.setLastLocation(location); + try { + Essentials ess = (Essentials) Bukkit.getServer().getPluginManager().getPlugin("Essentials"); + if (ess == null) + return; + User user = ess.getUser(player.getUniqueId()); + if (user == null) + return; + user.setLastLocation(location); + } catch (ClassCastException e) { + //Something wrong happened, idk why this would break... + } } } diff --git a/src/main/java/me/SuperRonanCraft/BetterRTP/references/helpers/HelperRTP.java b/src/main/java/me/SuperRonanCraft/BetterRTP/references/helpers/HelperRTP.java index 3083049c..e9295378 100644 --- a/src/main/java/me/SuperRonanCraft/BetterRTP/references/helpers/HelperRTP.java +++ b/src/main/java/me/SuperRonanCraft/BetterRTP/references/helpers/HelperRTP.java @@ -58,7 +58,7 @@ public static void tp(@NotNull Player player, boolean ignoreCooldown, boolean ignoreDelay, @Nullable WorldLocation location) { - tp(player, sendi, world, biomes, rtpType, location, new RTP_PlayerInfo(!ignoreDelay, !ignoreCooldown)); + tp(player, sendi, world, biomes, rtpType, location, new RTP_PlayerInfo(!ignoreDelay, true, !ignoreCooldown)); } public static void tp(@NotNull Player player,