From 98c568212f99347686cafb8b50e9433387857c2c Mon Sep 17 00:00:00 2001 From: shradinx Date: Fri, 11 Oct 2024 10:29:50 -0400 Subject: [PATCH 01/13] add MathUtils class since jdk 17 stinky --- .../vindicterralib/utils/MathUtils.java | 32 +++++++++++++++++++ .../vindicterralib/utils/StringUtils.java | 1 - 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 src/main/java/org/vindicterra/vindicterralib/utils/MathUtils.java diff --git a/src/main/java/org/vindicterra/vindicterralib/utils/MathUtils.java b/src/main/java/org/vindicterra/vindicterralib/utils/MathUtils.java new file mode 100644 index 0000000..b57c840 --- /dev/null +++ b/src/main/java/org/vindicterra/vindicterralib/utils/MathUtils.java @@ -0,0 +1,32 @@ +package org.vindicterra.vindicterralib.utils; + +@SuppressWarnings("unused") +public class MathUtils { + /** + * Clamps a value between a minimum and maximum value + *
+ *
+ * Clamped values will not go below or above the specified min and max values + * @param value Integer value to clamp + * @param min Minimum value allowed + * @param max Maximum value allowed + * @return Clamped value + */ + public static int clamp(int value, int min, int max) { + return Math.max(min, Math.min(max, value)); + } + + /** + * Clamps a value between a minimum and maximum value + *
+ *
+ * Clamped values will not go below or above the specified min and max values + * @param value Double value to clamp + * @param min Minimum value allowed + * @param max Maximum value allowed + * @return Clamped value + */ + public static double clamp(double value, double min, double max) { + return Math.max(min, Math.min(max, value)); + } +} diff --git a/src/main/java/org/vindicterra/vindicterralib/utils/StringUtils.java b/src/main/java/org/vindicterra/vindicterralib/utils/StringUtils.java index 4e8911f..ee74a19 100644 --- a/src/main/java/org/vindicterra/vindicterralib/utils/StringUtils.java +++ b/src/main/java/org/vindicterra/vindicterralib/utils/StringUtils.java @@ -13,7 +13,6 @@ import java.net.URL; import java.util.ArrayList; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; From 662ba7d91f122ddcd1ac262bf6decb4d743f5330 Mon Sep 17 00:00:00 2001 From: shradinx Date: Fri, 11 Oct 2024 10:48:41 -0400 Subject: [PATCH 02/13] add item utils class --- .../entities/players/ItemUtils.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/main/java/org/vindicterra/vindicterralib/entities/players/ItemUtils.java diff --git a/src/main/java/org/vindicterra/vindicterralib/entities/players/ItemUtils.java b/src/main/java/org/vindicterra/vindicterralib/entities/players/ItemUtils.java new file mode 100644 index 0000000..35363b2 --- /dev/null +++ b/src/main/java/org/vindicterra/vindicterralib/entities/players/ItemUtils.java @@ -0,0 +1,22 @@ +package org.vindicterra.vindicterralib.entities.players; + +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +public class ItemUtils { + /** + * Removes the specified amount of Bukkit material from the player's inventory + * @param player Player to remove item from + * @param material Bukkit material of item being removed + * @param amount Amount of item to be removed + */ + public static void removeItem(Player player, Material material, int amount) { + int index = player.getInventory().first(material); + if (index == -1) return; + ItemStack first = player.getInventory().getItem(index); + if (first == null) return; + first.setAmount(first.getAmount() - amount); + player.getInventory().setItem(index, first); + } +} From 18909b637fd47a9622cfa9b815e35fe074f40eff Mon Sep 17 00:00:00 2001 From: shradinx Date: Fri, 11 Oct 2024 10:48:48 -0400 Subject: [PATCH 03/13] add command utils class --- .../commandcreator/CommandUtils.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/main/java/org/vindicterra/vindicterralib/commandcreator/CommandUtils.java diff --git a/src/main/java/org/vindicterra/vindicterralib/commandcreator/CommandUtils.java b/src/main/java/org/vindicterra/vindicterralib/commandcreator/CommandUtils.java new file mode 100644 index 0000000..4a8ce4c --- /dev/null +++ b/src/main/java/org/vindicterra/vindicterralib/commandcreator/CommandUtils.java @@ -0,0 +1,31 @@ +package org.vindicterra.vindicterralib.commandcreator; + +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; + +import java.util.ArrayList; +import java.util.List; + +public class CommandUtils { + /** + * Returns the help menu containing all sub commands and their descriptions + * @param command Parent command to show menu for + * @return Component message to show to player + */ + public static Component returnHelpMenu(ParentCommand command) { + List subCommands = new ArrayList<>(); + for (ChildCommand sub : command.getSubCommands()) { + subCommands.add(Component.text(sub.getName() + " - " + sub.getDescription())); + } + Component header = Component.text("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-", NamedTextColor.GOLD) + .appendNewline() + .append(Component.text(String.format(" --- /%s Subcommands ---", + command.getName()), NamedTextColor.AQUA)) + .appendNewline().appendNewline(); + for (Component component : subCommands) { + header = header.append(component).appendNewline(); + } + return header.append(Component.text( + "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-", NamedTextColor.GOLD)); + } +} From 85d43ef014808e03b39949114f5838caf132fc34 Mon Sep 17 00:00:00 2001 From: TheSmimg <43554685+TheSmimg@users.noreply.github.com> Date: Sat, 19 Oct 2024 12:27:19 -0400 Subject: [PATCH 04/13] Fix GitHub Actions runner is broken :*( --- .github/workflows/releases.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/releases.yml b/.github/workflows/releases.yml index b3b68b5..2265979 100644 --- a/.github/workflows/releases.yml +++ b/.github/workflows/releases.yml @@ -17,7 +17,7 @@ on: jobs: build: - runs-on: self-hosted + runs-on: ubuntu-latest permissions: contents: write pull-requests: read From 036ec31a42834e733c0031745ac8b23fc0765cf8 Mon Sep 17 00:00:00 2001 From: bearofbusiness <61521224+bearofbusiness@users.noreply.github.com> Date: Sat, 19 Oct 2024 12:39:54 -0400 Subject: [PATCH 05/13] changed it back it should be fixed --- .github/workflows/releases.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/releases.yml b/.github/workflows/releases.yml index 2265979..b3b68b5 100644 --- a/.github/workflows/releases.yml +++ b/.github/workflows/releases.yml @@ -17,7 +17,7 @@ on: jobs: build: - runs-on: ubuntu-latest + runs-on: self-hosted permissions: contents: write pull-requests: read From 97e8606e1f83021840d8055fa9a59c95e0ed9aab Mon Sep 17 00:00:00 2001 From: Shradinx Date: Tue, 22 Oct 2024 17:54:14 -0400 Subject: [PATCH 06/13] add cooldown manager --- .../vindicterralib/VindicterraLib.java | 5 ++ .../vindicterralib/cooldown/Cooldown.java | 77 +++++++++++++++++++ .../cooldown/CooldownManager.java | 53 +++++++++++++ .../cooldown/CooldownStatus.java | 19 +++++ .../cooldown/CooldownUtils.java | 39 ++++++++++ 5 files changed, 193 insertions(+) create mode 100644 src/main/java/org/vindicterra/vindicterralib/cooldown/Cooldown.java create mode 100644 src/main/java/org/vindicterra/vindicterralib/cooldown/CooldownManager.java create mode 100644 src/main/java/org/vindicterra/vindicterralib/cooldown/CooldownStatus.java create mode 100644 src/main/java/org/vindicterra/vindicterralib/cooldown/CooldownUtils.java diff --git a/src/main/java/org/vindicterra/vindicterralib/VindicterraLib.java b/src/main/java/org/vindicterra/vindicterralib/VindicterraLib.java index 6d6cd5b..d154b40 100644 --- a/src/main/java/org/vindicterra/vindicterralib/VindicterraLib.java +++ b/src/main/java/org/vindicterra/vindicterralib/VindicterraLib.java @@ -1,12 +1,17 @@ package org.vindicterra.vindicterralib; +import lombok.Getter; import org.bukkit.plugin.java.JavaPlugin; + @SuppressWarnings("unused") public final class VindicterraLib extends JavaPlugin { + @Getter + private static VindicterraLib instance; @Override public void onEnable() { // Plugin startup logic + instance = this; getLogger().info("-- VindicterraLib Enabled! --"); } diff --git a/src/main/java/org/vindicterra/vindicterralib/cooldown/Cooldown.java b/src/main/java/org/vindicterra/vindicterralib/cooldown/Cooldown.java new file mode 100644 index 0000000..1dbac6a --- /dev/null +++ b/src/main/java/org/vindicterra/vindicterralib/cooldown/Cooldown.java @@ -0,0 +1,77 @@ +package org.vindicterra.vindicterralib.cooldown; + +import lombok.Getter; +import lombok.Setter; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; +import org.vindicterra.vindicterralib.StringUtil; + +@Getter +public class Cooldown extends BukkitRunnable { + @Setter + private long timeLeft; + private final long initialTime; + private final int duration; + private final String reason; + private final boolean showMessage; + private final Player player; + private long timeRan = 0L; + + public Cooldown(Player player, long initialTime, int duration, String reason, boolean showMessage) { + this.player = player; + this.initialTime = initialTime; + this.duration = duration; + this.timeLeft = duration; + this.reason = reason; + this.showMessage = showMessage; + } + + @Override + public void run() { + if (timeRan >= duration) { + sendOffCooldownMessage(); + remove(); + return; + } + timeRan++; + timeLeft = (long) ((((double) initialTime / 1000) + duration) + - ((double) System.currentTimeMillis() / 1000)); + } + + /** + * @param message Message to send to player + */ + public void sendActionBar(Component message) { + if (!showMessage) { + return; + } + player.sendActionBar(message); + } + + /** + * Send off cooldown message to player + */ + public void sendOffCooldownMessage() { + sendActionBar(Component.text( + "You are no longer on cooldown for " + StringUtil.format(reason) + "!", + NamedTextColor.GREEN) + ); + } + + /** + * Send on cooldown message to player + */ + public void sendOnCooldownMessage() { + sendActionBar(Component.text( + String.format("You are on cooldown for %s seconds...", timeLeft), + NamedTextColor.RED) + ); + } + + public void remove() { + CooldownManager.cooldowns.remove(this); + this.cancel(); + } +} diff --git a/src/main/java/org/vindicterra/vindicterralib/cooldown/CooldownManager.java b/src/main/java/org/vindicterra/vindicterralib/cooldown/CooldownManager.java new file mode 100644 index 0000000..ecb9444 --- /dev/null +++ b/src/main/java/org/vindicterra/vindicterralib/cooldown/CooldownManager.java @@ -0,0 +1,53 @@ +package org.vindicterra.vindicterralib.cooldown; + +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.vindicterra.vindicterralib.VindicterraLib; + +import javax.annotation.Nullable; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +public class CooldownManager { + public static final List cooldowns = new ArrayList<>(); + /** + * @param player Player to apply cooldown to + * @param event Cancellable event thrown by player + * @param seconds Duration of cooldown + * @param reason Reason for cooldown + * @param showMessage Whether to show cooldown message as actionbar + * @return Status of new or existing cooldown + */ + public static CooldownStatus handleCooldown(Player player, @Nullable Event event, int seconds, String reason, boolean showMessage) { + UUID uuid = player.getUniqueId(); + + if (player.hasPermission("vindicterraweapons.admin.cooldown-bypass")) { + return CooldownStatus.OFF_COOLDOWN; + } + + for (Cooldown cd : cooldowns) { + if (cd.getPlayer().getUniqueId() != uuid) continue; + if (!cd.getReason().equals(reason)) continue; + long timeLeft = cd.getTimeLeft(); + if (timeLeft > 0) { + cd.sendOnCooldownMessage(); + if (event instanceof Cancellable) { + ((Cancellable) event).setCancelled(true); + } + return CooldownStatus.ON_COOLDOWN; + } else if (timeLeft == 0) { + cd.remove(); + cd.sendOffCooldownMessage(); + return CooldownStatus.OFF_COOLDOWN; + } + } + + Cooldown cd = new Cooldown(player, System.currentTimeMillis(), seconds, reason, showMessage); + cd.runTaskTimer(VindicterraLib.getInstance(), 0, 20); + cooldowns.add(cd); + + return CooldownStatus.NEW_COOLDOWN; + } +} diff --git a/src/main/java/org/vindicterra/vindicterralib/cooldown/CooldownStatus.java b/src/main/java/org/vindicterra/vindicterralib/cooldown/CooldownStatus.java new file mode 100644 index 0000000..158d500 --- /dev/null +++ b/src/main/java/org/vindicterra/vindicterralib/cooldown/CooldownStatus.java @@ -0,0 +1,19 @@ +package org.vindicterra.vindicterralib.cooldown; + +/** + * Status of player cooldown + */ +public enum CooldownStatus { + /** + * Player is off cooldown + */ + OFF_COOLDOWN, + /** + * Player is on cooldown + */ + ON_COOLDOWN, + /** + * A new cooldown has been created for the player + */ + NEW_COOLDOWN +} diff --git a/src/main/java/org/vindicterra/vindicterralib/cooldown/CooldownUtils.java b/src/main/java/org/vindicterra/vindicterralib/cooldown/CooldownUtils.java new file mode 100644 index 0000000..ef70dde --- /dev/null +++ b/src/main/java/org/vindicterra/vindicterralib/cooldown/CooldownUtils.java @@ -0,0 +1,39 @@ +package org.vindicterra.vindicterralib.cooldown; + +import org.bukkit.entity.Player; + +import java.util.List; + +public class CooldownUtils { + /** + * @param player Player to check for cooldown + * @return True if player is on cooldown, otherwise false + * @apiNote This method will return if the player is on cooldown for ANY reason! + * To check for a specific reason, use {@link CooldownUtils#isOnCooldownForReason(Player, String)} + */ + public static boolean isOnCooldown(Player player) { + List cooldowns = CooldownManager.cooldowns; + for (Cooldown cd : cooldowns) { + if (!cd.getPlayer().getUniqueId().equals(player.getUniqueId())) continue; + return true; + } + return false; + } + + /** + * @param player Player to check for cooldown + * @param reason Reason for cooldown + * @return True if player is on cooldown for specified reason, otherwise false + * @apiNote This method will return if the player is on cooldown for a SPECIFIC reason! + * To check for any reason, use {@link CooldownUtils#isOnCooldown(Player)} + */ + public static boolean isOnCooldownForReason(Player player, String reason) { + if (!isOnCooldown(player)) return false; + for (Cooldown cd : CooldownManager.cooldowns) { + if (!cd.getPlayer().getUniqueId().equals(player.getUniqueId())) continue; + if (!cd.getReason().equals(reason)) continue; + return true; + } + return false; + } +} From 7836c2deb83be9df0675dfd4ef85de62c6b46315 Mon Sep 17 00:00:00 2001 From: Shradinx Date: Tue, 22 Oct 2024 18:06:10 -0400 Subject: [PATCH 07/13] update StringUtils#format and StringUtils#deformat methods --- .../vindicterralib/cooldown/Cooldown.java | 4 +-- .../vindicterralib/utils/StringUtils.java | 31 ++++++++++++------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/vindicterra/vindicterralib/cooldown/Cooldown.java b/src/main/java/org/vindicterra/vindicterralib/cooldown/Cooldown.java index 1dbac6a..d536d70 100644 --- a/src/main/java/org/vindicterra/vindicterralib/cooldown/Cooldown.java +++ b/src/main/java/org/vindicterra/vindicterralib/cooldown/Cooldown.java @@ -6,7 +6,7 @@ import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; -import org.vindicterra.vindicterralib.StringUtil; +import org.vindicterra.vindicterralib.utils.StringUtils; @Getter public class Cooldown extends BukkitRunnable { @@ -55,7 +55,7 @@ public void sendActionBar(Component message) { */ public void sendOffCooldownMessage() { sendActionBar(Component.text( - "You are no longer on cooldown for " + StringUtil.format(reason) + "!", + "You are no longer on cooldown for " + StringUtils.format(reason) + "!", NamedTextColor.GREEN) ); } diff --git a/src/main/java/org/vindicterra/vindicterralib/utils/StringUtils.java b/src/main/java/org/vindicterra/vindicterralib/utils/StringUtils.java index ee74a19..5f32dbd 100644 --- a/src/main/java/org/vindicterra/vindicterralib/utils/StringUtils.java +++ b/src/main/java/org/vindicterra/vindicterralib/utils/StringUtils.java @@ -168,24 +168,31 @@ public static double round(double value, int places) { return decimal.doubleValue(); } - //what is this for? is it really necessary to have it in lib? + // what is this for? is it really necessary to have it in lib? /** - * @param name Item name to format - * @return Formatted item name in the style of "Grass Block" + * Formats the given input into a readable format (Ex. Grass Block) + * + * @param input Input to format + * @return Formatted string */ - public static String format(final String name) { - StringBuilder output = new StringBuilder(); - for (String character : name.split("_")) { - output.append(character.substring(0, 1).toUpperCase()).append(character.substring(1).toLowerCase()).append(" "); + public static String format(final String input) { + StringBuilder builder = new StringBuilder(); + for (String s : input.split("_")) { + builder.append(s.substring(0, 1).toUpperCase()) + .append(s.substring(1).toLowerCase()) + .append(" "); } - return output.substring(0, output.length() - 1); + return builder.toString(); } /** - * @param name Name to remove formatting from - * @return Unformatted name in the style of "GRASS_BLOCK" + * Deformats a string into Bukkit material formatting (Ex. GRASS_BLOCK) + * + * @param input Input to deformat + * @return Deformatted String */ - public static String deformat(final String name) { - return ((TextComponent) Component.text(name.toUpperCase().replace(" ", "_")).compact()).content(); + public static String deformat(final String input) { + return ((TextComponent) Component.text(input.toUpperCase() + .replace(" ", "_")).compact()).content(); } } From 26529cf0b6747157519e956190655091886659f4 Mon Sep 17 00:00:00 2001 From: Shradinx Date: Tue, 22 Oct 2024 18:09:16 -0400 Subject: [PATCH 08/13] rename format and deformat string methods --- .../org/vindicterra/vindicterralib/cooldown/Cooldown.java | 2 +- .../org/vindicterra/vindicterralib/utils/StringUtils.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/vindicterra/vindicterralib/cooldown/Cooldown.java b/src/main/java/org/vindicterra/vindicterralib/cooldown/Cooldown.java index d536d70..d1294e6 100644 --- a/src/main/java/org/vindicterra/vindicterralib/cooldown/Cooldown.java +++ b/src/main/java/org/vindicterra/vindicterralib/cooldown/Cooldown.java @@ -55,7 +55,7 @@ public void sendActionBar(Component message) { */ public void sendOffCooldownMessage() { sendActionBar(Component.text( - "You are no longer on cooldown for " + StringUtils.format(reason) + "!", + "You are no longer on cooldown for " + StringUtils.toFriendlyFormat(reason) + "!", NamedTextColor.GREEN) ); } diff --git a/src/main/java/org/vindicterra/vindicterralib/utils/StringUtils.java b/src/main/java/org/vindicterra/vindicterralib/utils/StringUtils.java index 5f32dbd..5160409 100644 --- a/src/main/java/org/vindicterra/vindicterralib/utils/StringUtils.java +++ b/src/main/java/org/vindicterra/vindicterralib/utils/StringUtils.java @@ -175,7 +175,7 @@ public static double round(double value, int places) { * @param input Input to format * @return Formatted string */ - public static String format(final String input) { + public static String toFriendlyFormat(final String input) { StringBuilder builder = new StringBuilder(); for (String s : input.split("_")) { builder.append(s.substring(0, 1).toUpperCase()) @@ -191,7 +191,7 @@ public static String format(final String input) { * @param input Input to deformat * @return Deformatted String */ - public static String deformat(final String input) { + public static String toBukkitFormat(final String input) { return ((TextComponent) Component.text(input.toUpperCase() .replace(" ", "_")).compact()).content(); } From 9008a1c4935d2ef85e0bf9b3484149800776bb97 Mon Sep 17 00:00:00 2001 From: Shradinx Date: Thu, 24 Oct 2024 19:32:29 -0400 Subject: [PATCH 09/13] add getCooldown methods to cooldown manager --- .../cooldown/CooldownManager.java | 42 +++++++++++++++---- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/vindicterra/vindicterralib/cooldown/CooldownManager.java b/src/main/java/org/vindicterra/vindicterralib/cooldown/CooldownManager.java index ecb9444..94b2f87 100644 --- a/src/main/java/org/vindicterra/vindicterralib/cooldown/CooldownManager.java +++ b/src/main/java/org/vindicterra/vindicterralib/cooldown/CooldownManager.java @@ -27,19 +27,18 @@ public static CooldownStatus handleCooldown(Player player, @Nullable Event event return CooldownStatus.OFF_COOLDOWN; } - for (Cooldown cd : cooldowns) { - if (cd.getPlayer().getUniqueId() != uuid) continue; - if (!cd.getReason().equals(reason)) continue; - long timeLeft = cd.getTimeLeft(); + Cooldown pCooldown = getCooldown(player, reason); + if (pCooldown != null) { + long timeLeft = pCooldown.getTimeLeft(); if (timeLeft > 0) { - cd.sendOnCooldownMessage(); + pCooldown.sendOnCooldownMessage(); if (event instanceof Cancellable) { ((Cancellable) event).setCancelled(true); } return CooldownStatus.ON_COOLDOWN; - } else if (timeLeft == 0) { - cd.remove(); - cd.sendOffCooldownMessage(); + } else { + pCooldown.remove(); + pCooldown.sendOffCooldownMessage(); return CooldownStatus.OFF_COOLDOWN; } } @@ -47,7 +46,32 @@ public static CooldownStatus handleCooldown(Player player, @Nullable Event event Cooldown cd = new Cooldown(player, System.currentTimeMillis(), seconds, reason, showMessage); cd.runTaskTimer(VindicterraLib.getInstance(), 0, 20); cooldowns.add(cd); - return CooldownStatus.NEW_COOLDOWN; } + + /** + * @param player Player to get all cooldowns for + * @return Possibly-empty list of active cooldowns associated with the player + */ + public static List getCooldowns(Player player) { + List playerCooldowns = new ArrayList<>(); + for (Cooldown cd : cooldowns) { + if (cd.getPlayer().getUniqueId() != player.getUniqueId()) continue; + playerCooldowns.add(cd); + } + return playerCooldowns; + } + + /** + * @param player Player to get a cooldown for + * @param reason Reason for cooldown + * @return Possibly-null active cooldown associated with player + */ + public static @Nullable Cooldown getCooldown(Player player, String reason) { + for (Cooldown cd : getCooldowns(player)) { + if (!cd.getReason().equals(reason)) continue; + return cd; + } + return null; + } } From b85b76d3d2223c10bbc4426b4d30576d5028f9ef Mon Sep 17 00:00:00 2001 From: Shradinx Date: Mon, 28 Oct 2024 17:11:16 -0400 Subject: [PATCH 10/13] modify returned value in cooldown manager for perm bypass --- .../vindicterralib/cooldown/CooldownManager.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/vindicterra/vindicterralib/cooldown/CooldownManager.java b/src/main/java/org/vindicterra/vindicterralib/cooldown/CooldownManager.java index 94b2f87..082d717 100644 --- a/src/main/java/org/vindicterra/vindicterralib/cooldown/CooldownManager.java +++ b/src/main/java/org/vindicterra/vindicterralib/cooldown/CooldownManager.java @@ -23,8 +23,8 @@ public class CooldownManager { public static CooldownStatus handleCooldown(Player player, @Nullable Event event, int seconds, String reason, boolean showMessage) { UUID uuid = player.getUniqueId(); - if (player.hasPermission("vindicterraweapons.admin.cooldown-bypass")) { - return CooldownStatus.OFF_COOLDOWN; + if (player.hasPermission("vindicterralib.admin.cooldown-bypass")) { + return CooldownStatus.NEW_COOLDOWN; } Cooldown pCooldown = getCooldown(player, reason); @@ -32,9 +32,11 @@ public static CooldownStatus handleCooldown(Player player, @Nullable Event event long timeLeft = pCooldown.getTimeLeft(); if (timeLeft > 0) { pCooldown.sendOnCooldownMessage(); + /* if (event instanceof Cancellable) { ((Cancellable) event).setCancelled(true); } + */ return CooldownStatus.ON_COOLDOWN; } else { pCooldown.remove(); @@ -68,7 +70,8 @@ public static List getCooldowns(Player player) { * @return Possibly-null active cooldown associated with player */ public static @Nullable Cooldown getCooldown(Player player, String reason) { - for (Cooldown cd : getCooldowns(player)) { + List pCooldowns = getCooldowns(player); + for (Cooldown cd : pCooldowns) { if (!cd.getReason().equals(reason)) continue; return cd; } From de865c7cd3dbaaa180a9e40be5cb5c67c900a478 Mon Sep 17 00:00:00 2001 From: Shradinx Date: Mon, 28 Oct 2024 17:11:55 -0400 Subject: [PATCH 11/13] modify return type for ItemUtils#removeItem --- .../vindicterralib/entities/players/ItemUtils.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/vindicterra/vindicterralib/entities/players/ItemUtils.java b/src/main/java/org/vindicterra/vindicterralib/entities/players/ItemUtils.java index 35363b2..5f194f0 100644 --- a/src/main/java/org/vindicterra/vindicterralib/entities/players/ItemUtils.java +++ b/src/main/java/org/vindicterra/vindicterralib/entities/players/ItemUtils.java @@ -10,13 +10,16 @@ public class ItemUtils { * @param player Player to remove item from * @param material Bukkit material of item being removed * @param amount Amount of item to be removed + * + * @return True if item was successfully removed, otherwise false */ - public static void removeItem(Player player, Material material, int amount) { + public static boolean removeItem(Player player, Material material, int amount) { int index = player.getInventory().first(material); - if (index == -1) return; + if (index == -1) return false; ItemStack first = player.getInventory().getItem(index); - if (first == null) return; + if (first == null) return false; first.setAmount(first.getAmount() - amount); player.getInventory().setItem(index, first); + return true; } } From 8687a6281a83d4a702cde8398e00fb57930229f5 Mon Sep 17 00:00:00 2001 From: Shradinx Date: Mon, 28 Oct 2024 17:12:05 -0400 Subject: [PATCH 12/13] fix permission for cooldown bypass --- src/main/resources/plugin.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 545265b..4dd5289 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -4,3 +4,9 @@ main: org.vindicterra.vindicterralib.VindicterraLib api-version: '1.20' load: STARTUP description: Vindicterra Standard Library +permissions: + vindicterralib.admin: + default: op + description: Allows you to access admin commands or features + children: + - vindicterralib.admin.cooldown-bypass From 835afa3ab499dce7d4629c4cfbb827fa08fc68be Mon Sep 17 00:00:00 2001 From: Shradinx Date: Fri, 1 Nov 2024 23:23:57 -0400 Subject: [PATCH 13/13] add gamemode check in ItemUtils#removeItem --- .../vindicterralib/entities/players/ItemUtils.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/vindicterra/vindicterralib/entities/players/ItemUtils.java b/src/main/java/org/vindicterra/vindicterralib/entities/players/ItemUtils.java index 5f194f0..d229981 100644 --- a/src/main/java/org/vindicterra/vindicterralib/entities/players/ItemUtils.java +++ b/src/main/java/org/vindicterra/vindicterralib/entities/players/ItemUtils.java @@ -1,5 +1,6 @@ package org.vindicterra.vindicterralib.entities.players; +import org.bukkit.GameMode; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -13,7 +14,10 @@ public class ItemUtils { * * @return True if item was successfully removed, otherwise false */ - public static boolean removeItem(Player player, Material material, int amount) { + public static boolean removeItem(Player player, Material material, int amount, boolean checkGamemode) { + if (checkGamemode && player.getGameMode().equals(GameMode.CREATIVE)) { + return false; + } int index = player.getInventory().first(material); if (index == -1) return false; ItemStack first = player.getInventory().getItem(index);