From 593cdeb43f2ffd53090060564f6f67e1922a095e Mon Sep 17 00:00:00 2001 From: Thatsmusic99 <25277367+Thatsmusic99@users.noreply.github.com> Date: Mon, 24 Jul 2023 12:22:28 +0100 Subject: [PATCH 01/12] feat: initial commit for flag handling --- .../hooks/worldguard/FlagHandler.java | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 AdvancedTeleport-Bukkit/src/main/java/io/github/niestrat99/advancedteleport/hooks/worldguard/FlagHandler.java diff --git a/AdvancedTeleport-Bukkit/src/main/java/io/github/niestrat99/advancedteleport/hooks/worldguard/FlagHandler.java b/AdvancedTeleport-Bukkit/src/main/java/io/github/niestrat99/advancedteleport/hooks/worldguard/FlagHandler.java new file mode 100644 index 00000000..ecc75d85 --- /dev/null +++ b/AdvancedTeleport-Bukkit/src/main/java/io/github/niestrat99/advancedteleport/hooks/worldguard/FlagHandler.java @@ -0,0 +1,71 @@ +package io.github.niestrat99.advanceteleport.hooks.worldguard; + +import com.sk89q.worldguard.WorldGuard; +import com.sk89q.worldguard.LocalPlayer; +import com.sk89q.worldguard.bukkit.WorldGuardPlugin; +import com.sk89q.worldguard.protection.ApplicableRegionSet; +import com.sk89q.worldguard.protection.flags.StateFlag; +import com.sk89q.worldguard.protection.flags.StringFlag; +import com.sk89q.worldguard.protection.flags.registry.FlagConflictException; +import com.sk89q.worldguard.protection.flags.registry.FlagRegistry; +import com.sk89q.worldguard.protection.regions.RegionContainer; +import com.sk89q.worldguard.protection.regions.RegionQuery; + +import io.github.niestrat99.advancedteleport.config.CustomMessages; + +import org.bukkit.Player; + +public class FlagHandler { + + private static boolean enabled = false; + public static StateFlag DANGEROUS_AREA_FLAG; + public static StringFlag DANGEROUS_AREA_MESSAGE; + + static { + final FlagRegistry registry = WorldGuard.getInstance().getFlagRegistry(); + + // Create the flags + try { + StateFlag dangerousArea = new StateFlag("dangerous-area", false); + registry.register(dangerousArea); + DANGEROUS_AREA_FLAG = dangerousArea; + } catch (FlagConflictException ex) { + } + + try { + StringFlag areaMessage = new StringFlag("dangerous-area-message"); + registry.register(areaMessage); + DANGEROUS_AREA_MESSAGE = areaMessage; + } catch (FlagConflictException ex) { + } + enabled = true; + + } + + public static boolean isDangerous(@NotNull Location toLocation, @NotNull Player player) { + + // No WorldGuard? No problem. + if (!enabled) return false; + + // Get the region set + final RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer(); + final RegionQuery query = container.createQuery(); + final ApplicableRegionSet set = query.getApplicableRegions(toLocation); + + // Convert the player + final LocalPlayer wgPlayer = WorldGuardPlugin.inst().wrapPlayer(player); + + // Test the region + if (!set.testState(wgPlayer, DANGEROUS_AREA_FLAG)) return false; + + // Since it's dangerous, check for the message + String message = set.queryValue(wgPlayer, DANGEROUS_AREA_MESSAGE); + if (message != null) { + CustomMessages.asAudience(player).sendMessage(CustomMessages.translate(message)); + } else { + CustomMessages.sendMessage(player, "Info.dangerousArea"); + } + return true; + } + +} From 6ccd2f320ea616c7555e7890a2c951ef5a46051c Mon Sep 17 00:00:00 2001 From: Thatsmusic99 <25277367+Thatsmusic99@users.noreply.github.com> Date: Mon, 24 Jul 2023 12:22:28 +0100 Subject: [PATCH 02/12] feat: initial commit for flag handling Signed-off-by: Thatsmusic99 <25277367+thatsmusic99@users.noreply.github.com> --- .../hooks/worldguard/FlagHandler.java | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 AdvancedTeleport-Bukkit/src/main/java/io/github/niestrat99/advancedteleport/hooks/worldguard/FlagHandler.java diff --git a/AdvancedTeleport-Bukkit/src/main/java/io/github/niestrat99/advancedteleport/hooks/worldguard/FlagHandler.java b/AdvancedTeleport-Bukkit/src/main/java/io/github/niestrat99/advancedteleport/hooks/worldguard/FlagHandler.java new file mode 100644 index 00000000..2d016293 --- /dev/null +++ b/AdvancedTeleport-Bukkit/src/main/java/io/github/niestrat99/advancedteleport/hooks/worldguard/FlagHandler.java @@ -0,0 +1,74 @@ +package io.github.niestrat99.advancedteleport.hooks.worldguard; + +import com.sk89q.worldedit.bukkit.BukkitAdapter; +import com.sk89q.worldguard.WorldGuard; +import com.sk89q.worldguard.LocalPlayer; +import com.sk89q.worldguard.bukkit.WorldGuardPlugin; +import com.sk89q.worldguard.protection.ApplicableRegionSet; +import com.sk89q.worldguard.protection.flags.StateFlag; +import com.sk89q.worldguard.protection.flags.StringFlag; +import com.sk89q.worldguard.protection.flags.registry.FlagConflictException; +import com.sk89q.worldguard.protection.flags.registry.FlagRegistry; +import com.sk89q.worldguard.protection.regions.RegionContainer; +import com.sk89q.worldguard.protection.regions.RegionQuery; + +import io.github.niestrat99.advancedteleport.config.CustomMessages; + +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; + +public class FlagHandler { + + private static boolean enabled = false; + public static StateFlag DANGEROUS_AREA_FLAG; + public static StringFlag DANGEROUS_AREA_MESSAGE; + + static { + final FlagRegistry registry = WorldGuard.getInstance().getFlagRegistry(); + + // Create the flags + try { + StateFlag dangerousArea = new StateFlag("dangerous-area", false); + registry.register(dangerousArea); + DANGEROUS_AREA_FLAG = dangerousArea; + } catch (FlagConflictException ex) { + } + + try { + StringFlag areaMessage = new StringFlag("dangerous-area-message"); + registry.register(areaMessage); + DANGEROUS_AREA_MESSAGE = areaMessage; + } catch (FlagConflictException ex) { + } + enabled = true; + + } + + public static boolean isDangerous(@NotNull Location toLocation, @NotNull Player player) { + + // No WorldGuard? No problem. + if (!enabled) return false; + + // Get the region set + final RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer(); + final RegionQuery query = container.createQuery(); + final ApplicableRegionSet set = query.getApplicableRegions(BukkitAdapter.adapt(toLocation)); + + // Convert the player + final LocalPlayer wgPlayer = WorldGuardPlugin.inst().wrapPlayer(player); + + // Test the region + if (!set.testState(wgPlayer, DANGEROUS_AREA_FLAG)) return false; + + // Since it's dangerous, check for the message + String message = set.queryValue(wgPlayer, DANGEROUS_AREA_MESSAGE); + if (message != null) { + CustomMessages.asAudience(player).sendMessage(CustomMessages.translate(message)); + } else { + CustomMessages.sendMessage(player, "Info.dangerousArea"); + } + return true; + } + +} From 6c2199c875eda9f79a1c2ee104b4192fc7b273d4 Mon Sep 17 00:00:00 2001 From: Thatsmusic99 <25277367+thatsmusic99@users.noreply.github.com> Date: Wed, 2 Aug 2023 17:57:03 +0100 Subject: [PATCH 03/12] feat: add /tpconfirm and region checking Signed-off-by: Thatsmusic99 <25277367+thatsmusic99@users.noreply.github.com> --- AdvancedTeleport-Bukkit/build.gradle.kts | 6 + .../advancedteleport/CoreClass.java | 7 ++ .../advancedteleport/api/ATPlayer.java | 41 +++++++ .../commands/misc/TpConfirm.java | 39 +++++++ .../config/CustomMessages.java | 7 ++ .../hooks/worldguard/FlagHandler.java | 103 +++++++++--------- .../managers/CommandManager.java | 3 + 7 files changed, 155 insertions(+), 51 deletions(-) create mode 100644 AdvancedTeleport-Bukkit/src/main/java/io/github/niestrat99/advancedteleport/commands/misc/TpConfirm.java diff --git a/AdvancedTeleport-Bukkit/build.gradle.kts b/AdvancedTeleport-Bukkit/build.gradle.kts index 2974d22d..7bd7b7c1 100644 --- a/AdvancedTeleport-Bukkit/build.gradle.kts +++ b/AdvancedTeleport-Bukkit/build.gradle.kts @@ -461,6 +461,12 @@ bukkit { usage = "/tpofflinehere " aliases = listOf("tpofflh", "tpofflhere") } + + register("tpconfirm") { + description = "Confirms a teleportation to a dangerous zone." + permission = "at.member.confirm" + usage = "/tpconfirm" + } } permissions { diff --git a/AdvancedTeleport-Bukkit/src/main/java/io/github/niestrat99/advancedteleport/CoreClass.java b/AdvancedTeleport-Bukkit/src/main/java/io/github/niestrat99/advancedteleport/CoreClass.java index 8a5c7b78..9c2149e5 100644 --- a/AdvancedTeleport-Bukkit/src/main/java/io/github/niestrat99/advancedteleport/CoreClass.java +++ b/AdvancedTeleport-Bukkit/src/main/java/io/github/niestrat99/advancedteleport/CoreClass.java @@ -4,6 +4,7 @@ import io.github.niestrat99.advancedteleport.config.CustomMessages; import io.github.niestrat99.advancedteleport.config.GUIConfig; import io.github.niestrat99.advancedteleport.config.MainConfig; +import io.github.niestrat99.advancedteleport.hooks.worldguard.FlagHandler; import io.github.niestrat99.advancedteleport.listeners.MapEventListeners; import io.github.niestrat99.advancedteleport.listeners.PlayerListeners; import io.github.niestrat99.advancedteleport.listeners.SignInteractListener; @@ -61,6 +62,12 @@ public void onLoad() { err.printStackTrace(); Bukkit.getPluginManager().disablePlugin(this); } + + // Wakey wakey + try { + FlagHandler.init(); + } catch (NoClassDefFoundError ignored) { + } } @Override diff --git a/AdvancedTeleport-Bukkit/src/main/java/io/github/niestrat99/advancedteleport/api/ATPlayer.java b/AdvancedTeleport-Bukkit/src/main/java/io/github/niestrat99/advancedteleport/api/ATPlayer.java index e9186547..e5e78ad6 100644 --- a/AdvancedTeleport-Bukkit/src/main/java/io/github/niestrat99/advancedteleport/api/ATPlayer.java +++ b/AdvancedTeleport-Bukkit/src/main/java/io/github/niestrat99/advancedteleport/api/ATPlayer.java @@ -11,6 +11,7 @@ import io.github.niestrat99.advancedteleport.api.events.players.ToggleTeleportationEvent; import io.github.niestrat99.advancedteleport.config.CustomMessages; import io.github.niestrat99.advancedteleport.config.MainConfig; +import io.github.niestrat99.advancedteleport.hooks.worldguard.FlagHandler; import io.github.niestrat99.advancedteleport.managers.CooldownManager; import io.github.niestrat99.advancedteleport.managers.MovementManager; import io.github.niestrat99.advancedteleport.managers.ParticleManager; @@ -62,6 +63,7 @@ public class ATPlayer { protected @NotNull WeakReference player; protected @NotNull UUID uuid; protected @NotNull String name; + protected @Nullable Runnable confirmation; private final @NotNull PendingData> homes; private final @NotNull PendingData> blockedUsers; private final @NotNull PendingData isTeleportationEnabled; @@ -129,6 +131,7 @@ public ATPlayer( CompletableFuture.supplyAsync( () -> PlayerSQLManager.get().isTeleportationOn(uuid), CoreClass.async)); + this.confirmation = null; players.put(name.toLowerCase(), this); } @@ -162,6 +165,15 @@ public void teleport( @NotNull final ATTeleportEvent event, @NotNull final String command, @NotNull final String teleportMsg) { + this.teleport(event, command, teleportMsg, false); + } + + @ApiStatus.Internal + public void teleport( + @NotNull final ATTeleportEvent event, + @NotNull final String command, + @NotNull final String teleportMsg, + boolean confirmed) { Player player = event.getPlayer(); int warmUp = getWarmUp(command, event.getToLocation().getWorld()); if (event.isCancelled()) return; @@ -172,6 +184,17 @@ public void teleport( return; } + // If there's no confirmation, then check the area + if (!confirmed) { + try { + if (FlagHandler.isDangerous(event.getToLocation(), player)) { + requestConfirmation(() -> teleport(event, command, teleportMsg, true)); + return; + } + } catch (NoClassDefFoundError ignored) { + } + } + if (!PaymentManager.getInstance().canPay(command, player, event.getToLocation().getWorld())) return; @@ -433,6 +456,24 @@ public boolean hasBlocked(@NotNull final UUID otherPlayer) { CoreClass.async); } + @Contract(pure = true) + public boolean isAwaitingConfirmation() { + return this.confirmation != null; + } + + @Contract(pure = true) + public void requestConfirmation(@NotNull Runnable confirmed) { + this.confirmation = confirmed; + } + + @Contract(pure = true) + public void confirm() { + if (this.confirmation == null) return; + this.confirmation.run(); + this.confirmation = null; + } + + /** * Returns a hashmap of homes, where the key is the home name, and the value is the home object. * diff --git a/AdvancedTeleport-Bukkit/src/main/java/io/github/niestrat99/advancedteleport/commands/misc/TpConfirm.java b/AdvancedTeleport-Bukkit/src/main/java/io/github/niestrat99/advancedteleport/commands/misc/TpConfirm.java new file mode 100644 index 00000000..02d4560f --- /dev/null +++ b/AdvancedTeleport-Bukkit/src/main/java/io/github/niestrat99/advancedteleport/commands/misc/TpConfirm.java @@ -0,0 +1,39 @@ +package io.github.niestrat99.advancedteleport.commands.misc; + +import io.github.niestrat99.advancedteleport.api.ATPlayer; +import io.github.niestrat99.advancedteleport.commands.ATCommand; +import io.github.niestrat99.advancedteleport.commands.PlayerCommand; +import io.github.niestrat99.advancedteleport.config.CustomMessages; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; + +public class TpConfirm extends ATCommand implements PlayerCommand { + + @Override + public boolean getRequiredFeature() { + return true; + } + + @Override + public @NotNull String getPermission() { + return "at.member.confirm"; + } + + @Override + public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { + + // Get the player + ATPlayer player = ATPlayer.getPlayer((Player) sender); + if (!player.isAwaitingConfirmation()) { + CustomMessages.sendMessage(sender, "Error.notAwaitingConfirmation"); + return true; + } + + // Confirm! + CustomMessages.sendMessage(sender, "Info.confirmedTeleportation"); + player.confirm(); + return true; + } +} diff --git a/AdvancedTeleport-Bukkit/src/main/java/io/github/niestrat99/advancedteleport/config/CustomMessages.java b/AdvancedTeleport-Bukkit/src/main/java/io/github/niestrat99/advancedteleport/config/CustomMessages.java index 774509fa..2a309e46 100644 --- a/AdvancedTeleport-Bukkit/src/main/java/io/github/niestrat99/advancedteleport/config/CustomMessages.java +++ b/AdvancedTeleport-Bukkit/src/main/java/io/github/niestrat99/advancedteleport/config/CustomMessages.java @@ -393,6 +393,7 @@ If you prefer to use the Legacy Code format (i.e. &a, &b, etc.) then you can sti addDefault( "Error.randomLocFailed", " Sorry, we couldn't find a location to teleport you to :("); + addDefault("Error.notAwaitingConfirmation", " You don't need to confirm any teleportation! If you're headed towards a dangerous place, we'll let you know."); makeSectionLenient("Info"); addDefault("Info.tpOff", " Successfully disabled teleport requests!"); @@ -598,6 +599,12 @@ If you prefer to use the Legacy Code format (i.e. &a, &b, etc.) then you can sti "Info.mirrorSpawnSame", " The spawns for and already to go the same place! Don't worry :)"); + addDefault( + "Info.dangerousArea", + " WARNING: the area you are teleporting to has been marked as potentially unsafe, meaning you could die or lose your items.
" + + "If you are happy to teleport to the location, please run the command /tpconfirm."); + addDefault("Info.confirmedTeleportation", " You've confirmed the teleportation! Good luck out there."); + addDefault("Tooltip.homes", " Teleports you to your home: "); addDefault("Tooltip.warps", " Teleports you to warp: "); addDefault( diff --git a/AdvancedTeleport-Bukkit/src/main/java/io/github/niestrat99/advancedteleport/hooks/worldguard/FlagHandler.java b/AdvancedTeleport-Bukkit/src/main/java/io/github/niestrat99/advancedteleport/hooks/worldguard/FlagHandler.java index 2d016293..532f86eb 100644 --- a/AdvancedTeleport-Bukkit/src/main/java/io/github/niestrat99/advancedteleport/hooks/worldguard/FlagHandler.java +++ b/AdvancedTeleport-Bukkit/src/main/java/io/github/niestrat99/advancedteleport/hooks/worldguard/FlagHandler.java @@ -1,8 +1,8 @@ package io.github.niestrat99.advancedteleport.hooks.worldguard; import com.sk89q.worldedit.bukkit.BukkitAdapter; -import com.sk89q.worldguard.WorldGuard; import com.sk89q.worldguard.LocalPlayer; +import com.sk89q.worldguard.WorldGuard; import com.sk89q.worldguard.bukkit.WorldGuardPlugin; import com.sk89q.worldguard.protection.ApplicableRegionSet; import com.sk89q.worldguard.protection.flags.StateFlag; @@ -20,55 +20,56 @@ public class FlagHandler { - private static boolean enabled = false; - public static StateFlag DANGEROUS_AREA_FLAG; - public static StringFlag DANGEROUS_AREA_MESSAGE; - - static { - final FlagRegistry registry = WorldGuard.getInstance().getFlagRegistry(); - - // Create the flags - try { - StateFlag dangerousArea = new StateFlag("dangerous-area", false); - registry.register(dangerousArea); - DANGEROUS_AREA_FLAG = dangerousArea; - } catch (FlagConflictException ex) { - } - - try { - StringFlag areaMessage = new StringFlag("dangerous-area-message"); - registry.register(areaMessage); - DANGEROUS_AREA_MESSAGE = areaMessage; - } catch (FlagConflictException ex) { - } - enabled = true; - - } - - public static boolean isDangerous(@NotNull Location toLocation, @NotNull Player player) { - - // No WorldGuard? No problem. - if (!enabled) return false; - - // Get the region set - final RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer(); - final RegionQuery query = container.createQuery(); - final ApplicableRegionSet set = query.getApplicableRegions(BukkitAdapter.adapt(toLocation)); - - // Convert the player - final LocalPlayer wgPlayer = WorldGuardPlugin.inst().wrapPlayer(player); - - // Test the region - if (!set.testState(wgPlayer, DANGEROUS_AREA_FLAG)) return false; - - // Since it's dangerous, check for the message - String message = set.queryValue(wgPlayer, DANGEROUS_AREA_MESSAGE); - if (message != null) { - CustomMessages.asAudience(player).sendMessage(CustomMessages.translate(message)); - } else { - CustomMessages.sendMessage(player, "Info.dangerousArea"); - } - return true; - } + private static boolean enabled = false; + public static StateFlag DANGEROUS_AREA_FLAG; + public static StringFlag DANGEROUS_AREA_MESSAGE; + + public static void init() { + final FlagRegistry registry = WorldGuard.getInstance().getFlagRegistry(); + + // Create the flags + try { + StateFlag dangerousArea = new StateFlag("dangerous-area", false); + registry.register(dangerousArea); + DANGEROUS_AREA_FLAG = dangerousArea; + + } catch (FlagConflictException ex) { + } + + try { + StringFlag areaMessage = new StringFlag("dangerous-area-message"); + registry.register(areaMessage); + DANGEROUS_AREA_MESSAGE = areaMessage; + } catch (FlagConflictException ex) { + } + + enabled = DANGEROUS_AREA_FLAG != null && DANGEROUS_AREA_MESSAGE != null; + } + + public static boolean isDangerous(@NotNull Location toLocation, @NotNull Player player) { + + // No WorldGuard? No problem. + if (!enabled) return false; + + // Get the region set + final RegionContainer container = + WorldGuard.getInstance().getPlatform().getRegionContainer(); + final RegionQuery query = container.createQuery(); + final ApplicableRegionSet set = query.getApplicableRegions(BukkitAdapter.adapt(toLocation)); + + // Convert the player + final LocalPlayer wgPlayer = WorldGuardPlugin.inst().wrapPlayer(player); + + // Test the region + if (!set.testState(wgPlayer, DANGEROUS_AREA_FLAG)) return false; + // Since it's dangerous, check for the message + String message = set.queryValue(wgPlayer, DANGEROUS_AREA_MESSAGE); + if (message != null) { + CustomMessages.asAudience(player).sendMessage(CustomMessages.translate(message)); + } else { + CustomMessages.sendMessage(player, "Info.dangerousArea"); + } + return true; + } } diff --git a/AdvancedTeleport-Bukkit/src/main/java/io/github/niestrat99/advancedteleport/managers/CommandManager.java b/AdvancedTeleport-Bukkit/src/main/java/io/github/niestrat99/advancedteleport/managers/CommandManager.java index 4e6c505f..3df1a9c4 100644 --- a/AdvancedTeleport-Bukkit/src/main/java/io/github/niestrat99/advancedteleport/managers/CommandManager.java +++ b/AdvancedTeleport-Bukkit/src/main/java/io/github/niestrat99/advancedteleport/managers/CommandManager.java @@ -6,6 +6,7 @@ import io.github.niestrat99.advancedteleport.commands.SubATCommand; import io.github.niestrat99.advancedteleport.commands.core.*; import io.github.niestrat99.advancedteleport.commands.home.*; +import io.github.niestrat99.advancedteleport.commands.misc.TpConfirm; import io.github.niestrat99.advancedteleport.commands.spawn.*; import io.github.niestrat99.advancedteleport.commands.teleport.*; import io.github.niestrat99.advancedteleport.commands.warp.*; @@ -52,6 +53,8 @@ public static void registerCommands() { register("tpoffline", new TpOffline()); register("tpofflinehere", new TpHereOffline()); + register("tpconfirm", new TpConfirm()); + register("home", new HomeCommand()); register("sethome", new SetHomeCommand()); register("delhome", new DelHomeCommand()); From a86521b7d0cde702e12ff86951b7e923940870d1 Mon Sep 17 00:00:00 2001 From: Thatsmusic99 <25277367+thatsmusic99@users.noreply.github.com> Date: Wed, 2 Aug 2023 18:02:43 +0100 Subject: [PATCH 04/12] chore: add better registration checking Signed-off-by: Thatsmusic99 <25277367+thatsmusic99@users.noreply.github.com> --- .../hooks/worldguard/FlagHandler.java | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/AdvancedTeleport-Bukkit/src/main/java/io/github/niestrat99/advancedteleport/hooks/worldguard/FlagHandler.java b/AdvancedTeleport-Bukkit/src/main/java/io/github/niestrat99/advancedteleport/hooks/worldguard/FlagHandler.java index 532f86eb..89a42285 100644 --- a/AdvancedTeleport-Bukkit/src/main/java/io/github/niestrat99/advancedteleport/hooks/worldguard/FlagHandler.java +++ b/AdvancedTeleport-Bukkit/src/main/java/io/github/niestrat99/advancedteleport/hooks/worldguard/FlagHandler.java @@ -5,6 +5,7 @@ import com.sk89q.worldguard.WorldGuard; import com.sk89q.worldguard.bukkit.WorldGuardPlugin; import com.sk89q.worldguard.protection.ApplicableRegionSet; +import com.sk89q.worldguard.protection.flags.Flag; import com.sk89q.worldguard.protection.flags.StateFlag; import com.sk89q.worldguard.protection.flags.StringFlag; import com.sk89q.worldguard.protection.flags.registry.FlagConflictException; @@ -12,6 +13,7 @@ import com.sk89q.worldguard.protection.regions.RegionContainer; import com.sk89q.worldguard.protection.regions.RegionQuery; +import io.github.niestrat99.advancedteleport.CoreClass; import io.github.niestrat99.advancedteleport.config.CustomMessages; import org.bukkit.Location; @@ -21,8 +23,8 @@ public class FlagHandler { private static boolean enabled = false; - public static StateFlag DANGEROUS_AREA_FLAG; - public static StringFlag DANGEROUS_AREA_MESSAGE; + public static StateFlag DANGEROUS_AREA_FLAG = null; + public static StringFlag DANGEROUS_AREA_MESSAGE = null; public static void init() { final FlagRegistry registry = WorldGuard.getInstance().getFlagRegistry(); @@ -34,6 +36,13 @@ public static void init() { DANGEROUS_AREA_FLAG = dangerousArea; } catch (FlagConflictException ex) { + Flag flag = registry.get("dangerous-area"); + if (flag instanceof StateFlag goodFlag) { + DANGEROUS_AREA_FLAG = goodFlag; + } else { + CoreClass.getInstance().getLogger().warning( + "Another plugin has registered a conflicting dangerous-area flag! Custom WorldGuard flags for AT will not work."); + } } try { @@ -41,6 +50,13 @@ public static void init() { registry.register(areaMessage); DANGEROUS_AREA_MESSAGE = areaMessage; } catch (FlagConflictException ex) { + Flag flag = registry.get("dangerous-area-message"); + if (flag instanceof StringFlag goodFlag) { + DANGEROUS_AREA_MESSAGE = goodFlag; + } else { + CoreClass.getInstance().getLogger().warning( + "Another plugin has registered a conflicting dangerous-area-message flag! Custom WorldGuard flags for AT will not work."); + } } enabled = DANGEROUS_AREA_FLAG != null && DANGEROUS_AREA_MESSAGE != null; From 279ee472984f883b2e96fd73a7568d61f38b61cf Mon Sep 17 00:00:00 2001 From: Thatsmusic99 <25277367+thatsmusic99@users.noreply.github.com> Date: Tue, 25 Jul 2023 10:19:57 +0100 Subject: [PATCH 05/12] fix: return true by default if player is not stored in database for tp toggle (#116) Signed-off-by: Thatsmusic99 <25277367+thatsmusic99@users.noreply.github.com> --- .../niestrat99/advancedteleport/sql/PlayerSQLManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AdvancedTeleport-Bukkit/src/main/java/io/github/niestrat99/advancedteleport/sql/PlayerSQLManager.java b/AdvancedTeleport-Bukkit/src/main/java/io/github/niestrat99/advancedteleport/sql/PlayerSQLManager.java index 46c1a57a..fc369cfb 100644 --- a/AdvancedTeleport-Bukkit/src/main/java/io/github/niestrat99/advancedteleport/sql/PlayerSQLManager.java +++ b/AdvancedTeleport-Bukkit/src/main/java/io/github/niestrat99/advancedteleport/sql/PlayerSQLManager.java @@ -232,7 +232,7 @@ public boolean isTeleportationOn(UUID uuid) { } catch (SQLException exception) { throw new RuntimeException(exception); } - return false; + return true; } public void setTeleportationOn(UUID uuid, boolean enabled) { From 20cd666432246e2705f2320007b49288df4737ba Mon Sep 17 00:00:00 2001 From: Thatsmusic99 <25277367+thatsmusic99@users.noreply.github.com> Date: Tue, 25 Jul 2023 10:26:57 +0100 Subject: [PATCH 06/12] chore: add debugging for command registration Signed-off-by: Thatsmusic99 <25277367+thatsmusic99@users.noreply.github.com> --- .../advancedteleport/managers/CommandManager.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/AdvancedTeleport-Bukkit/src/main/java/io/github/niestrat99/advancedteleport/managers/CommandManager.java b/AdvancedTeleport-Bukkit/src/main/java/io/github/niestrat99/advancedteleport/managers/CommandManager.java index 3df1a9c4..6b37cd7e 100644 --- a/AdvancedTeleport-Bukkit/src/main/java/io/github/niestrat99/advancedteleport/managers/CommandManager.java +++ b/AdvancedTeleport-Bukkit/src/main/java/io/github/niestrat99/advancedteleport/managers/CommandManager.java @@ -89,13 +89,12 @@ public static void registerCommands() { private static void register(String name, ATCommand atCommand) { PluginCommand command = Bukkit.getPluginCommand("advancedteleport:" + name); + CoreClass.debug("Fetching " + command + " - " + command); if (command == null) command = atCommands.get(name); - if (command == null) return; - - if (command.getPlugin() != CoreClass.getInstance()) { - command = Bukkit.getPluginCommand("advancedteleport:" + name); + if (command == null) { + CoreClass.getInstance().getLogger().warning("Could not add command " + name + " - has it been set up properly?"); + return; } - if (command == null) return; atCommands.put(name, command); CommandMap map = getMap(); @@ -111,6 +110,7 @@ private static void register(String name, ATCommand atCommand) { if (MainConfig.get().DISABLED_COMMANDS.get().contains(alias) || removed || !atCommand.getRequiredFeature()) { + CoreClass.debug(alias + " has been marked for removal."); if (command.isRegistered()) { removed = true; command.unregister(map); @@ -123,6 +123,8 @@ private static void register(String name, ATCommand atCommand) { commands.remove(alias); commands.remove("advancedteleport:" + alias); + CoreClass.debug("Removed " + alias + "."); + // Let another plugin take over Bukkit.getScheduler() .runTaskLater( @@ -138,6 +140,7 @@ private static void register(String name, ATCommand atCommand) { if (parts.length < 2) continue; if (parts[1].equals(alias)) { if (parts[0].equals("advancedteleport")) continue; + CoreClass.debug("Letting " + parts[0] + "'s " + alias + " take over..."); pendingChanges.put(alias, commands.get(otherCmd)); break; } @@ -166,6 +169,8 @@ private static void register(String name, ATCommand atCommand) { command.setTabCompleter(atCommand); } + CoreClass.debug(aliases + " has " + (command.isRegistered() ? "" : "not ") + "been registed successfully."); + registeredCommands.put(name, command); } From e4e1fc68040478d40d42ff5bd3c843ea19b7b050 Mon Sep 17 00:00:00 2001 From: Holly P <25277367+Thatsmusic99@users.noreply.github.com> Date: Tue, 25 Jul 2023 11:35:42 +0100 Subject: [PATCH 07/12] chore: add debugging for payment parsing --- .../advancedteleport/payments/PaymentManager.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/AdvancedTeleport-Bukkit/src/main/java/io/github/niestrat99/advancedteleport/payments/PaymentManager.java b/AdvancedTeleport-Bukkit/src/main/java/io/github/niestrat99/advancedteleport/payments/PaymentManager.java index 5d2cef8e..8c05ef92 100644 --- a/AdvancedTeleport-Bukkit/src/main/java/io/github/niestrat99/advancedteleport/payments/PaymentManager.java +++ b/AdvancedTeleport-Bukkit/src/main/java/io/github/niestrat99/advancedteleport/payments/PaymentManager.java @@ -71,6 +71,14 @@ private Payment parsePayment(String rawPayment) { if (matcher.matches()) { String plugin = matcher.group(1); double payment = Double.parseDouble(matcher.group(2)); + + CoreClass.debug("Split payment into two, part 1: " + plugin + ", part two: " + payment); + CoreClass.debug("Material: " + Material.getMaterial(plugin == null ? "" : plugin); + + // If it's not a plugin and actually an item, lmao + if (plugin != null && Material.getMaterial(plugin) != null) { + return ItemsPayment.getFromString(rawPayment); + } return new VaultPayment( payment, plugin == null ? null : plugin.substring(0, plugin.length() - 1)); } @@ -87,6 +95,9 @@ private Payment parsePayment(String rawPayment) { String plugin = matcher.group(1); double payment = Double.parseDouble(matcher.group(2)); + CoreClass.debug("Split payment into two, part 1: " + plugin + ", part two: " + payment); + CoreClass.debug("Material: " + Material.getMaterial(plugin == null ? "" : plugin); + // If it's not a plugin and actually an item, lmao if (plugin != null && Material.getMaterial(plugin) != null) { return ItemsPayment.getFromString(rawPayment); From c347de7ac22b94ab60b83ea2285277e9d6a9c7cb Mon Sep 17 00:00:00 2001 From: Holly P <25277367+Thatsmusic99@users.noreply.github.com> Date: Tue, 25 Jul 2023 12:16:41 +0100 Subject: [PATCH 08/12] fix: missing brackets --- .../niestrat99/advancedteleport/payments/PaymentManager.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/AdvancedTeleport-Bukkit/src/main/java/io/github/niestrat99/advancedteleport/payments/PaymentManager.java b/AdvancedTeleport-Bukkit/src/main/java/io/github/niestrat99/advancedteleport/payments/PaymentManager.java index 8c05ef92..9131562a 100644 --- a/AdvancedTeleport-Bukkit/src/main/java/io/github/niestrat99/advancedteleport/payments/PaymentManager.java +++ b/AdvancedTeleport-Bukkit/src/main/java/io/github/niestrat99/advancedteleport/payments/PaymentManager.java @@ -73,7 +73,7 @@ private Payment parsePayment(String rawPayment) { double payment = Double.parseDouble(matcher.group(2)); CoreClass.debug("Split payment into two, part 1: " + plugin + ", part two: " + payment); - CoreClass.debug("Material: " + Material.getMaterial(plugin == null ? "" : plugin); + CoreClass.debug("Material: " + Material.getMaterial(plugin == null ? "" : plugin)); // If it's not a plugin and actually an item, lmao if (plugin != null && Material.getMaterial(plugin) != null) { @@ -96,7 +96,7 @@ private Payment parsePayment(String rawPayment) { double payment = Double.parseDouble(matcher.group(2)); CoreClass.debug("Split payment into two, part 1: " + plugin + ", part two: " + payment); - CoreClass.debug("Material: " + Material.getMaterial(plugin == null ? "" : plugin); + CoreClass.debug("Material: " + Material.getMaterial(plugin == null ? "" : plugin)); // If it's not a plugin and actually an item, lmao if (plugin != null && Material.getMaterial(plugin) != null) { From 5b67cd7ca481b656bd74d232c60ba91902b9cb42 Mon Sep 17 00:00:00 2001 From: Holly P <25277367+Thatsmusic99@users.noreply.github.com> Date: Tue, 25 Jul 2023 13:10:59 +0100 Subject: [PATCH 09/12] fix: item payments being parsed incorrectly --- .../advancedteleport/payments/PaymentManager.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/AdvancedTeleport-Bukkit/src/main/java/io/github/niestrat99/advancedteleport/payments/PaymentManager.java b/AdvancedTeleport-Bukkit/src/main/java/io/github/niestrat99/advancedteleport/payments/PaymentManager.java index 9131562a..2586f587 100644 --- a/AdvancedTeleport-Bukkit/src/main/java/io/github/niestrat99/advancedteleport/payments/PaymentManager.java +++ b/AdvancedTeleport-Bukkit/src/main/java/io/github/niestrat99/advancedteleport/payments/PaymentManager.java @@ -67,10 +67,10 @@ private void addCommand(String command, Object value) { private Payment parsePayment(String rawPayment) { if (rawPayment.length() - 3 <= 0) { - Matcher matcher = Pattern.compile("^(.+:)?([0-9]+(\\.[0-9]+)?)").matcher(rawPayment); + Matcher matcher = Pattern.compile("^((.+):)?([0-9]+(\\.[0-9]+)?)").matcher(rawPayment); if (matcher.matches()) { - String plugin = matcher.group(1); - double payment = Double.parseDouble(matcher.group(2)); + String plugin = matcher.group(2); + double payment = Double.parseDouble(matcher.group(3)); CoreClass.debug("Split payment into two, part 1: " + plugin + ", part two: " + payment); CoreClass.debug("Material: " + Material.getMaterial(plugin == null ? "" : plugin)); @@ -90,10 +90,10 @@ private Payment parsePayment(String rawPayment) { } else if (rawPayment.endsWith("EXP")) { return new PointsPayment(Integer.parseInt(points)); } else { - Matcher matcher = Pattern.compile("^(.+:)?([0-9]+(\\.[0-9]+)?)").matcher(rawPayment); + Matcher matcher = Pattern.compile("^((.+):)?([0-9]+(\\.[0-9]+)?)").matcher(rawPayment); if (matcher.matches()) { - String plugin = matcher.group(1); - double payment = Double.parseDouble(matcher.group(2)); + String plugin = matcher.group(2); + double payment = Double.parseDouble(matcher.group(3)); CoreClass.debug("Split payment into two, part 1: " + plugin + ", part two: " + payment); CoreClass.debug("Material: " + Material.getMaterial(plugin == null ? "" : plugin)); From 31a0df9dfef4e55d0d4bd061fbd3ddc909367c1a Mon Sep 17 00:00:00 2001 From: Holly P <25277367+Thatsmusic99@users.noreply.github.com> Date: Mon, 31 Jul 2023 12:05:28 +0100 Subject: [PATCH 10/12] fix: check if permission is set --- .../advancedteleport/payments/PaymentManager.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/AdvancedTeleport-Bukkit/src/main/java/io/github/niestrat99/advancedteleport/payments/PaymentManager.java b/AdvancedTeleport-Bukkit/src/main/java/io/github/niestrat99/advancedteleport/payments/PaymentManager.java index 2586f587..3655217f 100644 --- a/AdvancedTeleport-Bukkit/src/main/java/io/github/niestrat99/advancedteleport/payments/PaymentManager.java +++ b/AdvancedTeleport-Bukkit/src/main/java/io/github/niestrat99/advancedteleport/payments/PaymentManager.java @@ -176,10 +176,10 @@ private HashMap getPayments(String command, Player player, Worl var payments = new HashMap(); for (String key : customCosts.getKeys(false)) { String worldName = toWorld.getName().toLowerCase(Locale.ROOT); - if (!player.hasPermission("at.member.cost." + key) - && !player.hasPermission("at.member.cost." + command + "." + key) - && !player.hasPermission("at.member.cost." + worldName + "." + key) - && !player.hasPermission( + if (!hasPermission(player, "at.member.cost." + key) + && !hasPermission(player, "at.member.cost." + command + "." + key) + && !hasPermission(player, "at.member.cost." + worldName + "." + key) + && !hasPermission(player, "at.member.cost." + command + "." + worldName + "." + key)) continue; String rawPayment = customCosts.getString(key); if (rawPayment == null) continue; @@ -190,4 +190,8 @@ private HashMap getPayments(String command, Player player, Worl if (payments.isEmpty()) payments = teleportCosts.get(command); return payments; } + + private boolean hasPermission(Player player, String permission) { + return player.isPermissionSet(permission) && player.hasPermission(permission); + } } From cac3fe8023c631c6d87bd382c4a033f3f5ca7085 Mon Sep 17 00:00:00 2001 From: Thatsmusic99 <25277367+thatsmusic99@users.noreply.github.com> Date: Tue, 8 Aug 2023 22:22:35 +0100 Subject: [PATCH 11/12] fix: warning about slimjar and semi-fix for building Signed-off-by: Thatsmusic99 <25277367+thatsmusic99@users.noreply.github.com> --- AdvancedTeleport-Bukkit/build.gradle.kts | 4 ++++ README.md | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/AdvancedTeleport-Bukkit/build.gradle.kts b/AdvancedTeleport-Bukkit/build.gradle.kts index 7bd7b7c1..ef99283e 100644 --- a/AdvancedTeleport-Bukkit/build.gradle.kts +++ b/AdvancedTeleport-Bukkit/build.gradle.kts @@ -189,6 +189,10 @@ tasks { } } +tasks.shadowJar { + from(tasks.slimJar.get().outputDirectory) +} + // Lead development use only. modrinth { token.set(System.getenv("MODRINTH_TOKEN")) diff --git a/README.md b/README.md index baf5a6f7..432c551b 100644 --- a/README.md +++ b/README.md @@ -24,5 +24,7 @@ Advanced Teleport is a rapidly growing plugin that is not only increasing sharpl ## Installation/Cloning As of currently, Advanced Teleport uses Gradle to manage its dependencies. -The Gradle command used to build the plugin is `gradle shadowJar` and is done under the AdvancedTeleport-Bukkit module. +The Gradle command used to build the plugin is `gradle slimJar` and is done under the AdvancedTeleport-Bukkit module. + +> NOTE: Due to a bug with SlimJar you should try building twice when updating dependencies or building for the first time, or necessary files will not be installed. From 154c5f35c9981c12073b4586b385809af3f25e01 Mon Sep 17 00:00:00 2001 From: Thatsmusic99 <25277367+thatsmusic99@users.noreply.github.com> Date: Wed, 9 Aug 2023 16:49:49 +0100 Subject: [PATCH 12/12] chore(version): bump to v6.0.0-rc.3 Signed-off-by: Thatsmusic99 <25277367+thatsmusic99@users.noreply.github.com> --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index d22731fe..c5b2d9d4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ # suppress inspection "UnusedProperty" for whole file group=io.github.niestrat99 -version=6.0.0-rc.2 +version=6.0.0-rc.3 # Keep up to date with https://github.com/DaRacci/Minix-Conventions kotlinVersion=1.8.0 build=7