From e7ec7c06f9ce610ce661bc186ce18c762312afcd Mon Sep 17 00:00:00 2001 From: Foulest <43710301+Foulest@users.noreply.github.com> Date: Wed, 30 Oct 2024 03:40:53 -0700 Subject: [PATCH] 1.4.1 - Recoded entire codebase - Reworked every kit from the ground up --- build.gradle | 2 +- src/main/java/net/foulest/kitpvp/KitPvP.java | 18 +- .../foulest/kitpvp/cmds/ArmorColorCmd.java | 31 +- .../net/foulest/kitpvp/cmds/BalanceCmd.java | 16 +- .../net/foulest/kitpvp/cmds/BountyCmd.java | 66 +- .../net/foulest/kitpvp/cmds/ClearKitCmd.java | 45 +- .../net/foulest/kitpvp/cmds/CombatTagCmd.java | 21 +- .../java/net/foulest/kitpvp/cmds/EcoCmd.java | 45 +- .../foulest/kitpvp/cmds/KitEnchanterCmd.java | 26 +- .../net/foulest/kitpvp/cmds/KitPvPCmd.java | 20 +- .../net/foulest/kitpvp/cmds/KitShopCmd.java | 15 +- .../java/net/foulest/kitpvp/cmds/KitsCmd.java | 13 +- .../java/net/foulest/kitpvp/cmds/PayCmd.java | 34 +- .../net/foulest/kitpvp/cmds/PotionsCmd.java | 13 +- .../net/foulest/kitpvp/cmds/SetSpawnCmd.java | 12 +- .../java/net/foulest/kitpvp/cmds/SoupCmd.java | 13 +- .../net/foulest/kitpvp/cmds/SpawnCmd.java | 5 +- .../net/foulest/kitpvp/cmds/StatsCmd.java | 54 +- .../foulest/kitpvp/combattag/CombatTag.java | 13 +- .../net/foulest/kitpvp/data/PlayerData.java | 118 +- .../kitpvp/data/PlayerDataManager.java | 29 +- .../net/foulest/kitpvp/enchants/Enchants.java | 19 +- .../java/net/foulest/kitpvp/kits/Kit.java | 101 +- .../net/foulest/kitpvp/kits/KitManager.java | 7 +- .../net/foulest/kitpvp/kits/type/Archer.java | 19 +- .../foulest/kitpvp/kits/type/Burrower.java | 96 - .../net/foulest/kitpvp/kits/type/Cactus.java | 101 -- .../net/foulest/kitpvp/kits/type/Dragon.java | 101 -- .../foulest/kitpvp/kits/type/Fisherman.java | 6 +- .../net/foulest/kitpvp/kits/type/Ghost.java | 96 - .../net/foulest/kitpvp/kits/type/Hulk.java | 101 -- .../foulest/kitpvp/kits/type/Imprisoner.java | 98 - .../foulest/kitpvp/kits/type/Kangaroo.java | 6 +- .../net/foulest/kitpvp/kits/type/Knight.java | 4 +- .../net/foulest/kitpvp/kits/type/Mage.java | 11 +- .../net/foulest/kitpvp/kits/type/Monk.java | 98 - .../net/foulest/kitpvp/kits/type/Ninja.java | 10 +- .../net/foulest/kitpvp/kits/type/Pyro.java | 23 +- .../foulest/kitpvp/kits/type/Spiderman.java | 98 - .../foulest/kitpvp/kits/type/Summoner.java | 97 - .../net/foulest/kitpvp/kits/type/Tamer.java | 98 - .../net/foulest/kitpvp/kits/type/Tank.java | 22 +- .../net/foulest/kitpvp/kits/type/Thor.java | 93 - .../foulest/kitpvp/kits/type/Timelord.java | 97 - .../net/foulest/kitpvp/kits/type/Vampire.java | 12 +- .../net/foulest/kitpvp/kits/type/Zen.java | 98 - .../kitpvp/listeners/DeathListener.java | 131 +- .../kitpvp/listeners/EventListener.java | 175 +- .../kitpvp/listeners/FlaskListener.java | 237 +++ .../foulest/kitpvp/listeners/KitListener.java | 1601 +++++------------ .../foulest/kitpvp/menus/KitEnchanter.java | 7 +- .../net/foulest/kitpvp/menus/KitSelector.java | 41 +- .../net/foulest/kitpvp/menus/KitShop.java | 39 +- .../net/foulest/kitpvp/region/Regions.java | 29 +- .../java/net/foulest/kitpvp/region/Spawn.java | 18 +- .../net/foulest/kitpvp/util/BlockUtil.java | 39 +- .../net/foulest/kitpvp/util/ConstantUtil.java | 2 +- .../net/foulest/kitpvp/util/DatabaseUtil.java | 210 ++- .../net/foulest/kitpvp/util/MessageUtil.java | 8 +- .../java/net/foulest/kitpvp/util/NMSUtil.java | 7 +- .../foulest/kitpvp/util/PlaceholderUtil.java | 48 +- .../net/foulest/kitpvp/util/Settings.java | 232 +-- .../net/foulest/kitpvp/util/TaskUtil.java | 12 +- .../kitpvp/util/command/BukkitCompleter.java | 19 +- .../kitpvp/util/command/CommandArgs.java | 6 +- .../kitpvp/util/command/CommandFramework.java | 100 +- .../kitpvp/util/data/ConcurrentStream.java | 9 +- .../foulest/kitpvp/util/item/ItemBuilder.java | 10 +- .../kitpvp/util/item/SkullBuilder.java | 26 +- .../kitpvp/util/raytrace/BoundingBox.java | 46 +- .../util/yaml/CustomYamlConfiguration.java | 29 +- src/main/resources/config.yml | 109 +- 72 files changed, 1883 insertions(+), 3428 deletions(-) delete mode 100644 src/main/java/net/foulest/kitpvp/kits/type/Burrower.java delete mode 100644 src/main/java/net/foulest/kitpvp/kits/type/Cactus.java delete mode 100644 src/main/java/net/foulest/kitpvp/kits/type/Dragon.java delete mode 100644 src/main/java/net/foulest/kitpvp/kits/type/Ghost.java delete mode 100644 src/main/java/net/foulest/kitpvp/kits/type/Hulk.java delete mode 100644 src/main/java/net/foulest/kitpvp/kits/type/Imprisoner.java delete mode 100644 src/main/java/net/foulest/kitpvp/kits/type/Monk.java delete mode 100644 src/main/java/net/foulest/kitpvp/kits/type/Spiderman.java delete mode 100644 src/main/java/net/foulest/kitpvp/kits/type/Summoner.java delete mode 100644 src/main/java/net/foulest/kitpvp/kits/type/Tamer.java delete mode 100644 src/main/java/net/foulest/kitpvp/kits/type/Thor.java delete mode 100644 src/main/java/net/foulest/kitpvp/kits/type/Timelord.java delete mode 100644 src/main/java/net/foulest/kitpvp/kits/type/Zen.java create mode 100644 src/main/java/net/foulest/kitpvp/listeners/FlaskListener.java diff --git a/build.gradle b/build.gradle index 41cdaa5..7d9e92a 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ plugins { } group = 'net.foulest' -version = '1.4.0' +version = '1.4.1' description = 'KitPvP' // Set the project's language level diff --git a/src/main/java/net/foulest/kitpvp/KitPvP.java b/src/main/java/net/foulest/kitpvp/KitPvP.java index cd3548a..7be749c 100644 --- a/src/main/java/net/foulest/kitpvp/KitPvP.java +++ b/src/main/java/net/foulest/kitpvp/KitPvP.java @@ -27,6 +27,7 @@ import net.foulest.kitpvp.kits.type.*; import net.foulest.kitpvp.listeners.DeathListener; import net.foulest.kitpvp.listeners.EventListener; +import net.foulest.kitpvp.listeners.FlaskListener; import net.foulest.kitpvp.listeners.KitListener; import net.foulest.kitpvp.region.Spawn; import net.foulest.kitpvp.util.DatabaseUtil; @@ -42,7 +43,6 @@ import org.jetbrains.annotations.NotNull; import java.util.Collections; -import java.util.Objects; import java.util.logging.Level; /** @@ -72,6 +72,7 @@ public void onLoad() { @Override @SneakyThrows + @SuppressWarnings("NestedMethodCall") public void onEnable() { // Kicks all online players. Bukkit.getOnlinePlayers().forEach(player -> player.kickPlayer("Disconnected")); @@ -96,7 +97,7 @@ public void onEnable() { // Loads the plugin's listeners. MessageUtil.log(Level.INFO, "Loading Listeners..."); - loadListeners(new DeathListener(), new EventListener(), new KitListener()); + loadListeners(new DeathListener(), new EventListener(), new KitListener(), new FlaskListener()); // Loads the plugin's commands. MessageUtil.log(Level.INFO, "Loading Commands..."); @@ -107,10 +108,8 @@ public void onEnable() { // Loads the plugin's kits. MessageUtil.log(Level.INFO, "Loading Kits..."); - loadKits(new Archer(), new Burrower(), new Cactus(), new Dragon(), new Fisherman(), new Ghost(), new Tamer(), - new Hulk(), new Imprisoner(), new Kangaroo(), new Knight(), new Mage(), new Monk(), new Ninja(), - new Pyro(), new Spiderman(), new Summoner(), new Tank(), new Thor(), new Timelord(), new Vampire(), - new Zen()); + loadKits(new Archer(), new Fisherman(), new Kangaroo(), new Knight(), new Mage(), + new Ninja(), new Pyro(), new Tank(), new Vampire()); // Loads the spawn. MessageUtil.log(Level.INFO, "Loading Spawn..."); @@ -125,7 +124,12 @@ public void onEnable() { // Loads online players' user data. MessageUtil.log(Level.INFO, "Loading Player Data..."); for (Player player : Bukkit.getOnlinePlayers()) { - Objects.requireNonNull(PlayerDataManager.getPlayerData(player)).load(); + PlayerData playerData = PlayerDataManager.getPlayerData(player); + + if (playerData != null) { + playerData.load(); + } + Spawn.teleport(player); player.getInventory().setHeldItemSlot(0); } diff --git a/src/main/java/net/foulest/kitpvp/cmds/ArmorColorCmd.java b/src/main/java/net/foulest/kitpvp/cmds/ArmorColorCmd.java index aaeb555..3a8f6a7 100644 --- a/src/main/java/net/foulest/kitpvp/cmds/ArmorColorCmd.java +++ b/src/main/java/net/foulest/kitpvp/cmds/ArmorColorCmd.java @@ -17,7 +17,7 @@ */ package net.foulest.kitpvp.cmds; -import net.foulest.kitpvp.util.ConstantUtil; +import lombok.Data; import net.foulest.kitpvp.util.MessageUtil; import net.foulest.kitpvp.util.command.Command; import net.foulest.kitpvp.util.command.CommandArgs; @@ -27,6 +27,7 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.PlayerInventory; import org.jetbrains.annotations.NotNull; /** @@ -35,19 +36,14 @@ * * @author Foulest */ +@Data public class ArmorColorCmd { - @SuppressWarnings("MethodMayBeStatic") @Command(name = "armorcolor", description = "Colors your chestplate with an RGB hex.", permission = "kitpvp.armorcolor", usage = "/armorcolor [hex]", inGameOnly = true) - public void onCommand(@NotNull CommandArgs args) { - Player player = args.getPlayer(); + public static void onCommand(@NotNull CommandArgs args) { CommandSender sender = args.getSender(); - - if (player == null) { - MessageUtil.messagePlayer(sender, ConstantUtil.IN_GAME_ONLY); - return; - } + Player player = args.getPlayer(); // Prints the usage message. if (args.length() != 1) { @@ -55,22 +51,27 @@ public void onCommand(@NotNull CommandArgs args) { return; } - if (args.getArgs(0).length() != 6) { + String hex = args.getArgs(0); + + if (hex.length() != 6) { MessageUtil.messagePlayer(sender, "&cInvalid hex."); return; } - if (player.getInventory().getChestplate().getType() != Material.LEATHER_CHESTPLATE) { + PlayerInventory inventory = player.getInventory(); + ItemStack invChestplate = inventory.getChestplate(); + + if (invChestplate.getType() != Material.LEATHER_CHESTPLATE) { MessageUtil.messagePlayer(sender, "&cYou can't color that chestplate."); return; } - ItemStack chestplate = new ItemBuilder(player.getInventory().getChestplate()) - .color(Color.fromRGB(Integer.parseInt(args.getArgs(0), 16))).getItem(); + ItemStack chestplate = new ItemBuilder(invChestplate) + .color(Color.fromRGB(Integer.parseInt(hex, 16))).getItem(); - player.getInventory().setChestplate(chestplate); + inventory.setChestplate(chestplate); player.updateInventory(); - MessageUtil.messagePlayer(sender, "&aColor 0x" + args.getArgs(0) + " has been applied."); + MessageUtil.messagePlayer(sender, "&aColor 0x" + hex + " has been applied."); } } diff --git a/src/main/java/net/foulest/kitpvp/cmds/BalanceCmd.java b/src/main/java/net/foulest/kitpvp/cmds/BalanceCmd.java index 028fb93..7896aa5 100644 --- a/src/main/java/net/foulest/kitpvp/cmds/BalanceCmd.java +++ b/src/main/java/net/foulest/kitpvp/cmds/BalanceCmd.java @@ -17,6 +17,7 @@ */ package net.foulest.kitpvp.cmds; +import lombok.Data; import net.foulest.kitpvp.data.PlayerData; import net.foulest.kitpvp.data.PlayerDataManager; import net.foulest.kitpvp.util.ConstantUtil; @@ -33,13 +34,13 @@ * * @author Foulest */ +@Data public class BalanceCmd { - @SuppressWarnings("MethodMayBeStatic") @Command(name = "balance", aliases = {"bal", "money", "coins"}, description = "Shows your current balance.", permission = "kitpvp.balance", usage = "/balance [player]", inGameOnly = true) - public void onCommand(@NotNull CommandArgs args) { + public static void onCommand(@NotNull CommandArgs args) { CommandSender sender = args.getSender(); Player player = args.getPlayer(); @@ -53,11 +54,13 @@ public void onCommand(@NotNull CommandArgs args) { // Prints the usage message. if (args.length() != 1) { - MessageUtil.messagePlayer(sender, "&fCoins: &6" + playerData.getCoins()); + int coins = playerData.getCoins(); + MessageUtil.messagePlayer(sender, "&fCoins: &6" + coins); return; } - Player target = Bukkit.getPlayer(args.getArgs(0)); + String targetName = args.getArgs(0); + Player target = Bukkit.getPlayer(targetName); PlayerData targetData = PlayerDataManager.getPlayerData(target); if (!target.isOnline()) { @@ -65,6 +68,9 @@ public void onCommand(@NotNull CommandArgs args) { return; } - MessageUtil.messagePlayer(args.getSender(), "&f" + target.getName() + "'s Coins: &6" + targetData.getCoins()); + targetName = target.getName(); + int targetCoins = targetData.getCoins(); + + MessageUtil.messagePlayer(sender, "&f" + targetName + "'s Coins: &6" + targetCoins); } } diff --git a/src/main/java/net/foulest/kitpvp/cmds/BountyCmd.java b/src/main/java/net/foulest/kitpvp/cmds/BountyCmd.java index 5ea50d9..c821b67 100644 --- a/src/main/java/net/foulest/kitpvp/cmds/BountyCmd.java +++ b/src/main/java/net/foulest/kitpvp/cmds/BountyCmd.java @@ -17,6 +17,7 @@ */ package net.foulest.kitpvp.cmds; +import lombok.Data; import net.foulest.kitpvp.data.PlayerData; import net.foulest.kitpvp.data.PlayerDataManager; import net.foulest.kitpvp.util.ConstantUtil; @@ -30,18 +31,20 @@ import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; +import java.util.UUID; + /** * Command for placing bounties on other players. * * @author Foulest */ +@Data public class BountyCmd { - @SuppressWarnings("MethodMayBeStatic") @Command(name = "bounty", aliases = "bounties", description = "Allows players to place bounties on each other.", permission = "kitpvp.bounties", usage = "/bounty [player]", inGameOnly = true) - public void onCommand(@NotNull CommandArgs args) { + public static void onCommand(@NotNull CommandArgs args) { CommandSender sender = args.getSender(); Player player = args.getPlayer(); @@ -52,7 +55,12 @@ public void onCommand(@NotNull CommandArgs args) { } PlayerData playerData = PlayerDataManager.getPlayerData(player); - Player benefactor = Bukkit.getPlayer(playerData.getBenefactor()); + UUID playerUUID = player.getUniqueId(); + String playerName = player.getName(); + + UUID benefactorUUID = playerData.getBenefactor(); + Player benefactor = Bukkit.getPlayer(benefactorUUID); + String benefactorName = benefactor.getName(); // Checks if the bounties feature is enabled. if (!Settings.bountiesEnabled) { @@ -62,13 +70,14 @@ public void onCommand(@NotNull CommandArgs args) { if (args.length() == 0) { MessageUtil.messagePlayer(player, ""); + int activeBounty = playerData.getBounty(); - if (playerData.getBounty() == 0 || playerData.getBenefactor() == null || !benefactor.isOnline()) { + if (activeBounty == 0 || benefactorUUID == null || !benefactor.isOnline()) { MessageUtil.messagePlayer(player, " &aYou currently don't have a"); MessageUtil.messagePlayer(player, " &abounty on your head."); } else { - MessageUtil.messagePlayer(player, " &cYou currently have a &e$" + playerData.getBounty() + " &cbounty"); - MessageUtil.messagePlayer(player, " &con your head set by &e" + benefactor.getName() + "&c."); + MessageUtil.messagePlayer(player, " &cYou currently have a &e$" + activeBounty + " &cbounty"); + MessageUtil.messagePlayer(player, " &con your head set by &e" + benefactorName + "&c."); } MessageUtil.messagePlayer(player, ""); @@ -86,7 +95,8 @@ public void onCommand(@NotNull CommandArgs args) { return; } - Player target = Bukkit.getPlayer(args.getArgs(1)); + String targetName = args.getArgs(1); + Player target = Bukkit.getPlayer(targetName); PlayerData targetData = PlayerDataManager.getPlayerData(target); if (target.equals(player)) { @@ -94,14 +104,20 @@ public void onCommand(@NotNull CommandArgs args) { return; } - // TODO: Implement cooldown in between placing bounties. + if (!target.isOnline()) { + MessageUtil.messagePlayer(player, ConstantUtil.PLAYER_NOT_FOUND); + return; + } - if (!StringUtils.isNumeric(args.getArgs(2))) { - MessageUtil.messagePlayer(player, "&c'" + args.getArgs(3) + "' is not a valid amount."); + targetName = target.getName(); + String bountyAmount = args.getArgs(2); + + if (!StringUtils.isNumeric(bountyAmount)) { + MessageUtil.messagePlayer(player, "&c'" + bountyAmount + "' is not a valid amount."); return; } - int amount = Integer.parseInt(args.getArgs(2)); + int amount = Integer.parseInt(bountyAmount); int minCoins = Settings.bountiesMinAmount; int maxCoins = Settings.bountiesMaxAmount; @@ -120,38 +136,42 @@ public void onCommand(@NotNull CommandArgs args) { return; } - if (targetData.getBounty() > amount) { - MessageUtil.messagePlayer(player, "&c" + target.getName() + " already has a higher bounty."); + int targetBounty = targetData.getBounty(); + + if (targetBounty > amount) { + MessageUtil.messagePlayer(player, "&c" + targetName + " already has a higher bounty."); return; } - MessageUtil.messagePlayer(player, "&aYou set a $" + amount + " bounty on " + target.getName() + "'s head."); + MessageUtil.messagePlayer(player, "&aYou set a $" + amount + " bounty on " + targetName + "'s head."); MessageUtil.messagePlayer(target, ""); - MessageUtil.messagePlayer(target, " &c" + player.getName() + " &eset a &c$" + amount + " &ebounty on your head."); + MessageUtil.messagePlayer(target, " &c" + playerName + " &eset a &c$" + amount + " &ebounty on your head."); MessageUtil.messagePlayer(target, ""); for (Player online : Bukkit.getOnlinePlayers()) { if (!online.equals(target) && !online.equals(player)) { - MessageUtil.messagePlayer(online, "&c" + player.getName() + " &eset a &c$" + amount + " &ebounty on &c" + target.getName() + "&e's head."); + MessageUtil.messagePlayer(online, "&c" + playerName + " &eset a &c$" + amount + " &ebounty on &c" + targetName + "&e's head."); } } - targetData.addBounty(amount, player.getUniqueId()); + targetData.addBounty(amount, playerUUID); playerData.removeCoins(amount); + UUID targetBenefactor = targetData.getBenefactor(); + // Refund the original benefactor if they set a new bounty on the same player. - if (targetData.getBenefactor() != null) { - Player targetBenefactor = Bukkit.getPlayer(targetData.getBenefactor()); - PlayerData targetBenefactorData = PlayerDataManager.getPlayerData(targetBenefactor); + if (targetBenefactor != null) { + Player targetBenefactorPlayer = Bukkit.getPlayer(targetBenefactor); + PlayerData targetBenefactorData = PlayerDataManager.getPlayerData(targetBenefactorPlayer); - if (targetBenefactor.isOnline()) { - MessageUtil.messagePlayer(targetBenefactor, "&aYour bounty on " + target.getName() + "'s head has been refunded."); + if (targetBenefactorPlayer.isOnline()) { + MessageUtil.messagePlayer(targetBenefactorPlayer, "&aYour bounty on " + targetName + "'s head has been refunded."); } else { targetBenefactorData.load(); } - targetBenefactorData.addCoins(targetData.getBounty()); + targetBenefactorData.addCoins(targetBounty); } } } diff --git a/src/main/java/net/foulest/kitpvp/cmds/ClearKitCmd.java b/src/main/java/net/foulest/kitpvp/cmds/ClearKitCmd.java index dc37dd9..43c6cf9 100644 --- a/src/main/java/net/foulest/kitpvp/cmds/ClearKitCmd.java +++ b/src/main/java/net/foulest/kitpvp/cmds/ClearKitCmd.java @@ -17,19 +17,23 @@ */ package net.foulest.kitpvp.cmds; +import lombok.Data; import net.foulest.kitpvp.combattag.CombatTag; import net.foulest.kitpvp.data.PlayerData; import net.foulest.kitpvp.data.PlayerDataManager; +import net.foulest.kitpvp.kits.Kit; import net.foulest.kitpvp.region.Regions; import net.foulest.kitpvp.util.ConstantUtil; import net.foulest.kitpvp.util.MessageUtil; import net.foulest.kitpvp.util.command.Command; import net.foulest.kitpvp.util.command.CommandArgs; import org.bukkit.Bukkit; +import org.bukkit.Location; import org.bukkit.Sound; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; import org.jetbrains.annotations.NotNull; /** @@ -37,21 +41,14 @@ * * @author Foulest */ +@Data public class ClearKitCmd { - @SuppressWarnings("MethodMayBeStatic") @Command(name = "clearkit", description = "Clears your kit.", aliases = {"ck", "ckit"}, permission = "kitpvp.clearkit", usage = "/clearkit (player)", inGameOnly = true) - public void onCommand(@NotNull CommandArgs args) { + public static void onCommand(@NotNull CommandArgs args) { CommandSender sender = args.getSender(); - - // Checks if the sender is a player. - if (!(sender instanceof Player)) { - MessageUtil.messagePlayer(args.getSender(), ConstantUtil.IN_GAME_ONLY); - return; - } - Player player = args.getPlayer(); // Checks if the player is null. @@ -60,16 +57,17 @@ public void onCommand(@NotNull CommandArgs args) { return; } + Location location = player.getLocation(); PlayerData playerData = PlayerDataManager.getPlayerData(player); // Handles clearing your own kit. if (args.length() == 0) { - if (CombatTag.isInCombat(args.getPlayer())) { - MessageUtil.messagePlayer(args.getPlayer(), ConstantUtil.COMBAT_TAGGED); + if (CombatTag.isInCombat(player)) { + MessageUtil.messagePlayer(player, ConstantUtil.COMBAT_TAGGED); return; } - if (Regions.isInSafezone(player.getLocation())) { + if (Regions.isInSafezone(location)) { if (playerData.getActiveKit() == null) { MessageUtil.messagePlayer(player, ConstantUtil.NO_KIT_SELECTED); return; @@ -86,22 +84,24 @@ public void onCommand(@NotNull CommandArgs args) { // Handles clearing kits from other players. if (args.getPlayer().hasPermission("kitpvp.clearkit.others")) { - Player target = Bukkit.getPlayer(args.getArgs(1)); - PlayerData targetData = PlayerDataManager.getPlayerData(target); + String target = args.getArgs(1); + Player targetPlayer = Bukkit.getPlayer(target); + String targetName = targetPlayer.getName(); + PlayerData targetData = PlayerDataManager.getPlayerData(targetPlayer); - if (!target.isOnline()) { + if (!targetPlayer.isOnline()) { MessageUtil.messagePlayer(player, ConstantUtil.PLAYER_NOT_FOUND); return; } if (targetData.getActiveKit() == null) { - MessageUtil.messagePlayer(target, ConstantUtil.NO_KIT_SELECTED); + MessageUtil.messagePlayer(targetPlayer, ConstantUtil.NO_KIT_SELECTED); return; } clearKit(targetData); - MessageUtil.messagePlayer(target, "&aYour kit has been cleared by a staff member."); - MessageUtil.messagePlayer(player, "&aYou cleared " + target.getName() + "'s kit."); + MessageUtil.messagePlayer(targetPlayer, "&aYour kit has been cleared by a staff member."); + MessageUtil.messagePlayer(player, "&aYou cleared " + targetName + "'s kit."); } } @@ -112,8 +112,10 @@ public void onCommand(@NotNull CommandArgs args) { */ private static void clearKit(@NotNull PlayerData playerData) { Player player = playerData.getPlayer(); + Location location = player.getLocation(); + Kit activeKit = playerData.getActiveKit(); - playerData.setPreviousKit(playerData.getActiveKit()); + playerData.setPreviousKit(activeKit); playerData.clearCooldowns(); playerData.setActiveKit(null); @@ -121,10 +123,11 @@ private static void clearKit(@NotNull PlayerData playerData) { player.getInventory().setHeldItemSlot(0); for (PotionEffect effect : player.getActivePotionEffects()) { - player.removePotionEffect(effect.getType()); + PotionEffectType effectType = effect.getType(); + player.removePotionEffect(effectType); } playerData.giveDefaultItems(); - player.playSound(player.getLocation(), Sound.SLIME_WALK, 1, 1); + player.playSound(location, Sound.SLIME_WALK, 1, 1); } } diff --git a/src/main/java/net/foulest/kitpvp/cmds/CombatTagCmd.java b/src/main/java/net/foulest/kitpvp/cmds/CombatTagCmd.java index cac6a87..1b6bc23 100644 --- a/src/main/java/net/foulest/kitpvp/cmds/CombatTagCmd.java +++ b/src/main/java/net/foulest/kitpvp/cmds/CombatTagCmd.java @@ -17,12 +17,14 @@ */ package net.foulest.kitpvp.cmds; +import lombok.Data; import net.foulest.kitpvp.combattag.CombatTag; import net.foulest.kitpvp.util.ConstantUtil; import net.foulest.kitpvp.util.MessageUtil; import net.foulest.kitpvp.util.Settings; import net.foulest.kitpvp.util.command.Command; import net.foulest.kitpvp.util.command.CommandArgs; +import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; @@ -31,34 +33,41 @@ * * @author Foulest */ +@Data public class CombatTagCmd { - @SuppressWarnings("MethodMayBeStatic") @Command(name = "combattag", aliases = {"combatlog", "ct", "combat", "combattime", "combattimer"}, description = "Displays your current combat tag timer.", permission = "kitpvp.combattag", usage = "/combattag", inGameOnly = true) - public void onCommand(@NotNull CommandArgs args) { + public static void onCommand(@NotNull CommandArgs args) { + CommandSender sender = args.getSender(); Player player = args.getPlayer(); + // Checks if the player is null. + if (player == null) { + MessageUtil.messagePlayer(sender, ConstantUtil.IN_GAME_ONLY); + return; + } + // Prints the usage message. if (args.length() != 0) { - MessageUtil.messagePlayer(player, "&cUsage: /combattag"); + MessageUtil.messagePlayer(sender, "&cUsage: /combattag"); return; } // Checks if the combat tag feature is enabled. if (!Settings.combatTagEnabled) { - MessageUtil.messagePlayer(player, ConstantUtil.COMMAND_DISABLED); + MessageUtil.messagePlayer(sender, ConstantUtil.COMMAND_DISABLED); return; } if (CombatTag.isInCombat(player)) { int timeLeft = CombatTag.getRemainingTime(player); - MessageUtil.messagePlayer(player, "&cYou are in combat for " + timeLeft + MessageUtil.messagePlayer(sender, "&cYou are in combat for " + timeLeft + " more " + (timeLeft == 1 ? "second" : "seconds") + "."); } else { - MessageUtil.messagePlayer(player, "&aYou are not in combat."); + MessageUtil.messagePlayer(sender, "&aYou are not in combat."); } } } diff --git a/src/main/java/net/foulest/kitpvp/cmds/EcoCmd.java b/src/main/java/net/foulest/kitpvp/cmds/EcoCmd.java index a7e3471..4457df7 100644 --- a/src/main/java/net/foulest/kitpvp/cmds/EcoCmd.java +++ b/src/main/java/net/foulest/kitpvp/cmds/EcoCmd.java @@ -17,6 +17,7 @@ */ package net.foulest.kitpvp.cmds; +import lombok.Data; import net.foulest.kitpvp.data.PlayerData; import net.foulest.kitpvp.data.PlayerDataManager; import net.foulest.kitpvp.util.ConstantUtil; @@ -37,12 +38,12 @@ * * @author Foulest */ +@Data public class EcoCmd { - @SuppressWarnings("MethodMayBeStatic") @Command(name = "eco", description = "Main command for KitPvP's economy.", usage = "/eco ", permission = "kitpvp.eco") - public void onCommand(@NotNull CommandArgs args) { + public static void onCommand(@NotNull CommandArgs args) { CommandSender sender = args.getSender(); // No additional arguments, display usage message. @@ -51,29 +52,33 @@ public void onCommand(@NotNull CommandArgs args) { return; } - Player target = Bukkit.getPlayer(args.getArgs(1)); + String target = args.getArgs(1); + Player targetPlayer = Bukkit.getPlayer(target); // Checks if the target is online. - if (target == null || !target.isOnline()) { + if (targetPlayer == null || !targetPlayer.isOnline()) { MessageUtil.messagePlayer(sender, ConstantUtil.PLAYER_NOT_FOUND); return; } - String targetName = target.getName(); - PlayerData targetData = PlayerDataManager.getPlayerData(target); + String targetName = targetPlayer.getName(); + PlayerData targetData = PlayerDataManager.getPlayerData(targetPlayer); + int targetCoins = targetData.getCoins(); + + String desiredAmount = args.getArgs(2); // Checks if the amount is a number. - if (!StringUtils.isNumeric(args.getArgs(2))) { - MessageUtil.messagePlayer(args.getSender(), "&c'" + args.getArgs(1) + "' is not a valid amount."); + if (!StringUtils.isNumeric(desiredAmount)) { + MessageUtil.messagePlayer(sender, "&c'" + target + "' is not a valid amount."); return; } int totalCoins; - int amount = Integer.parseInt(args.getArgs(2)); + int amount = Integer.parseInt(desiredAmount); // Checks if the amount is negative. if (amount < 0) { - MessageUtil.messagePlayer(args.getSender(), "&cYou cannot use negative numbers."); + MessageUtil.messagePlayer(sender, "&cYou cannot use negative numbers."); return; } @@ -87,15 +92,15 @@ public void onCommand(@NotNull CommandArgs args) { return; } - targetData.setCoins(targetData.getCoins() + amount); + targetData.setCoins(targetCoins + amount); totalCoins = targetData.getCoins(); - if (sender instanceof Player && target.equals(sender)) { - MessageUtil.messagePlayer(target, "&aYou set your balance to " + totalCoins + " coins. &7(+" + amount + ")"); + if (sender instanceof Player && targetPlayer.equals(sender)) { + MessageUtil.messagePlayer(targetPlayer, "&aYou set your balance to " + totalCoins + " coins. &7(+" + amount + ")"); return; } - MessageUtil.messagePlayer(target, "&aYou were given " + amount + " coins! &7(Total: " + totalCoins + ")"); + MessageUtil.messagePlayer(targetPlayer, "&aYou were given " + amount + " coins! &7(Total: " + totalCoins + ")"); MessageUtil.messagePlayer(sender, "&aYou set " + targetName + "'s balance to " + totalCoins + " coins. &7(+" + amount + ")"); break; @@ -109,12 +114,12 @@ public void onCommand(@NotNull CommandArgs args) { targetData.setCoins(amount); totalCoins = targetData.getCoins(); - if (sender instanceof Player && target.equals(sender)) { - MessageUtil.messagePlayer(target, "&aYou set your balance to " + totalCoins + " coins."); + if (sender instanceof Player && targetPlayer.equals(sender)) { + MessageUtil.messagePlayer(targetPlayer, "&aYou set your balance to " + totalCoins + " coins."); return; } - MessageUtil.messagePlayer(target, "&aYour balance was set to " + totalCoins + " coins."); + MessageUtil.messagePlayer(targetPlayer, "&aYour balance was set to " + totalCoins + " coins."); MessageUtil.messagePlayer(sender, "&aYou set " + targetName + "'s balance to " + totalCoins + " coins."); break; @@ -128,12 +133,12 @@ public void onCommand(@NotNull CommandArgs args) { targetData.removeCoins(amount); totalCoins = targetData.getCoins(); - if (sender instanceof Player && target.equals(sender)) { - MessageUtil.messagePlayer(target, "&aYou set your balance to " + totalCoins + " coins. &7(-" + amount + ")"); + if (sender instanceof Player && targetPlayer.equals(sender)) { + MessageUtil.messagePlayer(targetPlayer, "&aYou set your balance to " + totalCoins + " coins. &7(-" + amount + ")"); return; } - MessageUtil.messagePlayer(target, "&aYour balance was set to " + totalCoins + " coins. &7(-" + amount + ")"); + MessageUtil.messagePlayer(targetPlayer, "&aYour balance was set to " + totalCoins + " coins. &7(-" + amount + ")"); MessageUtil.messagePlayer(sender, "&aYou set " + targetName + "'s balance to " + totalCoins + " coins. &7(-" + amount + ")"); break; diff --git a/src/main/java/net/foulest/kitpvp/cmds/KitEnchanterCmd.java b/src/main/java/net/foulest/kitpvp/cmds/KitEnchanterCmd.java index d82e5d5..118e14c 100644 --- a/src/main/java/net/foulest/kitpvp/cmds/KitEnchanterCmd.java +++ b/src/main/java/net/foulest/kitpvp/cmds/KitEnchanterCmd.java @@ -17,10 +17,14 @@ */ package net.foulest.kitpvp.cmds; +import lombok.Data; import net.foulest.kitpvp.menus.KitEnchanter; +import net.foulest.kitpvp.util.ConstantUtil; import net.foulest.kitpvp.util.MessageUtil; import net.foulest.kitpvp.util.command.Command; import net.foulest.kitpvp.util.command.CommandArgs; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; /** @@ -28,16 +32,28 @@ * * @author Foulest */ +@Data public class KitEnchanterCmd { - @SuppressWarnings("MethodMayBeStatic") - @Command(name = "enchanter", aliases = "kitenchanter", description = "Opens the Kit Enchanter.", usage = "/enchanter", inGameOnly = true, permission = "kitpvp.kitenchanter") - public void onCommand(@NotNull CommandArgs args) { + @Command(name = "enchanter", aliases = "kitenchanter", description = "Opens the Kit Enchanter.", + usage = "/enchanter", inGameOnly = true, permission = "kitpvp.kitenchanter") + public static void onCommand(@NotNull CommandArgs args) { + CommandSender sender = args.getSender(); + Player player = args.getPlayer(); + + // Checks if the player is null. + if (player == null) { + MessageUtil.messagePlayer(sender, ConstantUtil.IN_GAME_ONLY); + return; + } + + // Prints the usage message. if (args.length() != 0) { - MessageUtil.messagePlayer(args.getSender(), "&cUsage: /enchanter"); + MessageUtil.messagePlayer(sender, "&cUsage: /enchanter"); return; } - new KitEnchanter(args.getPlayer()); + // Opens the Kit Enchanter. + new KitEnchanter(player); } } diff --git a/src/main/java/net/foulest/kitpvp/cmds/KitPvPCmd.java b/src/main/java/net/foulest/kitpvp/cmds/KitPvPCmd.java index 8cfe559..8e6f133 100644 --- a/src/main/java/net/foulest/kitpvp/cmds/KitPvPCmd.java +++ b/src/main/java/net/foulest/kitpvp/cmds/KitPvPCmd.java @@ -17,8 +17,7 @@ */ package net.foulest.kitpvp.cmds; -import lombok.Getter; -import lombok.Setter; +import lombok.Data; import net.foulest.kitpvp.region.Spawn; import net.foulest.kitpvp.util.ConstantUtil; import net.foulest.kitpvp.util.MessageUtil; @@ -37,14 +36,12 @@ * * @author Foulest */ -@Getter -@Setter +@Data public class KitPvPCmd { - @SuppressWarnings("MethodMayBeStatic") @Command(name = "kitpvp", description = "Main command for KitPvP.", permission = "kitpvp.main", usage = "/kitpvp") - public void onCommand(@NotNull CommandArgs args) { + public static void onCommand(@NotNull CommandArgs args) { CommandSender sender = args.getSender(); // No additional arguments, display help menu. @@ -95,12 +92,14 @@ private static void handleHelp(@NotNull CommandSender sender, CommandArgs args) ); int itemsPerPage = 4; - int maxPages = (int) Math.ceil((double) commands.size() / itemsPerPage); + int size = commands.size(); + int maxPages = (int) Math.ceil((double) size / itemsPerPage); int page = 1; if (args.length() > 1) { try { - page = Integer.parseInt(args.getArgs(1)); + String pageNumber = args.getArgs(1); + page = Integer.parseInt(pageNumber); } catch (NumberFormatException ex) { MessageUtil.messagePlayer(sender, "&cInvalid page number. Choose between 1 and " + maxPages + "."); return; @@ -113,13 +112,14 @@ private static void handleHelp(@NotNull CommandSender sender, CommandArgs args) } int startIndex = (page - 1) * itemsPerPage; - int endIndex = Math.min(commands.size(), startIndex + itemsPerPage); + int endIndex = Math.min(size, startIndex + itemsPerPage); MessageUtil.messagePlayer(sender, ""); MessageUtil.messagePlayer(sender, "&eKitPvP Help &7(Page " + page + "/" + maxPages + ")"); for (int i = startIndex; i < endIndex; i++) { - MessageUtil.messagePlayer(sender, commands.get(i)); + String command = commands.get(i); + MessageUtil.messagePlayer(sender, command); } MessageUtil.messagePlayer(sender, ""); diff --git a/src/main/java/net/foulest/kitpvp/cmds/KitShopCmd.java b/src/main/java/net/foulest/kitpvp/cmds/KitShopCmd.java index deb7603..e9cefe5 100644 --- a/src/main/java/net/foulest/kitpvp/cmds/KitShopCmd.java +++ b/src/main/java/net/foulest/kitpvp/cmds/KitShopCmd.java @@ -17,12 +17,14 @@ */ package net.foulest.kitpvp.cmds; +import lombok.Data; import net.foulest.kitpvp.menus.KitShop; import net.foulest.kitpvp.region.Regions; import net.foulest.kitpvp.util.ConstantUtil; import net.foulest.kitpvp.util.MessageUtil; import net.foulest.kitpvp.util.command.Command; import net.foulest.kitpvp.util.command.CommandArgs; +import org.bukkit.Location; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; @@ -32,30 +34,33 @@ * * @author Foulest */ +@Data public class KitShopCmd { - @SuppressWarnings("MethodMayBeStatic") @Command(name = "kitshop", aliases = "shop", description = "Opens the Kit Shop.", usage = "/kitshop", inGameOnly = true, permission = "kitpvp.kitshop") - public void onCommand(@NotNull CommandArgs args) { + public static void onCommand(@NotNull CommandArgs args) { CommandSender sender = args.getSender(); Player player = args.getPlayer(); + // Checks if the player is null. if (player == null) { MessageUtil.messagePlayer(sender, ConstantUtil.IN_GAME_ONLY); return; } - if (!Regions.isInSafezone(player.getLocation())) { + Location location = player.getLocation(); + + if (!Regions.isInSafezone(location)) { MessageUtil.messagePlayer(player, ConstantUtil.NOT_IN_SPAWN); return; } if (args.length() != 0) { - MessageUtil.messagePlayer(args.getSender(), "&cUsage: /kitshop"); + MessageUtil.messagePlayer(sender, "&cUsage: /kitshop"); return; } - new KitShop(args.getPlayer(), 0); + new KitShop(player, 0); } } diff --git a/src/main/java/net/foulest/kitpvp/cmds/KitsCmd.java b/src/main/java/net/foulest/kitpvp/cmds/KitsCmd.java index 4e393f9..f77fcdd 100644 --- a/src/main/java/net/foulest/kitpvp/cmds/KitsCmd.java +++ b/src/main/java/net/foulest/kitpvp/cmds/KitsCmd.java @@ -17,6 +17,7 @@ */ package net.foulest.kitpvp.cmds; +import lombok.Data; import net.foulest.kitpvp.kits.Kit; import net.foulest.kitpvp.kits.KitManager; import net.foulest.kitpvp.menus.KitSelector; @@ -25,6 +26,7 @@ import net.foulest.kitpvp.util.MessageUtil; import net.foulest.kitpvp.util.command.Command; import net.foulest.kitpvp.util.command.CommandArgs; +import org.bukkit.Location; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; @@ -34,13 +36,13 @@ * * @author Foulest */ +@Data public class KitsCmd { - @SuppressWarnings("MethodMayBeStatic") @Command(name = "kit", aliases = {"kits", "kitselector"}, usage = "/kit [name]", description = "Selects a kit or opens the Kit Selector.", inGameOnly = true, permission = "kitpvp.kitselector") - public void onCommand(@NotNull CommandArgs args) { + public static void onCommand(@NotNull CommandArgs args) { CommandSender sender = args.getSender(); Player player = args.getPlayer(); @@ -50,8 +52,10 @@ public void onCommand(@NotNull CommandArgs args) { return; } + Location location = player.getLocation(); + // Checks if the player is in spawn. - if (!Regions.isInSafezone(player.getLocation())) { + if (!Regions.isInSafezone(location)) { MessageUtil.messagePlayer(player, ConstantUtil.NOT_IN_SPAWN); return; } @@ -66,7 +70,8 @@ public void onCommand(@NotNull CommandArgs args) { return; } - Kit kit = KitManager.getKit(args.getArgs(0)); + String desiredKit = args.getArgs(0); + Kit kit = KitManager.getKit(desiredKit); if (kit == null) { MessageUtil.messagePlayer(player, "&cCould not find the kit you wanted; opening the Kit Selector."); diff --git a/src/main/java/net/foulest/kitpvp/cmds/PayCmd.java b/src/main/java/net/foulest/kitpvp/cmds/PayCmd.java index e5c4fce..7ef2af1 100644 --- a/src/main/java/net/foulest/kitpvp/cmds/PayCmd.java +++ b/src/main/java/net/foulest/kitpvp/cmds/PayCmd.java @@ -17,6 +17,7 @@ */ package net.foulest.kitpvp.cmds; +import lombok.Data; import net.foulest.kitpvp.data.PlayerData; import net.foulest.kitpvp.data.PlayerDataManager; import net.foulest.kitpvp.util.ConstantUtil; @@ -25,6 +26,7 @@ import net.foulest.kitpvp.util.command.CommandArgs; import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; +import org.bukkit.Location; import org.bukkit.Sound; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -35,12 +37,12 @@ * * @author Foulest */ +@Data public class PayCmd { - @SuppressWarnings("MethodMayBeStatic") @Command(name = "pay", description = "Send coins to another player.", usage = "/pay ", inGameOnly = true, permission = "kitpvp.pay") - public void onCommand(@NotNull CommandArgs args) { + public static void onCommand(@NotNull CommandArgs args) { CommandSender sender = args.getSender(); if (args.length() == 2) { @@ -52,13 +54,11 @@ public void onCommand(@NotNull CommandArgs args) { return; } - // Checks if the sender is a player. - if (!(sender instanceof Player)) { - MessageUtil.messagePlayer(sender, ConstantUtil.IN_GAME_ONLY); - return; - } + Location location = player.getLocation(); + String playerName = player.getName(); - Player target = Bukkit.getPlayer(args.getArgs(0)); + String desiredTarget = args.getArgs(0); + Player target = Bukkit.getPlayer(desiredTarget); // Checks if the target is online. if (target == null) { @@ -66,13 +66,15 @@ public void onCommand(@NotNull CommandArgs args) { return; } + String desiredAmount = args.getArgs(1); + // Checks if the amount is a number. - if (!StringUtils.isNumeric(args.getArgs(1))) { - MessageUtil.messagePlayer(player, "&c'" + args.getArgs(1) + "' is not a valid amount."); + if (!StringUtils.isNumeric(desiredAmount)) { + MessageUtil.messagePlayer(player, "&c'" + desiredAmount + "' is not a valid amount."); return; } - int amount = Integer.parseInt(args.getArgs(1)); + int amount = Integer.parseInt(desiredAmount); // Checks if the amount is negative. if (amount < 0) { @@ -82,7 +84,7 @@ public void onCommand(@NotNull CommandArgs args) { // Checks if the sender is the target. if (sender == target) { - player.playSound(player.getLocation(), Sound.VILLAGER_NO, 1.0F, 1.0F); + player.playSound(location, Sound.VILLAGER_NO, 1.0F, 1.0F); MessageUtil.messagePlayer(player, "&cYou can't pay yourself."); return; } @@ -96,11 +98,13 @@ public void onCommand(@NotNull CommandArgs args) { return; } - targetData.setCoins(targetData.getCoins() + amount); + int targetCoins = targetData.getCoins(); + + targetData.setCoins(targetCoins + amount); senderData.removeCoins(amount); - MessageUtil.messagePlayer(player, "&a" + player.getName() + " sent you " + amount + " coins!"); - MessageUtil.messagePlayer(sender, "&aYou sent " + player.getName() + " " + amount + " coins!"); + MessageUtil.messagePlayer(player, "&a" + playerName + " sent you " + amount + " coins!"); + MessageUtil.messagePlayer(sender, "&aYou sent " + playerName + " " + amount + " coins!"); return; } diff --git a/src/main/java/net/foulest/kitpvp/cmds/PotionsCmd.java b/src/main/java/net/foulest/kitpvp/cmds/PotionsCmd.java index adcd93e..8cb3552 100644 --- a/src/main/java/net/foulest/kitpvp/cmds/PotionsCmd.java +++ b/src/main/java/net/foulest/kitpvp/cmds/PotionsCmd.java @@ -17,6 +17,7 @@ */ package net.foulest.kitpvp.cmds; +import lombok.Data; import net.foulest.kitpvp.data.PlayerData; import net.foulest.kitpvp.data.PlayerDataManager; import net.foulest.kitpvp.region.Regions; @@ -25,6 +26,7 @@ import net.foulest.kitpvp.util.command.Command; import net.foulest.kitpvp.util.command.CommandArgs; import net.foulest.kitpvp.util.item.ItemBuilder; +import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -36,12 +38,12 @@ * * @author Foulest */ +@Data public class PotionsCmd { - @SuppressWarnings("MethodMayBeStatic") @Command(name = "potions", aliases = "pots", description = "Sets your healing item to Potions.", usage = "/potions", inGameOnly = true, permission = "kitpvp.potions") - public void onCommand(@NotNull CommandArgs args) { + public static void onCommand(@NotNull CommandArgs args) { CommandSender sender = args.getSender(); Player player = args.getPlayer(); @@ -52,19 +54,20 @@ public void onCommand(@NotNull CommandArgs args) { } PlayerData playerData = PlayerDataManager.getPlayerData(player); + Location location = player.getLocation(); - if (!Regions.isInSafezone(player.getLocation())) { + if (!Regions.isInSafezone(location)) { MessageUtil.messagePlayer(player, ConstantUtil.NOT_IN_SPAWN); return; } if (args.length() != 0) { - MessageUtil.messagePlayer(args.getSender(), "&cUsage: /pots"); + MessageUtil.messagePlayer(sender, "&cUsage: /pots"); return; } if (!playerData.isUsingSoup()) { - MessageUtil.messagePlayer(args.getSender(), "&cYou are already using Potions."); + MessageUtil.messagePlayer(sender, "&cYou are already using Potions."); return; } diff --git a/src/main/java/net/foulest/kitpvp/cmds/SetSpawnCmd.java b/src/main/java/net/foulest/kitpvp/cmds/SetSpawnCmd.java index 1ae57a0..68738fd 100644 --- a/src/main/java/net/foulest/kitpvp/cmds/SetSpawnCmd.java +++ b/src/main/java/net/foulest/kitpvp/cmds/SetSpawnCmd.java @@ -17,12 +17,14 @@ */ package net.foulest.kitpvp.cmds; +import lombok.Data; import net.foulest.kitpvp.region.Regions; import net.foulest.kitpvp.region.Spawn; import net.foulest.kitpvp.util.ConstantUtil; import net.foulest.kitpvp.util.MessageUtil; import net.foulest.kitpvp.util.command.Command; import net.foulest.kitpvp.util.command.CommandArgs; +import org.bukkit.Location; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; @@ -32,12 +34,12 @@ * * @author Foulest */ +@Data public class SetSpawnCmd { - @SuppressWarnings("MethodMayBeStatic") @Command(name = "setspawn", usage = "/setspawn", description = "Sets the spawn point.", permission = "kitpvp.setspawn", inGameOnly = true) - public void onCommand(@NotNull CommandArgs args) { + public static void onCommand(@NotNull CommandArgs args) { CommandSender sender = args.getSender(); Player player = args.getPlayer(); @@ -47,14 +49,16 @@ public void onCommand(@NotNull CommandArgs args) { return; } + Location location = player.getLocation(); + // Checks if the player is in a safezone. - if (!Regions.isInSafezone(player.getLocation())) { + if (!Regions.isInSafezone(location)) { MessageUtil.messagePlayer(player, "&cYou cannot set spawn outside of a safezone."); return; } // Sets the spawn point to the player's location. - Spawn.setLocation(player.getLocation()); + Spawn.setLocation(location); MessageUtil.messagePlayer(player, "&aSpawn has been set."); } } diff --git a/src/main/java/net/foulest/kitpvp/cmds/SoupCmd.java b/src/main/java/net/foulest/kitpvp/cmds/SoupCmd.java index cb842ba..83560e7 100644 --- a/src/main/java/net/foulest/kitpvp/cmds/SoupCmd.java +++ b/src/main/java/net/foulest/kitpvp/cmds/SoupCmd.java @@ -17,6 +17,7 @@ */ package net.foulest.kitpvp.cmds; +import lombok.Data; import net.foulest.kitpvp.data.PlayerData; import net.foulest.kitpvp.data.PlayerDataManager; import net.foulest.kitpvp.region.Regions; @@ -25,6 +26,7 @@ import net.foulest.kitpvp.util.command.Command; import net.foulest.kitpvp.util.command.CommandArgs; import net.foulest.kitpvp.util.item.ItemBuilder; +import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -36,12 +38,12 @@ * * @author Foulest */ +@Data public class SoupCmd { - @SuppressWarnings("MethodMayBeStatic") @Command(name = "soup", description = "Sets your healing item to Soup.", usage = "/soup", inGameOnly = true, permission = "kitpvp.soup") - public void onCommand(@NotNull CommandArgs args) { + public static void onCommand(@NotNull CommandArgs args) { CommandSender sender = args.getSender(); Player player = args.getPlayer(); @@ -51,23 +53,24 @@ public void onCommand(@NotNull CommandArgs args) { return; } + Location location = player.getLocation(); PlayerData playerData = PlayerDataManager.getPlayerData(player); // Checks if the player is in spawn. - if (!Regions.isInSafezone(player.getLocation())) { + if (!Regions.isInSafezone(location)) { MessageUtil.messagePlayer(player, ConstantUtil.NOT_IN_SPAWN); return; } // Checks if the command arguments are invalid. if (args.length() != 0) { - MessageUtil.messagePlayer(args.getSender(), "&cUsage: /soup"); + MessageUtil.messagePlayer(sender, "&cUsage: /soup"); return; } // Checks if the player is already using soup. if (playerData.isUsingSoup()) { - MessageUtil.messagePlayer(args.getSender(), "&cYou are already using Soup."); + MessageUtil.messagePlayer(sender, "&cYou are already using Soup."); return; } diff --git a/src/main/java/net/foulest/kitpvp/cmds/SpawnCmd.java b/src/main/java/net/foulest/kitpvp/cmds/SpawnCmd.java index 4107c2f..3be89e8 100644 --- a/src/main/java/net/foulest/kitpvp/cmds/SpawnCmd.java +++ b/src/main/java/net/foulest/kitpvp/cmds/SpawnCmd.java @@ -17,6 +17,7 @@ */ package net.foulest.kitpvp.cmds; +import lombok.Data; import net.foulest.kitpvp.KitPvP; import net.foulest.kitpvp.combattag.CombatTag; import net.foulest.kitpvp.data.PlayerData; @@ -39,14 +40,14 @@ * * @author Foulest */ +@Data public class SpawnCmd { private static final int SECONDS_TO_WAIT = 5; - @SuppressWarnings("MethodMayBeStatic") @Command(name = "spawn", description = "Teleports you to spawn.", usage = "/spawn", inGameOnly = true, permission = "kitpvp.spawn") - public void onCommand(@NotNull CommandArgs args) { + public static void onCommand(@NotNull CommandArgs args) { CommandSender sender = args.getSender(); Player player = args.getPlayer(); diff --git a/src/main/java/net/foulest/kitpvp/cmds/StatsCmd.java b/src/main/java/net/foulest/kitpvp/cmds/StatsCmd.java index 08dcaba..3442c42 100644 --- a/src/main/java/net/foulest/kitpvp/cmds/StatsCmd.java +++ b/src/main/java/net/foulest/kitpvp/cmds/StatsCmd.java @@ -17,6 +17,7 @@ */ package net.foulest.kitpvp.cmds; +import lombok.Data; import net.foulest.kitpvp.data.PlayerData; import net.foulest.kitpvp.data.PlayerDataManager; import net.foulest.kitpvp.util.ConstantUtil; @@ -24,6 +25,7 @@ import net.foulest.kitpvp.util.command.Command; import net.foulest.kitpvp.util.command.CommandArgs; import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; @@ -32,14 +34,20 @@ * * @author Foulest */ +@Data public class StatsCmd { - @SuppressWarnings("MethodMayBeStatic") @Command(name = "stats", description = "Shows a player's statistics.", usage = "/stats", inGameOnly = true, permission = "kitpvp.stats") - public void onCommand(@NotNull CommandArgs args) { - Player player; - Player sender = args.getPlayer(); + public static void onCommand(@NotNull CommandArgs args) { + CommandSender sender = args.getSender(); + Player player = args.getPlayer(); + + // Checks if the player is null. + if (player == null) { + MessageUtil.messagePlayer(sender, ConstantUtil.IN_GAME_ONLY); + return; + } // Prints the usage message. if (args.length() > 1) { @@ -49,24 +57,26 @@ public void onCommand(@NotNull CommandArgs args) { // Display the sender's stats. if (args.length() == 0) { - displayStats(sender, true); + displayStats(player, true); } // Displays the stats of another player. if (args.length() == 1) { - if (args.getArgs(0).length() > 16) { + String targetName = args.getArgs(0); + + if (targetName.length() > 16) { MessageUtil.messagePlayer(sender, ConstantUtil.PLAYER_NOT_FOUND); return; } - player = Bukkit.getPlayer(args.getArgs(0)); + Player targetPlayer = Bukkit.getPlayer(targetName); - if (player == null || !player.isOnline()) { + if (targetPlayer == null || !targetPlayer.isOnline()) { MessageUtil.messagePlayer(sender, ConstantUtil.PLAYER_NOT_FOUND); return; } - displayStats(sender, false); + displayStats(targetPlayer, false); } } @@ -78,16 +88,26 @@ public void onCommand(@NotNull CommandArgs args) { */ public static void displayStats(Player player, boolean samePlayer) { PlayerData playerData = PlayerDataManager.getPlayerData(player); + String playerName = player.getName(); + int kills = playerData.getKills(); + int deaths = playerData.getDeaths(); + String kdrText = playerData.getKDRText(); + int killstreak = playerData.getKillstreak(); + int topKillstreak = playerData.getTopKillstreak(); + int level = playerData.getLevel(); + int expPercent = playerData.getExpPercent(); + int coins = playerData.getCoins(); + int bounty = playerData.getBounty(); MessageUtil.messagePlayer(player, ""); - MessageUtil.messagePlayer(player, " &a&l" + (samePlayer ? "Your" : player.getName() + "'s") + " Stats"); - MessageUtil.messagePlayer(player, " &fKills: &e" + playerData.getKills()); - MessageUtil.messagePlayer(player, " &fDeaths: &e" + playerData.getDeaths()); - MessageUtil.messagePlayer(player, " &fK/D Ratio: &e" + playerData.getKDRText()); - MessageUtil.messagePlayer(player, " &fStreak: &e" + playerData.getKillstreak() + " &7(" + playerData.getTopKillstreak() + ")"); - MessageUtil.messagePlayer(player, " &fLevel: &e" + playerData.getLevel() + " &7(" + playerData.getExpPercent() + "%)"); - MessageUtil.messagePlayer(player, " &fCoins: &6" + playerData.getCoins()); - MessageUtil.messagePlayer(player, " &fBounty: &6" + playerData.getBounty()); + MessageUtil.messagePlayer(player, " &a&l" + (samePlayer ? "Your" : playerName + "'s") + " Stats"); + MessageUtil.messagePlayer(player, " &fKills: &e" + kills); + MessageUtil.messagePlayer(player, " &fDeaths: &e" + deaths); + MessageUtil.messagePlayer(player, " &fK/D Ratio: &e" + kdrText); + MessageUtil.messagePlayer(player, " &fStreak: &e" + killstreak + " &7(" + topKillstreak + ")"); + MessageUtil.messagePlayer(player, " &fLevel: &e" + level + " &7(" + expPercent + "%)"); + MessageUtil.messagePlayer(player, " &fCoins: &6" + coins); + MessageUtil.messagePlayer(player, " &fBounty: &6" + bounty); MessageUtil.messagePlayer(player, ""); } } diff --git a/src/main/java/net/foulest/kitpvp/combattag/CombatTag.java b/src/main/java/net/foulest/kitpvp/combattag/CombatTag.java index decff50..5085e92 100644 --- a/src/main/java/net/foulest/kitpvp/combattag/CombatTag.java +++ b/src/main/java/net/foulest/kitpvp/combattag/CombatTag.java @@ -17,8 +17,7 @@ */ package net.foulest.kitpvp.combattag; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; +import lombok.Data; import net.foulest.kitpvp.KitPvP; import net.foulest.kitpvp.data.PlayerData; import net.foulest.kitpvp.data.PlayerDataManager; @@ -38,8 +37,8 @@ * * @author Foulest */ -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public final class CombatTag { +@Data +public class CombatTag { /** * The combat scheduler and handler for each player. @@ -79,7 +78,7 @@ public static void markForCombat(Player attacker, Player target) { } else { combatHandler.put(player, Settings.combatTagDuration); - combatScheduler.put(player, new BukkitRunnable() { + BukkitTask task = new BukkitRunnable() { @Override public void run() { if (isInCombat(player)) { @@ -90,7 +89,9 @@ public void run() { } } } - }.runTaskTimer(KitPvP.instance, 0L, 20L)); + }.runTaskTimer(KitPvP.instance, 0L, 20L); + + combatScheduler.put(player, task); } // Cancels the player's pending teleportation when taking damage for. diff --git a/src/main/java/net/foulest/kitpvp/data/PlayerData.java b/src/main/java/net/foulest/kitpvp/data/PlayerData.java index 87e4361..93abd16 100644 --- a/src/main/java/net/foulest/kitpvp/data/PlayerData.java +++ b/src/main/java/net/foulest/kitpvp/data/PlayerData.java @@ -17,9 +17,7 @@ */ package net.foulest.kitpvp.data; -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; +import lombok.Data; import net.foulest.kitpvp.KitPvP; import net.foulest.kitpvp.enchants.Enchants; import net.foulest.kitpvp.kits.Kit; @@ -29,6 +27,7 @@ import net.foulest.kitpvp.util.Settings; import net.foulest.kitpvp.util.item.ItemBuilder; import net.foulest.kitpvp.util.item.SkullBuilder; +import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.entity.Player; @@ -49,11 +48,8 @@ * * @author Foulest */ -@Getter -@Setter -@ToString -@SuppressWarnings("unused") -public final class PlayerData { +@Data +public class PlayerData { // Player data private final UUID uniqueId; @@ -90,6 +86,12 @@ public final class PlayerData { private @Nullable BukkitTask abilityCooldownNotifier; private BukkitTask teleportToSpawnTask; + // Flask data + private @Nullable BukkitTask flaskCooldownTask; + + // Vampire task + private @Nullable BukkitTask lifeStealCooldown; + /** * Creates a new player data object. * @@ -113,9 +115,13 @@ public boolean hasCooldown(boolean sendMessage) { if (cooldown > 0) { if (sendMessage) { - MessageUtil.messagePlayer(player, "&cYou are still on cooldown for %time% seconds." - .replace("%time%", String.valueOf(BigDecimal.valueOf((double) cooldown / 1000) - .setScale(1, RoundingMode.HALF_UP).doubleValue()))); + BigDecimal cooldownDecimal = BigDecimal.valueOf((double) cooldown / 1000).setScale(1, RoundingMode.HALF_UP); + double cooldownDouble = cooldownDecimal.doubleValue(); + + String cooldownMsg = "&cYou are still on cooldown for %time% seconds."; + cooldownMsg = cooldownMsg.replace("%time%", String.valueOf(cooldownDouble)); + + MessageUtil.messagePlayer(player, cooldownMsg); } return true; } @@ -132,6 +138,16 @@ public void clearCooldowns() { abilityCooldownNotifier.cancel(); abilityCooldownNotifier = null; } + + if (flaskCooldownTask != null) { + flaskCooldownTask.cancel(); + flaskCooldownTask = null; + } + + if (lifeStealCooldown != null) { + lifeStealCooldown.cancel(); + lifeStealCooldown = null; + } } /** @@ -163,7 +179,9 @@ public void run() { public boolean load() { // Inserts default values into PlayerStats. Map defaultStats = new HashMap<>(); - defaultStats.put("uuid", uniqueId.toString()); + String uuidString = uniqueId.toString(); + + defaultStats.put("uuid", uuidString); defaultStats.put("coins", 500); defaultStats.put("experience", 0); defaultStats.put("kills", 0); @@ -177,7 +195,7 @@ public boolean load() { // Loads values from PlayerStats. try { List> data = DatabaseUtil.loadDataFromTable("PlayerStats", - "uuid = ?", Collections.singletonList(uniqueId.toString())); + "uuid = ?", Collections.singletonList(uuidString)); if (!data.isEmpty()) { HashMap playerData = data.get(0); @@ -188,7 +206,9 @@ public boolean load() { killstreak = (Integer) playerData.get("killstreak"); topKillstreak = (Integer) playerData.get("topKillstreak"); usingSoup = (Integer) playerData.get("usingSoup") == 1; - previousKit = KitManager.getKit((String) playerData.get("previousKit")); + + Object previousKitObj = playerData.get("previousKit"); + previousKit = KitManager.getKit((String) previousKitObj); } } catch (SQLException ex) { ex.printStackTrace(); @@ -197,18 +217,22 @@ public boolean load() { // Inserts default values into PlayerKits. Map defaultKits = new HashMap<>(); - defaultKits.put("uuid", uniqueId.toString()); + defaultKits.put("uuid", uuidString); defaultKits.put("kitName", "Knight"); DatabaseUtil.addDefaultDataToTable("PlayerKits", defaultKits); // Loads values from PlayerKits. try { List> data = DatabaseUtil.loadDataFromTable("PlayerKits", - "uuid = ?", Collections.singletonList(uniqueId.toString())); + "uuid = ?", Collections.singletonList(uuidString)); if (!data.isEmpty()) { - for (HashMap row : data) { - ownedKits.add(KitManager.getKit((String) row.get("kitName"))); + for (Map row : data) { + Object kitNameObj = row.get("kitName"); + + if (kitNameObj != null && !kitNameObj.equals("")) { + ownedKits.add(KitManager.getKit((String) kitNameObj)); + } } } } catch (SQLException ex) { @@ -219,14 +243,16 @@ public boolean load() { // Loads values from Bounties. try { List> data = DatabaseUtil.loadDataFromTable("Bounties", - "uuid = ?", Collections.singletonList(uniqueId.toString())); + "uuid = ?", Collections.singletonList(uuidString)); if (!data.isEmpty()) { HashMap playerData = data.get(0); bounty = (Integer) playerData.get("bounty"); - if (!playerData.get("benefactor").equals("")) { - benefactor = UUID.fromString((String) playerData.get("benefactor")); + Object benefactorObj = playerData.get("benefactor"); + + if (!benefactorObj.equals("")) { + benefactor = UUID.fromString((String) benefactorObj); } } } catch (SQLException ex) { @@ -237,7 +263,7 @@ public boolean load() { // Loads values from Enchants. try { List> data = DatabaseUtil.loadDataFromTable("Enchants", - "uuid = ?", Collections.singletonList(uniqueId.toString())); + "uuid = ?", Collections.singletonList(uuidString)); if (!data.isEmpty()) { Map playerData = data.get(0); @@ -462,7 +488,9 @@ private float getExpDecimal() { } else { decimal = ((float) (experience - pastLevelXP) / (nextLevelXP - pastLevelXP)); } - return Float.parseFloat(format.format(decimal)); + + String formatted = format.format(decimal); + return Float.parseFloat(formatted); } /** @@ -500,7 +528,8 @@ private double getKDR() { public String getKDRText() { String decimalFormatStr = "####0.00"; DecimalFormat format = new DecimalFormat(decimalFormatStr); - return format.format(getKDR()); + double kdr = getKDR(); + return format.format(kdr); } /** @@ -516,50 +545,53 @@ public void calcLevel(boolean afterKill) { level += 1; if (afterKill) { - player.playSound(player.getLocation(), Sound.LEVEL_UP, 1.0F, 1.0F); + Location location = player.getLocation(); + player.playSound(location, Sound.LEVEL_UP, 1.0F, 1.0F); + MessageUtil.messagePlayer(player, ""); MessageUtil.messagePlayer(player, " &b&lLevel Up"); MessageUtil.messagePlayer(player, " &7You leveled up to &fLevel " + level + " &7and"); MessageUtil.messagePlayer(player, " &7earned yourself &f250 Coins&7!"); + setCoins(coins + 250); } } } + float expDecimal = getExpDecimal(); + player.setLevel(level); - player.setExp(getExpDecimal()); + player.setExp(expDecimal); } /** * Gives the player their default items. */ - @SuppressWarnings("LocalVariableHidesMemberVariable") public void giveDefaultItems() { + UUID playerUUID = player.getUniqueId(); + player.getInventory().clear(); player.getInventory().setArmorContents(null); - ItemStack kitSelector = new ItemBuilder(Material.NETHER_STAR).name("&aKit Selector &7(Right Click)").getItem(); - player.getInventory().setItem(0, kitSelector); + ItemStack kitSelectorItem = new ItemBuilder(Material.NETHER_STAR).name("&aKit Selector &7(Right Click)").getItem(); + player.getInventory().setItem(0, kitSelectorItem); - ItemStack shopSelector = new ItemBuilder(Material.ENDER_CHEST).name("&aKit Shop &7(Right Click)").getItem(); - player.getInventory().setItem(1, shopSelector); + ItemStack kitShopItem = new ItemBuilder(Material.ENDER_CHEST).name("&aKit Shop &7(Right Click)").getItem(); + player.getInventory().setItem(1, kitShopItem); - ItemStack previousKit = new ItemBuilder(Material.WATCH).name("&aPrevious Kit &7(Right Click)").getItem(); - player.getInventory().setItem(2, previousKit); + ItemStack previousKitItem = new ItemBuilder(Material.WATCH).name("&aPrevious Kit &7(Right Click)").getItem(); + player.getInventory().setItem(2, previousKitItem); - ItemStack yourStats = new ItemBuilder(SkullBuilder.itemFromUuid(player.getUniqueId())).name("&aYour Stats &7(Right Click)").getItem(); - player.getInventory().setItem(4, yourStats); + ItemStack yourStatsItem = new ItemBuilder(SkullBuilder.itemFromUuid(playerUUID)).name("&aYour Stats &7(Right Click)").getItem(); + player.getInventory().setItem(4, yourStatsItem); - ItemStack healingItem; - if (usingSoup) { - healingItem = new ItemBuilder(Material.MUSHROOM_SOUP).name("&aUsing Soup &7(Right Click)").getItem(); - } else { - healingItem = new ItemBuilder(Material.POTION).hideInfo().durability(16421).name("&aUsing Potions &7(Right Click)").getItem(); - } + ItemStack healingItem = usingSoup + ? new ItemBuilder(Material.MUSHROOM_SOUP).name("&aUsing Soup &7(Right Click)").getItem() + : new ItemBuilder(Material.POTION).hideInfo().durability(16421).name("&aUsing Potions &7(Right Click)").getItem(); player.getInventory().setItem(6, healingItem); - ItemStack kitEnchanter = new ItemBuilder(Material.ENCHANTED_BOOK).name("&aKit Enchanter &7(Right Click)").getItem(); - player.getInventory().setItem(7, kitEnchanter); + ItemStack kitEnchanterItem = new ItemBuilder(Material.ENCHANTED_BOOK).name("&aKit Enchanter &7(Right Click)").getItem(); + player.getInventory().setItem(7, kitEnchanterItem); player.updateInventory(); } diff --git a/src/main/java/net/foulest/kitpvp/data/PlayerDataManager.java b/src/main/java/net/foulest/kitpvp/data/PlayerDataManager.java index 8958052..ec29cd1 100644 --- a/src/main/java/net/foulest/kitpvp/data/PlayerDataManager.java +++ b/src/main/java/net/foulest/kitpvp/data/PlayerDataManager.java @@ -17,8 +17,7 @@ */ package net.foulest.kitpvp.data; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; +import lombok.Data; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; @@ -31,8 +30,8 @@ * * @author Foulest */ -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public final class PlayerDataManager { +@Data +public class PlayerDataManager { /** * Map of player UUIDs to their stored data. @@ -46,12 +45,14 @@ public final class PlayerDataManager { * @return The player's data. */ public static PlayerData getPlayerData(@NotNull Player player) { - if (playerDataMap.containsKey(player.getUniqueId())) { - return playerDataMap.get(player.getUniqueId()); + UUID playerUUID = player.getUniqueId(); + + if (playerDataMap.containsKey(playerUUID)) { + return playerDataMap.get(playerUUID); } else { addPlayerData(player); } - return playerDataMap.get(player.getUniqueId()); + return playerDataMap.get(playerUUID); } /** @@ -60,9 +61,11 @@ public static PlayerData getPlayerData(@NotNull Player player) { * @param player The player to add. */ private static void addPlayerData(@NotNull Player player) { - if (!playerDataMap.containsKey(player.getUniqueId())) { - PlayerData data = new PlayerData(player.getUniqueId(), player); - playerDataMap.put(player.getUniqueId(), data); + UUID playerUUID = player.getUniqueId(); + + if (!playerDataMap.containsKey(playerUUID)) { + PlayerData data = new PlayerData(playerUUID, player); + playerDataMap.put(playerUUID, data); } } @@ -72,7 +75,8 @@ private static void addPlayerData(@NotNull Player player) { * @param player The player to remove. */ public static void removePlayerData(@NotNull Player player) { - playerDataMap.remove(player.getUniqueId()); + UUID playerUUID = player.getUniqueId(); + playerDataMap.remove(playerUUID); } /** @@ -82,6 +86,7 @@ public static void removePlayerData(@NotNull Player player) { * @return True if the player has data stored, otherwise false. */ public static boolean hasPlayerData(@NotNull Player player) { - return playerDataMap.containsKey(player.getUniqueId()); + UUID playerUUID = player.getUniqueId(); + return playerDataMap.containsKey(playerUUID); } } diff --git a/src/main/java/net/foulest/kitpvp/enchants/Enchants.java b/src/main/java/net/foulest/kitpvp/enchants/Enchants.java index 2cc9266..2212172 100644 --- a/src/main/java/net/foulest/kitpvp/enchants/Enchants.java +++ b/src/main/java/net/foulest/kitpvp/enchants/Enchants.java @@ -69,15 +69,16 @@ public enum Enchants { * @return The formatted name. */ public @NotNull String getDatabaseName() { - String processedName = MessageUtil.capitalize(name().toLowerCase(Locale.ROOT) - .replace("_", " ")) - .replace(" ", ""); + String name = name().toLowerCase(Locale.ROOT); + name = name.replace("_", ""); + name = name.replace(" ", ""); + name = MessageUtil.capitalize(name); // De-capitalizes the first letter. - if (!processedName.isEmpty()) { - processedName = processedName.substring(0, 1).toLowerCase(Locale.ROOT) + processedName.substring(1); + if (!name.isEmpty()) { + name = name.substring(0, 1).toLowerCase(Locale.ROOT) + name.substring(1); } - return processedName; + return name; } /** @@ -87,8 +88,10 @@ public enum Enchants { * @return The formatted name. */ public @NotNull String getFormattedName() { - return MessageUtil.capitalize(name().toLowerCase(Locale.ROOT) - .replace("_", " ")); + String name = name().toLowerCase(Locale.ROOT); + name = name.replace("_", " "); + name = MessageUtil.capitalize(name); + return name; } /** diff --git a/src/main/java/net/foulest/kitpvp/kits/Kit.java b/src/main/java/net/foulest/kitpvp/kits/Kit.java index ebe0429..d6128da 100644 --- a/src/main/java/net/foulest/kitpvp/kits/Kit.java +++ b/src/main/java/net/foulest/kitpvp/kits/Kit.java @@ -20,8 +20,10 @@ import net.foulest.kitpvp.data.PlayerData; import net.foulest.kitpvp.data.PlayerDataManager; import net.foulest.kitpvp.enchants.Enchants; +import net.foulest.kitpvp.listeners.FlaskListener; import net.foulest.kitpvp.util.MessageUtil; import net.foulest.kitpvp.util.item.ItemBuilder; +import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.enchantments.Enchantment; @@ -30,6 +32,7 @@ import org.bukkit.permissions.Permission; import org.bukkit.permissions.PermissionDefault; import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; import java.util.ArrayList; import java.util.Collection; @@ -115,9 +118,11 @@ default void apply(Player player) { PlayerData playerData = PlayerDataManager.getPlayerData(player); Collection airSlots = new ArrayList<>(); + String kitName = getName(); + // Checks if the player owns the kit they're trying to equip. if (getCost() > 0 && !playerData.getOwnedKits().contains(this)) { - MessageUtil.messagePlayer(player, "&cYou do not own the " + getName() + " kit."); + MessageUtil.messagePlayer(player, "&cYou do not own the " + kitName + " kit."); return; } @@ -128,9 +133,10 @@ default void apply(Player player) { } // Checks if the player has permission to use the kit. - if (permission() != null - && permission().getDefault() != PermissionDefault.TRUE - && !player.hasPermission(permission())) { + Permission permission = permission(); + if (permission != null + && permission.getDefault() != PermissionDefault.TRUE + && !player.hasPermission(permission)) { MessageUtil.messagePlayer(player, "&cYou do not have permission to use this kit."); return; } @@ -142,7 +148,8 @@ && permission().getDefault() != PermissionDefault.TRUE // Clears the player's potion effects. for (PotionEffect effects : player.getActivePotionEffects()) { - player.removePotionEffect(effects.getType()); + PotionEffectType effectType = effects.getType(); + player.removePotionEffect(effectType); } // Sets the player's kit data. @@ -162,10 +169,12 @@ && permission().getDefault() != PermissionDefault.TRUE // Sets the player's kit items. for (ItemBuilder item : getItems()) { ItemBuilder itemBuilder = item; + ItemStack itemStack = itemBuilder.getItem(); + int slot = itemBuilder.getSlot(); - if (itemBuilder.getItem().getType().toString().toLowerCase(Locale.ROOT).contains("sword") - || itemBuilder.getItem().getType().toString().toLowerCase(Locale.ROOT).contains("cactus") - || itemBuilder.getItem().getType().toString().toLowerCase(Locale.ROOT).contains("axe")) { + if (itemStack.getType().toString().toLowerCase(Locale.ROOT).contains("sword") + || itemStack.getType().toString().toLowerCase(Locale.ROOT).contains("cactus") + || itemStack.getType().toString().toLowerCase(Locale.ROOT).contains("axe")) { if (playerData.getEnchants().contains(Enchants.KNOCKBACK)) { itemBuilder = itemBuilder.enchant(Enchantment.KNOCKBACK, 2); } @@ -175,7 +184,7 @@ && permission().getDefault() != PermissionDefault.TRUE } } - if (itemBuilder.getItem().getType().toString().toLowerCase(Locale.ROOT).contains("bow")) { + if (itemStack.getType().toString().toLowerCase(Locale.ROOT).contains("bow")) { if (playerData.getEnchants().contains(Enchants.PUNCH)) { itemBuilder = itemBuilder.enchant(Enchantment.ARROW_KNOCKBACK, 2); } @@ -185,14 +194,16 @@ && permission().getDefault() != PermissionDefault.TRUE } } - if (itemBuilder.getSlot() == 0) { - player.getInventory().addItem(itemBuilder.getItem()); + itemStack = itemBuilder.getItem(); + + if (slot == 0) { + player.getInventory().addItem(itemStack); } else { - if (itemBuilder.getItem().getType() == Material.AIR) { - airSlots.add(itemBuilder.getSlot()); + if (itemStack.getType() == Material.AIR) { + airSlots.add(slot); } - player.getInventory().setItem(itemBuilder.getSlot(), itemBuilder.getItem()); + player.getInventory().setItem(slot, itemStack); } } @@ -202,11 +213,22 @@ && permission().getDefault() != PermissionDefault.TRUE continue; } - if (playerData.isUsingSoup()) { - player.getInventory().setItem(i, new ItemBuilder(Material.MUSHROOM_SOUP).name("&fMushroom Stew").getItem()); - } else { - player.getInventory().setItem(i, new ItemBuilder(Material.POTION).durability(16421).name("&fSplash Potion of Healing").getItem()); - } + // Set the flask item. + ItemStack flaskItem = new ItemBuilder(Material.POTION).name("&aFlask &7(Right Click)").getItem(); + flaskItem.setDurability((short) 8229); + flaskItem.setAmount(FlaskListener.MAX_FLASKS); + player.getInventory().setItem(i, flaskItem); + break; + +// if (playerData.isUsingSoup()) { +// ItemBuilder soupItemBuilder = new ItemBuilder(Material.MUSHROOM_SOUP).name("&fMushroom Stew"); +// ItemStack soupItemStack = soupItemBuilder.getItem(); +// player.getInventory().setItem(i, soupItemStack); +// } else { +// ItemBuilder potionItemBuilder = new ItemBuilder(Material.POTION).durability(16421).name("&fSplash Potion of Healing"); +// ItemStack potionItemStack = potionItemBuilder.getItem(); +// player.getInventory().setItem(i, potionItemStack); +// } } // Sets the player's armor. @@ -216,57 +238,68 @@ && permission().getDefault() != PermissionDefault.TRUE ItemBuilder boots = (getArmor()[3] == null ? new ItemBuilder(Material.AIR) : getArmor()[3]); // Sets the player's thorns enchantments. + ItemStack helmetItem = helmet.getItem(); + ItemStack chestplateItem = chestplate.getItem(); + ItemStack leggingsItem = leggings.getItem(); + ItemStack bootsItem = boots.getItem(); + if (playerData.getEnchants().contains(Enchants.THORNS)) { - if (helmet.getItem().getType() != Material.AIR && helmet.getItem().getType() != Material.SKULL_ITEM) { + if (helmetItem.getType() != Material.AIR && helmetItem.getType() != Material.SKULL_ITEM) { helmet = helmet.enchant(Enchantment.THORNS, 2); } - if (chestplate.getItem().getType() != Material.AIR) { + if (chestplateItem.getType() != Material.AIR) { chestplate = chestplate.enchant(Enchantment.THORNS, 2); } - if (leggings.getItem().getType() != Material.AIR) { + if (leggingsItem.getType() != Material.AIR) { leggings = leggings.enchant(Enchantment.THORNS, 2); } - if (boots.getItem().getType() != Material.AIR) { + if (bootsItem.getType() != Material.AIR) { boots = boots.enchant(Enchantment.THORNS, 2); } } // Sets the player's protection enchantments. if (playerData.getEnchants().contains(Enchants.PROTECTION)) { - if (helmet.getItem().getType() != Material.AIR && helmet.getItem().getType() != Material.SKULL_ITEM) { + if (helmetItem.getType() != Material.AIR && helmetItem.getType() != Material.SKULL_ITEM) { helmet = helmet.enchant(Enchantment.PROTECTION_ENVIRONMENTAL, 2); } - if (chestplate.getItem().getType() != Material.AIR) { + if (chestplateItem.getType() != Material.AIR) { chestplate = chestplate.enchant(Enchantment.PROTECTION_ENVIRONMENTAL, 2); } - if (leggings.getItem().getType() != Material.AIR) { + if (leggingsItem.getType() != Material.AIR) { leggings = leggings.enchant(Enchantment.PROTECTION_ENVIRONMENTAL, 2); } - if (boots.getItem().getType() != Material.AIR) { + if (bootsItem.getType() != Material.AIR) { boots = boots.enchant(Enchantment.PROTECTION_ENVIRONMENTAL, 2); } } // Sets the player's feather falling enchantments. - if (playerData.getEnchants().contains(Enchants.FEATHER_FALLING) && boots.getItem().getType() != Material.AIR) { + if (playerData.getEnchants().contains(Enchants.FEATHER_FALLING) && bootsItem.getType() != Material.AIR) { boots = boots.enchant(Enchantment.PROTECTION_FALL, 4); } + helmetItem = helmet.getItem(); + chestplateItem = chestplate.getItem(); + leggingsItem = leggings.getItem(); + bootsItem = boots.getItem(); + // Sets the player's armor. - player.getInventory().setHelmet(helmet.getItem()); - player.getInventory().setChestplate(chestplate.getItem()); - player.getInventory().setLeggings(leggings.getItem()); - player.getInventory().setBoots(boots.getItem()); + player.getInventory().setHelmet(helmetItem); + player.getInventory().setChestplate(chestplateItem); + player.getInventory().setLeggings(leggingsItem); + player.getInventory().setBoots(bootsItem); // Sends the player a message and plays a sound. - MessageUtil.messagePlayer(player, "&aYou equipped the " + getName() + " kit."); - player.playSound(player.getLocation(), Sound.SLIME_WALK, 1, 1); + MessageUtil.messagePlayer(player, "&aYou equipped the " + kitName + " kit."); + Location location = player.getLocation(); + player.playSound(location, Sound.SLIME_WALK, 1, 1); player.updateInventory(); player.closeInventory(); } diff --git a/src/main/java/net/foulest/kitpvp/kits/KitManager.java b/src/main/java/net/foulest/kitpvp/kits/KitManager.java index 6580a6e..17f29a2 100644 --- a/src/main/java/net/foulest/kitpvp/kits/KitManager.java +++ b/src/main/java/net/foulest/kitpvp/kits/KitManager.java @@ -17,9 +17,8 @@ */ package net.foulest.kitpvp.kits; -import lombok.AccessLevel; +import lombok.Data; import lombok.Getter; -import lombok.NoArgsConstructor; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; @@ -30,8 +29,8 @@ * * @author Foulest */ -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public final class KitManager { +@Data +public class KitManager { /** * The list of loaded kits. diff --git a/src/main/java/net/foulest/kitpvp/kits/type/Archer.java b/src/main/java/net/foulest/kitpvp/kits/type/Archer.java index 983e19f..34aec72 100644 --- a/src/main/java/net/foulest/kitpvp/kits/type/Archer.java +++ b/src/main/java/net/foulest/kitpvp/kits/type/Archer.java @@ -47,23 +47,29 @@ public String getName() { @Override public ItemStack getDisplayItem() { - return new ItemStack(Material.BOW); + return new ItemBuilder(Material.BOW).hideInfo().getItem(); } @Override public PotionEffect[] getPotionEffects() { return new PotionEffect[]{ - new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, 1, false, false), - new PotionEffect(PotionEffectType.JUMP, Integer.MAX_VALUE, 0, false, false) + new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, 0, false, false) }; } @Override public List getItems() { - ItemBuilder sword = new ItemBuilder(Material.WOOD_SWORD).unbreakable(true).hideInfo().enchant(Enchantment.KNOCKBACK, 1); + // Damage value: 4.0 + ItemBuilder sword = new ItemBuilder(Material.WOOD_SWORD).unbreakable(true).hideInfo(); + + // Damage value: 4.5 ItemBuilder bow = new ItemBuilder(Material.BOW).unbreakable(true).hideInfo().enchant(Enchantment.ARROW_DAMAGE, 1); - ItemBuilder arrow = new ItemBuilder(Material.ARROW).unbreakable(true).hideInfo().amount(32).slot(9); - return Arrays.asList(sword, bow, arrow); + + ItemBuilder special = new ItemBuilder(Material.FEATHER).unbreakable(true).hideInfo().name("&aSpeed Boost &7(Right Click)") + .lore("&7Gain a temporary speed boost."); + + ItemBuilder arrow = new ItemBuilder(Material.ARROW).unbreakable(true).hideInfo().amount(32).slot(8); + return Arrays.asList(sword, bow, special, arrow); } @Override @@ -72,6 +78,7 @@ public ItemBuilder[] getArmor() { + "MwMzIyZDM1NjgzMjI4ZjMwZmJjYThjZDFjMmE2MDIwODczMDE1MTZmNmI0MzhiNDhkNjc2ZWU1NTIwNzU3MCJ9fX0="; return new ItemBuilder[]{ + // Armor value: 3.0 new ItemBuilder(SkullBuilder.itemFromBase64(base64)).name("&fArcher's Head"), new ItemBuilder(Material.LEATHER_CHESTPLATE).unbreakable(true).hideInfo(), new ItemBuilder(Material.LEATHER_LEGGINGS).unbreakable(true).hideInfo(), diff --git a/src/main/java/net/foulest/kitpvp/kits/type/Burrower.java b/src/main/java/net/foulest/kitpvp/kits/type/Burrower.java deleted file mode 100644 index dc179b3..0000000 --- a/src/main/java/net/foulest/kitpvp/kits/type/Burrower.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * KitPvP - a fully-featured core plugin for the KitPvP gamemode. - * Copyright (C) 2024 Foulest (https://github.com/Foulest) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package net.foulest.kitpvp.kits.type; - -import net.foulest.kitpvp.kits.Kit; -import net.foulest.kitpvp.util.Settings; -import net.foulest.kitpvp.util.item.ItemBuilder; -import net.foulest.kitpvp.util.item.SkullBuilder; -import org.bukkit.Material; -import org.bukkit.inventory.ItemStack; -import org.bukkit.permissions.Permission; -import org.bukkit.permissions.PermissionDefault; -import org.bukkit.potion.PotionEffect; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -/** - * Represents the Burrower kit. - * - * @author Foulest - */ -public class Burrower implements Kit { - - @Override - public String getName() { - return "Burrower"; - } - - @Override - public ItemStack getDisplayItem() { - return new ItemStack(Material.BRICK); - } - - @Override - public PotionEffect[] getPotionEffects() { - return new PotionEffect[0]; - } - - @Override - public List getItems() { - ItemBuilder sword = new ItemBuilder(Material.STONE_SWORD).unbreakable(true).hideInfo(); - ItemBuilder special = new ItemBuilder(Material.BRICK).name("&aPanic Room &7(Right Click)") - .lore("&7Create a panic room for protection."); - return Arrays.asList(sword, special); - } - - @Override - public ItemBuilder[] getArmor() { - String base64 = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMW" - + "M0NDBlYWM4YmQ1MzA4YzMyY2Y5ODJjM2I5YzNjOWI0OWQzNDVkYjY0ODNlZDQ0Nzg0ZmQyZDk0ZmNhMzIyZSJ9fX0="; - - return new ItemBuilder[]{ - new ItemBuilder(SkullBuilder.itemFromBase64(base64)).name("&fBurrower's Head"), - new ItemBuilder(Material.IRON_CHESTPLATE).unbreakable(true).hideInfo(), - new ItemBuilder(Material.CHAINMAIL_LEGGINGS).unbreakable(true).hideInfo(), - new ItemBuilder(Material.CHAINMAIL_BOOTS).unbreakable(true).hideInfo() - }; - } - - @Override - public List getLore() { - return new ArrayList<>(Arrays.asList("&7Style: &aDefensive", "", "&7Create a panic room for protection.")); - } - - @Override - public boolean enabled() { - return Settings.burrowerKitEnabled; - } - - @Override - public int getCost() { - return Settings.burrowerKitCost; - } - - @Override - public Permission permission() { - return new Permission("kitpvp.kit.burrower", PermissionDefault.TRUE); - } -} diff --git a/src/main/java/net/foulest/kitpvp/kits/type/Cactus.java b/src/main/java/net/foulest/kitpvp/kits/type/Cactus.java deleted file mode 100644 index 28ca978..0000000 --- a/src/main/java/net/foulest/kitpvp/kits/type/Cactus.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * KitPvP - a fully-featured core plugin for the KitPvP gamemode. - * Copyright (C) 2024 Foulest (https://github.com/Foulest) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package net.foulest.kitpvp.kits.type; - -import net.foulest.kitpvp.kits.Kit; -import net.foulest.kitpvp.util.Settings; -import net.foulest.kitpvp.util.item.ItemBuilder; -import net.foulest.kitpvp.util.item.SkullBuilder; -import org.bukkit.Color; -import org.bukkit.Material; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.inventory.ItemStack; -import org.bukkit.permissions.Permission; -import org.bukkit.permissions.PermissionDefault; -import org.bukkit.potion.PotionEffect; -import org.bukkit.potion.PotionEffectType; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -/** - * Represents the Cactus kit. - * - * @author Foulest - */ -public class Cactus implements Kit { - - @Override - public String getName() { - return "Cactus"; - } - - @Override - public ItemStack getDisplayItem() { - return new ItemStack(Material.CACTUS); - } - - @Override - public PotionEffect[] getPotionEffects() { - return new PotionEffect[]{ - new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, 0, false, false) - }; - } - - @Override - public List getItems() { - ItemBuilder sword = new ItemBuilder(Material.CACTUS).enchant(Enchantment.KNOCKBACK, 1) - .enchant(Enchantment.DAMAGE_ALL, 4).name("&aPrick").lore("&7Inflict knockback and poison."); - return Collections.singletonList(sword); - } - - @Override - public ItemBuilder[] getArmor() { - String base64 = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNm" - + "MwNzRlNjA2ZDIwNzg0YTc3OTZmYWIyYzBkMDM1NjRmNjVhODI2YzQwYTA1ZWU3NjkxYjYxODZjMjExYzlmMiJ9fX0="; - - return new ItemBuilder[]{ - new ItemBuilder(SkullBuilder.itemFromBase64(base64)).name("&fCactus's Head"), - new ItemBuilder(Material.LEATHER_CHESTPLATE).unbreakable(true).hideInfo().color(Color.fromRGB(0x197F22)), - new ItemBuilder(Material.LEATHER_LEGGINGS).unbreakable(true).hideInfo().color(Color.fromRGB(0x197F22)), - new ItemBuilder(Material.LEATHER_BOOTS).unbreakable(true).hideInfo().color(Color.fromRGB(0x197F22)) - }; - } - - @Override - public List getLore() { - return new ArrayList<>(Arrays.asList("&7Style: &aOffensive", "", "&7Inflict knockback and poison.")); - } - - @Override - public boolean enabled() { - return Settings.cactusKitEnabled; - } - - @Override - public int getCost() { - return Settings.cactusKitCost; - } - - @Override - public Permission permission() { - return new Permission("kitpvp.kit.cactus", PermissionDefault.TRUE); - } -} diff --git a/src/main/java/net/foulest/kitpvp/kits/type/Dragon.java b/src/main/java/net/foulest/kitpvp/kits/type/Dragon.java deleted file mode 100644 index 0ad654c..0000000 --- a/src/main/java/net/foulest/kitpvp/kits/type/Dragon.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * KitPvP - a fully-featured core plugin for the KitPvP gamemode. - * Copyright (C) 2024 Foulest (https://github.com/Foulest) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package net.foulest.kitpvp.kits.type; - -import net.foulest.kitpvp.kits.Kit; -import net.foulest.kitpvp.util.Settings; -import net.foulest.kitpvp.util.item.ItemBuilder; -import net.foulest.kitpvp.util.item.SkullBuilder; -import org.bukkit.Color; -import org.bukkit.Material; -import org.bukkit.inventory.ItemStack; -import org.bukkit.permissions.Permission; -import org.bukkit.permissions.PermissionDefault; -import org.bukkit.potion.PotionEffect; -import org.bukkit.potion.PotionEffectType; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Objects; - -/** - * Represents the Dragon kit. - * - * @author Foulest - */ -public class Dragon implements Kit { - - @Override - public String getName() { - return "Dragon"; - } - - @Override - public ItemStack getDisplayItem() { - return new ItemStack(Objects.requireNonNull(Material.FIREBALL)); - } - - @Override - public PotionEffect[] getPotionEffects() { - return new PotionEffect[]{ - new PotionEffect(PotionEffectType.FIRE_RESISTANCE, Integer.MAX_VALUE, 0, false, false) - }; - } - - @Override - public List getItems() { - ItemBuilder sword = new ItemBuilder(Material.STONE_SWORD).unbreakable(true).hideInfo(); - ItemBuilder special = new ItemBuilder(Material.FIREBALL).name("&aDragon's Breath &7(Right Click)") - .lore("&7Emits a powerful, fiery breath."); - return Arrays.asList(sword, special); - } - - @Override - public ItemBuilder[] getArmor() { - String base64 = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNzM" - + "0ODA1OTIyNjZkZDdmNTM2ODFlZmVlZTMxODhhZjUzMWVlYTUzZGE0YWY1ODNhNjc2MTdkZWViNGY0NzMifX19"; - - return new ItemBuilder[]{ - new ItemBuilder(SkullBuilder.itemFromBase64(base64)).name("&fDragon's Head"), - new ItemBuilder(Material.LEATHER_CHESTPLATE).unbreakable(true).hideInfo().color(Color.fromRGB(0xCC1E1E)), - new ItemBuilder(Material.IRON_LEGGINGS).unbreakable(true).hideInfo(), - new ItemBuilder(Material.IRON_BOOTS).unbreakable(true).hideInfo() - }; - } - - @Override - public List getLore() { - return new ArrayList<>(Arrays.asList("&7Style: &aOffensive", "", "&7Emits a powerful, fiery breath.")); - } - - @Override - public boolean enabled() { - return Settings.dragonKitEnabled; - } - - @Override - public int getCost() { - return Settings.dragonKitCost; - } - - @Override - public Permission permission() { - return new Permission("kitpvp.kit.dragon", PermissionDefault.TRUE); - } -} diff --git a/src/main/java/net/foulest/kitpvp/kits/type/Fisherman.java b/src/main/java/net/foulest/kitpvp/kits/type/Fisherman.java index 925333a..dc506cf 100644 --- a/src/main/java/net/foulest/kitpvp/kits/type/Fisherman.java +++ b/src/main/java/net/foulest/kitpvp/kits/type/Fisherman.java @@ -31,7 +31,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.Objects; /** * Represents the Fisherman kit. @@ -47,7 +46,7 @@ public String getName() { @Override public ItemStack getDisplayItem() { - return new ItemStack(Objects.requireNonNull(Material.FISHING_ROD)); + return new ItemStack(Material.FISHING_ROD); } @Override @@ -57,7 +56,9 @@ public PotionEffect[] getPotionEffects() { @Override public List getItems() { + // Damage value: 4.0 ItemBuilder sword = new ItemBuilder(Material.WOOD_SWORD).unbreakable(true).hideInfo(); + ItemBuilder special = new ItemBuilder(Material.FISHING_ROD).unbreakable(true).hideInfo().name("&aHookshot &7(Right Click)") .lore("&7Hooks players to your location."); return Arrays.asList(sword, special); @@ -69,6 +70,7 @@ public ItemBuilder[] getArmor() { + "MTcxNTI4NzZiYzNhOTZkZDJhMjI5OTI0NWVkYjNiZWVmNjQ3YzhhNTZhYzg4NTNhNjg3YzNlN2I1ZDhiYiJ9fX0="; return new ItemBuilder[]{ + // Armor value: 5.0 new ItemBuilder(SkullBuilder.itemFromBase64(base64)).name("&fFisherman's Head"), new ItemBuilder(Material.LEATHER_CHESTPLATE).unbreakable(true).hideInfo().color(Color.fromRGB(0xBF8426)), new ItemBuilder(Material.IRON_LEGGINGS).unbreakable(true).hideInfo(), diff --git a/src/main/java/net/foulest/kitpvp/kits/type/Ghost.java b/src/main/java/net/foulest/kitpvp/kits/type/Ghost.java deleted file mode 100644 index 32167ba..0000000 --- a/src/main/java/net/foulest/kitpvp/kits/type/Ghost.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * KitPvP - a fully-featured core plugin for the KitPvP gamemode. - * Copyright (C) 2024 Foulest (https://github.com/Foulest) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package net.foulest.kitpvp.kits.type; - -import net.foulest.kitpvp.kits.Kit; -import net.foulest.kitpvp.util.Settings; -import net.foulest.kitpvp.util.item.ItemBuilder; -import org.bukkit.Material; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.inventory.ItemStack; -import org.bukkit.permissions.Permission; -import org.bukkit.permissions.PermissionDefault; -import org.bukkit.potion.PotionEffect; -import org.bukkit.potion.PotionEffectType; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Objects; - -/** - * Represents the Ghost kit. - * - * @author Foulest - */ -public class Ghost implements Kit { - - @Override - public String getName() { - return "Ghost"; - } - - @Override - public ItemStack getDisplayItem() { - return new ItemStack(Objects.requireNonNull(Material.GHAST_TEAR)); - } - - @Override - public PotionEffect[] getPotionEffects() { - return new PotionEffect[]{ - new PotionEffect(PotionEffectType.INVISIBILITY, Integer.MAX_VALUE, 0, true) - }; - } - - @Override - public List getItems() { - ItemBuilder sword = new ItemBuilder(Material.DIAMOND_SWORD).unbreakable(true).hideInfo().enchant(Enchantment.DAMAGE_ALL, 1); - ItemBuilder air = new ItemBuilder(Material.AIR).slot(1); - return Arrays.asList(sword, air); - } - - @Override - public ItemBuilder[] getArmor() { - return new ItemBuilder[]{ - new ItemBuilder(Material.AIR), - new ItemBuilder(Material.AIR), - new ItemBuilder(Material.AIR), - new ItemBuilder(Material.AIR) - }; - } - - @Override - public List getLore() { - return new ArrayList<>(Arrays.asList("&7Style: &aOffensive", "", "&7Permanent invisibility.")); - } - - @Override - public boolean enabled() { - return Settings.ghostKitEnabled; - } - - @Override - public int getCost() { - return Settings.ghostKitCost; - } - - @Override - public Permission permission() { - return new Permission("kitpvp.kit.ghost", PermissionDefault.TRUE); - } -} diff --git a/src/main/java/net/foulest/kitpvp/kits/type/Hulk.java b/src/main/java/net/foulest/kitpvp/kits/type/Hulk.java deleted file mode 100644 index ad19fcc..0000000 --- a/src/main/java/net/foulest/kitpvp/kits/type/Hulk.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * KitPvP - a fully-featured core plugin for the KitPvP gamemode. - * Copyright (C) 2024 Foulest (https://github.com/Foulest) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package net.foulest.kitpvp.kits.type; - -import net.foulest.kitpvp.kits.Kit; -import net.foulest.kitpvp.util.Settings; -import net.foulest.kitpvp.util.item.ItemBuilder; -import net.foulest.kitpvp.util.item.SkullBuilder; -import org.bukkit.Color; -import org.bukkit.Material; -import org.bukkit.inventory.ItemStack; -import org.bukkit.permissions.Permission; -import org.bukkit.permissions.PermissionDefault; -import org.bukkit.potion.PotionEffect; -import org.bukkit.potion.PotionEffectType; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Objects; - -/** - * Represents the Hulk kit. - * - * @author Foulest - */ -public class Hulk implements Kit { - - @Override - public String getName() { - return "Hulk"; - } - - @Override - public ItemStack getDisplayItem() { - return new ItemStack(Objects.requireNonNull(Material.PISTON_STICKY_BASE)); - } - - @Override - public PotionEffect[] getPotionEffects() { - return new PotionEffect[]{ - new PotionEffect(PotionEffectType.SLOW, Integer.MAX_VALUE, 0, false, false) - }; - } - - @Override - public List getItems() { - ItemBuilder sword = new ItemBuilder(Material.STONE_SWORD).unbreakable(true).hideInfo(); - ItemBuilder special = new ItemBuilder(Material.PISTON_STICKY_BASE).name("&aHulk Smash &7(Right Click)") - .lore("&7Deals players immense knockback."); - return Arrays.asList(sword, special); - } - - @Override - public ItemBuilder[] getArmor() { - String base64 = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZ" - + "GJhMTIwZTM3MjdkZDc3MDY2Mjk3MThhNTE3MTI1YjFkNTgwNWZmYTUxM2E3ZDcxZmYyMmRiYTg4NjRmZWMzMSJ9fX0="; - - return new ItemBuilder[]{ - new ItemBuilder(SkullBuilder.itemFromBase64(base64)).name("&fHulk's Head"), - new ItemBuilder(Material.LEATHER_CHESTPLATE).unbreakable(true).hideInfo().color(Color.fromRGB(0x3E7F2B)), - new ItemBuilder(Material.DIAMOND_LEGGINGS).unbreakable(true).hideInfo(), - new ItemBuilder(Material.LEATHER_BOOTS).unbreakable(true).hideInfo().color(Color.fromRGB(0x3E7F2B)) - }; - } - - @Override - public List getLore() { - return new ArrayList<>(Arrays.asList("&7Style: &aOffensive", "", "&7Deals players immense knockback.")); - } - - @Override - public boolean enabled() { - return Settings.hulkKitEnabled; - } - - @Override - public int getCost() { - return Settings.hulkKitCost; - } - - @Override - public Permission permission() { - return new Permission("kitpvp.kit.hulk", PermissionDefault.TRUE); - } -} diff --git a/src/main/java/net/foulest/kitpvp/kits/type/Imprisoner.java b/src/main/java/net/foulest/kitpvp/kits/type/Imprisoner.java deleted file mode 100644 index 48ab5e6..0000000 --- a/src/main/java/net/foulest/kitpvp/kits/type/Imprisoner.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * KitPvP - a fully-featured core plugin for the KitPvP gamemode. - * Copyright (C) 2024 Foulest (https://github.com/Foulest) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package net.foulest.kitpvp.kits.type; - -import net.foulest.kitpvp.kits.Kit; -import net.foulest.kitpvp.util.Settings; -import net.foulest.kitpvp.util.item.ItemBuilder; -import net.foulest.kitpvp.util.item.SkullBuilder; -import org.bukkit.Color; -import org.bukkit.Material; -import org.bukkit.inventory.ItemStack; -import org.bukkit.permissions.Permission; -import org.bukkit.permissions.PermissionDefault; -import org.bukkit.potion.PotionEffect; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Objects; - -/** - * Represents the Imprisoner kit. - * - * @author Foulest - */ -public class Imprisoner implements Kit { - - @Override - public String getName() { - return "Imprisoner"; - } - - @Override - public ItemStack getDisplayItem() { - return new ItemStack(Objects.requireNonNull(Material.LAVA_BUCKET)); - } - - @Override - public PotionEffect[] getPotionEffects() { - return new PotionEffect[0]; - } - - @Override - public List getItems() { - ItemBuilder sword = new ItemBuilder(Material.STONE_SWORD).unbreakable(true).hideInfo(); - ItemBuilder special = new ItemBuilder(Material.DISPENSER).name("&aLava Prison &7(Right Click)") - .lore("&7Sends enemy players to jail."); - return Arrays.asList(sword, special); - } - - @Override - public ItemBuilder[] getArmor() { - String base64 = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNjc" - + "xNTdjZmZiMDYwNjNiMzUyZGM2ODQ3OGY0NzZlN2QyMDJjM2JhNmU3Y2JmMjk3MjQxYmU4MTY4MTA3NGJmIn19fQ=="; - - return new ItemBuilder[]{ - new ItemBuilder(SkullBuilder.itemFromBase64(base64)).name("&fImprisoner's Head"), - new ItemBuilder(Material.LEATHER_CHESTPLATE).unbreakable(true).hideInfo().color(Color.fromRGB(0x1E4866)), - new ItemBuilder(Material.IRON_LEGGINGS).unbreakable(true).hideInfo(), - new ItemBuilder(Material.IRON_BOOTS).unbreakable(true).hideInfo() - }; - } - - @Override - public List getLore() { - return new ArrayList<>(Arrays.asList("&7Style: &aOffensive", "", "&7Sends enemy players to jail.")); - } - - @Override - public boolean enabled() { - return Settings.imprisonerKitEnabled; - } - - @Override - public int getCost() { - return Settings.imprisonerKitCost; - } - - @Override - public Permission permission() { - return new Permission("kitpvp.kit.imprisoner", PermissionDefault.TRUE); - } -} diff --git a/src/main/java/net/foulest/kitpvp/kits/type/Kangaroo.java b/src/main/java/net/foulest/kitpvp/kits/type/Kangaroo.java index 57bc7d7..bb2ad1a 100644 --- a/src/main/java/net/foulest/kitpvp/kits/type/Kangaroo.java +++ b/src/main/java/net/foulest/kitpvp/kits/type/Kangaroo.java @@ -33,7 +33,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.Objects; /** * Represents the Kangaroo kit. @@ -49,7 +48,7 @@ public String getName() { @Override public ItemStack getDisplayItem() { - return new ItemStack(Objects.requireNonNull(Material.FIREWORK)); + return new ItemStack(Material.FIREWORK); } @Override @@ -61,7 +60,9 @@ public PotionEffect[] getPotionEffects() { @Override public List getItems() { + // Damage value: 5.0 ItemBuilder sword = new ItemBuilder(Material.STONE_SWORD).unbreakable(true).hideInfo(); + ItemBuilder special = new ItemBuilder(Material.FIREWORK).name("&aHop &7(Right Click)") .lore("&7Hop around like a Kangaroo."); return Arrays.asList(sword, special); @@ -73,6 +74,7 @@ public ItemBuilder[] getArmor() { + "hYjQyYWZhOTJhZGYxNWFiZmJmNDljZDA5NjY0NDA5NjQ5Mzk3N2YzNjYyMDNmNTIzMTFlYzk3ODJiY2YyNCJ9fX0="; return new ItemBuilder[]{ + // Armor value: 5.0 new ItemBuilder(SkullBuilder.itemFromBase64(base64)).name("&fKangaroo's Head"), new ItemBuilder(Material.LEATHER_CHESTPLATE).unbreakable(true).hideInfo().color(Color.fromRGB(0x7F4A19)), new ItemBuilder(Material.IRON_LEGGINGS).unbreakable(true).hideInfo(), diff --git a/src/main/java/net/foulest/kitpvp/kits/type/Knight.java b/src/main/java/net/foulest/kitpvp/kits/type/Knight.java index 6a81308..020a00c 100644 --- a/src/main/java/net/foulest/kitpvp/kits/type/Knight.java +++ b/src/main/java/net/foulest/kitpvp/kits/type/Knight.java @@ -43,7 +43,7 @@ public String getName() { @Override public ItemStack getDisplayItem() { - return new ItemStack(Objects.requireNonNull(Material.IRON_CHESTPLATE)); + return new ItemBuilder(Material.IRON_CHESTPLATE).hideInfo().getItem(); } @Override @@ -53,6 +53,7 @@ public PotionEffect[] getPotionEffects() { @Override public List getItems() { + // Attack value: 5.0 ItemBuilder sword = new ItemBuilder(Material.STONE_SWORD).unbreakable(true).hideInfo(); return Collections.singletonList(sword); } @@ -63,6 +64,7 @@ public ItemBuilder[] getArmor() { + "A1Mzk3M2U3YzUyMzcyYzNiMTExMzk0ZGZmOTUxOWNiYWMxZmJhM2Y2NTliMjE4NmJlZjhlZWY5ZTEwZmEyIn19fQ=="; return new ItemBuilder[]{ + // Armor value: 6.5 new ItemBuilder(SkullBuilder.itemFromBase64(base64)).name("&fKnight's Head"), new ItemBuilder(Material.IRON_CHESTPLATE).unbreakable(true).hideInfo(), new ItemBuilder(Material.IRON_LEGGINGS).unbreakable(true).hideInfo(), diff --git a/src/main/java/net/foulest/kitpvp/kits/type/Mage.java b/src/main/java/net/foulest/kitpvp/kits/type/Mage.java index 22af287..ec3536d 100644 --- a/src/main/java/net/foulest/kitpvp/kits/type/Mage.java +++ b/src/main/java/net/foulest/kitpvp/kits/type/Mage.java @@ -17,6 +17,7 @@ */ package net.foulest.kitpvp.kits.type; +import javafx.scene.effect.SepiaTone; import net.foulest.kitpvp.kits.Kit; import net.foulest.kitpvp.util.Settings; import net.foulest.kitpvp.util.item.ItemBuilder; @@ -30,7 +31,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.Objects; /** * Represents the Mage kit. @@ -46,7 +46,7 @@ public String getName() { @Override public ItemStack getDisplayItem() { - return new ItemStack(Objects.requireNonNull(Material.GLOWSTONE_DUST)); + return new ItemStack(Material.GLOWSTONE_DUST); } @Override @@ -56,9 +56,11 @@ public PotionEffect[] getPotionEffects() { @Override public List getItems() { + // Damage value: 5.0 ItemBuilder sword = new ItemBuilder(Material.STONE_SWORD).unbreakable(true).hideInfo(); + ItemBuilder special = new ItemBuilder(Material.GLOWSTONE_DUST).name("&aRandom Effect &7(Right Click)") - .lore("&7Gives you random potion effects."); + .lore("&7Gives you a random potion effect."); return Arrays.asList(sword, special); } @@ -68,6 +70,7 @@ public ItemBuilder[] getArmor() { + "MmIxNTQ4NTQ1ZTJhMjQ5N2JkMjRhYWM3OTE3OTI2NTRlZjU4N2E1YWI3M2QzNmFiN2Y1ZDliZjcyYTU0NyJ9fX0="; return new ItemBuilder[]{ + // Armor value: 5.0 new ItemBuilder(SkullBuilder.itemFromBase64(base64)).name("&fMage's Head"), new ItemBuilder(Material.LEATHER_CHESTPLATE).unbreakable(true).hideInfo(), new ItemBuilder(Material.IRON_LEGGINGS).unbreakable(true).hideInfo(), @@ -77,7 +80,7 @@ public ItemBuilder[] getArmor() { @Override public List getLore() { - return new ArrayList<>(Arrays.asList("&7Style: &aMixed", "", "&7Gives you random potion effects.")); + return new ArrayList<>(Arrays.asList("&7Style: &aMixed", "", "&7Gives you a random potion effect.")); } @Override diff --git a/src/main/java/net/foulest/kitpvp/kits/type/Monk.java b/src/main/java/net/foulest/kitpvp/kits/type/Monk.java deleted file mode 100644 index 1194ed1..0000000 --- a/src/main/java/net/foulest/kitpvp/kits/type/Monk.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * KitPvP - a fully-featured core plugin for the KitPvP gamemode. - * Copyright (C) 2024 Foulest (https://github.com/Foulest) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package net.foulest.kitpvp.kits.type; - -import net.foulest.kitpvp.kits.Kit; -import net.foulest.kitpvp.util.Settings; -import net.foulest.kitpvp.util.item.ItemBuilder; -import net.foulest.kitpvp.util.item.SkullBuilder; -import org.bukkit.Color; -import org.bukkit.Material; -import org.bukkit.inventory.ItemStack; -import org.bukkit.permissions.Permission; -import org.bukkit.permissions.PermissionDefault; -import org.bukkit.potion.PotionEffect; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Objects; - -/** - * Represents the Monk kit. - * - * @author Foulest - */ -public class Monk implements Kit { - - @Override - public String getName() { - return "Monk"; - } - - @Override - public ItemStack getDisplayItem() { - return new ItemStack(Objects.requireNonNull(Material.BLAZE_ROD)); - } - - @Override - public PotionEffect[] getPotionEffects() { - return new PotionEffect[0]; - } - - @Override - public List getItems() { - ItemBuilder sword = new ItemBuilder(Material.STONE_SWORD).unbreakable(true).hideInfo(); - ItemBuilder special = new ItemBuilder(Material.BLAZE_ROD).name("&aItem Scrambler &7(Right Click)") - .lore("&7Scrambles a player's hotbar items."); - return Arrays.asList(sword, special); - } - - @Override - public ItemBuilder[] getArmor() { - String base64 = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvY" - + "WM5NmY3NWY2YWQ2ZTZhNjNhNWY3ZmI3ZTVkNWE5MmI4NmI4MzI2MmQyNzgzZThlMjBiMWZkZDA2NDlmNjllIn19fQ=="; - - return new ItemBuilder[]{ - new ItemBuilder(SkullBuilder.itemFromBase64(base64)).name("&fMonk's Head"), - new ItemBuilder(Material.LEATHER_CHESTPLATE).unbreakable(true).hideInfo().color(Color.ORANGE), - new ItemBuilder(Material.IRON_LEGGINGS).unbreakable(true).hideInfo(), - new ItemBuilder(Material.IRON_BOOTS).unbreakable(true).hideInfo() - }; - } - - @Override - public List getLore() { - return new ArrayList<>(Arrays.asList("&7Style: &aOffensive", "", "&7Scramble a player's hotbar items.")); - } - - @Override - public boolean enabled() { - return Settings.monkKitEnabled; - } - - @Override - public int getCost() { - return Settings.monkKitCost; - } - - @Override - public Permission permission() { - return new Permission("kitpvp.kit.monk", PermissionDefault.TRUE); - } -} diff --git a/src/main/java/net/foulest/kitpvp/kits/type/Ninja.java b/src/main/java/net/foulest/kitpvp/kits/type/Ninja.java index c89c492..6433dab 100644 --- a/src/main/java/net/foulest/kitpvp/kits/type/Ninja.java +++ b/src/main/java/net/foulest/kitpvp/kits/type/Ninja.java @@ -24,6 +24,7 @@ import org.bukkit.Color; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; +import org.bukkit.material.Dye; import org.bukkit.permissions.Permission; import org.bukkit.permissions.PermissionDefault; import org.bukkit.potion.PotionEffect; @@ -45,7 +46,7 @@ public String getName() { @Override public ItemStack getDisplayItem() { - return new ItemStack(Objects.requireNonNull(Material.NETHER_STAR)); + return new ItemStack(Material.NETHER_STAR); } @Override @@ -57,8 +58,12 @@ public PotionEffect[] getPotionEffects() { @Override public List getItems() { + // Damage value: 5.0 ItemBuilder weapon = new ItemBuilder(Material.STONE_SWORD).unbreakable(true).hideInfo(); - return Collections.singletonList(weapon); + + ItemBuilder special = new ItemBuilder(Material.INK_SACK).durability(8).name("&aShadow Sneak &7(Right Click)") + .lore("&7Turns you completely invisible."); + return Arrays.asList(weapon, special); } @Override @@ -67,6 +72,7 @@ public ItemBuilder[] getArmor() { + "jQ2ZmZlNGY2OGRhYWEwZjgzNDUzNmNiNTM4NmEzYTc5ZTZiM2U4NDM1OTY5NDM4MDRlMWIwOGE4MmVkNDRhNiJ9fX0="; return new ItemBuilder[]{ + // Armor value: 3.5 new ItemBuilder(SkullBuilder.itemFromBase64(base64)).name("&fNinja's Head"), new ItemBuilder(Material.LEATHER_CHESTPLATE).unbreakable(true).hideInfo().color(Color.fromRGB(0x0C0C0C)), new ItemBuilder(Material.CHAINMAIL_LEGGINGS).unbreakable(true).hideInfo(), diff --git a/src/main/java/net/foulest/kitpvp/kits/type/Pyro.java b/src/main/java/net/foulest/kitpvp/kits/type/Pyro.java index aff8eb5..6217434 100644 --- a/src/main/java/net/foulest/kitpvp/kits/type/Pyro.java +++ b/src/main/java/net/foulest/kitpvp/kits/type/Pyro.java @@ -27,11 +27,11 @@ import org.bukkit.permissions.Permission; import org.bukkit.permissions.PermissionDefault; import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.Objects; /** * Represents the Pyro kit. @@ -47,20 +47,24 @@ public String getName() { @Override public ItemStack getDisplayItem() { - return new ItemStack(Objects.requireNonNull(Material.FLINT_AND_STEEL)); + return new ItemBuilder(Material.FLINT_AND_STEEL).hideInfo().getItem(); } @Override public PotionEffect[] getPotionEffects() { - return new PotionEffect[0]; + return new PotionEffect[]{ + new PotionEffect(PotionEffectType.FIRE_RESISTANCE, Integer.MAX_VALUE, 0, false, false) + }; } @Override public List getItems() { - ItemBuilder weapon = new ItemBuilder(Material.WOOD_SWORD).unbreakable(true).hideInfo().enchant(Enchantment.FIRE_ASPECT, 1); - ItemBuilder bow = new ItemBuilder(Material.BOW).unbreakable(true).hideInfo().enchant(Enchantment.ARROW_FIRE, 1); - ItemBuilder arrow = new ItemBuilder(Material.ARROW).amount(16).slot(9); - return Arrays.asList(weapon, bow, arrow); + // Damage value: 4.0 + ItemBuilder sword = new ItemBuilder(Material.WOOD_SWORD).enchant(Enchantment.FIRE_ASPECT, 1).unbreakable(true).hideInfo(); + + ItemBuilder special = new ItemBuilder(Material.FIREBALL).name("&aIgnite &7(Right Click)") + .lore("&7Ignites players on fire."); + return Arrays.asList(sword, special); } @Override @@ -69,10 +73,11 @@ public ItemBuilder[] getArmor() { + "mNTc2NDU0Y2I2NDFhNmU1OTVlZGY0ZTc3YTcwYzIwM2U4OGVjYWIwZjIyMGQzZmUzMGZiM2NjYzhjOGJhOCJ9fX0="; return new ItemBuilder[]{ + // Armor value: 4.5 new ItemBuilder(SkullBuilder.itemFromBase64(base64)).name("&fPyro's Head"), - new ItemBuilder(Material.CHAINMAIL_CHESTPLATE).unbreakable(true).hideInfo(), + new ItemBuilder(Material.GOLD_CHESTPLATE).unbreakable(true).hideInfo(), new ItemBuilder(Material.CHAINMAIL_LEGGINGS).unbreakable(true).hideInfo(), - new ItemBuilder(Material.GOLD_BOOTS).unbreakable(true).hideInfo().enchant(Enchantment.PROTECTION_FIRE, 4) + new ItemBuilder(Material.CHAINMAIL_BOOTS).unbreakable(true).hideInfo() }; } diff --git a/src/main/java/net/foulest/kitpvp/kits/type/Spiderman.java b/src/main/java/net/foulest/kitpvp/kits/type/Spiderman.java deleted file mode 100644 index 5169af9..0000000 --- a/src/main/java/net/foulest/kitpvp/kits/type/Spiderman.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * KitPvP - a fully-featured core plugin for the KitPvP gamemode. - * Copyright (C) 2024 Foulest (https://github.com/Foulest) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package net.foulest.kitpvp.kits.type; - -import net.foulest.kitpvp.kits.Kit; -import net.foulest.kitpvp.util.Settings; -import net.foulest.kitpvp.util.item.ItemBuilder; -import net.foulest.kitpvp.util.item.SkullBuilder; -import org.bukkit.Color; -import org.bukkit.Material; -import org.bukkit.inventory.ItemStack; -import org.bukkit.permissions.Permission; -import org.bukkit.permissions.PermissionDefault; -import org.bukkit.potion.PotionEffect; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Objects; - -/** - * Represents the Spiderman kit. - * - * @author Foulest - */ -public class Spiderman implements Kit { - - @Override - public String getName() { - return "Spiderman"; - } - - @Override - public ItemStack getDisplayItem() { - return new ItemStack(Objects.requireNonNull(Material.WEB)); - } - - @Override - public PotionEffect[] getPotionEffects() { - return new PotionEffect[0]; - } - - @Override - public List getItems() { - ItemBuilder sword = new ItemBuilder(Material.WOOD_SWORD).unbreakable(true).hideInfo(); - ItemBuilder special = new ItemBuilder(Material.WEB).name("&aWeb Slinger &7(Right Click)") - .lore("&7Traps players in cobwebs."); - return Arrays.asList(sword, special); - } - - @Override - public ItemBuilder[] getArmor() { - String base64 = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYW" - + "M0MGQ5ODBjNjEyNzI0M2NkM2JiZGMwN2FhOTY1NDgzZWI2YTdlZWFiOWFhY2U5NzAzZGY5ZGYyOGQ3ZjU1MiJ9fX0="; - - return new ItemBuilder[]{ - new ItemBuilder(SkullBuilder.itemFromBase64(base64)).name("&fSpiderman's Head"), - new ItemBuilder(Material.LEATHER_CHESTPLATE).unbreakable(true).hideInfo().color(Color.fromRGB(0xCC2E33)), - new ItemBuilder(Material.DIAMOND_LEGGINGS).unbreakable(true).hideInfo(), - new ItemBuilder(Material.DIAMOND_BOOTS).unbreakable(true).hideInfo() - }; - } - - @Override - public List getLore() { - return new ArrayList<>(Arrays.asList("&7Style: &aDefensive", "", "&7Traps players in cobwebs.")); - } - - @Override - public boolean enabled() { - return Settings.spidermanKitEnabled; - } - - @Override - public int getCost() { - return Settings.spidermanKitCost; - } - - @Override - public Permission permission() { - return new Permission("kitpvp.kit.spiderman", PermissionDefault.TRUE); - } -} diff --git a/src/main/java/net/foulest/kitpvp/kits/type/Summoner.java b/src/main/java/net/foulest/kitpvp/kits/type/Summoner.java deleted file mode 100644 index 96486de..0000000 --- a/src/main/java/net/foulest/kitpvp/kits/type/Summoner.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * KitPvP - a fully-featured core plugin for the KitPvP gamemode. - * Copyright (C) 2024 Foulest (https://github.com/Foulest) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package net.foulest.kitpvp.kits.type; - -import net.foulest.kitpvp.kits.Kit; -import net.foulest.kitpvp.util.Settings; -import net.foulest.kitpvp.util.item.ItemBuilder; -import net.foulest.kitpvp.util.item.SkullBuilder; -import org.bukkit.Material; -import org.bukkit.inventory.ItemStack; -import org.bukkit.permissions.Permission; -import org.bukkit.permissions.PermissionDefault; -import org.bukkit.potion.PotionEffect; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Objects; - -/** - * Represents the Summoner kit. - * - * @author Foulest - */ -public class Summoner implements Kit { - - @Override - public String getName() { - return "Summoner"; - } - - @Override - public ItemStack getDisplayItem() { - return new ItemStack(Objects.requireNonNull(Material.IRON_BLOCK)); - } - - @Override - public PotionEffect[] getPotionEffects() { - return new PotionEffect[0]; - } - - @Override - public List getItems() { - ItemBuilder sword = new ItemBuilder(Material.WOOD_SWORD).unbreakable(true).hideInfo(); - ItemBuilder special = new ItemBuilder(Material.IRON_BLOCK).name("&aSummon Golem &7(Right Click)") - .lore("&7Summons an Iron Golem."); - return Arrays.asList(sword, special); - } - - @Override - public ItemBuilder[] getArmor() { - String base64 = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZT" - + "RiNTcxYWY0M2JhZjBkYmI2ODI0OTNiZGUxY2U0ZTg0N2RiNzU4ZGQ5Njg1ZTliZWMyYjdhYmJjYzcyNzcyNiJ9fX0="; - - return new ItemBuilder[]{ - new ItemBuilder(SkullBuilder.itemFromBase64(base64)).name("&fSummoner's Head"), - new ItemBuilder(Material.IRON_CHESTPLATE).unbreakable(true).hideInfo(), - new ItemBuilder(Material.CHAINMAIL_LEGGINGS).unbreakable(true).hideInfo(), - new ItemBuilder(Material.CHAINMAIL_BOOTS).unbreakable(true).hideInfo() - }; - } - - @Override - public List getLore() { - return new ArrayList<>(Arrays.asList("&7Style: &aDefensive", "", "&7Summons an Iron Golem.")); - } - - @Override - public boolean enabled() { - return Settings.summonerKitEnabled; - } - - @Override - public int getCost() { - return Settings.summonerKitCost; - } - - @Override - public Permission permission() { - return new Permission("kitpvp.kit.summoner", PermissionDefault.TRUE); - } -} diff --git a/src/main/java/net/foulest/kitpvp/kits/type/Tamer.java b/src/main/java/net/foulest/kitpvp/kits/type/Tamer.java deleted file mode 100644 index 1b61ad7..0000000 --- a/src/main/java/net/foulest/kitpvp/kits/type/Tamer.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * KitPvP - a fully-featured core plugin for the KitPvP gamemode. - * Copyright (C) 2024 Foulest (https://github.com/Foulest) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package net.foulest.kitpvp.kits.type; - -import net.foulest.kitpvp.kits.Kit; -import net.foulest.kitpvp.util.Settings; -import net.foulest.kitpvp.util.item.ItemBuilder; -import net.foulest.kitpvp.util.item.SkullBuilder; -import org.bukkit.Color; -import org.bukkit.Material; -import org.bukkit.inventory.ItemStack; -import org.bukkit.permissions.Permission; -import org.bukkit.permissions.PermissionDefault; -import org.bukkit.potion.PotionEffect; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Objects; - -/** - * Represents the Tamer kit. - * - * @author Foulest - */ -public class Tamer implements Kit { - - @Override - public String getName() { - return "Tamer"; - } - - @Override - public ItemStack getDisplayItem() { - return new ItemStack(Objects.requireNonNull(Material.BONE)); - } - - @Override - public PotionEffect[] getPotionEffects() { - return new PotionEffect[0]; - } - - @Override - public List getItems() { - ItemBuilder sword = new ItemBuilder(Material.STONE_SWORD).unbreakable(true).hideInfo(); - ItemBuilder special = new ItemBuilder(Material.BONE).name("&aSummon Wolves &7(Right Click)") - .lore("&7Summons a pack of wolves."); - return Arrays.asList(sword, special); - } - - @Override - public ItemBuilder[] getArmor() { - String base64 = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMW" - + "U2ZjU4NmZiZjViMTMxNmVlODI4Mjk0NmM4NTA4NzUxYzk3MTk0ZGFjZWVjNTk5ZDIxNDg4ZjNhYTU0NTAyNSJ9fX0="; - - return new ItemBuilder[]{ - new ItemBuilder(SkullBuilder.itemFromBase64(base64)).name("&fTamer's Head"), - new ItemBuilder(Material.LEATHER_CHESTPLATE).unbreakable(true).hideInfo().color(Color.fromRGB(0xCCAA7A)), - new ItemBuilder(Material.IRON_LEGGINGS).unbreakable(true).hideInfo(), - new ItemBuilder(Material.IRON_BOOTS).unbreakable(true).hideInfo() - }; - } - - @Override - public List getLore() { - return new ArrayList<>(Arrays.asList("&7Style: &aMixed", "", "&7Summons a pack of wolves.")); - } - - @Override - public boolean enabled() { - return Settings.tamerKitEnabled; - } - - @Override - public int getCost() { - return Settings.tamerKitCost; - } - - @Override - public Permission permission() { - return new Permission("kitpvp.kit.tamer", PermissionDefault.TRUE); - } -} diff --git a/src/main/java/net/foulest/kitpvp/kits/type/Tank.java b/src/main/java/net/foulest/kitpvp/kits/type/Tank.java index 8907a17..cecbeba 100644 --- a/src/main/java/net/foulest/kitpvp/kits/type/Tank.java +++ b/src/main/java/net/foulest/kitpvp/kits/type/Tank.java @@ -28,7 +28,10 @@ import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Set; /** * Represents the Tank kit. @@ -44,20 +47,24 @@ public String getName() { @Override public ItemStack getDisplayItem() { - return new ItemStack(Objects.requireNonNull(Material.DIAMOND_CHESTPLATE)); + return new ItemBuilder(Material.DIAMOND_CHESTPLATE).hideInfo().getItem(); } @Override public PotionEffect[] getPotionEffects() { return new PotionEffect[]{ - new PotionEffect(PotionEffectType.SLOW, Integer.MAX_VALUE, 1, false, false) + new PotionEffect(PotionEffectType.SLOW, Integer.MAX_VALUE, 0, false, false) }; } @Override public List getItems() { - ItemBuilder weapon = new ItemBuilder(Material.STONE_AXE).unbreakable(true).hideInfo(); - return Collections.singletonList(weapon); + // Damage value: 4.0 + ItemBuilder axe = new ItemBuilder(Material.STONE_AXE).unbreakable(true).hideInfo(); + + ItemBuilder special = new ItemBuilder(Material.ANVIL).name("&aFortify &7(Right Click)") + .lore("&7Reduce all incoming damage."); + return Arrays.asList(axe, special); } @Override @@ -66,10 +73,11 @@ public ItemBuilder[] getArmor() { + "Y1OWIyYmIwNzBjMTIwOGJhNTE0NTIzNjFmZDMwYTY2NzIxMzI5NWYyMWRiNDM3ZGY1NzI4MWQ1ODJjODlhZCJ9fX0="; return new ItemBuilder[]{ + // Armor value: 6.0 new ItemBuilder(SkullBuilder.itemFromBase64(base64)).name("&fTank's Head"), new ItemBuilder(Material.DIAMOND_CHESTPLATE).unbreakable(true).hideInfo(), - new ItemBuilder(Material.DIAMOND_LEGGINGS).unbreakable(true).hideInfo(), - new ItemBuilder(Material.DIAMOND_BOOTS).unbreakable(true).hideInfo() + new ItemBuilder(Material.CHAINMAIL_LEGGINGS).unbreakable(true).hideInfo(), + new ItemBuilder(Material.CHAINMAIL_BOOTS).unbreakable(true).hideInfo() }; } diff --git a/src/main/java/net/foulest/kitpvp/kits/type/Thor.java b/src/main/java/net/foulest/kitpvp/kits/type/Thor.java deleted file mode 100644 index a328f63..0000000 --- a/src/main/java/net/foulest/kitpvp/kits/type/Thor.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * KitPvP - a fully-featured core plugin for the KitPvP gamemode. - * Copyright (C) 2024 Foulest (https://github.com/Foulest) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package net.foulest.kitpvp.kits.type; - -import net.foulest.kitpvp.kits.Kit; -import net.foulest.kitpvp.util.Settings; -import net.foulest.kitpvp.util.item.ItemBuilder; -import net.foulest.kitpvp.util.item.SkullBuilder; -import org.bukkit.Material; -import org.bukkit.inventory.ItemStack; -import org.bukkit.permissions.Permission; -import org.bukkit.permissions.PermissionDefault; -import org.bukkit.potion.PotionEffect; - -import java.util.*; - -/** - * Represents the Thor kit. - * - * @author Foulest - */ -public class Thor implements Kit { - - @Override - public String getName() { - return "Thor"; - } - - @Override - public ItemStack getDisplayItem() { - return new ItemStack(Objects.requireNonNull(Material.IRON_AXE)); - } - - @Override - public PotionEffect[] getPotionEffects() { - return new PotionEffect[0]; - } - - @Override - public List getItems() { - ItemBuilder sword = new ItemBuilder(Material.IRON_AXE).name("&aMjolnir &7(Right Click)") - .lore("&7Strike enemies with lightning.").unbreakable(true).hideInfo(); - return Collections.singletonList(sword); - } - - @Override - public ItemBuilder[] getArmor() { - String base64 = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUv" - + "Zjg2NDRkZmQyNGM4MjRmNTU1NTY5ZWMwNjVjMDcwYTk3ZWQ5M2U1ZTY0M2E3MmQ1MzA0OGUyMDMyMWUwYjI3MCJ9fX0="; - - return new ItemBuilder[]{ - new ItemBuilder(SkullBuilder.itemFromBase64(base64)).name("&fThor's Head"), - new ItemBuilder(Material.IRON_CHESTPLATE).unbreakable(true).hideInfo(), - new ItemBuilder(Material.GOLD_LEGGINGS).unbreakable(true).hideInfo(), - new ItemBuilder(Material.GOLD_BOOTS).unbreakable(true).hideInfo() - }; - } - - @Override - public List getLore() { - return new ArrayList<>(Arrays.asList("&7Style: &aOffensive", "", "&7Strike enemies with lightning.")); - } - - @Override - public boolean enabled() { - return Settings.thorKitEnabled; - } - - @Override - public int getCost() { - return Settings.thorKitCost; - } - - @Override - public Permission permission() { - return new Permission("kitpvp.kit.thor", PermissionDefault.TRUE); - } -} diff --git a/src/main/java/net/foulest/kitpvp/kits/type/Timelord.java b/src/main/java/net/foulest/kitpvp/kits/type/Timelord.java deleted file mode 100644 index 9755545..0000000 --- a/src/main/java/net/foulest/kitpvp/kits/type/Timelord.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * KitPvP - a fully-featured core plugin for the KitPvP gamemode. - * Copyright (C) 2024 Foulest (https://github.com/Foulest) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package net.foulest.kitpvp.kits.type; - -import net.foulest.kitpvp.kits.Kit; -import net.foulest.kitpvp.util.Settings; -import net.foulest.kitpvp.util.item.ItemBuilder; -import net.foulest.kitpvp.util.item.SkullBuilder; -import org.bukkit.Material; -import org.bukkit.inventory.ItemStack; -import org.bukkit.permissions.Permission; -import org.bukkit.permissions.PermissionDefault; -import org.bukkit.potion.PotionEffect; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Objects; - -/** - * Represents the Timelord kit. - * - * @author Foulest - */ -public class Timelord implements Kit { - - @Override - public String getName() { - return "Timelord"; - } - - @Override - public ItemStack getDisplayItem() { - return new ItemStack(Objects.requireNonNull(Material.WATCH)); - } - - @Override - public PotionEffect[] getPotionEffects() { - return new PotionEffect[0]; - } - - @Override - public List getItems() { - ItemBuilder sword = new ItemBuilder(Material.STONE_SWORD).unbreakable(true).hideInfo(); - ItemBuilder special = new ItemBuilder(Material.WATCH).name("&aFreeze Time &7(Right Click)") - .lore("&7Freezes players in time."); - return Arrays.asList(sword, special); - } - - @Override - public ItemBuilder[] getArmor() { - String base64 = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYz" - + "M3Mjc0ZWMyODg5YjdjYWZhYjc2OGFkMjE2YzNlM2FlNjZmODAwNTQ3MDljNDcwNTI3NGVhNDAyMDA1Yzk2YiJ9fX0="; - - return new ItemBuilder[]{ - new ItemBuilder(SkullBuilder.itemFromBase64(base64)).name("&fTimelord's Head"), - new ItemBuilder(Material.IRON_CHESTPLATE).unbreakable(true).hideInfo(), - new ItemBuilder(Material.LEATHER_LEGGINGS).unbreakable(true).hideInfo(), - new ItemBuilder(Material.IRON_BOOTS).unbreakable(true).hideInfo() - }; - } - - @Override - public List getLore() { - return new ArrayList<>(Arrays.asList("&7Style: &aMixed", "", "&7Freezes players in time.")); - } - - @Override - public boolean enabled() { - return Settings.timelordKitEnabled; - } - - @Override - public int getCost() { - return Settings.timelordKitCost; - } - - @Override - public Permission permission() { - return new Permission("kitpvp.kit.timelord", PermissionDefault.TRUE); - } -} diff --git a/src/main/java/net/foulest/kitpvp/kits/type/Vampire.java b/src/main/java/net/foulest/kitpvp/kits/type/Vampire.java index 81e6f06..f522aec 100644 --- a/src/main/java/net/foulest/kitpvp/kits/type/Vampire.java +++ b/src/main/java/net/foulest/kitpvp/kits/type/Vampire.java @@ -31,7 +31,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.Objects; /** * Represents the Vampire kit. @@ -47,7 +46,7 @@ public String getName() { @Override public ItemStack getDisplayItem() { - return new ItemStack(Objects.requireNonNull(Material.REDSTONE)); + return new ItemStack(Material.REDSTONE); } @Override @@ -57,9 +56,11 @@ public PotionEffect[] getPotionEffects() { @Override public List getItems() { + // Damage value: 5.0 ItemBuilder sword = new ItemBuilder(Material.STONE_SWORD).unbreakable(true).hideInfo(); - ItemBuilder special = new ItemBuilder(Material.REDSTONE).name("&aDrain Effects &7(Right Click)") - .lore("&7Drains players potion effects."); + + ItemBuilder special = new ItemBuilder(Material.REDSTONE).name("&aLife-Steal &7(Right Click)") + .lore("&7Get life-steal on hit."); return Arrays.asList(sword, special); } @@ -69,6 +70,7 @@ public ItemBuilder[] getArmor() { + "0NDc1NmUwYjRlY2U4ZDc0NjI5NmEzZDVlMjk3ZTE0MTVmNGJhMTc2NDdmZmUyMjgzODUzODNkMTYxYTkifX19"; return new ItemBuilder[]{ + // Armor value: 5.0 new ItemBuilder(SkullBuilder.itemFromBase64(base64)).name("&fVampire's Head").unbreakable(true), new ItemBuilder(Material.LEATHER_CHESTPLATE).unbreakable(true).hideInfo().color(Color.fromRGB(0x191919)), new ItemBuilder(Material.IRON_LEGGINGS).unbreakable(true).hideInfo(), @@ -78,7 +80,7 @@ public ItemBuilder[] getArmor() { @Override public List getLore() { - return new ArrayList<>(Arrays.asList("&7Style: &aOffensive", "", "&7Drains players potion effects.")); + return new ArrayList<>(Arrays.asList("&7Style: &aOffensive", "", "&7Get life-steal on hit.")); } @Override diff --git a/src/main/java/net/foulest/kitpvp/kits/type/Zen.java b/src/main/java/net/foulest/kitpvp/kits/type/Zen.java deleted file mode 100644 index 8361d2f..0000000 --- a/src/main/java/net/foulest/kitpvp/kits/type/Zen.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * KitPvP - a fully-featured core plugin for the KitPvP gamemode. - * Copyright (C) 2024 Foulest (https://github.com/Foulest) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package net.foulest.kitpvp.kits.type; - -import net.foulest.kitpvp.kits.Kit; -import net.foulest.kitpvp.util.Settings; -import net.foulest.kitpvp.util.item.ItemBuilder; -import net.foulest.kitpvp.util.item.SkullBuilder; -import org.bukkit.Color; -import org.bukkit.Material; -import org.bukkit.inventory.ItemStack; -import org.bukkit.permissions.Permission; -import org.bukkit.permissions.PermissionDefault; -import org.bukkit.potion.PotionEffect; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Objects; - -/** - * Represents the Zen kit. - * - * @author Foulest - */ -public class Zen implements Kit { - - @Override - public String getName() { - return "Zen"; - } - - @Override - public ItemStack getDisplayItem() { - return new ItemStack(Objects.requireNonNull(Material.SLIME_BALL)); - } - - @Override - public PotionEffect[] getPotionEffects() { - return new PotionEffect[0]; - } - - @Override - public List getItems() { - ItemBuilder sword = new ItemBuilder(Material.STONE_SWORD).unbreakable(true).hideInfo(); - ItemBuilder special = new ItemBuilder(Material.SLIME_BALL).name("&aTeleporter &7(Right Click)") - .lore("&7Teleport to the nearest player."); - return Arrays.asList(sword, special); - } - - @Override - public ItemBuilder[] getArmor() { - String base64 = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMT" - + "g2ZDMxZTRkZDE2OWI0YzFjNjRkNDg1YjhlODRjN2IxY2NlYTdmNmZhYzg4ZTI1YTA4ZDJiN2ZmYmI4NDBhOCJ9fX0="; - - return new ItemBuilder[]{ - new ItemBuilder(SkullBuilder.itemFromBase64(base64)).name("&fZen's Head"), - new ItemBuilder(Material.LEATHER_CHESTPLATE).unbreakable(true).hideInfo().color(Color.fromRGB(0x3E7F2B)), - new ItemBuilder(Material.IRON_LEGGINGS).unbreakable(true).hideInfo(), - new ItemBuilder(Material.IRON_BOOTS).unbreakable(true).hideInfo() - }; - } - - @Override - public List getLore() { - return new ArrayList<>(Arrays.asList("&7Style: &aOffensive", "", "&7Teleports to the nearest player.")); - } - - @Override - public boolean enabled() { - return Settings.zenKitEnabled; - } - - @Override - public int getCost() { - return Settings.zenKitCost; - } - - @Override - public Permission permission() { - return new Permission("kitpvp.kit.zen", PermissionDefault.TRUE); - } -} diff --git a/src/main/java/net/foulest/kitpvp/listeners/DeathListener.java b/src/main/java/net/foulest/kitpvp/listeners/DeathListener.java index 7a8396a..a1fe6ad 100644 --- a/src/main/java/net/foulest/kitpvp/listeners/DeathListener.java +++ b/src/main/java/net/foulest/kitpvp/listeners/DeathListener.java @@ -17,35 +17,34 @@ */ package net.foulest.kitpvp.listeners; +import lombok.Data; import net.foulest.kitpvp.KitPvP; import net.foulest.kitpvp.combattag.CombatTag; import net.foulest.kitpvp.data.PlayerData; import net.foulest.kitpvp.data.PlayerDataManager; import net.foulest.kitpvp.kits.Kit; -import net.foulest.kitpvp.kits.type.Summoner; -import net.foulest.kitpvp.kits.type.Tamer; +//import net.foulest.kitpvp.kits.type.old.Summoner; +//import net.foulest.kitpvp.kits.type.old.Tamer; import net.foulest.kitpvp.region.Spawn; import net.foulest.kitpvp.util.MessageUtil; import net.foulest.kitpvp.util.NMSUtil; import net.foulest.kitpvp.util.Settings; import net.minecraft.server.v1_8_R3.PacketPlayInClientCommand; -import org.bukkit.Bukkit; -import org.bukkit.Effect; -import org.bukkit.Material; -import org.bukkit.Sound; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.IronGolem; -import org.bukkit.entity.Player; -import org.bukkit.entity.Wolf; +import org.bukkit.*; +import org.bukkit.entity.*; import org.bukkit.event.Listener; import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.util.Vector; +import org.jetbrains.annotations.NotNull; + +import java.util.UUID; /** * Handles all player deaths. * * @author Foulest */ +@Data public class DeathListener implements Listener { /** @@ -54,61 +53,59 @@ public class DeathListener implements Listener { * @param receiver The player that died. * @param onPlayerQuit Whether the player died from quitting. */ - static void handleDeath(Player receiver, boolean onPlayerQuit) { - PlayerData receiverData = PlayerDataManager.getPlayerData(receiver); - Kit currentKit = receiverData.getActiveKit(); - Vector vec = new Vector(); - + static void handleDeath(@NotNull Player receiver, boolean onPlayerQuit) { // Cancels deaths while in flying. if (receiver.getAllowFlight()) { return; } - // Removes potential player created Wolves. - if (currentKit != null) { - if (currentKit instanceof Tamer) { - Bukkit.getWorld(receiver.getWorld().getUID()).getEntities().stream() - .filter(entity -> entity.getType() == EntityType.WOLF) - .map(Wolf.class::cast) - .filter(wolf -> wolf.getOwner() == receiver) - .forEach(Wolf::remove); - } - - // Removes potential player created Iron Golems. - if (currentKit instanceof Summoner) { - Bukkit.getWorld(receiver.getWorld().getUID()).getEntities().stream() - .filter(entity -> entity.getType() == EntityType.IRON_GOLEM) - .map(IronGolem.class::cast) - .filter(golem -> golem.hasMetadata(receiver.getName())) - .forEach(IronGolem::remove); - } - } + // Receiver data + World world = receiver.getWorld(); + Location receiverLoc = receiver.getLocation(); + String receiverName = receiver.getName(); + PlayerData receiverData = PlayerDataManager.getPlayerData(receiver); + int receiverKillstreak = receiverData.getKillstreak(); + int receiverDeaths = receiverData.getDeaths(); + int receiverBounty = receiverData.getBounty(); + UUID receiverBenefactor = receiverData.getBenefactor(); + Kit currentKit = receiverData.getActiveKit(); // On-death blood splatter effect. - receiver.getWorld().playEffect(receiver.getLocation(), Effect.STEP_SOUND, Material.REDSTONE_BLOCK); - receiver.getWorld().playEffect(receiver.getLocation(), Effect.STEP_SOUND, Material.REDSTONE_BLOCK); - receiver.getWorld().playEffect(receiver.getLocation(), Effect.STEP_SOUND, Material.REDSTONE_BLOCK); + world.playEffect(receiverLoc, Effect.STEP_SOUND, Material.REDSTONE_BLOCK); + world.playEffect(receiverLoc, Effect.STEP_SOUND, Material.REDSTONE_BLOCK); + world.playEffect(receiverLoc, Effect.STEP_SOUND, Material.REDSTONE_BLOCK); // Sets the player's current kit and adds a death. if (currentKit != null) { receiverData.setPreviousKit(currentKit); } - receiverData.setDeaths(receiverData.getDeaths() + 1); + receiverData.setDeaths(receiverDeaths + 1); // Runs specific code if the player is killed by another player. if (CombatTag.getLastAttacker(receiver) != null && CombatTag.getLastAttacker(receiver) != receiver) { + + // Damager data Player damager = CombatTag.getLastAttacker(receiver); + String damagerName = damager.getName(); PlayerData damagerData = PlayerDataManager.getPlayerData(damager); + Location damagerLoc = damager.getLocation(); + double damagerHealth = damager.getHealth(); + int damagerKills = damagerData.getKills(); + int damagerKillstreak = damagerData.getKillstreak(); + int damagerCoins = damagerData.getCoins(); + + // Adds a Flask to the damager's inventory. + FlaskListener.addFlaskToInventory(damager, FlaskListener.MAX_FLASKS); // Adds a kill to the damager. - damagerData.setKills(damagerData.getKills() + 1); + damagerData.setKills(damagerKills + 1); damagerData.addKillstreak(); - damager.playSound(damager.getLocation(), Sound.CHICKEN_EGG_POP, 0.5f, 0.0f); + damager.playSound(damagerLoc, Sound.CHICKEN_EGG_POP, 0.5f, 0.0f); // Run specific code if the damager is on a multiple of 5 killstreak. - if (damagerData.getKillstreak() >= 5 && damagerData.getKillstreak() % 5 == 0) { + if (damagerKillstreak >= 5 && damagerKillstreak % 5 == 0) { // Sends all online players a killstreak message in chat. - MessageUtil.broadcast("&6" + damager.getName() + " &eis on a &6" + damagerData.getKillstreak() + " &ekillstreak!"); + MessageUtil.broadcast("&6" + damagerName + " &eis on a &6" + damagerKillstreak + " &ekillstreak!"); // Re-adds the damager's kit items. damager.getInventory().clear(); @@ -117,36 +114,37 @@ static void handleDeath(Player receiver, boolean onPlayerQuit) { } // Gives the damager coins and experience. - int rewardAmount = 5 * (damagerData.getKillstreak() / 5); + int rewardAmount = 5 * (damagerKillstreak / 5); int coinsGiven = Settings.coinsOnKill + rewardAmount; int experienceGiven = Settings.expOnKill + rewardAmount; damagerData.addCoins(coinsGiven); damagerData.addExperience(experienceGiven); // Removes the player's potential bounty. - if (receiverData.getBounty() > 0 && Bukkit.getPlayer(receiverData.getBenefactor()) != damager) { - if (Bukkit.getPlayer(receiverData.getBenefactor()) != null - && Bukkit.getPlayer(receiverData.getBenefactor()).isOnline()) { - Player benefactor = Bukkit.getPlayer(receiverData.getBenefactor()); - - benefactor.playSound(benefactor.getLocation(), Sound.DONKEY_IDLE, 1.0f, 1.0f); - MessageUtil.messagePlayer(benefactor, "&aYour $" + receiverData.getBounty() - + " bounty on " + receiver.getName() + " was claimed by " + damager.getName() + "."); + if (receiverBounty > 0 && Bukkit.getPlayer(receiverBenefactor) != damager) { + if (Bukkit.getPlayer(receiverBenefactor) != null + && Bukkit.getPlayer(receiverBenefactor).isOnline()) { + Player benefactor = Bukkit.getPlayer(receiverBenefactor); + Location benefactorLoc = benefactor.getLocation(); + + benefactor.playSound(benefactorLoc, Sound.DONKEY_IDLE, 1.0f, 1.0f); + MessageUtil.messagePlayer(benefactor, "&aYour $" + receiverBounty + + " bounty on " + receiverName + " was claimed by " + damagerName + "."); } - damager.playSound(damager.getLocation(), Sound.BLAZE_DEATH, 1.0f, 1.0f); - damager.playSound(damager.getLocation(), Sound.LEVEL_UP, 1.0f, 1.0f); - MessageUtil.messagePlayer(damager, "&eYou claimed the &a$" + receiverData.getBounty() - + " &ebounty on &a" + receiver.getName() + "&e's head."); - damagerData.setCoins(damagerData.getCoins() + receiverData.getBounty()); + damager.playSound(damagerLoc, Sound.BLAZE_DEATH, 1.0f, 1.0f); + damager.playSound(damagerLoc, Sound.LEVEL_UP, 1.0f, 1.0f); + MessageUtil.messagePlayer(damager, "&eYou claimed the &a$" + receiverBounty + + " &ebounty on &a" + receiverName + "&e's head."); + damagerData.setCoins(damagerCoins + receiverBounty); receiverData.removeBounty(); } // Prints kill messages to both the damager and receiver. - MessageUtil.messagePlayer(receiver.getPlayer(), "&eYou were killed by &c" + damager.getName() - + " &eon &6" + String.format("%.01f", damager.getHealth()) + "\u2764&e."); - MessageUtil.messagePlayer(damager, "&eYou killed &a" + receiver.getPlayer().getName() + MessageUtil.messagePlayer(receiver, "&eYou were killed by &c" + damagerName + + " &eon &6" + String.format("%.01f", damagerHealth) + "\u2764&e."); + MessageUtil.messagePlayer(damager, "&eYou killed &a" + receiverName + "&e for &a" + coinsGiven + " coins &eand &a" + experienceGiven + " exp&e."); } else { MessageUtil.messagePlayer(receiver, "&cYou killed yourself."); @@ -156,30 +154,27 @@ static void handleDeath(Player receiver, boolean onPlayerQuit) { receiverData.clearCooldowns(); // Sends all online players a killstreak message in chat. - if (receiverData.getKillstreak() >= 5) { - MessageUtil.broadcast("&a" + receiver.getPlayer().getName() + " &edied and lost their &a" - + receiverData.getKillstreak() + " &ekillstreak."); + if (receiverKillstreak >= 5) { + MessageUtil.broadcast("&a" + receiverName + " &edied and lost their &a" + + receiverKillstreak + " &ekillstreak."); } // Removes the player's combat tag. CombatTag.remove(receiver); - // Removes the player from a Vampire's drained effects list. - KitListener.drainedEffects.remove(receiver.getUniqueId()); - if (!onPlayerQuit) { // Sets the player's experience bar (fixes a rare bug). receiverData.calcLevel(false); // Plays a death sound at the player's death location. - receiver.playSound(receiver.getLocation(), Sound.FALL_BIG, 0.5f, 0.0f); + receiver.playSound(receiverLoc, Sound.FALL_BIG, 0.5f, 0.0f); // Removes knockback before teleporting the player to spawn. - receiver.setVelocity(vec); + receiver.setVelocity(new Vector()); new BukkitRunnable() { @Override public void run() { - receiver.setVelocity(vec); + receiver.setVelocity(new Vector()); } }.runTaskLater(KitPvP.instance, 1L); diff --git a/src/main/java/net/foulest/kitpvp/listeners/EventListener.java b/src/main/java/net/foulest/kitpvp/listeners/EventListener.java index 5baf17d..f645301 100644 --- a/src/main/java/net/foulest/kitpvp/listeners/EventListener.java +++ b/src/main/java/net/foulest/kitpvp/listeners/EventListener.java @@ -17,6 +17,7 @@ */ package net.foulest.kitpvp.listeners; +import lombok.Data; import net.foulest.kitpvp.cmds.StatsCmd; import net.foulest.kitpvp.combattag.CombatTag; import net.foulest.kitpvp.data.PlayerData; @@ -24,6 +25,7 @@ import net.foulest.kitpvp.enchants.Enchants; import net.foulest.kitpvp.kits.Kit; import net.foulest.kitpvp.kits.KitManager; +import net.foulest.kitpvp.kits.type.Knight; import net.foulest.kitpvp.menus.KitEnchanter; import net.foulest.kitpvp.menus.KitSelector; import net.foulest.kitpvp.menus.KitShop; @@ -36,7 +38,10 @@ import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; -import org.bukkit.entity.*; +import org.bukkit.entity.Arrow; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Item; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; @@ -50,6 +55,7 @@ import org.bukkit.event.weather.WeatherChangeEvent; import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.scheduler.BukkitTask; import org.jetbrains.annotations.NotNull; @@ -60,6 +66,7 @@ * * @author Foulest */ +@Data public class EventListener implements Listener { /** @@ -172,9 +179,10 @@ public static void onDropItem(@NotNull PlayerDropItemEvent event) { public static void onBowShoot(@NotNull EntityShootBowEvent event) { if (event.getEntity() instanceof Player) { Player player = (Player) event.getEntity(); + Location location = player.getLocation(); // Cancels the event if the player is in a safezone. - if (Regions.isInSafezone(player.getLocation())) { + if (Regions.isInSafezone(location)) { event.setCancelled(true); player.updateInventory(); } @@ -188,6 +196,8 @@ public static void onBowShoot(@NotNull EntityShootBowEvent event) { */ @EventHandler(ignoreCancelled = true) public static void onArrowShoot(@NotNull EntityDamageByEntityEvent event) { + double finalDamage = event.getFinalDamage(); + if (event.getDamager() instanceof Arrow) { Arrow arrow = (Arrow) event.getDamager(); @@ -195,6 +205,8 @@ public static void onArrowShoot(@NotNull EntityDamageByEntityEvent event) { if (arrow.getShooter() instanceof Player && event.getEntity() instanceof Player) { Player damager = (Player) arrow.getShooter(); Player receiver = (Player) event.getEntity(); + String receiverName = receiver.getName(); + double receiverHealth = receiver.getHealth(); // Cancels the event if the receiver is the damager. if (receiver.equals(damager)) { @@ -206,11 +218,14 @@ public static void onArrowShoot(@NotNull EntityDamageByEntityEvent event) { CombatTag.markForCombat(damager, receiver); // Prints the Archer arrow tag message. - MessageUtil.messagePlayer(damager, "&c" + receiver.getName() + " &eis on &6" - + String.format("%.01f", Math.max(receiver.getHealth() - event.getFinalDamage(), 0.0)) + "\u2764&e."); + MessageUtil.messagePlayer(damager, "&c" + receiverName + " &eis on &6" + + String.format("%.01f", Math.max(receiverHealth - finalDamage, 0.0)) + "\u2764&e."); // Removes arrows from the receiver's body. - TaskUtil.runTaskLater(() -> ((CraftEntity) receiver).getHandle().getDataWatcher().watch(9, (byte) 0), 100L); + TaskUtil.runTaskLater(() -> { + net.minecraft.server.v1_8_R3.Entity entity = ((CraftEntity) receiver).getHandle(); + entity.getDataWatcher().watch(9, (byte) 0); + }, 100L); } } } @@ -271,36 +286,10 @@ public static void onEntityDamageEntity(@NotNull EntityDamageByEntityEvent event if (damagerEntity instanceof Player) { Player damager = (Player) damagerEntity; - // Prevents players from hitting their own entities. - if ((targetEntity instanceof Wolf && ((Tameable) targetEntity).getOwner() == damager) - || (targetEntity instanceof IronGolem && targetEntity.hasMetadata(damager.getName()))) { - event.setCancelled(true); - return; - } - // Combat tags players for Player on Player damage. if (targetEntity instanceof Player) { CombatTag.markForCombat(damager, (Player) targetEntity); } - return; - } - - // Combat tags players for player-owned entity damage. - if (targetEntity instanceof Player && damagerEntity instanceof Tameable) { - Tameable tameable = (Tameable) damagerEntity; - AnimalTamer owner = tameable.getOwner(); - - if (tameable.isTamed() && owner instanceof Player) { - CombatTag.markForCombat((Player) owner, (Player) targetEntity); - } - } - - // Combat tags players for Iron Golem damage. - if (damagerEntity instanceof IronGolem && targetEntity instanceof Player) { - Bukkit.getOnlinePlayers().stream() - .filter(player -> damagerEntity.hasMetadata(player.getName())) - .findFirst() - .ifPresent(damager -> CombatTag.markForCombat(damager, (Player) targetEntity)); } } @@ -340,6 +329,7 @@ public static void onInventoryClick(@NotNull InventoryClickEvent event) { // Player-related variables Player player = (Player) event.getWhoClicked(); + String playerName = player.getName(); PlayerData playerData = PlayerDataManager.getPlayerData(player); Location playerLocation = player.getLocation(); @@ -351,6 +341,7 @@ public static void onInventoryClick(@NotNull InventoryClickEvent event) { // Cancels inventory clicks based on inventory type. switch (clickedInventoryType) { case PLAYER: + // Cancels players clicking their own inventory without a kit. if (playerData.getActiveKit() == null) { event.setCancelled(true); player.updateInventory(); @@ -372,7 +363,8 @@ public static void onInventoryClick(@NotNull InventoryClickEvent event) { case ENCHANTING: case ENDER_CHEST: // Ignores players in creative mode with the modify permission. - if (player.getGameMode() == GameMode.CREATIVE && player.hasPermission("kitpvp.modify")) { + if (player.getGameMode() == GameMode.CREATIVE + && player.hasPermission("kitpvp.modify")) { break; } @@ -380,7 +372,6 @@ public static void onInventoryClick(@NotNull InventoryClickEvent event) { player.updateInventory(); return; - case CHEST: default: break; } @@ -396,19 +387,27 @@ public static void onInventoryClick(@NotNull InventoryClickEvent event) { player.updateInventory(); return; - case CONTAINER: - case QUICKBAR: default: break; } + ItemMeta itemMeta = currentItem.getItemMeta(); + + // Ignores items without item metadata. + if (itemMeta == null) { + return; + } + + String displayName = itemMeta.getDisplayName(); + // Ignores items without display names. - if (currentItem.getItemMeta() == null - || currentItem.getItemMeta().getDisplayName() == null) { + if (displayName == null) { return; } - String itemName = ChatColor.stripColor(currentItem.getItemMeta().getDisplayName().trim()); + displayName = displayName.trim(); + + String itemName = ChatColor.stripColor(displayName); Kit kit = KitManager.getKit(itemName); int kitCost = (kit == null ? 0 : kit.getCost()); String kitName = (kit == null ? null : kit.getName()); @@ -446,8 +445,10 @@ public static void onInventoryClick(@NotNull InventoryClickEvent event) { return; } + int cost = enchant.getCost(); + // Checks if the player has enough coins. - if (playerData.getCoins() - enchant.getCost() < 0) { + if (playerData.getCoins() - cost < 0) { player.playSound(playerLocation, Sound.VILLAGER_NO, 1.0F, 1.0F); MessageUtil.messagePlayer(player, "&cYou do not have enough coins to purchase this enchant."); event.setCancelled(true); @@ -460,7 +461,7 @@ public static void onInventoryClick(@NotNull InventoryClickEvent event) { MessageUtil.messagePlayer(player, "&eThe &a" + enchantName + " &eenchantment has been purchased."); MessageUtil.messagePlayer(player, "&eThis enchantment only lasts one life."); MessageUtil.messagePlayer(player, ""); - playerData.removeCoins(enchant.getCost()); + playerData.removeCoins(cost); playerData.getEnchants().add(enchant); // Re-applies the player's active kit. @@ -495,7 +496,7 @@ public static void onInventoryClick(@NotNull InventoryClickEvent event) { default: // Ignores invalid kits from being selected. if (kit == null) { - MessageUtil.log(Level.INFO, "Invalid kit in Kit Selector for " + player.getName() + "."); + MessageUtil.log(Level.INFO, "Invalid kit in Kit Selector for " + playerName + "."); return; } @@ -511,7 +512,7 @@ public static void onInventoryClick(@NotNull InventoryClickEvent event) { // Ignores invalid kits from being selected. if (kit == null) { - MessageUtil.log(Level.INFO, "Invalid kit in Kit Shop for " + player.getName() + "."); + MessageUtil.log(Level.INFO, "Invalid kit in Kit Shop for " + playerName + "."); return; } @@ -592,6 +593,9 @@ public static void onRightClick(@NotNull PlayerInteractEvent event) { Block block = event.getClickedBlock(); Action action = event.getAction(); + double health = player.getHealth(); + double maxHealth = player.getMaxHealth(); + // ??? if (action.toString().contains("RIGHT") && block != null && block.getState() instanceof InventoryHolder) { @@ -600,18 +604,12 @@ public static void onRightClick(@NotNull PlayerInteractEvent event) { } if (action.toString().contains("RIGHT") && item != null) { - switch (item.getType()) { - case WEB: - case BLAZE_ROD: - case IRON_BLOCK: - case SLIME_BALL: - case DISPENSER: - // Ignores right-clicking certain items. - break; + Location playerLoc = player.getLocation(); + switch (item.getType()) { case FISHING_ROD: // Cancels using the fishing rod in spawn. - if (Regions.isInSafezone(player.getLocation())) { + if (Regions.isInSafezone(playerLoc)) { event.setCancelled(true); } break; @@ -630,7 +628,7 @@ public static void onRightClick(@NotNull PlayerInteractEvent event) { } // Cancels using potions in spawn. - if (Regions.isInSafezone(player.getLocation())) { + if (Regions.isInSafezone(playerLoc)) { event.setCancelled(true); player.updateInventory(); } @@ -650,27 +648,39 @@ public static void onRightClick(@NotNull PlayerInteractEvent event) { } // Cancels using soup in spawn. - if (Regions.isInSafezone(player.getLocation())) { + if (Regions.isInSafezone(playerLoc)) { event.setCancelled(true); break; } // Heals the player when using soup. - if (player.getHealth() < player.getMaxHealth()) { + if (health < maxHealth) { event.setCancelled(true); - player.setHealth(Math.min(player.getHealth() + 7, player.getMaxHealth())); - player.setItemInHand(new ItemBuilder(Material.BOWL).name("&fBowl").getItem()); + player.setHealth(Math.min(health + 7, maxHealth)); + + ItemBuilder bowl = new ItemBuilder(Material.BOWL).name("&fBowl"); + ItemStack bowlItem = bowl.getItem(); + player.setItemInHand(bowlItem); } break; case WATCH: + Kit previousKit = playerData.getPreviousKit(); + + if (previousKit == null) { + previousKit = new Knight(); + } + + String previousKitName = previousKit.getName(); + // Handles using the Previous Kit item. - if (item.hasItemMeta() && item.getItemMeta().getDisplayName().contains("Previous Kit") - && playerData.getPreviousKit() != null && playerData.getActiveKit() == null) { + if (item.hasItemMeta() + && item.getItemMeta().getDisplayName().contains("Previous Kit") + && playerData.getActiveKit() == null) { event.setCancelled(true); - playerData.getPreviousKit().apply(player); - MessageUtil.messagePlayer(player, "&aYou equipped the " + playerData.getPreviousKit().getName() + " kit."); - player.playSound(player.getLocation(), Sound.SLIME_WALK, 1, 1); + previousKit.apply(player); + MessageUtil.messagePlayer(player, "&aYou equipped the " + previousKitName + " kit."); + player.playSound(playerLoc, Sound.SLIME_WALK, 1, 1); player.updateInventory(); player.closeInventory(); } @@ -732,9 +742,21 @@ public static void onRightClick(@NotNull PlayerInteractEvent event) { @EventHandler public static void onPlayerMove(@NotNull PlayerMoveEvent event) { Player player = event.getPlayer(); + Location location = player.getLocation(); PlayerData playerData = PlayerDataManager.getPlayerData(player); - double deltaY = event.getTo().getY() - event.getFrom().getY(); - double deltaXZ = StrictMath.hypot(event.getTo().getX() - event.getFrom().getX(), event.getTo().getZ() - event.getFrom().getZ()); + + Location to = event.getTo(); + Location from = event.getFrom(); + + double toX = to.getX(); + double toZ = to.getZ(); + + double fromX = from.getX(); + double fromZ = from.getZ(); + + double deltaY = to.getY() - from.getY(); + double deltaXZ = StrictMath.hypot(toX - fromX, toZ - fromZ); + boolean playerMoved = (deltaXZ > 0.05 || Math.abs(deltaY) > 0.05); // Ignores rotation updates. @@ -750,14 +772,14 @@ public static void onPlayerMove(@NotNull PlayerMoveEvent event) { } // Kills the player if they leave the map/fall into the void. - if (player.getLocation().getY() < 0 && !player.getAllowFlight()) { + if (location.getY() < 0 && !player.getAllowFlight()) { DeathListener.handleDeath(player, false); return; } // Equips the player's previously used kit when they leave spawn without a kit equipped. if (playerData.getActiveKit() == null && !player.isDead() && !player.getAllowFlight() - && !Regions.isInSafezone(event.getFrom())) { + && !Regions.isInSafezone(from)) { player.closeInventory(); playerData.getPreviousKit().apply(player); MessageUtil.messagePlayer(player, "&cYour previous kit has been automatically applied."); @@ -766,9 +788,9 @@ public static void onPlayerMove(@NotNull PlayerMoveEvent event) { // Denies entry into spawn while combat tagged. // Also heals the player whilst in a safe zone. - if (Regions.isInSafezone(event.getTo())) { + if (Regions.isInSafezone(to)) { if (Settings.combatTagDenyEnteringSpawn && CombatTag.isInCombat(player)) { - player.teleport(event.getFrom()); + player.teleport(from); MessageUtil.messagePlayer(player, "&cYou can't enter spawn while combat tagged."); } else { player.setHealth(20); @@ -782,13 +804,13 @@ public static void onPlayerMove(@NotNull PlayerMoveEvent event) { // Removes the player's no-fall status. if (playerData.isNoFall() && !playerData.isPendingNoFallRemoval() - && !Regions.isInSafezone(player.getLocation())) { + && !Regions.isInSafezone(location)) { playerData.setPendingNoFallRemoval(true); TaskUtil.runTaskLater(() -> { playerData.setPendingNoFallRemoval(false); - if (playerData.isNoFall() && !Regions.isInSafezone(player.getLocation())) { + if (playerData.isNoFall() && !Regions.isInSafezone(location)) { playerData.setNoFall(false); } }, 30L); @@ -1004,6 +1026,10 @@ public static void onBlockPhysics(@NotNull BlockPhysicsEvent event) { switch (event.getChangedType()) { case SAND: case GRAVEL: + case LAVA: + case STATIONARY_LAVA: + case WATER: + case STATIONARY_WATER: event.setCancelled(true); break; @@ -1011,4 +1037,15 @@ public static void onBlockPhysics(@NotNull BlockPhysicsEvent event) { break; } } + + /** + * Handles block spreading. + * + * @param event BlockSpreadEvent + */ + @EventHandler + public static void onBlockSpread(@NotNull BlockSpreadEvent event) { + // Cancels the event. + event.setCancelled(true); + } } diff --git a/src/main/java/net/foulest/kitpvp/listeners/FlaskListener.java b/src/main/java/net/foulest/kitpvp/listeners/FlaskListener.java new file mode 100644 index 0000000..25edf9b --- /dev/null +++ b/src/main/java/net/foulest/kitpvp/listeners/FlaskListener.java @@ -0,0 +1,237 @@ +package net.foulest.kitpvp.listeners; + +import lombok.Data; +import net.foulest.kitpvp.KitPvP; +import net.foulest.kitpvp.data.PlayerData; +import net.foulest.kitpvp.data.PlayerDataManager; +import net.foulest.kitpvp.region.Regions; +import net.foulest.kitpvp.util.MessageUtil; +import net.foulest.kitpvp.util.item.ItemBuilder; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.inventory.InventoryHolder; +import org.bukkit.inventory.ItemStack; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.scheduler.BukkitTask; +import org.jetbrains.annotations.NotNull; + +@Data +public class FlaskListener implements Listener { + + public static int MAX_FLASKS = 5; + + private static ItemStack FLASK = new ItemBuilder(Material.POTION).hideInfo().durability(8229) + .name("&aFlask &7(Right Click)").getItem(); + + private static ItemStack EMPTY_FLASK = new ItemBuilder(Material.GLASS_BOTTLE) + .name("&cFlask &7(On Cooldown)").getItem(); + + /** + * Sets a cooldown for a specific kit. + * + * @param cooldownTime The time in seconds for the cooldown. + */ + private static void setFlaskCooldown(@NotNull PlayerData playerData, int cooldownTime) { + Player player = playerData.getPlayer(); + + BukkitTask cooldownTask = new BukkitRunnable() { + @Override + public void run() { + MessageUtil.messagePlayer(player, "&aYour Flask cooldown has expired."); + + // Set the player's flask back to a potion. + for (ItemStack item : player.getInventory().getContents()) { + if (item == null + || item.getItemMeta() == null + || item.getItemMeta().getDisplayName() == null) { + continue; + } + + int itemAmount = item.getAmount(); + + if (item.getItemMeta().getDisplayName().contains("Flask")) { + FLASK.setAmount(itemAmount); + player.getInventory().remove(item); + player.getInventory().addItem(FLASK); + player.updateInventory(); + return; + } + } + } + }.runTaskLater(KitPvP.instance, cooldownTime * 20L); + + // Set the Flask cooldown and regeneration tasks. + playerData.setFlaskCooldownTask(cooldownTask); + } + + static void addFlaskToInventory(@NotNull Player player, int amount) { + boolean hasFlasks = false; + + // Check if the player already has a flask. + for (ItemStack item : player.getInventory().getContents()) { + if (item == null + || item.getItemMeta() == null + || item.getItemMeta().getDisplayName() == null) { + continue; + } + + if (item.getItemMeta().getDisplayName().contains("Flask")) { + hasFlasks = true; + + // Update the Flask amount. + int itemAmount = item.getAmount(); + + if (itemAmount < MAX_FLASKS) { + MessageUtil.messagePlayer(player, "&aYou received a Flask."); + item.setAmount(Math.min(itemAmount + amount, MAX_FLASKS)); + player.updateInventory(); + return; + } + } + } + + if (!hasFlasks) { + // Add the Flask to the player's inventory. + FLASK.setAmount(Math.min(amount, MAX_FLASKS)); + player.getInventory().addItem(FLASK); + player.updateInventory(); + } + } + + /** + * Handles right-clicking blocks and items. + * + * @param event PlayerInteractEvent + */ + @EventHandler(priority = EventPriority.HIGHEST) + public static void onRightClick(@NotNull PlayerInteractEvent event) { + Player player = event.getPlayer(); + PlayerData playerData = PlayerDataManager.getPlayerData(player); + ItemStack item = event.getItem(); + Block block = event.getClickedBlock(); + Action action = event.getAction(); + + double health = player.getHealth(); + double maxHealth = player.getMaxHealth(); + + // ??? + if (action.toString().contains("RIGHT") && block != null + && block.getState() instanceof InventoryHolder) { + event.setCancelled(true); + return; + } + + if (action.toString().contains("RIGHT") && item != null) { + Location playerLoc = player.getLocation(); + + switch (item.getType()) { + case POTION: + // Cancels using potions in spawn. + if (Regions.isInSafezone(playerLoc)) { + if (item.hasItemMeta() && item.getItemMeta().getDisplayName().contains("Flask")) { + MessageUtil.messagePlayer(player, "&cYou cannot use Flasks in spawn."); + } + + event.setCancelled(true); + player.updateInventory(); + return; + } + + // Check if the item contains the name "Flask". + if (item.hasItemMeta() && !item.getItemMeta().getDisplayName().contains("Flask")) { + break; + } + + int itemAmount = item.getAmount(); + + // We can assume the player right-clicked the Flask. + // The Flask is ready to be used, as it's not a GLASS_BOTTLE. + + if (health < maxHealth) { + int flaskDuration = 3; + + // Removes the Flask from the player's inventory if there is only one. + // Otherwise, sets the Flask to a GLASS_BOTTLE with the amount of the Flask. + if (itemAmount == 1) { + player.getInventory().remove(item); + } else { + EMPTY_FLASK.setAmount(itemAmount - 1); + player.setItemInHand(EMPTY_FLASK); + } + + event.setCancelled(true); + player.updateInventory(); + + // Set the Flask cooldown. + setFlaskCooldown(playerData, flaskDuration); + + // Send the player a message and play a sound. + MessageUtil.messagePlayer(player, "&aYou used a Flask."); + player.playSound(playerLoc, Sound.DRINK, 1, 1); + + // Heal the player for 5 hearts (10 health) over 3 seconds. + PotionEffect regeneration = new PotionEffect(PotionEffectType.REGENERATION, flaskDuration * 20, 3); + player.addPotionEffect(regeneration); + } else { + MessageUtil.messagePlayer(player, "&cYou are already at full health."); + event.setCancelled(true); + player.updateInventory(); + } + break; + + case GLASS_BOTTLE: + // Handles using the Flask item. + if (item.hasItemMeta() && item.getItemMeta().getDisplayName().contains("Flask")) { + event.setCancelled(true); + player.updateInventory(); + + // Cancels using the Flask if it's on cooldown. + if (playerData.getFlaskCooldownTask() != null) { + MessageUtil.messagePlayer(player, "&cThe Flask is still on cooldown."); + break; + } + } + break; + + default: + break; + } + } + } + + /** + * Handles players clicking inside of inventories. + * + * @param event InventoryClickEvent + */ + @EventHandler + public static void onInventoryClick(@NotNull InventoryClickEvent event) { + // Nullability checks. + if (event.getWhoClicked() == null + || event.getClickedInventory() == null) { + return; + } + + Player player = (Player) event.getWhoClicked(); + ItemStack currentItem = event.getCurrentItem(); + + // Cancels players clicking flasks. + if (currentItem != null + && currentItem.hasItemMeta() + && currentItem.getItemMeta().getDisplayName().contains("Flask")) { + event.setCancelled(true); + player.updateInventory(); + } + } +} diff --git a/src/main/java/net/foulest/kitpvp/listeners/KitListener.java b/src/main/java/net/foulest/kitpvp/listeners/KitListener.java index 7df5bb0..a14c2b0 100644 --- a/src/main/java/net/foulest/kitpvp/listeners/KitListener.java +++ b/src/main/java/net/foulest/kitpvp/listeners/KitListener.java @@ -1,513 +1,201 @@ -/* - * KitPvP - a fully-featured core plugin for the KitPvP gamemode. - * Copyright (C) 2024 Foulest (https://github.com/Foulest) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ package net.foulest.kitpvp.listeners; +import lombok.Data; import net.foulest.kitpvp.KitPvP; import net.foulest.kitpvp.combattag.CombatTag; import net.foulest.kitpvp.data.PlayerData; import net.foulest.kitpvp.data.PlayerDataManager; +import net.foulest.kitpvp.kits.Kit; import net.foulest.kitpvp.kits.type.*; import net.foulest.kitpvp.region.Regions; import net.foulest.kitpvp.util.*; -import org.bukkit.Effect; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.Sound; -import org.bukkit.block.Block; -import org.bukkit.block.BlockState; -import org.bukkit.block.Sign; -import org.bukkit.entity.*; +import org.bukkit.*; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.player.PlayerFishEvent; -import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.event.player.PlayerMoveEvent; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.PlayerInventory; -import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.scheduler.BukkitTask; import org.bukkit.util.Vector; import org.jetbrains.annotations.NotNull; import java.security.SecureRandom; import java.util.*; -import java.util.stream.Collectors; -import java.util.stream.IntStream; - -/** - * Handles all kit-related events in the plugin. - * - * @author Foulest - */ + +@Data public class KitListener implements Listener { - static final Map> drainedEffects = new HashMap<>(); - private static final Map imprisonedPlayers = new HashMap<>(); private static final Random RANDOM = new SecureRandom(); /** - * Handles the Burrower ability, which creates a room of bricks above the player. + * Handles the Archer ability. * * @param event The event. */ @EventHandler - public static void onBurrowerAbility(@NotNull PlayerInteractEvent event) { + public static void onArcherAbility(@NotNull PlayerInteractEvent event) { + // Player data Player player = event.getPlayer(); PlayerData playerData = PlayerDataManager.getPlayerData(player); - List roomLocations = getRoomLocations(player.getLocation()); - - if (playerData.getActiveKit() instanceof Burrower - && event.getAction().toString().contains("RIGHT") - && player.getItemInHand().getType() == Material.BRICK) { - - // Ignores the event if the player is in spawn. - if (Regions.isInSafezone(player.getLocation())) { - MessageUtil.messagePlayer(player, ConstantUtil.ABILITY_IN_SPAWN); - return; - } - - // Ignores the event if the player's ability is on cooldown. - if (playerData.hasCooldown(true)) { - return; - } - - // Checks if there's enough space above the player to burrow. - for (Location loc : roomLocations) { - if (loc.getBlock().getType() != Material.AIR) { - MessageUtil.messagePlayer(player, "&cThere's not enough space above you to burrow."); - playerData.setCooldown(new Burrower(), 5, true); - return; - } - } - - // Adds the room of bricks above the player. - Collection pendingRollback = new ArrayList<>(); - for (Location location : roomLocations) { - pendingRollback.add(location.getBlock().getState()); - location.getBlock().setType(Material.BRICK); - } - roomLocations.get(0).getBlock().setType(Material.GLOWSTONE); - - // Teleports the player into the room. - player.teleport(player.getLocation().add(0.0, 10.0, 0.0)); - - // Rolls back the room after the set ability duration. - TaskUtil.runTaskLater(() -> { - for (BlockState block : pendingRollback) { - rollback(block); - } - }, Settings.burrowerKitDuration * 20L); - - // Gives the player the no-fall status. - playerData.setNoFall(true); - playerData.setPendingNoFallRemoval(true); - - MessageUtil.messagePlayer(player, "&aYour ability has been used."); - playerData.setCooldown(playerData.getActiveKit(), Settings.burrowerKitCooldown, true); + Location playerLoc = player.getLocation(); + Kit playerKit = playerData.getActiveKit(); + + // Ignores the event if the player isn't using the Archer ability. + if (!(playerKit instanceof Archer) + || !event.getAction().toString().contains("RIGHT") + || player.getItemInHand().getType() != Material.FEATHER) { + return; } - } - /** - * Handles the Cactus ability, which poisons the target on hit. - * - * @param event The event. - */ - @EventHandler(ignoreCancelled = true) - public static void onCactusHit(@NotNull EntityDamageByEntityEvent event) { - if (event.getDamager() instanceof Player && event.getEntity() instanceof Player) { - Player damager = (Player) event.getDamager(); - Player receiver = (Player) event.getEntity(); - PlayerData damagerData = PlayerDataManager.getPlayerData(damager); - PlayerData receiverData = PlayerDataManager.getPlayerData(receiver); - - // Inflicts the poison effect on the target. - if (damagerData.getActiveKit() instanceof Cactus - && receiverData.getActiveKit() != null - && damager.getItemInHand().getType() == Material.CACTUS - && !Regions.isInSafezone(damager.getLocation()) - && !Regions.isInSafezone(receiver.getLocation())) { - - receiver.addPotionEffect(new PotionEffect(PotionEffectType.POISON, - Settings.cactusKitPassiveDuration * 20, 0, false, false)); - } + // Ignores the event if the player is in spawn. + if (Regions.isInSafezone(playerLoc)) { + MessageUtil.messagePlayer(player, ConstantUtil.ABILITY_IN_SPAWN); + return; } - } - - /** - * Handles the Dragon ability, which shoots a wave of fire that damages nearby players. - * - * @param event The event. - */ - @EventHandler - public static void onDragonAbility(@NotNull PlayerInteractEvent event) { - Player player = event.getPlayer(); - PlayerData playerData = PlayerDataManager.getPlayerData(player); - - if (playerData.getActiveKit() instanceof Dragon - && event.getAction().toString().contains("RIGHT") - && player.getItemInHand().getType() == Material.FIREBALL) { - - // Ignores the event if the player is in spawn. - if (Regions.isInSafezone(player.getLocation())) { - MessageUtil.messagePlayer(player, ConstantUtil.ABILITY_IN_SPAWN); - return; - } - - // Ignores the event if the player's ability is on cooldown. - if (playerData.hasCooldown(true)) { - return; - } - - Collection nearbyPlayers = new ArrayList<>(); - // Adds nearby players to a list. - for (Entity entity : player.getNearbyEntities(Settings.dragonKitRange, Settings.dragonKitRange, Settings.dragonKitRange)) { - if (entity instanceof Player) { - Player nearbyPlayer = (Player) entity; - PlayerData nearbyPlayerData = PlayerDataManager.getPlayerData(nearbyPlayer); - - if (nearbyPlayerData.getActiveKit() != null - && !Regions.isInSafezone(nearbyPlayer.getLocation())) { - nearbyPlayers.add(nearbyPlayer); - } - } - } + // Ignores the event if the player's ability is on cooldown. + if (playerData.hasCooldown(true)) { + return; + } - // Ignores the event if no players are nearby. - if (nearbyPlayers.isEmpty()) { - player.playSound(player.getLocation(), Sound.VILLAGER_NO, 1.0F, 1.0F); - MessageUtil.messagePlayer(player, "&cAbility failed; no players found nearby."); - playerData.setCooldown(playerData.getActiveKit(), 5, true); - return; - } + // Plays the ability sound. + player.getWorld().playSound(playerLoc, Sound.BAT_TAKEOFF, 1, 1); - // Plays flame effects and fireball sounds. - player.getWorld().playEffect(player.getLocation(), Effect.MOBSPAWNER_FLAMES, 1); - player.getWorld().playEffect(player.getEyeLocation(), Effect.MOBSPAWNER_FLAMES, 1); - player.playSound(player.getEyeLocation(), Sound.GHAST_FIREBALL, 1.0F, 0.0F); + // Remove the player's existing speed, resistance, and weakness effects. + player.removePotionEffect(PotionEffectType.SPEED); + player.removePotionEffect(PotionEffectType.DAMAGE_RESISTANCE); + player.removePotionEffect(PotionEffectType.WEAKNESS); - // Damages and strikes nearby players with lightning. - for (Player nearbyPlayer : nearbyPlayers) { - PlayerData nearbyPlayerData = PlayerDataManager.getPlayerData(nearbyPlayer); + // Gives the player speed, resistance, weakness, and regeneration. + player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, Settings.archerKitDuration * 20, 2, false, false)); + player.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, Settings.archerKitDuration * 20, 0, false, false)); + player.addPotionEffect(new PotionEffect(PotionEffectType.WEAKNESS, Settings.archerKitDuration * 20, 1, false, false)); + player.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, Settings.archerKitDuration * 20, 1, false, false)); - if (player.hasLineOfSight(nearbyPlayer) - && nearbyPlayerData.getActiveKit() != null - && !Regions.isInSafezone(nearbyPlayer.getLocation())) { - nearbyPlayer.damage(Settings.dragonKitDamage, player); - nearbyPlayer.setFireTicks(Settings.dragonKitDuration * 20); - } + // Create a task that restores the Archer's speed. + TaskUtil.runTaskLater(() -> { + if (playerData.getActiveKit() instanceof Archer) { + player.removePotionEffect(PotionEffectType.SPEED); + player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, 0, false, false)); } + }, Settings.archerKitDuration * 20L); - MessageUtil.messagePlayer(player, "&aYour ability has been used."); - playerData.setCooldown(playerData.getActiveKit(), Settings.dragonKitCooldown, true); - } + // Sets the player's ability cooldown. + MessageUtil.messagePlayer(player, "&aYour ability has been used."); + playerData.setCooldown(playerKit, Settings.archerKitCooldown, true); } /** - * Handles the Fisherman ability, which pulls the target towards the player. + * Handles the Fisherman ability. * * @param event The event. */ @EventHandler public static void onFishermanAbility(@NotNull PlayerFishEvent event) { - Player player = event.getPlayer(); - PlayerData playerData = PlayerDataManager.getPlayerData(player); - - if (event.getCaught() instanceof Player) { - Player receiver = (Player) event.getCaught(); - PlayerData receiverData = PlayerDataManager.getPlayerData(receiver); - - // Marks both players for combat. - CombatTag.markForCombat(player, receiver); - - if (playerData.getActiveKit() instanceof Fisherman - && event.getState() == PlayerFishEvent.State.CAUGHT_ENTITY) { - - // Ignores the event if the player is in spawn. - if (Regions.isInSafezone(player.getLocation())) { - MessageUtil.messagePlayer(player, ConstantUtil.ABILITY_IN_SPAWN); - return; - } - - // Ignores the event if the player's ability is on cooldown. - if (playerData.hasCooldown(true)) { - return; - } - - if (receiverData.getActiveKit() != null && !Regions.isInSafezone(receiver.getLocation())) { - // Teleports the target to the player's location. - imprisonedPlayers.remove(receiver.getUniqueId()); - event.getCaught().teleport(player.getLocation()); - - MessageUtil.messagePlayer(player, "&aYour ability has been used."); - playerData.setCooldown(playerData.getActiveKit(), Settings.fishermanKitCooldown, true); - } else { - event.setCancelled(true); - } - } + // Ignores the event if the target is not a player. + if (!(event.getCaught() instanceof Player)) { + return; } - } - /** - * Handles the Ghost ability, which plays a sound when the player moves. - * - * @param event The event. - */ - @EventHandler - public static void onGhostMove(@NotNull PlayerMoveEvent event) { + // Player data Player player = event.getPlayer(); PlayerData playerData = PlayerDataManager.getPlayerData(player); + Location playerLoc = player.getLocation(); + Kit playerKit = playerData.getActiveKit(); - if (playerData.getActiveKit() instanceof Ghost && !player.isSneaking() - && !Regions.isInSafezone(player.getLocation())) { - - // Plays a sound when the player moves. - for (Entity entity : player.getNearbyEntities(Settings.ghostKitRange, Settings.ghostKitRange, Settings.ghostKitRange)) { - if (entity instanceof Player) { - ((Player) entity).playSound(player.getLocation(), Sound.CHICKEN_WALK, 0.01F, 0.5F); - } - } - } - } - - /** - * Handles the Hulk ability, which launches other players into the air. - * - * @param event The event. - */ - @EventHandler - public static void onHulkAbility(@NotNull PlayerInteractEvent event) { - Player player = event.getPlayer(); - PlayerData playerData = PlayerDataManager.getPlayerData(player); + // Target data + Player target = (Player) event.getCaught(); + PlayerData targetData = PlayerDataManager.getPlayerData(target); + Location targetLoc = target.getLocation(); - if (playerData.getActiveKit() instanceof Hulk - && event.getAction().toString().contains("RIGHT") - && player.getItemInHand().getType() == Material.PISTON_STICKY_BASE) { + // Marks both players for combat. + CombatTag.markForCombat(player, target); - // Ignores the event if the player is in spawn. - if (Regions.isInSafezone(player.getLocation())) { - MessageUtil.messagePlayer(player, ConstantUtil.ABILITY_IN_SPAWN); - return; - } - - // Ignores the event if the player's ability is on cooldown. - if (playerData.hasCooldown(true)) { - return; - } - - Collection nearbyPlayers = new ArrayList<>(); - - // Adds nearby players to a list. - for (Entity entity : player.getNearbyEntities(Settings.hulkKitRange, Settings.hulkKitRange, Settings.hulkKitRange)) { - if (entity instanceof Player) { - Player nearbyPlayer = (Player) entity; - PlayerData nearbyPlayerData = PlayerDataManager.getPlayerData(nearbyPlayer); - - if (nearbyPlayerData.getActiveKit() != null - && !Regions.isInSafezone(nearbyPlayer.getLocation())) { - nearbyPlayers.add(nearbyPlayer); - } - } - } - - // Ignores the event if no players are nearby. - if (nearbyPlayers.isEmpty()) { - player.playSound(player.getLocation(), Sound.VILLAGER_NO, 1.0F, 1.0F); - MessageUtil.messagePlayer(player, "&cAbility failed; no players found nearby."); - playerData.setCooldown(playerData.getActiveKit(), 5, true); - return; - } - - // Creates an explosion at the player's location. - player.getWorld().createExplosion(player.getLocation(), 0.0F, false); - - // Damages and launches nearby players into the air. - for (Player nearbyPlayer : nearbyPlayers) { - PlayerData nearbyPlayerData = PlayerDataManager.getPlayerData(nearbyPlayer); - - if (nearbyPlayerData.getActiveKit() != null - && !Regions.isInSafezone(nearbyPlayer.getLocation())) { - // Gets the direction to launch the player in. - Vector direction = nearbyPlayer.getEyeLocation().getDirection(); - direction.multiply(Settings.hulkKitMultiplier); - direction.setY(1.0); - - // Damages and launches the player into the air. - nearbyPlayer.setVelocity(direction); - nearbyPlayer.damage(Settings.hulkKitDamage, player); - } - } - - MessageUtil.messagePlayer(player, "&aYour ability has been used."); - playerData.setCooldown(playerData.getActiveKit(), Settings.hulkKitCooldown, true); + // Ignores the event if the player isn't using the Fisherman ability. + if (!(playerKit instanceof Fisherman) + || event.getState() != PlayerFishEvent.State.CAUGHT_ENTITY) { + return; } - } - /** - * Handles the Imprisoner ability, which shoots a projectile that imprisons the target in a cage. - * - * @param event The event. - */ - @EventHandler - public static void onImprisonerAbility(@NotNull PlayerInteractEvent event) { - Player player = event.getPlayer(); - PlayerData playerData = PlayerDataManager.getPlayerData(player); - - if (playerData.getActiveKit() instanceof Imprisoner - && event.getAction().toString().contains("RIGHT") - && player.getItemInHand().getType() == Material.DISPENSER) { - - // Ignores the event if the player is in spawn. - if (Regions.isInSafezone(player.getLocation())) { - MessageUtil.messagePlayer(player, ConstantUtil.ABILITY_IN_SPAWN); - return; - } - - // Ignores the event if the player's ability is on cooldown. - if (playerData.hasCooldown(true)) { - return; - } - - // Shoots a snowball that imprisons the target in a cage. - player.launchProjectile(Snowball.class).setMetadata("imprisoner", - new FixedMetadataValue(KitPvP.instance, true)); + // Ignores the event if the player is in spawn. + if (Regions.isInSafezone(playerLoc)) { + MessageUtil.messagePlayer(player, ConstantUtil.ABILITY_IN_SPAWN); + return; + } - MessageUtil.messagePlayer(player, "&aYour ability has been used."); - playerData.setCooldown(playerData.getActiveKit(), Settings.imprisonerKitCooldown, true); + // Ignores the event if the player's ability is on cooldown. + if (playerData.hasCooldown(true)) { + return; } - } - /** - * Handles the Imprisoner ability, which imprisons the target in a cage when hit. - * - * @param event The event. - */ - @EventHandler(ignoreCancelled = true) - public static void onImprisonerHit(@NotNull EntityDamageByEntityEvent event) { - if (event.getDamager() instanceof Snowball) { - Snowball snowball = (Snowball) event.getDamager(); - - if (snowball.getShooter() instanceof Player) { - Player damager = (Player) snowball.getShooter(); - PlayerData damagerData = PlayerDataManager.getPlayerData(damager); - - if (event.getEntity() instanceof Player) { - Player receiver = (Player) event.getEntity(); - PlayerData receiverData = PlayerDataManager.getPlayerData(damager); - - if (damagerData.getActiveKit() instanceof Imprisoner - && receiverData.getActiveKit() != null - && snowball.hasMetadata("imprisoner") - && !imprisonedPlayers.containsKey(receiver.getUniqueId()) - && !Regions.isInSafezone(receiver.getLocation())) { - - // Checks if there's enough space above the target to imprison them. - List cageBlocks = getCageBlocks(receiver.getLocation().add(0.0, Settings.imprisonerKitHeight, 0.0)); - for (Block cageBlock : cageBlocks) { - if (cageBlock.getType() != Material.AIR) { - MessageUtil.messagePlayer(damager, "&cThere's not enough space above the target."); - damagerData.setCooldown(damagerData.getActiveKit(), 5, true); - return; - } - } - - // Adds the cage blocks to a list for rollback. - Collection pendingRollback = new ArrayList<>(); - for (Block block : cageBlocks) { - pendingRollback.add(block.getState()); - } - - // Adds the cage blocks to the world. - cageBlocks.get(0).setType(Material.MOSSY_COBBLESTONE); - for (int i = 1; i < 9; ++i) { - cageBlocks.get(i).setType(Material.IRON_FENCE); - } - cageBlocks.get(9).setType(Material.MOSSY_COBBLESTONE); - cageBlocks.get(10).setType(Material.LAVA); - - // Damages the target. - receiver.damage(Settings.imprisonerKitDamage, damager); - - // Teleports the target into the cage. - Location prisonLoc = receiver.getLocation().add(0.0, Settings.imprisonerKitHeight, 0.0); - prisonLoc.setX(prisonLoc.getBlockX() + 0.5); - prisonLoc.setY(Math.floor(prisonLoc.getY())); - prisonLoc.setZ(prisonLoc.getBlockZ() + 0.5); - receiver.teleport(prisonLoc); - - // Adds the target to the imprisoned players list. - imprisonedPlayers.put(receiver.getUniqueId(), prisonLoc); - - // Rolls back the cage after the set ability duration. - TaskUtil.runTaskLater(() -> { - imprisonedPlayers.remove(receiver.getUniqueId()); - - for (BlockState block : pendingRollback) { - rollback(block); - } - }, Settings.imprisonerKitDuration * 20L); - } - } - } + // Ignores ineligible players. + if (targetData.getActiveKit() == null + || Regions.isInSafezone(targetLoc)) { + event.setCancelled(true); + return; } + + // Teleports the target to the player's location. + MessageUtil.messagePlayer(target, "&cYou have been hooked by a Fisherman!"); + event.getCaught().teleport(playerLoc); + + // Sets the player's ability cooldown. + MessageUtil.messagePlayer(player, "&aYour ability has been used."); + playerData.setCooldown(playerKit, Settings.fishermanKitCooldown, true); } /** - * Handles the Kangaroo ability, which launches the player into the air. + * Handles the Kangaroo ability. * * @param event The event. */ @EventHandler public static void onKangarooAbility(@NotNull PlayerInteractEvent event) { + // Player data Player player = event.getPlayer(); PlayerData playerData = PlayerDataManager.getPlayerData(player); + Location playerLoc = player.getLocation(); + Kit playerKit = playerData.getActiveKit(); + + // Ignores the event if the player isn't using the Kangaroo ability. + if (!(playerKit instanceof Kangaroo) + || !event.getAction().toString().contains("RIGHT") + || player.getItemInHand().getType() != Material.FIREWORK) { + return; + } - if (playerData.getActiveKit() instanceof Kangaroo - && event.getAction().toString().contains("RIGHT") - && player.getItemInHand().getType() == Material.FIREWORK) { + // Ignores the event if the player is not on the ground. + if (!BlockUtil.isOnGroundOffset(player, 0.001)) { + MessageUtil.messagePlayer(player, ConstantUtil.NOT_ON_GROUND); + return; + } - // Ignores the event if the player is not on the ground. - if (!BlockUtil.isOnGroundOffset(player, 0.001)) { - MessageUtil.messagePlayer(player, ConstantUtil.NOT_ON_GROUND); - return; - } + // Ignores the event if the player is in spawn. + if (Regions.isInSafezone(playerLoc)) { + MessageUtil.messagePlayer(player, ConstantUtil.ABILITY_IN_SPAWN); + return; + } - // Ignores the event if the player is in spawn. - if (Regions.isInSafezone(player.getLocation())) { - MessageUtil.messagePlayer(player, ConstantUtil.ABILITY_IN_SPAWN); - return; - } + // Ignores the event if the player's ability is on cooldown. + if (playerData.hasCooldown(true)) { + return; + } - // Ignores the event if the player's ability is on cooldown. - if (playerData.hasCooldown(true)) { - return; - } + // Play the ability sound. + player.getWorld().playSound(playerLoc, Sound.HORSE_JUMP, 1, 1); - // Launches the player into the air. - Vector direction = getKangarooLaunchVector(player); - player.setVelocity(direction); + // Launches the player into the air. + Vector direction = getKangarooLaunchVector(player); + player.setVelocity(direction); - MessageUtil.messagePlayer(player, "&aYour ability has been used."); - playerData.setCooldown(playerData.getActiveKit(), Settings.kangarooKitCooldown, true); - } + // Sets the player's ability cooldown. + MessageUtil.messagePlayer(player, "&aYour ability has been used."); + playerData.setCooldown(playerKit, Settings.kangarooKitCooldown, true); } /** @@ -516,854 +204,465 @@ public static void onKangarooAbility(@NotNull PlayerInteractEvent event) { * @param player The player. * @return The launch vector. */ - private static @NotNull Vector getKangarooLaunchVector(@NotNull Player player) { + private static @NotNull org.bukkit.util.Vector getKangarooLaunchVector(@NotNull Player player) { Vector direction = player.getEyeLocation().getDirection(); + // Adjusts the direction based on whether the player is sneaking. if (player.isSneaking()) { - direction.setY(Settings.kangarooKitSneakingHeight); - - if (Settings.kangarooKitSneakingMultiplier != 0.0) { - direction.multiply(Settings.kangarooKitSneakingMultiplier); - } + direction.setY(0.3); + direction.multiply(2.5); } else { - direction.setY(Settings.kangarooKitNormalHeight); - - if (Settings.kangarooKitNormalMultiplier != 0.0) { - direction.multiply(Settings.kangarooKitNormalMultiplier); - } + direction.setY(1.2); } return direction; } /** - * Handles the Mage ability, which gives the player a random potion effect. + * Handles the Mage ability. * * @param event The event. */ + @SuppressWarnings("NestedConditionalExpression") @EventHandler public static void onMageAbility(@NotNull PlayerInteractEvent event) { + // Player data Player player = event.getPlayer(); PlayerData playerData = PlayerDataManager.getPlayerData(player); - - if (playerData.getActiveKit() instanceof Mage - && event.getAction().toString().contains("RIGHT") - && player.getItemInHand().getType() == Material.GLOWSTONE_DUST) { - - // Ignores the event if the player is in spawn. - if (Regions.isInSafezone(player.getLocation())) { - MessageUtil.messagePlayer(player, ConstantUtil.ABILITY_IN_SPAWN); - return; - } - - // Ignores the event if the player's ability is on cooldown. - if (playerData.hasCooldown(true)) { - return; - } - - // Checks if the player's effects are still drained. - if (drainedEffects.containsKey(player.getUniqueId())) { - MessageUtil.messagePlayer(player, "&cAbility failed; your effects are still drained."); - return; - } - - // List of available potion effects. - List effects = Arrays.asList( - PotionEffectType.SPEED, PotionEffectType.SLOW, - PotionEffectType.FAST_DIGGING, PotionEffectType.SLOW_DIGGING, - PotionEffectType.INCREASE_DAMAGE, PotionEffectType.HEAL, - PotionEffectType.HARM, PotionEffectType.JUMP, - PotionEffectType.CONFUSION, PotionEffectType.REGENERATION, - PotionEffectType.DAMAGE_RESISTANCE, PotionEffectType.FIRE_RESISTANCE, - PotionEffectType.WATER_BREATHING, PotionEffectType.INVISIBILITY, - PotionEffectType.BLINDNESS, PotionEffectType.NIGHT_VISION, - PotionEffectType.WEAKNESS, PotionEffectType.POISON, - PotionEffectType.WITHER, PotionEffectType.HEALTH_BOOST, - PotionEffectType.ABSORPTION); - - // Randomly selects and applies an effect from the list. - PotionEffectType randomEffect = effects.get(RANDOM.nextInt(effects.size())); - int amplifier = RANDOM.nextInt(3); - int duration = Math.max(5, (RANDOM.nextInt(30) + 1)) * 20; - player.addPotionEffect(new PotionEffect(randomEffect, duration, amplifier, false, false)); - - MessageUtil.messagePlayer(player, "&aYour ability has been used."); - playerData.setCooldown(playerData.getActiveKit(), Settings.mageKitCooldown, true); + Location playerLoc = player.getLocation(); + Kit playerKit = playerData.getActiveKit(); + + // Ignores the event if the player isn't using the Mage ability. + if (!(playerKit instanceof Mage) + || !event.getAction().toString().contains("RIGHT") + || player.getItemInHand().getType() != Material.GLOWSTONE_DUST) { + return; } - } - - /** - * Handles the Monk ability, which swaps the items in the target's hotbar. - * - * @param event The event. - */ - @EventHandler(ignoreCancelled = true) - public static void onMonkAbility(@NotNull PlayerInteractEntityEvent event) { - Player damager = event.getPlayer(); - PlayerData damagerData = PlayerDataManager.getPlayerData(damager); - - if (event.getRightClicked() instanceof Player) { - Player receiver = (Player) event.getRightClicked(); - PlayerData receiverData = PlayerDataManager.getPlayerData(receiver); - - if (damagerData.getActiveKit() instanceof Monk - && damager.getItemInHand().getType() == Material.BLAZE_ROD - && receiverData.getActiveKit() != null - && !Regions.isInSafezone(receiver.getLocation())) { - - // Ignores the event if the player is in spawn. - if (Regions.isInSafezone(damager.getLocation())) { - MessageUtil.messagePlayer(damager, ConstantUtil.ABILITY_IN_SPAWN); - return; - } - - // Ignores the event if the player's ability is on cooldown. - if (damagerData.hasCooldown(true)) { - return; - } - // Generates a shuffled list of hotbar indices (0-8). - List slots = IntStream.range(0, 9).boxed().collect(Collectors.toList()); - Collections.shuffle(slots); + // Ignores the event if the player is in spawn. + if (Regions.isInSafezone(playerLoc)) { + MessageUtil.messagePlayer(player, ConstantUtil.ABILITY_IN_SPAWN); + return; + } - // Swaps items in the hotbar based on the shuffled indices. - PlayerInventory inventory = receiver.getInventory(); - ItemStack[] hotbar = new ItemStack[9]; + // Ignores the event if the player's ability is on cooldown. + if (playerData.hasCooldown(true)) { + return; + } - // Stores the current items in a temporary array. - for (int i = 0; i < 9; i++) { - hotbar[i] = inventory.getItem(i); - } + // List of available potion effects. + List effects = Arrays.asList( + // Good effects + PotionEffectType.SPEED, + PotionEffectType.INCREASE_DAMAGE, // Capped at Strength I + PotionEffectType.JUMP, + PotionEffectType.DAMAGE_RESISTANCE, // Capped at Resistance I + PotionEffectType.FIRE_RESISTANCE, // Capped at Fire Resistance I + PotionEffectType.ABSORPTION, + + // Bad effects + PotionEffectType.SLOW, + PotionEffectType.WEAKNESS, // Capped at Weakness I + PotionEffectType.POISON, + PotionEffectType.BLINDNESS, // Capped at Blindness I + PotionEffectType.WITHER, + + // Neutral effects + PotionEffectType.FAST_DIGGING, + PotionEffectType.SLOW_DIGGING, + PotionEffectType.WATER_BREATHING, // Capped at Water Breathing I + PotionEffectType.INVISIBILITY // Capped at Invisibility I + ); + + // Randomly selects an effect. + int effectSize = effects.size(); + int effectId = RANDOM.nextInt(effectSize); + PotionEffectType randomEffect = effects.get(effectId); + String effectName = randomEffect.getName(); + + // Sets the default amplifier to zero. + int amplifier = 0; + + // Sets the effect name and amplifier if necessary. + if (randomEffect.equals(PotionEffectType.SPEED)) { + amplifier = RANDOM.nextInt(3); + effectName = "Speed " + (amplifier == 0 ? "I" : amplifier == 1 ? "II" : "III"); + } else if (randomEffect.equals(PotionEffectType.INCREASE_DAMAGE)) { + effectName = "Strength"; + } else if (randomEffect.equals(PotionEffectType.JUMP)) { + amplifier = RANDOM.nextInt(3); + effectName = "Jump Boost " + (amplifier == 0 ? "I" : amplifier == 1 ? "II" : "III"); + } else if (randomEffect.equals(PotionEffectType.DAMAGE_RESISTANCE)) { + effectName = "Resistance"; + } else if (randomEffect.equals(PotionEffectType.FIRE_RESISTANCE)) { + effectName = "Fire Resistance"; + } else if (randomEffect.equals(PotionEffectType.ABSORPTION)) { + amplifier = RANDOM.nextInt(3); + effectName = "Absorption " + (amplifier == 0 ? "I" : amplifier == 1 ? "II" : "III"); + } else if (randomEffect.equals(PotionEffectType.SLOW)) { + amplifier = RANDOM.nextInt(3); + effectName = "Slowness " + (amplifier == 0 ? "I" : amplifier == 1 ? "II" : "III"); + } else if (randomEffect.equals(PotionEffectType.WEAKNESS)) { + effectName = "Weakness"; + } else if (randomEffect.equals(PotionEffectType.POISON)) { + amplifier = RANDOM.nextInt(3); + effectName = "Poison " + (amplifier == 0 ? "I" : amplifier == 1 ? "II" : "III"); + } else if (randomEffect.equals(PotionEffectType.BLINDNESS)) { + effectName = "Blindness"; + } else if (randomEffect.equals(PotionEffectType.WITHER)) { + amplifier = RANDOM.nextInt(3); + effectName = "Wither " + (amplifier == 0 ? "I" : amplifier == 1 ? "II" : "III"); + } else if (randomEffect.equals(PotionEffectType.FAST_DIGGING)) { + amplifier = RANDOM.nextInt(3); + effectName = "Haste " + (amplifier == 0 ? "I" : amplifier == 1 ? "II" : "III"); + } else if (randomEffect.equals(PotionEffectType.SLOW_DIGGING)) { + amplifier = RANDOM.nextInt(3); + effectName = "Mining Fatigue " + (amplifier == 0 ? "I" : amplifier == 1 ? "II" : "III"); + } else if (randomEffect.equals(PotionEffectType.WATER_BREATHING)) { + effectName = "Water Breathing"; + } else if (randomEffect.equals(PotionEffectType.INVISIBILITY)) { + effectName = "Invisibility"; + } - // Swaps items based on the shuffled list. - for (int i = 0; i < 9; i++) { - inventory.setItem(i, hotbar[slots.get(i)]); - } + // Randomly selects a duration. + int duration = RANDOM.nextInt(15); + duration = Math.max(5, (duration + 1)) * 20; - receiver.updateInventory(); - MessageUtil.messagePlayer(receiver, "&cYour items have been swapped by a Monk!"); + // Applies the effect to the player. + player.addPotionEffect(new PotionEffect(randomEffect, duration, amplifier, false, false)); - MessageUtil.messagePlayer(damager, "&aYour ability has been used."); - damagerData.setCooldown(damagerData.getActiveKit(), Settings.monkKitCooldown, true); - } - } + // Sets the player's ability cooldown. + MessageUtil.messagePlayer(player, "&aAbility used; you rolled &e" + effectName + "&a for &e" + duration / 20 + " &aseconds."); + playerData.setCooldown(playerKit, Settings.mageKitCooldown, true); } /** - * Handles the Spiderman ability, which shoots a projectile that creates a web. + * Handles the Ninja ability. * * @param event The event. */ - @EventHandler(ignoreCancelled = true) - public static void onSpidermanAbility(@NotNull PlayerInteractEvent event) { + @EventHandler + public static void onNinjaAbility(@NotNull PlayerInteractEvent event) { + // Player data Player player = event.getPlayer(); PlayerData playerData = PlayerDataManager.getPlayerData(player); - - if (playerData.getActiveKit() instanceof Spiderman - && event.getAction().toString().contains("RIGHT") - && player.getItemInHand().getType() == Material.WEB) { - - // Ignores the event if the player is in spawn. - if (Regions.isInSafezone(player.getLocation())) { - MessageUtil.messagePlayer(player, ConstantUtil.ABILITY_IN_SPAWN); - return; - } - - // Ignores the event if the player's ability is on cooldown. - if (playerData.hasCooldown(true)) { - return; - } - - // Shoots a snowball that creates a web around a player. - player.launchProjectile(Snowball.class).setMetadata("spiderman", - new FixedMetadataValue(KitPvP.instance, true)); - - MessageUtil.messagePlayer(player, "&aYour ability has been used."); - playerData.setCooldown(playerData.getActiveKit(), Settings.spidermanKitCooldown, true); + Location playerLoc = player.getLocation(); + Kit playerKit = playerData.getActiveKit(); + + // Ignores the event if the player isn't using the Kangaroo ability. + if (!(playerKit instanceof Ninja) + || !event.getAction().toString().contains("RIGHT") + || player.getItemInHand().getType() != Material.INK_SACK) { + return; } - } - /** - * Handles the Spiderman ability, which traps the target in webs when hit. - * - * @param event The event. - */ - @EventHandler(ignoreCancelled = true) - public static void onSpidermanHit(@NotNull EntityDamageByEntityEvent event) { - if (event.getDamager() instanceof Snowball) { - Snowball snowball = (Snowball) event.getDamager(); - - if (snowball.getShooter() instanceof Player && event.getEntity() instanceof Player) { - Player damager = (Player) snowball.getShooter(); - Player receiver = (Player) event.getEntity(); - PlayerData damagerData = PlayerDataManager.getPlayerData(damager); - PlayerData receiverData = PlayerDataManager.getPlayerData(receiver); - - if (damagerData.getActiveKit() instanceof Spiderman) { - // Checks if the target is in spawn. - if (receiverData.getActiveKit() == null || Regions.isInSafezone(receiver.getLocation())) { - damager.playSound(damager.getLocation(), Sound.VILLAGER_NO, 1.0F, 1.0F); - MessageUtil.messagePlayer(damager, "&cYou can't use your ability on players in spawn."); - damagerData.setCooldown(damagerData.getActiveKit(), 5, true); - return; - } - - if (snowball.hasMetadata("spiderman")) { - Collection blockStates = new ArrayList<>(); - Block block = receiver.getLocation().getBlock(); - - // Ignores water and lava and moves the target to the nearest air block. - while (block.getType() == Material.STATIONARY_WATER - || block.getType() == Material.STATIONARY_LAVA) { - receiver.getLocation().add(0.0, 1.0, 0.0); - block = receiver.getLocation().getBlock(); - } - - // Ignores webs and ladders and adds the surrounding blocks to a list for rollback. - for (Location loc : getSurroundingLocations(receiver.getLocation())) { - if (loc.getBlock().getType() == Material.WEB) { - continue; - } - - for (Location loc2 : getSurroundingLocations(loc)) { - if (loc2.getBlock().getType() != Material.LADDER) { - blockStates.add(loc.getBlock().getState()); - } - } - } - - // Adds webs around the target. - if (block.getType() != Material.WEB) { - blockStates.add(block.getState()); - } - for (BlockState blockState : blockStates) { - blockState.getBlock().setType(Material.WEB); - } - - // Rolls back the web after the set ability duration. - TaskUtil.runTaskLater(() -> { - for (BlockState blockState : blockStates) { - rollback(blockState); - } - }, Settings.spidermanKitDuration * 20L); - } - } - } + // Ignores the event if the player is in spawn. + if (Regions.isInSafezone(playerLoc)) { + MessageUtil.messagePlayer(player, ConstantUtil.ABILITY_IN_SPAWN); + return; } - } - /** - * Handles the Summoner ability, which summons an iron golem that attacks nearby players. - * - * @param event The event. - */ - @EventHandler - public static void onSummonerAbility(@NotNull PlayerInteractEvent event) { - Player player = event.getPlayer(); - PlayerData playerData = PlayerDataManager.getPlayerData(player); + // Ignores the event if the player's ability is on cooldown. + if (playerData.hasCooldown(true)) { + return; + } - if (playerData.getActiveKit() instanceof Summoner - && event.getAction().toString().contains("RIGHT") - && player.getItemInHand().getType() == Material.IRON_BLOCK) { + // Gives the player Invisibility. + player.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, + Settings.ninjaKitDuration * 20, 0, false, false)); - // Ignores the event if the player is in spawn. - if (Regions.isInSafezone(player.getLocation())) { - MessageUtil.messagePlayer(player, ConstantUtil.ABILITY_IN_SPAWN); - return; + // Hides the player from other players. + for (Player target : Bukkit.getOnlinePlayers()) { + if (target == player) { + continue; } - // Ignores the event if the player's ability is on cooldown. - if (playerData.hasCooldown(true)) { - return; - } - - Collection nearbyPlayers = new ArrayList<>(); + target.hidePlayer(player); + } - // Adds nearby players to a list. - for (Entity entity : player.getNearbyEntities(Settings.summonerKitRange, Settings.summonerKitRange, Settings.summonerKitRange)) { - if (entity instanceof Player) { - Player nearbyPlayer = (Player) entity; - PlayerData nearbyPlayerData = PlayerDataManager.getPlayerData(nearbyPlayer); + // Create a task that restores the player's visibility. + TaskUtil.runTaskLater(() -> { + player.getWorld().playSound(playerLoc, Sound.BAT_IDLE, 1, 1); + MessageUtil.messagePlayer(player, "&cYou are no longer invisible."); - if (nearbyPlayerData.getActiveKit() != null - && !Regions.isInSafezone(nearbyPlayer.getLocation())) { - nearbyPlayers.add(nearbyPlayer); - } + for (Player target : Bukkit.getOnlinePlayers()) { + if (target == player) { + continue; } - } - - // Ignores the event if no players are nearby. - if (nearbyPlayers.isEmpty()) { - player.playSound(player.getLocation(), Sound.VILLAGER_NO, 1.0F, 1.0F); - MessageUtil.messagePlayer(player, "&cAbility failed; no players found nearby."); - playerData.setCooldown(playerData.getActiveKit(), 5, true); - return; - } - - // Spawns an iron golem that attacks nearby players. - IronGolem ironGolem = (IronGolem) player.getWorld().spawnEntity(player.getLocation(), EntityType.IRON_GOLEM); - ironGolem.setMetadata(player.getName(), new FixedMetadataValue(KitPvP.instance, true)); - ironGolem.addPotionEffect(new PotionEffect(PotionEffectType.WEAKNESS, 99999, 1, false, false)); - - // Sets the iron golem's target to nearby players. - for (Player nearbyPlayer : nearbyPlayers) { - PlayerData nearbyPlayerData = PlayerDataManager.getPlayerData(nearbyPlayer); - if (nearbyPlayerData.getActiveKit() != null - && !Regions.isInSafezone(nearbyPlayer.getLocation())) { - ironGolem.setTarget(nearbyPlayer); - } + target.showPlayer(player); } + }, Settings.ninjaKitDuration * 20L); - // Removes the iron golem after the set ability duration. - TaskUtil.runTaskLater(ironGolem::remove, Settings.summonerKitDuration * 20L); - - MessageUtil.messagePlayer(player, "&aYour ability has been used."); - playerData.setCooldown(playerData.getActiveKit(), Settings.summonerKitCooldown, true); - } + // Sets the player's ability cooldown. + player.getWorld().playSound(playerLoc, Sound.BAT_DEATH, 1, 1); + MessageUtil.messagePlayer(player, "&aYou are now invisible."); + playerData.setCooldown(playerKit, Settings.ninjaKitCooldown, true); } /** - * Handles the Tamer ability, which spawns wolves that follow the player. + * Handles Ninjas damaging players while invisible. * - * @param event The event. + * @param event EntityDamageByEntityEvent */ - @EventHandler - public static void onTamerAbility(@NotNull PlayerInteractEvent event) { - Player player = event.getPlayer(); - PlayerData playerData = PlayerDataManager.getPlayerData(player); - - if (playerData.getActiveKit() instanceof Tamer - && event.getAction().toString().contains("RIGHT") - && player.getItemInHand().getType() == Material.BONE) { - - // Ignores the event if the player is in spawn. - if (Regions.isInSafezone(player.getLocation())) { - MessageUtil.messagePlayer(player, ConstantUtil.ABILITY_IN_SPAWN); - return; - } - - // Ignores the event if the player's ability is on cooldown. - if (playerData.hasCooldown(true)) { - return; - } - - Collection wolves = new ArrayList<>(); + @EventHandler(ignoreCancelled = true) + public static void onNinjaHit(@NotNull EntityDamageByEntityEvent event) { + Entity damagerEntity = event.getDamager(); + Entity targetEntity = event.getEntity(); - // Spawns wolves that follow the player. - for (int i = 0; i < Settings.tamerKitAmount; ++i) { - Wolf wolf = (Wolf) player.getWorld().spawnEntity(player.getLocation(), EntityType.WOLF); - wolf.setOwner(player); - wolf.isAngry(); - wolf.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 999999, 1)); - wolves.add(wolf); - } + // Handles players damaging other entities. + if (damagerEntity instanceof Player) { + Player damager = (Player) damagerEntity; + PlayerData damagerData = PlayerDataManager.getPlayerData(damager); - // Removes the wolves after the set ability duration. - TaskUtil.runTaskLater(() -> { - for (Wolf wolf : wolves) { - wolf.remove(); + // Cancels hits while Ninja is invisible. + if (targetEntity instanceof Player) { + if (damagerData.getActiveKit() instanceof Ninja + && damager.hasPotionEffect(PotionEffectType.INVISIBILITY)) { + MessageUtil.messagePlayer(damager, "&cYou can't damage other players while invisible."); + event.setCancelled(true); } - }, Settings.tamerKitDuration * 20L); - - MessageUtil.messagePlayer(player, "&aYour ability has been used."); - playerData.setCooldown(playerData.getActiveKit(), Settings.tamerKitCooldown, true); + } } } /** - * Handles the Thor ability, which strikes nearby players with lightning. + * Handles the Pyro ability. * * @param event The event. */ @EventHandler - public static void onThorAbility(@NotNull PlayerInteractEvent event) { + public static void onPyroAbility(@NotNull PlayerInteractEvent event) { + // Player data Player player = event.getPlayer(); PlayerData playerData = PlayerDataManager.getPlayerData(player); + Location playerLoc = player.getLocation(); + Kit playerKit = playerData.getActiveKit(); + + // Ignores the event if the player isn't using the Tank ability. + if (!(playerKit instanceof Pyro) + || !event.getAction().toString().contains("RIGHT") + || player.getItemInHand().getType() != Material.FIREBALL) { + return; + } - if (playerData.getActiveKit() instanceof Thor - && event.getAction().toString().contains("RIGHT") - && player.getItemInHand().getType() == Material.IRON_AXE) { - - // Ignores the event if the player is in spawn. - if (Regions.isInSafezone(player.getLocation())) { - MessageUtil.messagePlayer(player, ConstantUtil.ABILITY_IN_SPAWN); - return; - } + // Ignores the event if the player is in spawn. + if (Regions.isInSafezone(playerLoc)) { + MessageUtil.messagePlayer(player, ConstantUtil.ABILITY_IN_SPAWN); + return; + } - // Ignores the event if the player's ability is on cooldown. - if (playerData.hasCooldown(true)) { - return; - } + // Ignores the event if the player's ability is on cooldown. + if (playerData.hasCooldown(true)) { + return; + } - Collection nearbyPlayers = new ArrayList<>(); + // Gets the nearby players within a 5 block radius. + Collection nearbyPlayers = getNearbyPlayers(player, 5, 5, 5); - // Adds nearby players to a list. - for (Entity entity : player.getNearbyEntities(Settings.thorKitRange, Settings.thorKitRange, Settings.thorKitRange)) { - if (entity instanceof Player) { - Player nearbyPlayer = (Player) entity; - PlayerData nearbyPlayerData = PlayerDataManager.getPlayerData(nearbyPlayer); + // Ignores the event if there are no players nearby. + if (nearbyPlayers.isEmpty()) { + MessageUtil.messagePlayer(player, "&cAbility failed: no players nearby."); + playerData.setCooldown(new Pyro(), 5, true); + return; + } - if (nearbyPlayerData.getActiveKit() != null - && !Regions.isInSafezone(nearbyPlayer.getLocation())) { - nearbyPlayers.add(nearbyPlayer); - } - } - } + // Play the ability sound and effect. + player.getWorld().playSound(playerLoc, Sound.GHAST_FIREBALL, 1, 1); + player.getWorld().playEffect(playerLoc, Effect.MOBSPAWNER_FLAMES, 1); - // Ignores the event if no players are nearby. - if (nearbyPlayers.isEmpty()) { - player.playSound(player.getLocation(), Sound.VILLAGER_NO, 1.0F, 1.0F); - MessageUtil.messagePlayer(player, "&cAbility failed; no players found nearby."); - playerData.setCooldown(playerData.getActiveKit(), 5, true); - return; - } + for (Player target : nearbyPlayers) { + // Damage the target and light them on fire. + target.damage(Settings.pyroKitDamage); + target.setFireTicks(Settings.pyroKitDuration * 20); - // Damages and strikes nearby players with lightning. - for (Player nearbyPlayer : nearbyPlayers) { - PlayerData nearbyPlayerData = PlayerDataManager.getPlayerData(nearbyPlayer); + // Play a sound to the target. + Location targetLoc = target.getLocation(); + target.playSound(targetLoc, Sound.GHAST_FIREBALL, 1, 1); - if (nearbyPlayerData.getActiveKit() != null - && !Regions.isInSafezone(nearbyPlayer.getLocation())) { - player.getWorld().strikeLightningEffect(nearbyPlayer.getLocation()); - nearbyPlayer.damage(Settings.thorKitDamage, player); - nearbyPlayer.setFireTicks(Settings.thorKitDuration * 20); - } - } - - MessageUtil.messagePlayer(player, "&aYour ability has been used."); - playerData.setCooldown(playerData.getActiveKit(), Settings.thorKitCooldown, true); + // Play a particle effect at the target's location. + target.playEffect(targetLoc, Effect.MOBSPAWNER_FLAMES, 1); } + + // Sets the player's ability cooldown. + MessageUtil.messagePlayer(player, "&aYour ability has been used."); + playerData.setCooldown(playerKit, Settings.pyroKitCooldown, true); } /** - * Handles the Timelord ability, which freezes nearby players. + * Handles the Tank ability. * * @param event The event. */ @EventHandler - public static void onTimelordAbility(@NotNull PlayerInteractEvent event) { + public static void onTankAbility(@NotNull PlayerInteractEvent event) { + // Player data Player player = event.getPlayer(); PlayerData playerData = PlayerDataManager.getPlayerData(player); + Location playerLoc = player.getLocation(); + Kit playerKit = playerData.getActiveKit(); + + // Ignores the event if the player isn't using the Tank ability. + if (!(playerKit instanceof Tank) + || !event.getAction().toString().contains("RIGHT") + || player.getItemInHand().getType() != Material.ANVIL) { + return; + } - if (playerData.getActiveKit() instanceof Timelord - && event.getAction().toString().contains("RIGHT") - && player.getItemInHand().getType() == Material.WATCH) { - - // Ignores the event if the player is in spawn. - if (Regions.isInSafezone(player.getLocation())) { - MessageUtil.messagePlayer(player, ConstantUtil.ABILITY_IN_SPAWN); - return; - } - - // Ignores the event if the player's ability is on cooldown. - if (playerData.hasCooldown(true)) { - return; - } - - Collection nearbyPlayers = new ArrayList<>(); - - // Adds nearby players to a list. - for (Entity entity : player.getNearbyEntities(Settings.timelordKitRange, Settings.timelordKitRange, Settings.timelordKitRange)) { - if (entity instanceof Player) { - Player nearbyPlayer = (Player) entity; - PlayerData nearbyPlayerData = PlayerDataManager.getPlayerData(nearbyPlayer); - - if (nearbyPlayerData.getActiveKit() != null - && !Regions.isInSafezone(nearbyPlayer.getLocation())) { - nearbyPlayers.add(nearbyPlayer); - } - } - } - - // Ignores the event if no players are nearby. - if (nearbyPlayers.isEmpty()) { - player.playSound(player.getLocation(), Sound.VILLAGER_NO, 1.0F, 1.0F); - MessageUtil.messagePlayer(player, "&cAbility failed; no players found nearby."); - playerData.setCooldown(playerData.getActiveKit(), 5, true); - return; - } + // Ignores the event if the player is in spawn. + if (Regions.isInSafezone(playerLoc)) { + MessageUtil.messagePlayer(player, ConstantUtil.ABILITY_IN_SPAWN); + return; + } - // Plays a wither shoot sound effect. - player.playSound(player.getLocation(), Sound.WITHER_SHOOT, 1, 1); + // Ignores the event if the player's ability is on cooldown. + if (playerData.hasCooldown(true)) { + return; + } - // Freezes nearby players. - for (Player nearbyPlayer : nearbyPlayers) { - PlayerData nearbyPlayerData = PlayerDataManager.getPlayerData(nearbyPlayer); + // Play the ability sound. + player.getWorld().playSound(playerLoc, Sound.ANVIL_BREAK, 1, 1); - if (nearbyPlayerData.getActiveKit() != null - && !Regions.isInSafezone(nearbyPlayer.getLocation())) { - // Plays a sound effect and particle effects. - nearbyPlayer.playSound(nearbyPlayer.getLocation(), Sound.GHAST_FIREBALL, 1, 1); - nearbyPlayer.getWorld().playEffect(nearbyPlayer.getLocation(), Effect.STEP_SOUND, 152); - nearbyPlayer.getWorld().playEffect(nearbyPlayer.getLocation().add(0.0, 1.0, 0.0), Effect.STEP_SOUND, 152); + // Add the damage resistance effect. + player.removePotionEffect(PotionEffectType.SLOW); + player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, Settings.tankKitDuration * 20, 2, false, false)); + player.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, Settings.tankKitDuration * 20, 2)); - // Freezes the player using potion effects. - nearbyPlayer.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, Settings.timelordKitDuration * 20, 128, false, false)); - nearbyPlayer.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, Settings.timelordKitDuration * 20, 10, false, false)); - nearbyPlayer.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, Settings.timelordKitDuration * 20, 254, false, false)); - } + // Create a task that restores the Tank's slowness after 5 seconds. + TaskUtil.runTaskLater(() -> { + if (playerData.getActiveKit() instanceof Tank) { + player.removePotionEffect(PotionEffectType.SLOW); + player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, Integer.MAX_VALUE, 0, false, false)); } + }, Settings.tankKitDuration * 20L); - MessageUtil.messagePlayer(player, "&aYour ability has been used."); - playerData.setCooldown(playerData.getActiveKit(), Settings.timelordKitCooldown, true); - } + // Sets the player's ability cooldown. + MessageUtil.messagePlayer(player, "&aYour ability has been used."); + playerData.setCooldown(playerKit, Settings.tankKitCooldown, true); } /** - * Handles the Vampire ability, which drains the target's potion effects. + * Handles the Vampire ability. * * @param event The event. */ @EventHandler + @SuppressWarnings("NestedMethodCall") public static void onVampireAbility(@NotNull PlayerInteractEvent event) { + // Player data Player player = event.getPlayer(); PlayerData playerData = PlayerDataManager.getPlayerData(player); + Location playerLoc = player.getLocation(); + Kit playerKit = playerData.getActiveKit(); + + // Ignores the event if the player isn't using the Tank ability. + if (!(playerKit instanceof Vampire) + || !event.getAction().toString().contains("RIGHT") + || player.getItemInHand().getType() != Material.REDSTONE) { + return; + } - if (playerData.getActiveKit() instanceof Vampire - && event.getAction().toString().contains("RIGHT") - && player.getItemInHand().getType() == Material.REDSTONE) { - - // Ignores the event if the player is in spawn. - if (Regions.isInSafezone(player.getLocation())) { - MessageUtil.messagePlayer(player, ConstantUtil.ABILITY_IN_SPAWN); - return; - } - - // Ignores the event if the player's ability is on cooldown. - if (playerData.hasCooldown(true)) { - return; - } - - Collection nearbyPlayers = new ArrayList<>(); - Collection playerEffects = new ArrayList<>(); - - // Adds nearby players to a list. - for (Entity entity : player.getNearbyEntities(Settings.vampireKitRange, Settings.vampireKitRange, Settings.vampireKitRange)) { - if (entity instanceof Player) { - Player nearbyPlayer = (Player) entity; - PlayerData nearbyPlayerData = PlayerDataManager.getPlayerData(nearbyPlayer); - - if (nearbyPlayerData.getActiveKit() != null - && !Regions.isInSafezone(nearbyPlayer.getLocation())) { - nearbyPlayers.add(nearbyPlayer); - } - } - } - - // Ignores the event if no players are nearby. - if (nearbyPlayers.isEmpty()) { - player.playSound(player.getLocation(), Sound.VILLAGER_NO, 1.0F, 1.0F); - MessageUtil.messagePlayer(player, "&cAbility failed; no players found nearby."); - playerData.setCooldown(playerData.getActiveKit(), 5, true); - return; - } - - // Adds all potion effects from nearby players to a list. - for (Player nearbyPlayer : nearbyPlayers) { - PlayerData nearbyPlayerData = PlayerDataManager.getPlayerData(nearbyPlayer); + // Ignores the event if the player is in spawn. + if (Regions.isInSafezone(playerLoc)) { + MessageUtil.messagePlayer(player, ConstantUtil.ABILITY_IN_SPAWN); + return; + } - if (nearbyPlayerData.getActiveKit() != null - && !Regions.isInSafezone(nearbyPlayer.getLocation())) { - playerEffects.addAll(nearbyPlayer.getActivePotionEffects()); - } - } + // Ignores the event if the player's ability is on cooldown. + if (playerData.hasCooldown(true)) { + return; + } - // Ignores the event if no potion effects are found. - if (playerEffects.isEmpty()) { - MessageUtil.messagePlayer(player, "&cAbility failed; no effects found to drain."); - playerData.setCooldown(playerData.getActiveKit(), 5, true); - return; + // Create a task to notify the player that the Life Steal ability has ended. + BukkitTask lifeStealTask = new BukkitRunnable() { + @Override + public void run() { + player.playSound(playerLoc, Sound.BAT_IDLE, 1, 1); + MessageUtil.messagePlayer(player, "&cLife Steal is no longer active."); } + }.runTaskLater(KitPvP.instance, Settings.vampireKitDuration * 20L); - // Plays a sound effect. - player.playSound(player.getLocation(), Sound.CAT_HISS, 1, 1); - - // Drains the potion effects of nearby players. - for (Player nearbyPlayer : nearbyPlayers) { - UUID nearbyPlayerId = nearbyPlayer.getUniqueId(); + // Cancel the Life Steal cooldown task if it's active. + TaskUtil.runTaskLater(() -> playerData.setLifeStealCooldown(null), Settings.vampireKitDuration * 20L); - // Puts the target's potion effects into a map for rollback. - drainedEffects.put(nearbyPlayerId, nearbyPlayer.getActivePotionEffects()); + // Set the Life Steal cooldown task. + playerData.setLifeStealCooldown(lifeStealTask); - MessageUtil.messagePlayer(nearbyPlayer, "&cYour effects have been drained by a Vampire!"); - - for (PotionEffect potionEffect : drainedEffects.get(nearbyPlayerId)) { - if (potionEffect.getType() != PotionEffectType.INCREASE_DAMAGE) { - // Plays a sound effect and removes the target's potion effects. - nearbyPlayer.playSound(nearbyPlayer.getLocation(), Sound.CAT_HISS, 1, 1); - nearbyPlayer.removePotionEffect(potionEffect.getType()); - - // Adds the target's potion effects to the player. - player.addPotionEffect(potionEffect); - MessageUtil.messagePlayer(player, ("&aYou drained the " + potionEffect.getType().getName() - + " effect from " + nearbyPlayer.getName() + ".")); - } - } - - // Restores the target's potion effects after 10 seconds. - TaskUtil.runTaskLater(() -> { - Collection effectsToRestore = drainedEffects.remove(nearbyPlayerId); - - if (effectsToRestore != null && !effectsToRestore.isEmpty()) { - if (nearbyPlayer.isOnline()) { - // Clears current potion effects if necessary. - nearbyPlayer.getActivePotionEffects().forEach(effect -> nearbyPlayer.removePotionEffect(effect.getType())); - - // Restores the original potion effects. - effectsToRestore.forEach(nearbyPlayer::addPotionEffect); - MessageUtil.messagePlayer(nearbyPlayer, "&cYour drained effects have been restored."); - } - - if (player.isOnline()) { - effectsToRestore.forEach(effect -> { - // Check and apply only if the potion effect is relevant. - if (effect.getType() != PotionEffectType.INCREASE_DAMAGE) { - player.addPotionEffect(effect); - } - }); - MessageUtil.messagePlayer(player, "&aYour drained effects were restored."); - } - } - }, Settings.vampireKitDuration * 20L); - } - - MessageUtil.messagePlayer(player, "&aYour ability has been used."); - playerData.setCooldown(playerData.getActiveKit(), Settings.vampireKitCooldown, true); - } + // Sets the player's ability cooldown. + player.playSound(playerLoc, Sound.BAT_HURT, 1, 1); + MessageUtil.messagePlayer(player, "&aLife Steal has been activated."); + playerData.setCooldown(playerKit, Settings.vampireKitCooldown, true); } /** - * Handles the Vampire ability, which gives the player regeneration when hitting another player. + * Handles the Life Steal ability. * * @param event The event. */ @EventHandler(ignoreCancelled = true) public static void onVampireHit(@NotNull EntityDamageByEntityEvent event) { - if (event.getDamager() instanceof Player && event.getEntity() instanceof Player) { - Player damager = (Player) event.getDamager(); - Player receiver = (Player) event.getEntity(); - PlayerData damagerData = PlayerDataManager.getPlayerData(damager); - PlayerData receiverData = PlayerDataManager.getPlayerData(receiver); - - // Gives the player regeneration when hitting another player. - if (damagerData.getActiveKit() instanceof Vampire - && receiverData.getActiveKit() != null - && !Regions.isInSafezone(damager.getLocation()) - && !Regions.isInSafezone(receiver.getLocation())) { - - damager.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, - Settings.vampireKitPassiveDuration, 0, false, false)); - } + // Ignores the event if the damager or target is not a player. + if (!(event.getDamager() instanceof Player) + || !(event.getEntity() instanceof Player)) { + return; } - } - /** - * Handles the Zen ability, which teleports the player to the nearest player. - * - * @param event The event. - */ - @EventHandler - public static void onZenAbility(@NotNull PlayerInteractEvent event) { - Player player = event.getPlayer(); + // Player data + Player player = (Player) event.getDamager(); PlayerData playerData = PlayerDataManager.getPlayerData(player); - - if (playerData.getActiveKit() instanceof Zen - && event.getAction().toString().contains("RIGHT") - && player.getItemInHand().getType() == Material.SLIME_BALL) { - - // Ignores the event if the player is in spawn. - if (Regions.isInSafezone(player.getLocation())) { - MessageUtil.messagePlayer(player, ConstantUtil.ABILITY_IN_SPAWN); - return; - } - - // Ignores the event if the player's ability is on cooldown. - if (playerData.hasCooldown(true)) { - return; - } - - Player closest = null; - double closestDistance = 0; - Collection nearbyPlayers = new ArrayList<>(); - - // Adds nearby players to a list. - for (Entity entity : player.getNearbyEntities(Settings.zenKitRange, Settings.zenKitRange, Settings.zenKitRange)) { - if (entity instanceof Player) { - Player nearbyPlayer = (Player) entity; - PlayerData nearbyPlayerData = PlayerDataManager.getPlayerData(nearbyPlayer); - - if (nearbyPlayerData.getActiveKit() != null - && !Regions.isInSafezone(nearbyPlayer.getLocation())) { - nearbyPlayers.add(nearbyPlayer); - } - } - } - - // Ignores the event if no players are nearby. - if (nearbyPlayers.isEmpty()) { - player.playSound(player.getLocation(), Sound.VILLAGER_NO, 1.0F, 1.0F); - MessageUtil.messagePlayer(player, "&cAbility failed; no players found nearby."); - playerData.setCooldown(playerData.getActiveKit(), 5, true); - return; - } - - // Finds the closest player to teleport to. - for (Player nearbyPlayer : nearbyPlayers) { - PlayerData nearbyPlayerData = PlayerDataManager.getPlayerData(nearbyPlayer); - - if (nearbyPlayerData.getActiveKit() != null - && !Regions.isInSafezone(nearbyPlayer.getLocation())) { - double distance = nearbyPlayer.getLocation().distanceSquared(player.getLocation()); - - if (closest == null || distance < closestDistance) { - closest = nearbyPlayer; - closestDistance = distance; - } - } - } - - if (closest != null) { - // Removes the player from the list of imprisoned players. - imprisonedPlayers.remove(player.getUniqueId()); - - // Plays a sound effect before teleporting. - player.getWorld().playEffect(player.getLocation(), Effect.ENDER_SIGNAL, 1); - player.playSound(player.getLocation(), Sound.ENDERMAN_TELEPORT, 1, 1); - - // Teleports the player to the closest player. - player.teleport(closest.getLocation()); - - // Plays a sound effect after teleporting. - player.getWorld().playEffect(player.getLocation(), Effect.ENDER_SIGNAL, 1); - player.playSound(player.getLocation(), Sound.ENDERMAN_TELEPORT, 1, 1); - - // Applies blindness to the target. - closest.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, - Settings.zenKitDuration * 20, 0, false, false)); - - MessageUtil.messagePlayer(player, "&aYou teleported to " + closest.getDisplayName() + "."); - playerData.setCooldown(playerData.getActiveKit(), Settings.zenKitCooldown, true); - - } else { - player.playSound(player.getLocation(), Sound.VILLAGER_NO, 1.0F, 1.0F); - MessageUtil.messagePlayer(player, "&cAbility failed; no players found nearby."); - playerData.setCooldown(playerData.getActiveKit(), 5, true); - } + Location playerLoc = player.getLocation(); + + // Target data + Player target = (Player) event.getEntity(); + PlayerData targetData = PlayerDataManager.getPlayerData(target); + Location targetLoc = target.getLocation(); + + // Ignores the event if the damager is not using the Vampire kit. + if (!(playerData.getActiveKit() instanceof Vampire) + || targetData.getActiveKit() == null + || Regions.isInSafezone(playerLoc) + || Regions.isInSafezone(targetLoc)) { + return; } - } - - /** - * Gets the blocks that make up a cage. - * - * @param location The location of the cage. - * @return The blocks that make up the cage. - */ - private static @NotNull List getCageBlocks(@NotNull Location location) { - List list = new ArrayList<>(); - list.add(location.clone().add(0.0, -1.0, 0.0).getBlock()); - list.add(location.clone().add(-1.0, 0.0, 0.0).getBlock()); - list.add(location.clone().add(0.0, 0.0, 1.0).getBlock()); - list.add(location.clone().add(0.0, 0.0, -1.0).getBlock()); - list.add(location.clone().add(1.0, 0.0, 0.0).getBlock()); - list.add(location.clone().add(-1.0, 0.0, -1.0).getBlock()); - list.add(location.clone().add(-1.0, 0.0, 1.0).getBlock()); - list.add(location.clone().add(1.0, 0.0, -1.0).getBlock()); - list.add(location.clone().add(1.0, 0.0, 1.0).getBlock()); - list.add(location.clone().add(0.0, 2.0, 0.0).getBlock()); - list.add(location.getBlock()); - list.add(location.add(0.0, 1.0, 0.0).getBlock()); - return list; - } - /** - * Gets the locations of the blocks that make up a cage. - * - * @param location The location of the cage. - * @return The locations of the blocks that make up the cage. - */ - private static @NotNull List getPlatform(@NotNull Location location) { - List list = new ArrayList<>(); - list.add(location.clone()); - list.add(location.clone().add(-1.0, 0.0, 0.0)); - list.add(location.clone().add(0.0, 0.0, -1.0)); - list.add(location.clone().add(1.0, 0.0, 0.0)); - list.add(location.clone().add(0.0, 0.0, 1.0)); - list.add(location.clone().add(-1.0, 0.0, -1.0)); - list.add(location.clone().add(1.0, 0.0, -1.0)); - list.add(location.clone().add(1.0, 0.0, 1.0)); - list.add(location.clone().add(-1.0, 0.0, 1.0)); - return list; + // Gives the player half a heart per hit. + if (playerData.getLifeStealCooldown() != null) { + double health = player.getHealth(); + double maxHealth = player.getMaxHealth(); + player.playSound(playerLoc, Sound.CHICKEN_WALK, 1, 1); + player.setHealth(Math.min(health + 1, maxHealth)); + } } /** - * Gets the locations of the blocks that make up a room. + * Gets the nearby players within a certain range. * - * @param location The location of the room. - * @return The locations of the blocks that make up the room. + * @param player The player. + * @param x The x range. + * @param y The y range. + * @param z The z range. + * @return The nearby players. */ - private static @NotNull List getRoomLocations(@NotNull Location location) { - location.add(0.0, 9.0, 0.0); - - List list = new ArrayList<>(getPlatform(location)); - - for (int i = 0; i < 3; ++i) { - location.add(0.0, 1.0, 0.0); - list.add(location.clone().add(0.0, 0.0, -2.0)); - list.add(location.clone().add(0.0, 0.0, 2.0)); - list.add(location.clone().add(2.0, 0.0, 0.0)); - list.add(location.clone().add(-2.0, 0.0, 0.0)); - list.add(location.clone().add(-2.0, 0.0, 2.0)); - list.add(location.clone().add(-2.0, 0.0, -2.0)); - list.add(location.clone().add(2.0, 0.0, -2.0)); - list.add(location.clone().add(2.0, 0.0, 2.0)); - list.add(location.clone().add(1.0, 0.0, 2.0)); - list.add(location.clone().add(-1.0, 0.0, 2.0)); - list.add(location.clone().add(-2.0, 0.0, 1.0)); - list.add(location.clone().add(-2.0, 0.0, -1.0)); - list.add(location.clone().add(-1.0, 0.0, -2.0)); - list.add(location.clone().add(1.0, 0.0, -2.0)); - list.add(location.clone().add(2.0, 0.0, -1.0)); - list.add(location.clone().add(2.0, 0.0, 1.0)); - } + private static @NotNull Collection getNearbyPlayers(@NotNull Player player, double x, double y, double z) { + Collection nearbyPlayers = new ArrayList<>(); - list.addAll(getPlatform(location.add(0.0, 1.0, 0.0))); - return list; - } + for (Entity entity : player.getNearbyEntities(x, y, z)) { + // Ignores the entity if it's not a player. + if (!(entity instanceof Player)) { + continue; + } - /** - * Gets the locations of the blocks surrounding a location. - * - * @param location The location. - * @return The locations of the blocks surrounding the location. - */ - private static @NotNull List getSurroundingLocations(@NotNull Location location) { - List list = new ArrayList<>(); - list.add(location.clone().add(-1.0, 0.0, 0.0)); - list.add(location.clone().add(0.0, 0.0, 1.0)); - list.add(location.clone().add(0.0, 0.0, -1.0)); - list.add(location.clone().add(1.0, 0.0, 0.0)); - return list; - } + Player target = (Player) entity; + PlayerData targetData = PlayerDataManager.getPlayerData(target); + Location targetLoc = target.getLocation(); - /** - * Rolls back a block state. - * - * @param blockState The block state. - */ - private static void rollback(BlockState blockState) { - if (blockState instanceof Sign) { - Sign sign = (Sign) blockState; - Location location = sign.getLocation(); - location.getWorld().getBlockAt(location).setType(blockState.getType()); - Sign sign2 = (Sign) location.getWorld().getBlockAt(location).getState(); - - for (int i = 0; i < 4; ++i) { - sign2.setLine(i, sign.getLines()[i]); + // Ignores ineligible players. + if (targetData.getActiveKit() == null + || Regions.isInSafezone(targetLoc)) { + continue; } - sign2.update(true); - } else { - blockState.update(true); + nearbyPlayers.add(target); } + return nearbyPlayers; } } diff --git a/src/main/java/net/foulest/kitpvp/menus/KitEnchanter.java b/src/main/java/net/foulest/kitpvp/menus/KitEnchanter.java index 547d2dc..f40606a 100644 --- a/src/main/java/net/foulest/kitpvp/menus/KitEnchanter.java +++ b/src/main/java/net/foulest/kitpvp/menus/KitEnchanter.java @@ -17,6 +17,7 @@ */ package net.foulest.kitpvp.menus; +import lombok.Data; import net.foulest.kitpvp.data.PlayerData; import net.foulest.kitpvp.data.PlayerDataManager; import net.foulest.kitpvp.enchants.Enchants; @@ -38,6 +39,7 @@ * * @author Foulest */ +@Data public class KitEnchanter { private final Inventory inventory; @@ -47,12 +49,13 @@ public class KitEnchanter { * * @param player The player to open the GUI for. */ - public KitEnchanter(Player player) { + public KitEnchanter(@NotNull Player player) { + player.closeInventory(); + String inventoryName = MessageUtil.colorize("Kit Enchanter"); inventory = Bukkit.createInventory(player, 27, inventoryName); populateInventory(player); - player.closeInventory(); player.openInventory(inventory); } diff --git a/src/main/java/net/foulest/kitpvp/menus/KitSelector.java b/src/main/java/net/foulest/kitpvp/menus/KitSelector.java index 0d8dfee..b02879d 100644 --- a/src/main/java/net/foulest/kitpvp/menus/KitSelector.java +++ b/src/main/java/net/foulest/kitpvp/menus/KitSelector.java @@ -17,6 +17,7 @@ */ package net.foulest.kitpvp.menus; +import lombok.Data; import net.foulest.kitpvp.data.PlayerData; import net.foulest.kitpvp.data.PlayerDataManager; import net.foulest.kitpvp.kits.Kit; @@ -37,6 +38,7 @@ * * @author Foulest */ +@Data public class KitSelector { private final String inventoryName = MessageUtil.colorize("Kit Selector"); @@ -49,7 +51,8 @@ public class KitSelector { * @param player The player to open the GUI for. */ public KitSelector(Player player) { - inventory = Bukkit.createInventory(player, ensureSize(KitManager.getKits().size()) + 18, inventoryName); + int size = KitManager.getKits().size(); + inventory = Bukkit.createInventory(player, ensureSize(size) + 18, inventoryName); populateInventory(player, 0); player.closeInventory(); @@ -63,12 +66,13 @@ public KitSelector(Player player) { * @param player The player to open the GUI for. * @param page The page to open the GUI on. */ - public KitSelector(Player player, int page) { - inventory = Bukkit.createInventory(player, ensureSize(KitManager.getKits().size()) + 18, - inventoryName + " - Page: " + (page + 1)); + public KitSelector(@NotNull Player player, int page) { + player.closeInventory(); + + int size = KitManager.getKits().size(); + inventory = Bukkit.createInventory(player, ensureSize(size) + 18, inventoryName + " - Page: " + (page + 1)); populateInventory(player, page); - player.closeInventory(); player.openInventory(inventory); pages.put(player, page); } @@ -111,17 +115,20 @@ private static int ensureSize(int size) { * @return The kit item. */ private static ItemStack createKitItem(@NotNull Kit kit) { + ItemStack displayItem = kit.getDisplayItem(); List lore = kit.getLore(); + String name = kit.getName(); + int cost = kit.getCost(); - if (kit.getCost() == 0) { + if (cost == 0) { lore.add(1, "&7Cost: &fFree"); } else { - lore.add(1, "&7Cost: &f" + kit.getCost() + " coins"); + lore.add(1, "&7Cost: &f" + cost + " coins"); } lore.add("&7"); lore.add("&aClick to equip this kit."); - return new ItemBuilder(kit.getDisplayItem()).name("&a" + kit.getName()).lore(lore).getItem(); + return new ItemBuilder(displayItem).name("&a" + name).lore(lore).getItem(); } /** @@ -140,21 +147,29 @@ private void populateInventory(Player player, int page) { for (int i = 0; i < rowSize; i++) { inventory.setItem(i, glass); } - for (int i = (inventory.getSize() - rowSize); i < inventory.getSize(); i++) { + + int inventorySize = inventory.getSize(); + int kitsSize = KitManager.getKits().size(); + + for (int i = (inventorySize - rowSize); i < inventorySize; i++) { inventory.setItem(i, glass); } // Previous page item if (page > 0) { - inventory.setItem(inventory.getSize() - 9, new ItemBuilder(Material.BOOK).name("&aPrevious Page").getItem()); + ItemBuilder previousPage = new ItemBuilder(Material.BOOK).name("&aPrevious Page"); + ItemStack previousPageItem = previousPage.getItem(); + inventory.setItem(inventorySize - 9, previousPageItem); } int start = page * kitsPerPage; - int end = Math.min((page + 1) * kitsPerPage, KitManager.getKits().size()); + int end = Math.min((page + 1) * kitsPerPage, kitsSize); // Next page item - if (end < KitManager.getKits().size()) { // Correct check for the existence of a next page - inventory.setItem(inventory.getSize() - 1, new ItemBuilder(Material.BOOK).name("&aNext Page").getItem()); + if (end < kitsSize) { + ItemBuilder nextPage = new ItemBuilder(Material.BOOK).name("&aNext Page"); + ItemStack nextPageItem = nextPage.getItem(); + inventory.setItem(inventorySize - 1, nextPageItem); } List pageKits = KitManager.getKits().subList(start, end); diff --git a/src/main/java/net/foulest/kitpvp/menus/KitShop.java b/src/main/java/net/foulest/kitpvp/menus/KitShop.java index 4b6e62f..b830619 100644 --- a/src/main/java/net/foulest/kitpvp/menus/KitShop.java +++ b/src/main/java/net/foulest/kitpvp/menus/KitShop.java @@ -17,6 +17,7 @@ */ package net.foulest.kitpvp.menus; +import lombok.Data; import net.foulest.kitpvp.data.PlayerData; import net.foulest.kitpvp.data.PlayerDataManager; import net.foulest.kitpvp.kits.Kit; @@ -37,7 +38,7 @@ * * @author Foulest */ -@SuppressWarnings("MismatchedQueryAndUpdateOfCollection") +@Data public class KitShop { private static final Map pages = new HashMap<>(); @@ -59,15 +60,17 @@ public KitShop(Player player) { * @param page The page to open the GUI on. */ public KitShop(@NotNull Player player, int page) { - String inventoryName = MessageUtil.colorize("Kit Shop"); player.closeInventory(); + String inventoryName = MessageUtil.colorize("Kit Shop"); + int kitsSize = KitManager.getKits().size(); + if (page > 0) { inventory = Bukkit.createInventory(player, - ensureSize(KitManager.getKits().size()) + 18, inventoryName + " - Page: " + (page + 1)); + ensureSize(kitsSize) + 18, inventoryName + " - Page: " + (page + 1)); } else { inventory = Bukkit.createInventory(player, - ensureSize(KitManager.getKits().size()) + 18, inventoryName); + ensureSize(kitsSize) + 18, inventoryName); } if (populateInventory(player, page)) { @@ -95,6 +98,7 @@ private static int ensureSize(int size) { if ((size + halfMaxSize) % rowSize == 0) { return size; } + ++size; return ensureSize(size); } @@ -106,17 +110,20 @@ private static int ensureSize(int size) { * @return The kit item. */ private static ItemStack createKitItem(@NotNull Kit kit) { + ItemStack displayItem = kit.getDisplayItem(); List lore = kit.getLore(); + String name = kit.getName(); + int cost = kit.getCost(); - if (kit.getCost() == 0) { + if (cost == 0) { lore.add(1, "&7Cost: &fFree"); } else { - lore.add(1, "&7Cost: &f" + kit.getCost() + " coins"); + lore.add(1, "&7Cost: &f" + cost + " coins"); } lore.add(""); lore.add("&aClick to purchase this kit."); - return new ItemBuilder(kit.getDisplayItem()).name("&c" + kit.getName()).lore(lore).getItem(); + return new ItemBuilder(displayItem).name("&c" + name).lore(lore).getItem(); } /** @@ -135,21 +142,29 @@ private boolean populateInventory(Player player, int page) { for (int i = 0; i < rowSize; i++) { inventory.setItem(i, glass); } - for (int i = (inventory.getSize() - rowSize); i < inventory.getSize(); i++) { + + int inventorySize = inventory.getSize(); + int kitsSize = KitManager.getKits().size(); + + for (int i = (inventorySize - rowSize); i < inventorySize; i++) { inventory.setItem(i, glass); } // Previous page item if (page > 0) { - inventory.setItem(inventory.getSize() - 9, new ItemBuilder(Material.BOOK).name("&aPrevious Page").getItem()); + ItemBuilder previousPage = new ItemBuilder(Material.BOOK).name("&aPrevious Page"); + ItemStack previousPageItem = previousPage.getItem(); + inventory.setItem(inventorySize - 9, previousPageItem); } int start = page * kitsPerPage; - int end = Math.min((page + 1) * kitsPerPage, KitManager.getKits().size()); // Correct calculation of the end index + int end = Math.min((page + 1) * kitsPerPage, kitsSize); // Next page item - if (end < KitManager.getKits().size()) { // Correct check for the existence of a next page - inventory.setItem(inventory.getSize() - 1, new ItemBuilder(Material.BOOK).name("&aNext Page").getItem()); + if (end < kitsSize) { + ItemBuilder nextPage = new ItemBuilder(Material.BOOK).name("&aNext Page"); + ItemStack nextPageItem = nextPage.getItem(); + inventory.setItem(inventorySize - 1, nextPageItem); } List pageKits = KitManager.getKits().subList(start, end); diff --git a/src/main/java/net/foulest/kitpvp/region/Regions.java b/src/main/java/net/foulest/kitpvp/region/Regions.java index 8226c79..f72d787 100644 --- a/src/main/java/net/foulest/kitpvp/region/Regions.java +++ b/src/main/java/net/foulest/kitpvp/region/Regions.java @@ -24,13 +24,13 @@ import com.sk89q.worldguard.protection.flags.StateFlag; import com.sk89q.worldguard.protection.managers.RegionManager; import com.sk89q.worldguard.protection.regions.ProtectedRegion; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; +import lombok.Data; import net.foulest.kitpvp.util.MessageUtil; import net.minecraft.server.v1_8_R3.AxisAlignedBB; import net.minecraft.server.v1_8_R3.BlockPosition; import net.minecraft.server.v1_8_R3.Vec3D; import org.bukkit.Location; +import org.bukkit.World; import java.util.HashMap; import java.util.Map; @@ -41,8 +41,8 @@ * * @author Foulest */ -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public final class Regions { +@Data +public class Regions { private static final WorldGuardPlugin worldGuard = WorldGuardPlugin.inst(); private static Map regionMap = new HashMap<>(); @@ -51,8 +51,9 @@ public final class Regions { * Caches WorldGuard regions for later use. */ static void cacheRegions() { + World world = Spawn.getLocation().getWorld(); RegionContainer container = worldGuard.getRegionContainer(); - RegionManager regionManager = container.get(Spawn.getLocation().getWorld()); + RegionManager regionManager = container.get(world); if (regionManager == null) { MessageUtil.log(Level.WARNING, "ERROR: No regions found."); @@ -74,12 +75,24 @@ public static boolean isInSafezone(Location loc) { BlockVector regionMin = region.getMinimumPoint(); BlockVector regionMax = region.getMaximumPoint(); + double minX = regionMin.getX(); + double minY = regionMin.getY(); + double minZ = regionMin.getZ(); + + double maxX = regionMax.getX(); + double maxY = regionMax.getY(); + double maxZ = regionMax.getZ(); + AxisAlignedBB regionZone = new AxisAlignedBB( - new BlockPosition(region.getMinimumPoint().getX(), regionMin.getY(), regionMin.getZ()), - new BlockPosition((regionMax.getX() + 1), regionMax.getY(), (regionMax.getZ() + 1)) + new BlockPosition(minX, minY, minZ), + new BlockPosition((maxX + 1), maxY, (maxZ + 1)) ); - Vec3D vec3D = new Vec3D(loc.getX(), loc.getY(), loc.getZ()); + double locX = loc.getX(); + double locY = loc.getY(); + double locZ = loc.getZ(); + + Vec3D vec3D = new Vec3D(locX, locY, locZ); if (regionZone.a(vec3D) && region.getFlag(DefaultFlag.PVP) == StateFlag.State.DENY) { return true; diff --git a/src/main/java/net/foulest/kitpvp/region/Spawn.java b/src/main/java/net/foulest/kitpvp/region/Spawn.java index b123a57..bde7812 100644 --- a/src/main/java/net/foulest/kitpvp/region/Spawn.java +++ b/src/main/java/net/foulest/kitpvp/region/Spawn.java @@ -17,9 +17,8 @@ */ package net.foulest.kitpvp.region; -import lombok.AccessLevel; +import lombok.Data; import lombok.Getter; -import lombok.NoArgsConstructor; import net.foulest.kitpvp.combattag.CombatTag; import net.foulest.kitpvp.data.PlayerData; import net.foulest.kitpvp.data.PlayerDataManager; @@ -29,6 +28,7 @@ import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; import org.jetbrains.annotations.NotNull; /** @@ -36,8 +36,8 @@ * * @author Foulest */ -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public final class Spawn { +@Data +public class Spawn { @Getter public static Location location; @@ -57,7 +57,12 @@ public static void setLocation(@NotNull Location loc) { Settings.saveConfig(); location = loc; - loc.getWorld().setSpawnLocation(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); + + int blockX = loc.getBlockX(); + int blockY = loc.getBlockY(); + int blockZ = loc.getBlockZ(); + + loc.getWorld().setSpawnLocation(blockX, blockY, blockZ); } /** @@ -78,7 +83,8 @@ public static void teleport(Player player) { playerData.setActiveKit(null); for (PotionEffect effect : player.getActivePotionEffects()) { - player.removePotionEffect(effect.getType()); + PotionEffectType effectType = effect.getType(); + player.removePotionEffect(effectType); } playerData.giveDefaultItems(); diff --git a/src/main/java/net/foulest/kitpvp/util/BlockUtil.java b/src/main/java/net/foulest/kitpvp/util/BlockUtil.java index 1fea898..b105164 100644 --- a/src/main/java/net/foulest/kitpvp/util/BlockUtil.java +++ b/src/main/java/net/foulest/kitpvp/util/BlockUtil.java @@ -17,27 +17,25 @@ */ package net.foulest.kitpvp.util; -import lombok.AccessLevel; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; +import lombok.Data; import net.foulest.kitpvp.util.data.ConcurrentStream; import net.foulest.kitpvp.util.raytrace.BoundingBox; +import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; +import java.util.List; + /** * Utility class for block-related methods. * * @author Foulest */ -@Getter -@Setter -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public final class BlockUtil { +@Data +public class BlockUtil { /** * Checks if a player is in an unloaded chunk. @@ -46,8 +44,10 @@ public final class BlockUtil { * @return Whether the player is in an unloaded chunk. */ private static boolean isPlayerInUnloadedChunk(@NotNull Player player) { - return !player.getLocation().getWorld().isChunkLoaded(player.getLocation().getBlockX() >> 4, - player.getLocation().getBlockZ() >> 4); + Location location = player.getLocation(); + int blockX = location.getBlockX(); + int blockZ = location.getBlockZ(); + return !location.getWorld().isChunkLoaded(blockX >> 4, blockZ >> 4); } /** @@ -59,7 +59,8 @@ private static boolean isPlayerInUnloadedChunk(@NotNull Player player) { */ @Contract("_, _ -> new") private static @NotNull ConcurrentStream getCollidingBlocks(Player player, @NotNull BoundingBox boundingBox) { - return new ConcurrentStream<>(boundingBox.getCollidingBlocks(player), false); + List collidingBlocks = boundingBox.getCollidingBlocks(player); + return new ConcurrentStream<>(collidingBlocks, false); } /** @@ -71,12 +72,16 @@ private static boolean isPlayerInUnloadedChunk(@NotNull Player player) { private static boolean collidesWithSolid(Player player, BoundingBox boundingBox) { ConcurrentStream collidingBlocks = getCollidingBlocks(player, boundingBox); - return collidingBlocks.any(block -> block.getType().isSolid() - || block.getType() == Material.WATER_LILY - || block.getType() == Material.FLOWER_POT - || block.getType() == Material.CARPET - || block.getType() == Material.SNOW - || block.getType() == Material.SKULL); + return collidingBlocks.any(block -> { + Material type = block.getType(); + + return type.isSolid() + || type == Material.WATER_LILY + || type == Material.FLOWER_POT + || type == Material.CARPET + || type == Material.SNOW + || type == Material.SKULL; + }); } /** diff --git a/src/main/java/net/foulest/kitpvp/util/ConstantUtil.java b/src/main/java/net/foulest/kitpvp/util/ConstantUtil.java index 07afd07..60e0fc7 100644 --- a/src/main/java/net/foulest/kitpvp/util/ConstantUtil.java +++ b/src/main/java/net/foulest/kitpvp/util/ConstantUtil.java @@ -38,7 +38,7 @@ public class ConstantUtil { /** * Constant for when a player needs to be in the game to use a command. */ - public final String IN_GAME_ONLY = "&cOnly players can execute this command."; + public final String IN_GAME_ONLY = "&cOnly players may execute this command."; /** * Constant for when a tab completer is unable to be registered. diff --git a/src/main/java/net/foulest/kitpvp/util/DatabaseUtil.java b/src/main/java/net/foulest/kitpvp/util/DatabaseUtil.java index 5d0d994..a5bb318 100644 --- a/src/main/java/net/foulest/kitpvp/util/DatabaseUtil.java +++ b/src/main/java/net/foulest/kitpvp/util/DatabaseUtil.java @@ -18,9 +18,7 @@ package net.foulest.kitpvp.util; import com.zaxxer.hikari.HikariDataSource; -import lombok.AccessLevel; -import lombok.Cleanup; -import lombok.NoArgsConstructor; +import lombok.Data; import lombok.Synchronized; import net.foulest.kitpvp.data.PlayerData; import net.foulest.kitpvp.enchants.Enchants; @@ -42,9 +40,8 @@ * * @author Foulest */ -@SuppressWarnings({"SqlSourceToSinkFlow", "unused"}) -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public final class DatabaseUtil { +@Data +public class DatabaseUtil { private static HikariDataSource dataSource; @@ -130,15 +127,29 @@ public static void loadDatabase() { */ public static void updatePlayerStatsTable(@NotNull PlayerData playerData) { Map playerDataMap = new HashMap<>(); - playerDataMap.put("uuid", playerData.getUniqueId().toString()); - playerDataMap.put("coins", playerData.getCoins()); - playerDataMap.put("experience", playerData.getExperience()); - playerDataMap.put("kills", playerData.getKills()); - playerDataMap.put("deaths", playerData.getDeaths()); - playerDataMap.put("killstreak", playerData.getKillstreak()); - playerDataMap.put("topKillstreak", playerData.getTopKillstreak()); - playerDataMap.put("usingSoup", playerData.isUsingSoup() ? 1 : 0); - playerDataMap.put("previousKit", playerData.getPreviousKit().getName()); + + UUID playerUUID = playerData.getUniqueId(); + String playerUUIDString = playerUUID.toString(); + int coins = playerData.getCoins(); + int experience = playerData.getExperience(); + int kills = playerData.getKills(); + int deaths = playerData.getDeaths(); + int killstreak = playerData.getKillstreak(); + int topKillstreak = playerData.getTopKillstreak(); + boolean usingSoup = playerData.isUsingSoup(); + Kit previousKit = playerData.getPreviousKit(); + String previousKitName = previousKit.getName(); + + playerDataMap.put("uuid", playerUUIDString); + playerDataMap.put("coins", coins); + playerDataMap.put("experience", experience); + playerDataMap.put("kills", kills); + playerDataMap.put("deaths", deaths); + playerDataMap.put("killstreak", killstreak); + playerDataMap.put("topKillstreak", topKillstreak); + playerDataMap.put("usingSoup", usingSoup ? 1 : 0); + playerDataMap.put("previousKit", previousKitName); + addDataToTable("PlayerStats", playerDataMap); } @@ -152,17 +163,19 @@ public static void updatePlayerKitsTable(@NotNull PlayerData playerData) { String uuid = playerData.getUniqueId().toString(); if (!ownedKits.isEmpty()) { - deleteDataFromTable("PlayerKits", - "uuid = ?", Collections.singletonList(uuid)); + deleteDataFromTable("PlayerKits", "uuid = ?", Collections.singletonList(uuid)); - for (Kit kits : ownedKits) { - if (kits == null) { + for (Kit kit : ownedKits) { + if (kit == null) { continue; } Map playerKitsData = new HashMap<>(); + String kitName = kit.getName(); + playerKitsData.put("uuid", uuid); - playerKitsData.put("kitName", kits.getName()); + playerKitsData.put("kitName", kitName); + addDataToTable("PlayerKits", playerKitsData); } } @@ -184,14 +197,23 @@ public static void updateEnchantsTable(@NotNull PlayerData playerData) { "uuid = ?", Collections.singletonList(uuid)); } else { Map enchantsData = new HashMap<>(); + boolean featherFalling = enchants.contains(Enchants.FEATHER_FALLING); + boolean thorns = enchants.contains(Enchants.THORNS); + boolean protection = enchants.contains(Enchants.PROTECTION); + boolean knockback = enchants.contains(Enchants.KNOCKBACK); + boolean sharpness = enchants.contains(Enchants.SHARPNESS); + boolean punch = enchants.contains(Enchants.PUNCH); + boolean power = enchants.contains(Enchants.POWER); + enchantsData.put("uuid", uuid); - enchantsData.put("featherFalling", enchants.contains(Enchants.FEATHER_FALLING) ? 1 : 0); - enchantsData.put("thorns", enchants.contains(Enchants.THORNS) ? 1 : 0); - enchantsData.put("protection", enchants.contains(Enchants.PROTECTION) ? 1 : 0); - enchantsData.put("knockback", enchants.contains(Enchants.KNOCKBACK) ? 1 : 0); - enchantsData.put("sharpness", enchants.contains(Enchants.SHARPNESS) ? 1 : 0); - enchantsData.put("punch", enchants.contains(Enchants.PUNCH) ? 1 : 0); - enchantsData.put("power", enchants.contains(Enchants.POWER) ? 1 : 0); + enchantsData.put("featherFalling", featherFalling ? 1 : 0); + enchantsData.put("thorns", thorns ? 1 : 0); + enchantsData.put("protection", protection ? 1 : 0); + enchantsData.put("knockback", knockback ? 1 : 0); + enchantsData.put("sharpness", sharpness ? 1 : 0); + enchantsData.put("punch", punch ? 1 : 0); + enchantsData.put("power", power ? 1 : 0); + addDataToTable("Enchants", enchantsData); } } @@ -213,9 +235,11 @@ public static void updateBountiesTable(@NotNull PlayerData playerData) { "uuid = ?", Collections.singletonList(uuid)); } else { Map bountiesData = new HashMap<>(); + String benefactorString = benefactor.toString(); + bountiesData.put("uuid", uuid); bountiesData.put("bounty", bounty); - bountiesData.put("benefactor", benefactor.toString()); + bountiesData.put("benefactor", benefactorString); addDataToTable("Bounties", bountiesData); } } @@ -279,14 +303,20 @@ public static void closeDbcp() { */ private static void createTableIfNotExists(String tableName, String tableColumns) { try (Connection connection = (Settings.usingFlatFile ? getSQLiteConnection() : dataSource.getConnection())) { - DatabaseMetaData metaData = Objects.requireNonNull(connection).getMetaData(); - ResultSet tables = metaData.getTables(null, null, tableName, null); + if (connection == null) { + MessageUtil.log(Level.SEVERE, "Failed to establish a connection to the database."); + return; + } + + DatabaseMetaData metaData = connection.getMetaData(); - if (!tables.next()) { - String createTableSQL = String.format("CREATE TABLE %s (%s)", tableName, tableColumns); + try (ResultSet tables = metaData.getTables(null, null, tableName, null)) { + if (!tables.next()) { + String createTableSQL = String.format("CREATE TABLE %s (%s)", tableName, tableColumns); - try (PreparedStatement preparedStatement = connection.prepareStatement(createTableSQL)) { - preparedStatement.execute(); + try (PreparedStatement preparedStatement = connection.prepareStatement(createTableSQL)) { + preparedStatement.execute(); + } } } } catch (SQLException ex) { @@ -302,14 +332,20 @@ private static void createTableIfNotExists(String tableName, String tableColumns */ public static void deleteTableIfExists(String tableName) throws SQLException { try (Connection connection = (Settings.usingFlatFile ? getSQLiteConnection() : dataSource.getConnection())) { - DatabaseMetaData metaData = Objects.requireNonNull(connection).getMetaData(); - ResultSet tables = metaData.getTables(null, null, tableName, null); + if (connection == null) { + MessageUtil.log(Level.SEVERE, "Failed to establish a connection to the database."); + return; + } + + DatabaseMetaData metaData = connection.getMetaData(); - if (tables.next()) { - String deleteTableSQL = String.format("DROP TABLE %s", tableName); + try (ResultSet tables = metaData.getTables(null, null, tableName, null)) { + if (tables.next()) { + String deleteTableSQL = String.format("DROP TABLE %s", tableName); - try (PreparedStatement preparedStatement = connection.prepareStatement(deleteTableSQL)) { - preparedStatement.execute(); + try (PreparedStatement preparedStatement = connection.prepareStatement(deleteTableSQL)) { + preparedStatement.execute(); + } } } } @@ -322,8 +358,11 @@ public static void deleteTableIfExists(String tableName) throws SQLException { * @param tableData The data to be added. */ private static void addDataToTable(String tableName, @NotNull Map tableData) { - String columns = String.join(", ", tableData.keySet()); - String placeholders = IntStream.range(0, tableData.size()) + int size = tableData.size(); + Set keySet = tableData.keySet(); + String columns = String.join(", ", keySet); + + String placeholders = IntStream.range(0, size) .mapToObj(i -> "?") .collect(Collectors.joining(", ")); @@ -335,7 +374,7 @@ private static void addDataToTable(String tableName, @NotNull Map String.format("%s = VALUES(%s)", column, column)) .collect(Collectors.joining(", ")); @@ -344,8 +383,14 @@ private static void addDataToTable(String tableName, @NotNull Map 0) { - return; // Table is not empty, no need to insert default data + try (Connection connection = (Settings.usingFlatFile ? getSQLiteConnection() : dataSource.getConnection())) { + if (connection == null) { + MessageUtil.log(Level.SEVERE, "Failed to establish a connection to the database."); + return; } - // Proceed with insert since table is empty - String columns = String.join(", ", tableData.keySet()); - String placeholders = String.join(", ", Collections.nCopies(tableData.size(), "?")); - String insertSQL = String.format("INSERT INTO %s (%s) VALUES (%s)", tableName, columns, placeholders); + try (PreparedStatement checkTableEmptyStmt = connection.prepareStatement(checkTableEmptySQL)) { + try (ResultSet resultSet = checkTableEmptyStmt.executeQuery()) { + if (resultSet.next() && resultSet.getInt(1) > 0) { + return; // Table is not empty, no need to insert default data + } + } - try (PreparedStatement insertStmt = connection.prepareStatement(insertSQL)) { - int index = 1; - for (Object value : tableData.values()) { - insertStmt.setObject(index, value); - index++; + // Proceed with insert since table is empty + int size = tableData.size(); + Set keySet = tableData.keySet(); + String columns = String.join(", ", keySet); + String placeholders = String.join(", ", Collections.nCopies(size, "?")); + String insertSQL = String.format("INSERT INTO %s (%s) VALUES (%s)", tableName, columns, placeholders); + + try (PreparedStatement insertStmt = connection.prepareStatement(insertSQL)) { + int index = 1; + for (Object value : tableData.values()) { + insertStmt.setObject(index, value); + index++; + } + insertStmt.executeUpdate(); } - insertStmt.executeUpdate(); } } catch (SQLException ex) { ex.printStackTrace(); @@ -410,9 +463,15 @@ public static void addDefaultDataToTable(String tableName, @NotNull Map row = new HashMap<>(); - for (int i = 1; i <= resultSet.getMetaData().getColumnCount(); i++) { - row.put(resultSet.getMetaData().getColumnName(i), resultSet.getObject(i)); + ResultSetMetaData metaData = resultSet.getMetaData(); + + for (int i = 1; i <= metaData.getColumnCount(); i++) { + String columnName = metaData.getColumnName(i); + Object object = resultSet.getObject(i); + row.put(columnName, object); } + rows.add(row); } return rows; @@ -442,12 +506,20 @@ private static void deleteDataFromTable(String tableName, String condition, @NotNull List parameters) { String deleteSQL = String.format("DELETE FROM %s WHERE %s", tableName, condition); - try (Connection connection = (Settings.usingFlatFile ? getSQLiteConnection() : dataSource.getConnection()); - PreparedStatement preparedStatement = Objects.requireNonNull(connection).prepareStatement(deleteSQL)) { - for (int i = 0; i < parameters.size(); i++) { - preparedStatement.setObject(i + 1, parameters.get(i)); + try (Connection connection = (Settings.usingFlatFile ? getSQLiteConnection() : dataSource.getConnection())) { + if (connection == null) { + MessageUtil.log(Level.SEVERE, "Failed to establish a connection to the database."); + return; + } + + try (PreparedStatement preparedStatement = connection.prepareStatement(deleteSQL)) { + for (int i = 0; i < parameters.size(); i++) { + Object obj = parameters.get(i); + preparedStatement.setObject(i + 1, obj); + } + + preparedStatement.executeUpdate(); } - preparedStatement.executeUpdate(); } catch (SQLException ex) { ex.printStackTrace(); } diff --git a/src/main/java/net/foulest/kitpvp/util/MessageUtil.java b/src/main/java/net/foulest/kitpvp/util/MessageUtil.java index 7ff4020..5ecf6b2 100644 --- a/src/main/java/net/foulest/kitpvp/util/MessageUtil.java +++ b/src/main/java/net/foulest/kitpvp/util/MessageUtil.java @@ -17,8 +17,7 @@ */ package net.foulest.kitpvp.util; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; +import lombok.Data; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; @@ -38,9 +37,8 @@ * * @author Foulest */ -@SuppressWarnings("unused") -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public final class MessageUtil { +@Data +public class MessageUtil { private static final Logger logger = Bukkit.getLogger(); diff --git a/src/main/java/net/foulest/kitpvp/util/NMSUtil.java b/src/main/java/net/foulest/kitpvp/util/NMSUtil.java index 8df8c1b..fbd5eb0 100644 --- a/src/main/java/net/foulest/kitpvp/util/NMSUtil.java +++ b/src/main/java/net/foulest/kitpvp/util/NMSUtil.java @@ -17,8 +17,7 @@ */ package net.foulest.kitpvp.util; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; +import lombok.Data; import net.minecraft.server.v1_8_R3.EntityPlayer; import net.minecraft.server.v1_8_R3.PlayerConnection; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; @@ -29,8 +28,8 @@ * * @author Foulest */ -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public final class NMSUtil { +@Data +public class NMSUtil { /** * Gets the NMS ({@link net.minecraft.server}) EntityPlayer for a Bukkit Player. diff --git a/src/main/java/net/foulest/kitpvp/util/PlaceholderUtil.java b/src/main/java/net/foulest/kitpvp/util/PlaceholderUtil.java index 23c48a6..ec10c51 100644 --- a/src/main/java/net/foulest/kitpvp/util/PlaceholderUtil.java +++ b/src/main/java/net/foulest/kitpvp/util/PlaceholderUtil.java @@ -21,6 +21,7 @@ import net.foulest.kitpvp.combattag.CombatTag; import net.foulest.kitpvp.data.PlayerData; import net.foulest.kitpvp.data.PlayerDataManager; +import net.foulest.kitpvp.kits.Kit; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; @@ -49,59 +50,80 @@ public class PlaceholderUtil extends PlaceholderExpansion { @Override public String onPlaceholderRequest(Player player, @NotNull String identifier) { PlayerData playerData = PlayerDataManager.getPlayerData(player); + int bounty = playerData.getBounty(); + StringBuilder builder = new StringBuilder(); switch (identifier) { case "kills": - builder.append(playerData.getKills()); + int kills = playerData.getKills(); + builder.append(kills); break; case "deaths": - builder.append(playerData.getDeaths()); + int deaths = playerData.getDeaths(); + builder.append(deaths); break; case "kdr": - builder.append(playerData.getKDRText()); + String kdrText = playerData.getKDRText(); + builder.append(kdrText); break; case "killstreak": - builder.append(playerData.getKillstreak()); + int killstreak = playerData.getKillstreak(); + builder.append(killstreak); break; case "top_killstreak": - builder.append(playerData.getTopKillstreak()); + int topKillstreak = playerData.getTopKillstreak(); + builder.append(topKillstreak); break; case "coins": - builder.append(playerData.getCoins()); + int coins = playerData.getCoins(); + builder.append(coins); break; case "level": - builder.append(playerData.getLevel()); + int level = playerData.getLevel(); + builder.append(level); break; case "experience": - builder.append(playerData.getExperience()); + int experience = playerData.getExperience(); + builder.append(experience); break; case "experience_percent": - builder.append(playerData.getExpPercent()).append("%"); + int expPercent = playerData.getExpPercent(); + builder.append(expPercent).append("%"); break; case "combattag": - builder.append(CombatTag.isInCombat(player) ? "&c00:" + String.format("%02d", CombatTag.getRemainingTime(player)) : "&aSafe"); + builder.append(CombatTag.isInCombat(player) + ? "&c00:" + String.format("%02d", CombatTag.getRemainingTime(player)) + : "&aSafe"); break; case "activekit": - builder.append(playerData.getActiveKit() == null ? "None" : playerData.getActiveKit().getName()); + Kit activeKit = playerData.getActiveKit(); + + if (activeKit == null) { + builder.append("None"); + break; + } + + String kitName = activeKit.getName(); + builder.append(kitName); break; case "bounty": - builder.append(playerData.getBounty() == 0 ? "" : playerData.getBounty()); + builder.append(bounty == 0 ? "" : bounty); break; case "bounty_tab": - builder.append(playerData.getBounty() == 0 ? "" : "&6Bounty: &e&l$" + playerData.getBounty()); + builder.append(bounty == 0 ? "" : "&6Bounty: &e&l$" + bounty); break; default: diff --git a/src/main/java/net/foulest/kitpvp/util/Settings.java b/src/main/java/net/foulest/kitpvp/util/Settings.java index 298f4dd..1b0bae1 100644 --- a/src/main/java/net/foulest/kitpvp/util/Settings.java +++ b/src/main/java/net/foulest/kitpvp/util/Settings.java @@ -17,7 +17,8 @@ */ package net.foulest.kitpvp.util; -import lombok.*; +import lombok.Cleanup; +import lombok.Data; import net.foulest.kitpvp.KitPvP; import net.foulest.kitpvp.util.yaml.CustomYamlConfiguration; import org.bukkit.configuration.file.FileConfiguration; @@ -34,11 +35,8 @@ * * @author Foulest */ -@Getter -@Setter -@NoArgsConstructor(access = AccessLevel.PRIVATE) -@SuppressWarnings("WeakerAccess") -public final class Settings { +@Data +public class Settings { // File settings public static File file; @@ -93,139 +91,55 @@ public final class Settings { public static boolean powerEnabled; public static int powerCost; - // Knight kit settings - public static boolean knightKitEnabled; - public static int knightKitCost; - // Archer kit settings public static boolean archerKitEnabled; public static int archerKitCost; - - // Burrower kit settings - public static boolean burrowerKitEnabled; - public static int burrowerKitCost; - public static int burrowerKitCooldown; - public static int burrowerKitDuration; - - // Cactus kit settings - public static boolean cactusKitEnabled; - public static int cactusKitCost; - public static int cactusKitPassiveDuration; - - // Dragon kit settings - public static boolean dragonKitEnabled; - public static int dragonKitCost; - public static int dragonKitCooldown; - public static int dragonKitDuration; - public static int dragonKitRange; - public static int dragonKitDamage; + public static int archerKitCooldown; + public static int archerKitDuration; // Fisherman kit settings public static boolean fishermanKitEnabled; public static int fishermanKitCost; public static int fishermanKitCooldown; - // Ghost kit settings - public static boolean ghostKitEnabled; - public static int ghostKitCost; - public static int ghostKitRange; - - // Hulk kit settings - public static boolean hulkKitEnabled; - public static int hulkKitCost; - public static int hulkKitCooldown; - public static int hulkKitRange; - public static int hulkKitDamage; - public static double hulkKitMultiplier; - - // Imprisoner kit settings - public static boolean imprisonerKitEnabled; - public static int imprisonerKitCost; - public static int imprisonerKitCooldown; - public static int imprisonerKitDuration; - public static int imprisonerKitDamage; - public static int imprisonerKitHeight; - // Kangaroo kit settings public static boolean kangarooKitEnabled; public static int kangarooKitCost; public static int kangarooKitCooldown; - public static double kangarooKitSneakingHeight; - public static double kangarooKitSneakingMultiplier; - public static double kangarooKitNormalHeight; - public static double kangarooKitNormalMultiplier; + + // Knight kit settings + public static boolean knightKitEnabled; + public static int knightKitCost; // Mage kit settings public static boolean mageKitEnabled; public static int mageKitCost; public static int mageKitCooldown; - // Monk kit settings - public static boolean monkKitEnabled; - public static int monkKitCost; - public static int monkKitCooldown; - // Ninja kit settings public static boolean ninjaKitEnabled; public static int ninjaKitCost; + public static int ninjaKitCooldown; + public static int ninjaKitDuration; // Pyro kit settings public static boolean pyroKitEnabled; public static int pyroKitCost; - - // Spiderman kit settings - public static boolean spidermanKitEnabled; - public static int spidermanKitCost; - public static int spidermanKitCooldown; - public static int spidermanKitDuration; - - // Summoner kit settings - public static boolean summonerKitEnabled; - public static int summonerKitCost; - public static int summonerKitCooldown; - public static int summonerKitDuration; - public static int summonerKitRange; - - // Tamer kit settings - public static boolean tamerKitEnabled; - public static int tamerKitCost; - public static int tamerKitCooldown; - public static int tamerKitDuration; - public static int tamerKitAmount; + public static int pyroKitCooldown; + public static int pyroKitDuration; + public static double pyroKitDamage; // Tank kit settings public static boolean tankKitEnabled; public static int tankKitCost; - - // Thor kit settings - public static boolean thorKitEnabled; - public static int thorKitCost; - public static int thorKitCooldown; - public static int thorKitDuration; - public static int thorKitRange; - public static int thorKitDamage; - - // Timelord kit settings - public static boolean timelordKitEnabled; - public static int timelordKitCost; - public static int timelordKitCooldown; - public static int timelordKitDuration; - public static int timelordKitRange; + public static int tankKitCooldown; + public static int tankKitDuration; // Vampire kit settings public static boolean vampireKitEnabled; public static int vampireKitCost; - public static int vampireKitPassiveDuration; public static int vampireKitCooldown; public static int vampireKitDuration; - public static int vampireKitRange; - - // Zen kit settings - public static boolean zenKitEnabled; - public static int zenKitCost; - public static int zenKitCooldown; - public static int zenKitDuration; - public static int zenKitRange; // Database settings public static boolean usingFlatFile; @@ -248,7 +162,7 @@ public static void loadSettings() { /** * Initializes the configuration file and loads defaults. */ - @SuppressWarnings("OverlyBroadCatchBlock") + @SuppressWarnings({"WeakerAccess", "OverlyBroadCatchBlock"}) public static void loadConfigFile() { try { // First, attempt to load the default configuration as a stream to check if it exists in the plugin JAR @@ -297,6 +211,7 @@ public static void saveConfig() { /** * Loads configuration values into the relevant static fields. */ + @SuppressWarnings("WeakerAccess") public static void loadConfigValues() { // Spawn settings spawnWorld = config.getString("kitpvp.spawn.world"); @@ -346,138 +261,55 @@ public static void loadConfigValues() { powerEnabled = config.getBoolean("kitpvp.kit-enchanter.power.enabled"); powerCost = config.getInt("kitpvp.kit-enchanter.power.cost"); - // Knight kit settings - knightKitEnabled = config.getBoolean("kitpvp.kits.knight.enabled"); - knightKitCost = config.getInt("kitpvp.kits.knight.cost"); - // Archer kit settings archerKitEnabled = config.getBoolean("kitpvp.kits.archer.enabled"); archerKitCost = config.getInt("kitpvp.kits.archer.cost"); - - // Burrower kit settings - burrowerKitEnabled = config.getBoolean("kitpvp.kits.burrower.enabled"); - burrowerKitCost = config.getInt("kitpvp.kits.burrower.cost"); - burrowerKitCooldown = config.getInt("kitpvp.kits.burrower.ability.cooldown"); - burrowerKitDuration = config.getInt("kitpvp.kits.burrower.ability.duration"); - - // Cactus kit settings - cactusKitEnabled = config.getBoolean("kitpvp.kits.cactus.enabled"); - cactusKitCost = config.getInt("kitpvp.kits.cactus.cost"); - cactusKitPassiveDuration = config.getInt("kitpvp.kits.cactus.passive.duration"); - - // Dragon kit settings - dragonKitEnabled = config.getBoolean("kitpvp.kits.dragon.enabled"); - dragonKitCost = config.getInt("kitpvp.kits.dragon.cost"); - dragonKitCooldown = config.getInt("kitpvp.kits.dragon.ability.cooldown"); - dragonKitDuration = config.getInt("kitpvp.kits.dragon.ability.duration"); - dragonKitRange = config.getInt("kitpvp.kits.dragon.ability.range"); - dragonKitDamage = config.getInt("kitpvp.kits.dragon.ability.damage"); + archerKitCooldown = config.getInt("kitpvp.kits.archer.ability.cooldown"); + archerKitDuration = config.getInt("kitpvp.kits.archer.ability.duration"); // Fisherman kit settings fishermanKitEnabled = config.getBoolean("kitpvp.kits.fisherman.enabled"); fishermanKitCost = config.getInt("kitpvp.kits.fisherman.cost"); fishermanKitCooldown = config.getInt("kitpvp.kits.fisherman.ability.cooldown"); - // Ghost kit settings - ghostKitEnabled = config.getBoolean("kitpvp.kits.ghost.enabled"); - ghostKitCost = config.getInt("kitpvp.kits.ghost.cost"); - - // Hulk kit settings - hulkKitEnabled = config.getBoolean("kitpvp.kits.hulk.enabled"); - hulkKitCost = config.getInt("kitpvp.kits.hulk.cost"); - hulkKitCooldown = config.getInt("kitpvp.kits.hulk.ability.cooldown"); - hulkKitRange = config.getInt("kitpvp.kits.hulk.ability.range"); - hulkKitDamage = config.getInt("kitpvp.kits.hulk.ability.damage"); - hulkKitMultiplier = config.getDouble("kitpvp.kits.hulk.ability.multiplier"); - - // Imprisoner kit settings - imprisonerKitEnabled = config.getBoolean("kitpvp.kits.imprisoner.enabled"); - imprisonerKitCost = config.getInt("kitpvp.kits.imprisoner.cost"); - imprisonerKitCooldown = config.getInt("kitpvp.kits.imprisoner.ability.cooldown"); - imprisonerKitDuration = config.getInt("kitpvp.kits.imprisoner.ability.duration"); - imprisonerKitDamage = config.getInt("kitpvp.kits.imprisoner.ability.damage"); - imprisonerKitHeight = config.getInt("kitpvp.kits.imprisoner.ability.height"); - // Kangaroo kit settings kangarooKitEnabled = config.getBoolean("kitpvp.kits.kangaroo.enabled"); kangarooKitCost = config.getInt("kitpvp.kits.kangaroo.cost"); kangarooKitCooldown = config.getInt("kitpvp.kits.kangaroo.ability.cooldown"); - kangarooKitSneakingHeight = config.getDouble("kitpvp.kits.kangaroo.ability.sneaking.height"); - kangarooKitSneakingMultiplier = config.getDouble("kitpvp.kits.kangaroo.ability.sneaking.multiplier"); - kangarooKitNormalHeight = config.getDouble("kitpvp.kits.kangaroo.ability.normal.height"); - kangarooKitNormalMultiplier = config.getDouble("kitpvp.kits.kangaroo.ability.normal.multiplier"); + + // Knight kit settings + knightKitEnabled = config.getBoolean("kitpvp.kits.knight.enabled"); + knightKitCost = config.getInt("kitpvp.kits.knight.cost"); // Mage kit settings mageKitEnabled = config.getBoolean("kitpvp.kits.mage.enabled"); mageKitCost = config.getInt("kitpvp.kits.mage.cost"); mageKitCooldown = config.getInt("kitpvp.kits.mage.ability.cooldown"); - // Monk kit settings - monkKitEnabled = config.getBoolean("kitpvp.kits.monk.enabled"); - monkKitCost = config.getInt("kitpvp.kits.monk.cost"); - monkKitCooldown = config.getInt("kitpvp.kits.monk.ability.cooldown"); - // Ninja kit settings ninjaKitEnabled = config.getBoolean("kitpvp.kits.ninja.enabled"); ninjaKitCost = config.getInt("kitpvp.kits.ninja.cost"); + ninjaKitCooldown = config.getInt("kitpvp.kits.ninja.ability.cooldown"); + ninjaKitDuration = config.getInt("kitpvp.kits.ninja.ability.duration"); // Pyro kit settings pyroKitEnabled = config.getBoolean("kitpvp.kits.pyro.enabled"); pyroKitCost = config.getInt("kitpvp.kits.pyro.cost"); - - // Spiderman kit settings - spidermanKitEnabled = config.getBoolean("kitpvp.kits.spiderman.enabled"); - spidermanKitCost = config.getInt("kitpvp.kits.spiderman.cost"); - spidermanKitCooldown = config.getInt("kitpvp.kits.spiderman.ability.cooldown"); - spidermanKitDuration = config.getInt("kitpvp.kits.spiderman.ability.duration"); - - // Summoner kit settings - summonerKitEnabled = config.getBoolean("kitpvp.kits.summoner.enabled"); - summonerKitCost = config.getInt("kitpvp.kits.summoner.cost"); - summonerKitCooldown = config.getInt("kitpvp.kits.summoner.ability.cooldown"); - summonerKitDuration = config.getInt("kitpvp.kits.summoner.ability.duration"); - summonerKitRange = config.getInt("kitpvp.kits.summoner.ability.range"); - - // Tamer kit settings - tamerKitEnabled = config.getBoolean("kitpvp.kits.tamer.enabled"); - tamerKitCost = config.getInt("kitpvp.kits.tamer.cost"); - tamerKitCooldown = config.getInt("kitpvp.kits.tamer.ability.cooldown"); - tamerKitDuration = config.getInt("kitpvp.kits.tamer.ability.duration"); - tamerKitAmount = config.getInt("kitpvp.kits.tamer.ability.amount"); + pyroKitCooldown = config.getInt("kitpvp.kits.pyro.ability.cooldown"); + pyroKitDuration = config.getInt("kitpvp.kits.pyro.ability.duration"); + pyroKitDamage = config.getDouble("kitpvp.kits.pyro.ability.damage"); // Tank kit settings tankKitEnabled = config.getBoolean("kitpvp.kits.tank.enabled"); tankKitCost = config.getInt("kitpvp.kits.tank.cost"); - - // Thor kit settings - thorKitEnabled = config.getBoolean("kitpvp.kits.thor.enabled"); - thorKitCost = config.getInt("kitpvp.kits.thor.cost"); - thorKitCooldown = config.getInt("kitpvp.kits.thor.ability.cooldown"); - thorKitDuration = config.getInt("kitpvp.kits.thor.ability.duration"); - thorKitRange = config.getInt("kitpvp.kits.thor.ability.range"); - thorKitDamage = config.getInt("kitpvp.kits.thor.ability.damage"); - - // Timelord kit settings - timelordKitEnabled = config.getBoolean("kitpvp.kits.timelord.enabled"); - timelordKitCost = config.getInt("kitpvp.kits.timelord.cost"); - timelordKitCooldown = config.getInt("kitpvp.kits.timelord.ability.cooldown"); - timelordKitDuration = config.getInt("kitpvp.kits.timelord.ability.duration"); - timelordKitRange = config.getInt("kitpvp.kits.timelord.ability.range"); + tankKitCooldown = config.getInt("kitpvp.kits.tank.ability.cooldown"); + tankKitDuration = config.getInt("kitpvp.kits.tank.ability.duration"); // Vampire kit settings vampireKitEnabled = config.getBoolean("kitpvp.kits.vampire.enabled"); vampireKitCost = config.getInt("kitpvp.kits.vampire.cost"); - vampireKitPassiveDuration = config.getInt("kitpvp.kits.vampire.passive.duration"); vampireKitCooldown = config.getInt("kitpvp.kits.vampire.ability.cooldown"); vampireKitDuration = config.getInt("kitpvp.kits.vampire.ability.duration"); - vampireKitRange = config.getInt("kitpvp.kits.vampire.ability.range"); - - // Zen kit settings - zenKitEnabled = config.getBoolean("kitpvp.kits.zen.enabled"); - zenKitCost = config.getInt("kitpvp.kits.zen.cost"); - zenKitCooldown = config.getInt("kitpvp.kits.zen.ability.cooldown"); - zenKitDuration = config.getInt("kitpvp.kits.zen.ability.duration"); - zenKitRange = config.getInt("kitpvp.kits.zen.ability.range"); // Database settings usingFlatFile = config.getString("kitpvp.storage.type").trim().equalsIgnoreCase("sqlite"); diff --git a/src/main/java/net/foulest/kitpvp/util/TaskUtil.java b/src/main/java/net/foulest/kitpvp/util/TaskUtil.java index 7fba0fa..178bca9 100644 --- a/src/main/java/net/foulest/kitpvp/util/TaskUtil.java +++ b/src/main/java/net/foulest/kitpvp/util/TaskUtil.java @@ -17,10 +17,7 @@ */ package net.foulest.kitpvp.util; -import lombok.AccessLevel; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; +import lombok.Data; import net.foulest.kitpvp.KitPvP; import org.bukkit.Bukkit; import org.bukkit.scheduler.BukkitTask; @@ -28,11 +25,8 @@ import java.util.List; -@Getter -@Setter -@SuppressWarnings("unused") -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public final class TaskUtil { +@Data +public class TaskUtil { public static void runTask(Runnable runnable) { Bukkit.getScheduler().runTask(KitPvP.instance, runnable); diff --git a/src/main/java/net/foulest/kitpvp/util/command/BukkitCompleter.java b/src/main/java/net/foulest/kitpvp/util/command/BukkitCompleter.java index 8db0bcf..19c43a1 100644 --- a/src/main/java/net/foulest/kitpvp/util/command/BukkitCompleter.java +++ b/src/main/java/net/foulest/kitpvp/util/command/BukkitCompleter.java @@ -17,8 +17,7 @@ */ package net.foulest.kitpvp.util.command; -import lombok.Getter; -import lombok.Setter; +import lombok.Data; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; @@ -35,8 +34,7 @@ * @author minnymin3 * @see CommandFramework GitHub */ -@Getter -@Setter +@Data public class BukkitCompleter implements TabCompleter { private final Map> completers = new HashMap<>(); @@ -69,11 +67,13 @@ public List onTabComplete(@NotNull CommandSender sender, String @NotNull [] args) { for (int i = args.length; i >= 0; i--) { StringBuilder buffer = new StringBuilder(); - buffer.append(label.toLowerCase(Locale.ROOT)); + String labelLower = label.toLowerCase(Locale.ROOT); + buffer.append(labelLower); for (int x = 0; x < i; x++) { if (!args[x].isEmpty() && !(" ").equals(args[x])) { - buffer.append(".").append(args[x].toLowerCase(Locale.ROOT)); + String argsLower = args[x].toLowerCase(Locale.ROOT); + buffer.append(".").append(argsLower); } } @@ -83,8 +83,11 @@ public List onTabComplete(@NotNull CommandSender sender, Map.Entry entry = completers.get(cmdLabel); try { - return (List) entry.getKey().invoke(entry.getValue(), - new CommandArgs(sender, command, label, args, cmdLabel.split("\\.").length - 1)); + Object entryValue = entry.getValue(); + String[] split = cmdLabel.split("\\."); + + return (List) entry.getKey().invoke(entryValue, + new CommandArgs(sender, command, label, args, split.length - 1)); } catch (IllegalArgumentException | InvocationTargetException | IllegalAccessException ex) { ex.printStackTrace(); } diff --git a/src/main/java/net/foulest/kitpvp/util/command/CommandArgs.java b/src/main/java/net/foulest/kitpvp/util/command/CommandArgs.java index 4fdd33b..64478ab 100644 --- a/src/main/java/net/foulest/kitpvp/util/command/CommandArgs.java +++ b/src/main/java/net/foulest/kitpvp/util/command/CommandArgs.java @@ -17,8 +17,7 @@ */ package net.foulest.kitpvp.util.command; -import lombok.Getter; -import lombok.Setter; +import lombok.Data; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; @@ -32,9 +31,8 @@ * @author minnymin3 * @see CommandFramework GitHub */ +@Data @SuppressWarnings("WeakerAccess") -@Getter -@Setter public class CommandArgs { private final CommandSender sender; diff --git a/src/main/java/net/foulest/kitpvp/util/command/CommandFramework.java b/src/main/java/net/foulest/kitpvp/util/command/CommandFramework.java index edcb932..4c497ac 100644 --- a/src/main/java/net/foulest/kitpvp/util/command/CommandFramework.java +++ b/src/main/java/net/foulest/kitpvp/util/command/CommandFramework.java @@ -17,8 +17,7 @@ */ package net.foulest.kitpvp.util.command; -import lombok.Getter; -import lombok.Setter; +import lombok.Data; import net.foulest.kitpvp.util.ConstantUtil; import net.foulest.kitpvp.util.MessageUtil; import org.bukkit.command.*; @@ -40,8 +39,7 @@ * @author minnymin3 * @see CommandFramework GitHub */ -@Getter -@Setter +@Data public class CommandFramework implements CommandExecutor { private final Map> commandMap = new HashMap<>(); @@ -75,7 +73,8 @@ public CommandFramework(@NotNull Plugin plugin) { * @param args The CommandArgs object representing the command arguments. */ private static void defaultCommand(@NotNull CommandArgs args) { - args.getSender().sendMessage(args.getLabel() + " is disabled on this server."); + String label = args.getLabel(); + args.getSender().sendMessage(label + " is disabled on this server."); } @Override @@ -101,10 +100,13 @@ private void handleCommand(CommandSender sender, String @NotNull [] args) { for (int i = args.length; i >= 0; i--) { StringBuilder buffer = new StringBuilder(); - buffer.append(label.toLowerCase(Locale.ROOT)); + + String labelLower = label.toLowerCase(Locale.ROOT); + buffer.append(labelLower); for (int x = 0; x < i; x++) { - buffer.append(".").append(args[x].toLowerCase(Locale.ROOT)); + String argsLower = args[x].toLowerCase(Locale.ROOT); + buffer.append(".").append(argsLower); } String cmdLabel = buffer.toString(); @@ -114,21 +116,33 @@ private void handleCommand(CommandSender sender, Object value = commandMap.get(cmdLabel).getValue(); Command command = key.getAnnotation(Command.class); - if (command.inGameOnly() && !(sender instanceof Player)) { - MessageUtil.messagePlayer(sender, "&cOnly players may execute this command."); - return; + if (command.inGameOnly()) { + if (!(sender instanceof Player)) { + MessageUtil.messagePlayer(sender, ConstantUtil.IN_GAME_ONLY); + return; + } + + Player player = (Player) sender; + + if (!player.isOnline()) { + MessageUtil.messagePlayer(sender, ConstantUtil.IN_GAME_ONLY); + return; + } } - if (!("").equals(command.permission()) - && !sender.hasPermission(command.permission()) + String permission = command.permission(); + + if (!("").equals(permission) + && !sender.hasPermission(permission) && !(sender instanceof ConsoleCommandSender)) { - MessageUtil.messagePlayer(sender, command.noPermission()); + String noPermission = command.noPermission(); + MessageUtil.messagePlayer(sender, noPermission); return; } try { - key.invoke(value, new CommandArgs(sender, cmd, label, args, - cmdLabel.split("\\.").length - 1)); + String[] split = cmdLabel.split("\\."); + key.invoke(value, new CommandArgs(sender, cmd, label, args, split.length - 1)); } catch (IllegalArgumentException | IllegalAccessException | InvocationTargetException ex) { ex.printStackTrace(); } @@ -148,20 +162,21 @@ public void registerCommands(@NotNull Object obj) { for (Method method : obj.getClass().getMethods()) { Command command = method.getAnnotation(Command.class); Completer completer = method.getAnnotation(Completer.class); + String methodName = method.getName(); boolean invalidMethod = false; if (command != null) { if (method.getParameterTypes().length > 1 || method.getParameterTypes()[0] != CommandArgs.class) { MessageUtil.log(Level.WARNING, "Unable to register command: " - + method.getName() + "; unexpected method arguments."); + + methodName + "; unexpected method arguments."); invalidMethod = true; } } else if (completer != null && (method.getParameterTypes().length != 1 || method.getParameterTypes()[0] != CommandArgs.class || method.getReturnType() != List.class)) { MessageUtil.log(Level.WARNING, ConstantUtil.UNABLE_TO_REGISTER_TAB_COMPLETER - + method.getName() + "; unexpected method arguments or return type."); + + methodName + "; unexpected method arguments or return type."); invalidMethod = true; } @@ -170,13 +185,15 @@ public void registerCommands(@NotNull Object obj) { } if (command != null) { - registerCommand(command, command.name(), method, obj); + String commandName = command.name(); + registerCommand(command, commandName, method, obj); for (String alias : command.aliases()) { registerCommand(command, alias, method, obj); } } else if (completer != null) { - registerCompleter(completer.name(), method, obj); + String commandName = completer.name(); + registerCompleter(commandName, method, obj); for (String alias : completer.aliases()) { registerCompleter(alias, method, obj); @@ -193,26 +210,35 @@ public void registerCommands(@NotNull Object obj) { * @param method The method representing the command handler. * @param obj The object containing the command method. */ - private void registerCommand(@NotNull Command command, - @NotNull String label, - Method method, - Object obj) { - commandMap.put(label.toLowerCase(Locale.ROOT), new AbstractMap.SimpleEntry<>(method, obj)); - commandMap.put(plugin.getName() + ':' + label.toLowerCase(Locale.ROOT), new AbstractMap.SimpleEntry<>(method, obj)); + private void registerCommand(@NotNull Command command, @NotNull String label, Method method, Object obj) { + String pluginName = plugin.getName(); + String lowerCase = label.toLowerCase(Locale.ROOT); + + commandMap.put(lowerCase, new AbstractMap.SimpleEntry<>(method, obj)); + commandMap.put(pluginName + ':' + lowerCase, new AbstractMap.SimpleEntry<>(method, obj)); String cmdLabel = label.replace(".", ",").split(",")[0].toLowerCase(Locale.ROOT); + org.bukkit.command.Command mapCommand = map.getCommand(cmdLabel); - if (map.getCommand(cmdLabel) == null) { + if (mapCommand == null) { org.bukkit.command.Command cmd = new BukkitCommand(cmdLabel, this, plugin); - map.register(plugin.getName(), cmd); + map.register(pluginName, cmd); } - if (!("").equalsIgnoreCase(command.description()) && cmdLabel.equalsIgnoreCase(label)) { - Objects.requireNonNull(map.getCommand(cmdLabel)).setDescription(command.description()); + String description = command.description(); + + if (mapCommand != null + && !description.equalsIgnoreCase("") + && cmdLabel.equalsIgnoreCase(label)) { + mapCommand.setDescription(description); } - if (!("").equalsIgnoreCase(command.usage()) && cmdLabel.equalsIgnoreCase(label)) { - Objects.requireNonNull(map.getCommand(cmdLabel)).setUsage(command.usage()); + String usage = command.usage(); + + if (mapCommand != null + && !usage.equalsIgnoreCase("") + && cmdLabel.equalsIgnoreCase(label)) { + mapCommand.setUsage(usage); } } @@ -223,12 +249,14 @@ private void registerCommand(@NotNull Command command, * @param method The method representing the tab completer. * @param obj The object containing the tab completer method. */ - private void registerCompleter(@NotNull String label, Method method, Object obj) { + private void registerCompleter(@NotNull String label, @NotNull Method method, Object obj) { String cmdLabel = label.replace(".", ",").split(",")[0].toLowerCase(Locale.ROOT); + String pluginName = plugin.getName(); + String methodName = method.getName(); if (map.getCommand(cmdLabel) == null) { org.bukkit.command.Command command = new BukkitCommand(cmdLabel, this, plugin); - map.register(plugin.getName(), command); + map.register(pluginName, command); } if (map.getCommand(cmdLabel) instanceof BukkitCommand) { @@ -236,7 +264,7 @@ private void registerCompleter(@NotNull String label, Method method, Object obj) if (command == null) { MessageUtil.log(Level.WARNING, ConstantUtil.UNABLE_TO_REGISTER_TAB_COMPLETER - + method.getName() + "; a command with that name doesn't exist."); + + methodName + "; a command with that name doesn't exist."); return; } @@ -252,7 +280,7 @@ private void registerCompleter(@NotNull String label, Method method, Object obj) if (command == null) { MessageUtil.log(Level.WARNING, ConstantUtil.UNABLE_TO_REGISTER_TAB_COMPLETER - + method.getName() + "; a command with that name doesn't exist."); + + methodName + "; a command with that name doesn't exist."); return; } @@ -270,7 +298,7 @@ private void registerCompleter(@NotNull String label, Method method, Object obj) } else { MessageUtil.log(Level.WARNING, ConstantUtil.UNABLE_TO_REGISTER_TAB_COMPLETER - + method.getName() + "; a tab completer is already registered for that command."); + + methodName + "; a tab completer is already registered for that command."); } } catch (IllegalAccessException | NoSuchFieldException ex) { ex.printStackTrace(); diff --git a/src/main/java/net/foulest/kitpvp/util/data/ConcurrentStream.java b/src/main/java/net/foulest/kitpvp/util/data/ConcurrentStream.java index 490f697..f3d18f7 100644 --- a/src/main/java/net/foulest/kitpvp/util/data/ConcurrentStream.java +++ b/src/main/java/net/foulest/kitpvp/util/data/ConcurrentStream.java @@ -17,8 +17,7 @@ */ package net.foulest.kitpvp.util.data; -import lombok.Getter; -import lombok.Setter; +import lombok.Data; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; @@ -35,10 +34,8 @@ * @see Stream * @author Foulest */ -@Getter -@Setter -@SuppressWarnings("unused") -public final class ConcurrentStream { +@Data +public class ConcurrentStream { /** * The supplier of the stream. diff --git a/src/main/java/net/foulest/kitpvp/util/item/ItemBuilder.java b/src/main/java/net/foulest/kitpvp/util/item/ItemBuilder.java index 1375162..0ee655f 100644 --- a/src/main/java/net/foulest/kitpvp/util/item/ItemBuilder.java +++ b/src/main/java/net/foulest/kitpvp/util/item/ItemBuilder.java @@ -17,8 +17,7 @@ */ package net.foulest.kitpvp.util.item; -import lombok.Getter; -import lombok.ToString; +import lombok.Data; import net.foulest.kitpvp.util.MessageUtil; import org.bukkit.Color; import org.bukkit.Material; @@ -39,9 +38,7 @@ * @author nonamesldev * @see Spigot Thread */ -@Getter -@ToString -@SuppressWarnings("unused") +@Data public class ItemBuilder { private final ItemStack item; @@ -216,7 +213,8 @@ public ItemBuilder clearEnchantment(Enchantment enchantment) { */ public ItemBuilder enchant(Enchantment enchantment, int level) { if (item.containsEnchantment(enchantment)) { - item.addUnsafeEnchantment(enchantment, level + item.getEnchantmentLevel(enchantment)); + int enchantmentLevel = item.getEnchantmentLevel(enchantment); + item.addUnsafeEnchantment(enchantment, level + enchantmentLevel); } else { item.addUnsafeEnchantment(enchantment, level); } diff --git a/src/main/java/net/foulest/kitpvp/util/item/SkullBuilder.java b/src/main/java/net/foulest/kitpvp/util/item/SkullBuilder.java index 4585013..1612d1c 100644 --- a/src/main/java/net/foulest/kitpvp/util/item/SkullBuilder.java +++ b/src/main/java/net/foulest/kitpvp/util/item/SkullBuilder.java @@ -19,8 +19,7 @@ import com.mojang.authlib.GameProfile; import com.mojang.authlib.properties.Property; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; +import lombok.Data; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.SkullType; @@ -46,8 +45,8 @@ * @author deanveloper * @see SkullCreator GitHub */ -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public final class SkullBuilder { +@Data +public class SkullBuilder { private static Field blockProfileField; private static Method metaSetProfileMethod; @@ -136,7 +135,9 @@ public final class SkullBuilder { @Contract("_, _ -> param1") private static @NotNull ItemStack itemWithUuid(@NotNull ItemStack item, UUID id) { SkullMeta meta = (SkullMeta) item.getItemMeta(); - meta.setOwner(Bukkit.getOfflinePlayer(id).getName()); + String playerName = Bukkit.getOfflinePlayer(id).getName(); + + meta.setOwner(playerName); item.setItemMeta(meta); return item; } @@ -194,8 +195,11 @@ public static void blockWithName(@NotNull Block block, String name) { */ private static void blockWithUuid(Block block, UUID id) { setToSkull(block); + Skull state = (Skull) block.getState(); - state.setOwner(Bukkit.getOfflinePlayer(id).getName()); + String playerName = Bukkit.getOfflinePlayer(id).getName(); + + state.setOwner(playerName); state.update(false, false); } @@ -260,7 +264,8 @@ private static String urlToBase64(String url) { } String toEncode = "{\"textures\":{\"SKIN\":{\"url\":\"" + actualUrl + "\"}}}"; - return Base64.getEncoder().encodeToString(toEncode.getBytes(StandardCharsets.UTF_8)); + byte[] bytes = toEncode.getBytes(StandardCharsets.UTF_8); + return Base64.getEncoder().encodeToString(bytes); } /** @@ -270,8 +275,11 @@ private static String urlToBase64(String url) { * @return The GameProfile with the specified texture. */ private static @NotNull GameProfile makeProfile(@NotNull String b64) { - UUID id = new UUID(b64.substring(b64.length() - 20).hashCode(), - b64.substring(b64.length() - 10).hashCode()); + int length = b64.length(); + int mostSigBits = b64.substring(length - 20).hashCode(); + int leastSigBits = b64.substring(length - 10).hashCode(); + UUID id = new UUID(mostSigBits, leastSigBits); + GameProfile profile = new GameProfile(id, "aaaaa"); profile.getProperties().put("textures", new Property("textures", b64)); return profile; diff --git a/src/main/java/net/foulest/kitpvp/util/raytrace/BoundingBox.java b/src/main/java/net/foulest/kitpvp/util/raytrace/BoundingBox.java index 858ef11..345316f 100644 --- a/src/main/java/net/foulest/kitpvp/util/raytrace/BoundingBox.java +++ b/src/main/java/net/foulest/kitpvp/util/raytrace/BoundingBox.java @@ -18,13 +18,13 @@ package net.foulest.kitpvp.util.raytrace; import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.Setter; -import lombok.ToString; +import lombok.Data; import net.minecraft.server.v1_8_R3.AxisAlignedBB; import net.minecraft.server.v1_8_R3.BlockPosition; import net.minecraft.server.v1_8_R3.IBlockData; +import net.minecraft.server.v1_8_R3.WorldServer; import org.bukkit.Location; +import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity; @@ -42,11 +42,8 @@ *

* ... */ -@Getter -@Setter -@ToString +@Data @AllArgsConstructor -@SuppressWarnings("unused") public class BoundingBox { private Vector min; @@ -56,13 +53,28 @@ public class BoundingBox { * Gets the min and max point of a block. */ private BoundingBox(@NotNull Block block) { - IBlockData blockData = ((CraftWorld) block.getWorld()).getHandle().getType(new BlockPosition(block.getX(), block.getY(), block.getZ())); + int blockX = block.getX(); + int blockY = block.getY(); + int blockZ = block.getZ(); + + World world = block.getWorld(); + WorldServer worldHandle = ((CraftWorld) world).getHandle(); + + IBlockData blockData = worldHandle.getType(new BlockPosition(blockX, blockY, blockZ)); net.minecraft.server.v1_8_R3.Block blockNative = blockData.getBlock(); - blockNative.updateShape(((CraftWorld) block.getWorld()).getHandle(), new BlockPosition(block.getX(), block.getY(), block.getZ())); + blockNative.updateShape(worldHandle, new BlockPosition(blockX, blockY, blockZ)); + + double minX = blockNative.B(); + double minY = blockNative.D(); + double minZ = blockNative.F(); + + double maxX = blockNative.C(); + double maxY = blockNative.E(); + double maxZ = blockNative.G(); - min = new Vector(block.getX() + blockNative.B(), block.getY() + blockNative.D(), block.getZ() + blockNative.F()); - max = new Vector(block.getX() + blockNative.C(), block.getY() + blockNative.E(), block.getZ() + blockNative.G()); + min = new Vector(blockX + minX, blockY + minY, blockZ + minZ); + max = new Vector(blockX + maxX, blockY + maxY, blockZ + maxZ); } /** @@ -192,13 +204,17 @@ public List getCollidingBlocks(Player player) { for (int x = min.getBlockX(); x <= max.getBlockX(); x++) { for (int y = min.getBlockY(); y <= max.getBlockY(); y++) { for (int z = min.getBlockZ(); z <= max.getBlockZ(); z++) { - Location loc = new Location(player.getWorld(), x, y, z); + World world = player.getWorld(); + Location loc = new Location(world, x, y, z); + int blockX = loc.getBlockX(); + int blockZ = loc.getBlockZ(); - if (loc.getWorld().isChunkLoaded(loc.getBlockX() >> 4, loc.getBlockZ() >> 4)) { - BoundingBox boundingBox = new BoundingBox(loc.getBlock()); + if (loc.getWorld().isChunkLoaded(blockX >> 4, blockZ >> 4)) { + Block block = loc.getBlock(); + BoundingBox boundingBox = new BoundingBox(block); if (boundingBox.collidesWith(this)) { - blocks.add(loc.getBlock()); + blocks.add(block); } } } diff --git a/src/main/java/net/foulest/kitpvp/util/yaml/CustomYamlConfiguration.java b/src/main/java/net/foulest/kitpvp/util/yaml/CustomYamlConfiguration.java index c24126c..48d7c4e 100644 --- a/src/main/java/net/foulest/kitpvp/util/yaml/CustomYamlConfiguration.java +++ b/src/main/java/net/foulest/kitpvp/util/yaml/CustomYamlConfiguration.java @@ -29,6 +29,7 @@ import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; +import java.util.stream.Collectors; /** * CustomYamlConfiguration is an extension of YamlConfiguration @@ -151,15 +152,8 @@ public void load(File file) throws IOException, InvalidConfigurationException { @Override public void load(Reader reader) throws IOException, InvalidConfigurationException { @Cleanup BufferedReader input = reader instanceof BufferedReader ? (BufferedReader) reader : new BufferedReader(reader); - StringBuilder builder = new StringBuilder(); - String line; - - while ((line = input.readLine()) != null) { - builder.append(line); - builder.append('\n'); - } - - loadFromString(builder.toString()); + String builder = input.lines().map(line -> line + '\n').collect(Collectors.joining()); + loadFromString(builder); } /** @@ -217,22 +211,30 @@ public void load(Reader reader) throws IOException, InvalidConfigurationExceptio private void parseAndStoreComments(@NotNull String contents) { String[] lines = contents.split("\n"); StringBuilder commentBuilder = new StringBuilder(); + String lastComment = commentBuilder.toString(); boolean isHeader = true; // Assume the first comments are header comments // Define the pattern within this method Pattern keyPattern = Pattern.compile("^\\s*([\\w\\-]+):.*"); - for (String line : lines) { + for (String entry : lines) { + String line = entry; + if (!line.trim().isEmpty() && line.trim().charAt(0) == '#') { if (commentBuilder.length() > 0) { commentBuilder.append("\n"); } - commentBuilder.append(line.trim().substring(1).trim()); // Remove '#' and trim + + // Remove '#' and trim + line = line.trim(); + line = line.replaceFirst("^#", ""); + line = line.trim(); + + commentBuilder.append(line); } else { if (!line.trim().isEmpty() && isHeader) { // Store header comments and mark that we've found a non-comment line - String lastComment = commentBuilder.toString(); commentsMap.put("__header__", lastComment); commentBuilder.setLength(0); isHeader = false; // No longer reading header comments @@ -244,7 +246,6 @@ private void parseAndStoreComments(@NotNull String contents) { // Found a key, store the accumulated comments if any String key = matcher.group(1); if (commentBuilder.length() > 0) { - String lastComment = commentBuilder.toString(); commentsMap.put(key, lastComment); commentBuilder.setLength(0); // Reset comment builder } @@ -254,7 +255,7 @@ private void parseAndStoreComments(@NotNull String contents) { // In case the file ends with comments not associated with a key if (commentBuilder.length() > 0 && !isHeader) { - commentsMap.put("__footer__", commentBuilder.toString()); + commentsMap.put("__footer__", lastComment); } } } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 4010819..32be9f0 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -97,135 +97,52 @@ kitpvp: # Kit Settings # ----------------------------------------------- kits: - knight: - enabled: true - cost: 0 archer: enabled: true cost: 250 - burrower: - enabled: true - cost: 250 ability: - cooldown: 30 - duration: 5 - cactus: - enabled: true - cost: 250 - passive: - duration: 5 - dragon: - enabled: true - cost: 250 - ability: - cooldown: 30 - duration: 8 - range: 6 - damage: 8 + cooldown: 20 + duration: 3 fisherman: enabled: true cost: 250 ability: - cooldown: 30 - ghost: - enabled: true - cost: 250 - ability: - range: 6 - hulk: - enabled: true - cost: 250 - ability: - cooldown: 30 - range: 6 - damage: 10 - multiplier: -4.0 - imprisoner: - enabled: true - cost: 250 - ability: - cooldown: 30 - duration: 4 - damage: 4 - height: 9 + cooldown: 20 kangaroo: enabled: true cost: 250 ability: cooldown: 20 - sneaking: - height: 0.3 - multiplier: 2.5 - normal: - height: 1.2 - multiplier: 0.0 - mage: + knight: enabled: true - cost: 250 - ability: - cooldown: 30 - monk: + cost: 0 + mage: enabled: true cost: 250 ability: - cooldown: 30 + cooldown: 20 ninja: enabled: true cost: 250 + ability: + cooldown: 20 + duration: 3 pyro: enabled: true cost: 250 - spiderman: - enabled: true - cost: 250 ability: cooldown: 20 duration: 5 - summoner: - enabled: true - cost: 250 - ability: - cooldown: 30 - duration: 10 - range: 15 - tamer: - enabled: true - cost: 250 - ability: - cooldown: 30 - duration: 10 - amount: 3 + damage: 6.0 tank: enabled: true cost: 250 - thor: - enabled: true - cost: 250 - ability: - cooldown: 30 - duration: 5 - range: 6 - damage: 10 - timelord: - enabled: true - cost: 250 ability: - cooldown: 30 + cooldown: 20 duration: 5 - range: 6 vampire: - enabled: true - cost: 250 - passive: - duration: 5 - ability: - cooldown: 30 - duration: 10 - range: 6 - zen: enabled: true cost: 250 ability: - cooldown: 30 + cooldown: 20 duration: 5 - range: 25