diff --git a/src/main/java/net/momirealms/customfishing/CustomFishing.java b/src/main/java/net/momirealms/customfishing/CustomFishing.java index 9667ab06..bcfe5ba2 100644 --- a/src/main/java/net/momirealms/customfishing/CustomFishing.java +++ b/src/main/java/net/momirealms/customfishing/CustomFishing.java @@ -26,7 +26,7 @@ import net.momirealms.customfishing.commands.SellFishCommand; import net.momirealms.customfishing.helper.LibraryLoader; import net.momirealms.customfishing.helper.VersionHelper; import net.momirealms.customfishing.manager.*; -import net.momirealms.customfishing.util.AdventureUtil; +import net.momirealms.customfishing.util.AdventureUtils; import org.bstats.bukkit.Metrics; import org.bukkit.Bukkit; import org.bukkit.command.PluginCommand; @@ -79,7 +79,7 @@ public final class CustomFishing extends JavaPlugin { this.reload(); this.registerCommands(); this.registerQuests(); - AdventureUtil.consoleMessage("[CustomFishing] Plugin Enabled!"); + AdventureUtils.consoleMessage("[CustomFishing] Plugin Enabled!"); if (ConfigManager.bStats) new Metrics(this, 16648); if (ConfigManager.updateChecker) this.versionHelper.checkUpdate(); } diff --git a/src/main/java/net/momirealms/customfishing/api/CustomFishingAPI.java b/src/main/java/net/momirealms/customfishing/api/CustomFishingAPI.java index c27247e6..1a26181d 100644 --- a/src/main/java/net/momirealms/customfishing/api/CustomFishingAPI.java +++ b/src/main/java/net/momirealms/customfishing/api/CustomFishingAPI.java @@ -26,7 +26,7 @@ import net.momirealms.customfishing.fishing.loot.DroppedItem; import net.momirealms.customfishing.fishing.loot.Item; import net.momirealms.customfishing.fishing.loot.Loot; import net.momirealms.customfishing.manager.ConfigManager; -import net.momirealms.customfishing.util.ItemStackUtil; +import net.momirealms.customfishing.util.ItemStackUtils; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; @@ -169,7 +169,7 @@ public class CustomFishingAPI { */ public static ItemStack getRodItemByID(String id) { Item item = CustomFishing.getInstance().getEffectManager().getRodItem(id); - return item == null ? null : ItemStackUtil.getFromItem(item); + return item == null ? null : ItemStackUtils.getFromItem(item); } /** @@ -180,7 +180,7 @@ public class CustomFishingAPI { */ public static ItemStack getBaitItemByID(String id) { Item item = CustomFishing.getInstance().getEffectManager().getBaitItem(id); - return item == null ? null : ItemStackUtil.getFromItem(item); + return item == null ? null : ItemStackUtils.getFromItem(item); } /** @@ -191,7 +191,7 @@ public class CustomFishingAPI { */ public static ItemStack getUtilItemByID(String id) { Item item = CustomFishing.getInstance().getEffectManager().getUtilItem(id); - return item == null ? null : ItemStackUtil.getFromItem(item); + return item == null ? null : ItemStackUtils.getFromItem(item); } /** diff --git a/src/main/java/net/momirealms/customfishing/commands/AbstractMainCommand.java b/src/main/java/net/momirealms/customfishing/commands/AbstractMainCommand.java index 9d309152..0eada606 100644 --- a/src/main/java/net/momirealms/customfishing/commands/AbstractMainCommand.java +++ b/src/main/java/net/momirealms/customfishing/commands/AbstractMainCommand.java @@ -18,7 +18,7 @@ package net.momirealms.customfishing.commands; import net.momirealms.customfishing.manager.MessageManager; -import net.momirealms.customfishing.util.AdventureUtil; +import net.momirealms.customfishing.util.AdventureUtils; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabExecutor; @@ -38,14 +38,14 @@ public abstract class AbstractMainCommand implements TabExecutor { public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) { List argList = Arrays.asList(args); if (argList.size() < 1) { - AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.nonArgs); + AdventureUtils.sendMessage(sender, MessageManager.prefix + MessageManager.nonArgs); return true; } AbstractSubCommand subCommand = subCommandMap.get(argList.get(0)); if (subCommand != null) return subCommand.onCommand(sender, argList.subList(1, argList.size())); else { - AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.unavailableArgs); + AdventureUtils.sendMessage(sender, MessageManager.prefix + MessageManager.unavailableArgs); return true; } } diff --git a/src/main/java/net/momirealms/customfishing/commands/AbstractSubCommand.java b/src/main/java/net/momirealms/customfishing/commands/AbstractSubCommand.java index 83ac9ac4..ddb2371f 100644 --- a/src/main/java/net/momirealms/customfishing/commands/AbstractSubCommand.java +++ b/src/main/java/net/momirealms/customfishing/commands/AbstractSubCommand.java @@ -19,7 +19,7 @@ package net.momirealms.customfishing.commands; import net.momirealms.customfishing.api.CustomFishingAPI; import net.momirealms.customfishing.manager.MessageManager; -import net.momirealms.customfishing.util.AdventureUtil; +import net.momirealms.customfishing.util.AdventureUtils; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -46,7 +46,7 @@ public abstract class AbstractSubCommand { } AbstractSubCommand subCommand = subCommandMap.get(args.get(0)); if (subCommand == null) { - AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.unavailableArgs); + AdventureUtils.sendMessage(sender, MessageManager.prefix + MessageManager.unavailableArgs); } else { subCommand.onCommand(sender, args.subList(1, args.size())); } @@ -84,7 +84,7 @@ public abstract class AbstractSubCommand { protected boolean noConsoleExecute(CommandSender commandSender) { if (!(commandSender instanceof Player)) { - AdventureUtil.consoleMessage(MessageManager.prefix + MessageManager.noConsole); + AdventureUtils.consoleMessage(MessageManager.prefix + MessageManager.noConsole); return true; } return false; @@ -92,7 +92,7 @@ public abstract class AbstractSubCommand { protected boolean itemNotExist(CommandSender commandSender, String type, String key) { if (!CustomFishingAPI.doesItemExist(type, key)) { - AdventureUtil.sendMessage(commandSender, MessageManager.prefix + MessageManager.itemNotExist); + AdventureUtils.sendMessage(commandSender, MessageManager.prefix + MessageManager.itemNotExist); return true; } return false; @@ -100,7 +100,7 @@ public abstract class AbstractSubCommand { protected boolean playerNotOnline(CommandSender commandSender, String player) { if (Bukkit.getPlayer(player) == null) { - AdventureUtil.sendMessage(commandSender, MessageManager.prefix + MessageManager.notOnline.replace("{Player}", player)); + AdventureUtils.sendMessage(commandSender, MessageManager.prefix + MessageManager.notOnline.replace("{Player}", player)); return true; } return false; @@ -108,18 +108,18 @@ public abstract class AbstractSubCommand { protected boolean lackArgs(CommandSender commandSender, int required, int current) { if (required > current) { - AdventureUtil.sendMessage(commandSender, MessageManager.prefix + MessageManager.lackArgs); + AdventureUtils.sendMessage(commandSender, MessageManager.prefix + MessageManager.lackArgs); return true; } return false; } protected void giveItemMsg(CommandSender sender, String name, String item, int amount) { - AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.giveItem.replace("{Amount}", String.valueOf(amount)).replace("{Player}",name).replace("{Item}",item)); + AdventureUtils.sendMessage(sender, MessageManager.prefix + MessageManager.giveItem.replace("{Amount}", String.valueOf(amount)).replace("{Player}",name).replace("{Item}",item)); } protected void getItemMsg(CommandSender sender, String item, int amount) { - AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.getItem.replace("{Amount}", String.valueOf(amount)).replace("{Item}", item)); + AdventureUtils.sendMessage(sender, MessageManager.prefix + MessageManager.getItem.replace("{Amount}", String.valueOf(amount)).replace("{Item}", item)); } protected List online_players() { diff --git a/src/main/java/net/momirealms/customfishing/commands/FishingBagCommand.java b/src/main/java/net/momirealms/customfishing/commands/FishingBagCommand.java index 39d5bbd8..1b490e9c 100644 --- a/src/main/java/net/momirealms/customfishing/commands/FishingBagCommand.java +++ b/src/main/java/net/momirealms/customfishing/commands/FishingBagCommand.java @@ -20,7 +20,7 @@ package net.momirealms.customfishing.commands; import net.momirealms.customfishing.CustomFishing; import net.momirealms.customfishing.manager.ConfigManager; import net.momirealms.customfishing.manager.MessageManager; -import net.momirealms.customfishing.util.AdventureUtil; +import net.momirealms.customfishing.util.AdventureUtils; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.command.CommandSender; @@ -48,7 +48,7 @@ public class FishingBagCommand extends AbstractMainCommand { Player player = (Player) sender; if (args.size() == 0) { if (!sender.hasPermission("fishingbag.open")) { - AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.noPerm); + AdventureUtils.sendMessage(sender, MessageManager.prefix + MessageManager.noPerm); return true; } player.closeInventory(); @@ -56,12 +56,12 @@ public class FishingBagCommand extends AbstractMainCommand { } if (args.size() >= 1) { if (!sender.hasPermission("customfishing.admin")) { - AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.noPerm); + AdventureUtils.sendMessage(sender, MessageManager.prefix + MessageManager.noPerm); return true; } OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayerIfCached(args.get(0)); if (offlinePlayer == null) { - AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.playerNotExist); + AdventureUtils.sendMessage(sender, MessageManager.prefix + MessageManager.playerNotExist); return true; } player.closeInventory(); diff --git a/src/main/java/net/momirealms/customfishing/commands/SellFishCommand.java b/src/main/java/net/momirealms/customfishing/commands/SellFishCommand.java index a8952116..7158c7ef 100644 --- a/src/main/java/net/momirealms/customfishing/commands/SellFishCommand.java +++ b/src/main/java/net/momirealms/customfishing/commands/SellFishCommand.java @@ -19,7 +19,7 @@ package net.momirealms.customfishing.commands; import net.momirealms.customfishing.CustomFishing; import net.momirealms.customfishing.manager.MessageManager; -import net.momirealms.customfishing.util.AdventureUtil; +import net.momirealms.customfishing.util.AdventureUtils; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.command.TabExecutor; @@ -34,7 +34,7 @@ public class SellFishCommand implements TabExecutor { @Override public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { if (!(sender instanceof Player player)) { - AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.noConsole); + AdventureUtils.sendMessage(sender, MessageManager.prefix + MessageManager.noConsole); return true; } player.closeInventory(); diff --git a/src/main/java/net/momirealms/customfishing/commands/subcmd/AboutCommand.java b/src/main/java/net/momirealms/customfishing/commands/subcmd/AboutCommand.java index 891a3b14..a433b83b 100644 --- a/src/main/java/net/momirealms/customfishing/commands/subcmd/AboutCommand.java +++ b/src/main/java/net/momirealms/customfishing/commands/subcmd/AboutCommand.java @@ -19,7 +19,7 @@ package net.momirealms.customfishing.commands.subcmd; import net.momirealms.customfishing.CustomFishing; import net.momirealms.customfishing.commands.AbstractSubCommand; -import net.momirealms.customfishing.util.AdventureUtil; +import net.momirealms.customfishing.util.AdventureUtils; import org.bukkit.command.CommandSender; import java.util.List; @@ -34,11 +34,11 @@ public class AboutCommand extends AbstractSubCommand { @Override public boolean onCommand(CommandSender sender, List args) { - AdventureUtil.sendMessage(sender, "<#00BFFF>\uD83C\uDFA3 CustomFishing - <#87CEEB>" + CustomFishing.getInstance().getVersionHelper().getPluginVersion()); - AdventureUtil.sendMessage(sender, "<#B0C4DE>A fishing plugin that provides innovative mechanics and powerful loot system"); - AdventureUtil.sendMessage(sender, "<#DA70D6>\uD83E\uDDEA Author: <#FFC0CB>XiaoMoMi"); - AdventureUtil.sendMessage(sender, "<#FF7F50>\uD83D\uDD25 Contributors: <#FFA07A>0ft3n, <#FFA07A>Peng_Lx, <#FFA07A>Masaki"); - AdventureUtil.sendMessage(sender, "<#FFD700>⭐ Document <#A9A9A9>| <#FAFAD2>⛏ Github <#A9A9A9>| <#48D1CC>\uD83D\uDD14 Polymart"); + AdventureUtils.sendMessage(sender, "<#00BFFF>\uD83C\uDFA3 CustomFishing - <#87CEEB>" + CustomFishing.getInstance().getVersionHelper().getPluginVersion()); + AdventureUtils.sendMessage(sender, "<#B0C4DE>A fishing plugin that provides innovative mechanics and powerful loot system"); + AdventureUtils.sendMessage(sender, "<#DA70D6>\uD83E\uDDEA Author: <#FFC0CB>XiaoMoMi"); + AdventureUtils.sendMessage(sender, "<#FF7F50>\uD83D\uDD25 Contributors: <#FFA07A>0ft3n, <#FFA07A>Peng_Lx, <#FFA07A>Masaki"); + AdventureUtils.sendMessage(sender, "<#FFD700>⭐ Document <#A9A9A9>| <#FAFAD2>⛏ Github <#A9A9A9>| <#48D1CC>\uD83D\uDD14 Polymart"); return true; } } diff --git a/src/main/java/net/momirealms/customfishing/commands/subcmd/CompetitionCommand.java b/src/main/java/net/momirealms/customfishing/commands/subcmd/CompetitionCommand.java index f47bea47..ea974284 100644 --- a/src/main/java/net/momirealms/customfishing/commands/subcmd/CompetitionCommand.java +++ b/src/main/java/net/momirealms/customfishing/commands/subcmd/CompetitionCommand.java @@ -22,7 +22,7 @@ import net.momirealms.customfishing.commands.AbstractSubCommand; import net.momirealms.customfishing.fishing.competition.CompetitionSchedule; import net.momirealms.customfishing.manager.ConfigManager; import net.momirealms.customfishing.manager.MessageManager; -import net.momirealms.customfishing.util.AdventureUtil; +import net.momirealms.customfishing.util.AdventureUtils; import org.bukkit.command.CommandSender; import java.util.ArrayList; @@ -42,19 +42,19 @@ public class CompetitionCommand extends AbstractSubCommand { switch (args.get(0)) { case "start" -> { if (args.size() < 2) { - AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.lackArgs); + AdventureUtils.sendMessage(sender, MessageManager.prefix + MessageManager.lackArgs); return true; } - if (CompetitionSchedule.startCompetition(args.get(1))) AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.forceSuccess); - else AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.forceFailure); + if (CompetitionSchedule.startCompetition(args.get(1))) AdventureUtils.sendMessage(sender, MessageManager.prefix + MessageManager.forceSuccess); + else AdventureUtils.sendMessage(sender, MessageManager.prefix + MessageManager.forceFailure); } case "end" -> { CompetitionSchedule.endCompetition(); - AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.forceEnd); + AdventureUtils.sendMessage(sender, MessageManager.prefix + MessageManager.forceEnd); } case "cancel" -> { CompetitionSchedule.cancelCompetition(); - AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.forceCancel); + AdventureUtils.sendMessage(sender, MessageManager.prefix + MessageManager.forceCancel); } } return true; diff --git a/src/main/java/net/momirealms/customfishing/commands/subcmd/HelpCommand.java b/src/main/java/net/momirealms/customfishing/commands/subcmd/HelpCommand.java index 91a15602..4e341ddb 100644 --- a/src/main/java/net/momirealms/customfishing/commands/subcmd/HelpCommand.java +++ b/src/main/java/net/momirealms/customfishing/commands/subcmd/HelpCommand.java @@ -18,7 +18,7 @@ package net.momirealms.customfishing.commands.subcmd; import net.momirealms.customfishing.commands.AbstractSubCommand; -import net.momirealms.customfishing.util.AdventureUtil; +import net.momirealms.customfishing.util.AdventureUtils; import org.bukkit.command.CommandSender; import java.util.List; @@ -33,39 +33,39 @@ public class HelpCommand extends AbstractSubCommand { @Override public boolean onCommand(CommandSender sender, List args) { - AdventureUtil.sendMessage(sender, "<#4169E1>Command usage:"); - AdventureUtil.sendMessage(sender, " ├─<#FFFACD> "); - AdventureUtil.sendMessage(sender, " └─<#FFFACD><#E1FFFF>[Optional Augument]"); - AdventureUtil.sendMessage(sender, "<#4169E1>/customfishing"); - AdventureUtil.sendMessage(sender, " ├─help"); - AdventureUtil.sendMessage(sender, " ├─about"); - AdventureUtil.sendMessage(sender, " ├─reload <#87CEFA>Reload the plugin"); - AdventureUtil.sendMessage(sender, " ├─forceopenbag <#FFFACD> <#87CEFA>Force a player to open his fishing bag"); - AdventureUtil.sendMessage(sender, " ├─sellshop <#FFFACD> <#87CEFA>Force a player to open sell shop"); - AdventureUtil.sendMessage(sender, " ├─competition"); - AdventureUtil.sendMessage(sender, " │ ├─start <#FFFACD> <#87CEFA>Start a competition"); - AdventureUtil.sendMessage(sender, " │ ├─end <#87CEFA>End the ongoing competition"); - AdventureUtil.sendMessage(sender, " │ └─cancel <#87CEFA>Cancel the ongoing competition"); - AdventureUtil.sendMessage(sender, " ├─items"); - AdventureUtil.sendMessage(sender, " │ ├─loot"); - AdventureUtil.sendMessage(sender, " │ │ ├─get <#FFFACD> <#E1FFFF>[amount]"); - AdventureUtil.sendMessage(sender, " │ │ ├─give <#FFFACD> <#E1FFFF>[amount]"); - AdventureUtil.sendMessage(sender, " │ │ └─import <#FFFACD> <#87CEFA>Import the item in hand"); - AdventureUtil.sendMessage(sender, " │ ├─rod"); - AdventureUtil.sendMessage(sender, " │ │ ├─get <#FFFACD> <#E1FFFF>[amount]"); - AdventureUtil.sendMessage(sender, " │ │ └─give <#FFFACD> <#E1FFFF>[amount]"); - AdventureUtil.sendMessage(sender, " │ ├─bait"); - AdventureUtil.sendMessage(sender, " │ │ ├─get <#FFFACD> <#E1FFFF>[amount]"); - AdventureUtil.sendMessage(sender, " │ │ └─give <#FFFACD> <#E1FFFF>[amount]"); - AdventureUtil.sendMessage(sender, " │ └─util"); - AdventureUtil.sendMessage(sender, " │ ├─get <#FFFACD> <#E1FFFF>[amount]"); - AdventureUtil.sendMessage(sender, " │ └─give <#FFFACD> <#E1FFFF>[amount]"); - AdventureUtil.sendMessage(sender, " └─statistics"); - AdventureUtil.sendMessage(sender, " ├─reset <#FFFACD> <#87CEFA>Reset a player's statistics"); - AdventureUtil.sendMessage(sender, " └─set <#FFFACD> <#87CEFA>Set certain statistics' value"); - AdventureUtil.sendMessage(sender, "<#4169E1>/fishingbag"); - AdventureUtil.sendMessage(sender, " └─open <#E1FFFF>[player] <#87CEFA>Open the fishing bag"); - AdventureUtil.sendMessage(sender, "<#4169E1>/sellshop <#87CEFA>Open the sell shop"); + AdventureUtils.sendMessage(sender, "<#4169E1>Command usage:"); + AdventureUtils.sendMessage(sender, " ├─<#FFFACD> "); + AdventureUtils.sendMessage(sender, " └─<#FFFACD><#E1FFFF>[Optional Augument]"); + AdventureUtils.sendMessage(sender, "<#4169E1>/customfishing"); + AdventureUtils.sendMessage(sender, " ├─help"); + AdventureUtils.sendMessage(sender, " ├─about"); + AdventureUtils.sendMessage(sender, " ├─reload <#87CEFA>Reload the plugin"); + AdventureUtils.sendMessage(sender, " ├─forceopenbag <#FFFACD> <#87CEFA>Force a player to open his fishing bag"); + AdventureUtils.sendMessage(sender, " ├─sellshop <#FFFACD> <#87CEFA>Force a player to open sell shop"); + AdventureUtils.sendMessage(sender, " ├─competition"); + AdventureUtils.sendMessage(sender, " │ ├─start <#FFFACD> <#87CEFA>Start a competition"); + AdventureUtils.sendMessage(sender, " │ ├─end <#87CEFA>End the ongoing competition"); + AdventureUtils.sendMessage(sender, " │ └─cancel <#87CEFA>Cancel the ongoing competition"); + AdventureUtils.sendMessage(sender, " ├─items"); + AdventureUtils.sendMessage(sender, " │ ├─loot"); + AdventureUtils.sendMessage(sender, " │ │ ├─get <#FFFACD> <#E1FFFF>[amount]"); + AdventureUtils.sendMessage(sender, " │ │ ├─give <#FFFACD> <#E1FFFF>[amount]"); + AdventureUtils.sendMessage(sender, " │ │ └─import <#FFFACD> <#87CEFA>Import the item in hand"); + AdventureUtils.sendMessage(sender, " │ ├─rod"); + AdventureUtils.sendMessage(sender, " │ │ ├─get <#FFFACD> <#E1FFFF>[amount]"); + AdventureUtils.sendMessage(sender, " │ │ └─give <#FFFACD> <#E1FFFF>[amount]"); + AdventureUtils.sendMessage(sender, " │ ├─bait"); + AdventureUtils.sendMessage(sender, " │ │ ├─get <#FFFACD> <#E1FFFF>[amount]"); + AdventureUtils.sendMessage(sender, " │ │ └─give <#FFFACD> <#E1FFFF>[amount]"); + AdventureUtils.sendMessage(sender, " │ └─util"); + AdventureUtils.sendMessage(sender, " │ ├─get <#FFFACD> <#E1FFFF>[amount]"); + AdventureUtils.sendMessage(sender, " │ └─give <#FFFACD> <#E1FFFF>[amount]"); + AdventureUtils.sendMessage(sender, " └─statistics"); + AdventureUtils.sendMessage(sender, " ├─reset <#FFFACD> <#87CEFA>Reset a player's statistics"); + AdventureUtils.sendMessage(sender, " └─set <#FFFACD> <#87CEFA>Set certain statistics' value"); + AdventureUtils.sendMessage(sender, "<#4169E1>/fishingbag"); + AdventureUtils.sendMessage(sender, " └─open <#E1FFFF>[player] <#87CEFA>Open the fishing bag"); + AdventureUtils.sendMessage(sender, "<#4169E1>/sellshop <#87CEFA>Open the sell shop"); return true; } } diff --git a/src/main/java/net/momirealms/customfishing/commands/subcmd/ReloadCommand.java b/src/main/java/net/momirealms/customfishing/commands/subcmd/ReloadCommand.java index 09e34e84..1c77876a 100644 --- a/src/main/java/net/momirealms/customfishing/commands/subcmd/ReloadCommand.java +++ b/src/main/java/net/momirealms/customfishing/commands/subcmd/ReloadCommand.java @@ -21,7 +21,7 @@ package net.momirealms.customfishing.commands.subcmd; import net.momirealms.customfishing.CustomFishing; import net.momirealms.customfishing.commands.AbstractSubCommand; import net.momirealms.customfishing.manager.MessageManager; -import net.momirealms.customfishing.util.AdventureUtil; +import net.momirealms.customfishing.util.AdventureUtils; import org.bukkit.command.CommandSender; import java.util.List; @@ -38,7 +38,7 @@ public final class ReloadCommand extends AbstractSubCommand { public boolean onCommand(CommandSender sender, List args) { long time1 = System.currentTimeMillis(); CustomFishing.getInstance().reload(); - AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.reload.replace("{time}", String.valueOf(System.currentTimeMillis() - time1))); + AdventureUtils.sendMessage(sender, MessageManager.prefix + MessageManager.reload.replace("{time}", String.valueOf(System.currentTimeMillis() - time1))); return true; } } diff --git a/src/main/java/net/momirealms/customfishing/commands/subcmd/StatisticsCommand.java b/src/main/java/net/momirealms/customfishing/commands/subcmd/StatisticsCommand.java index 5e8b7cf7..6c375563 100644 --- a/src/main/java/net/momirealms/customfishing/commands/subcmd/StatisticsCommand.java +++ b/src/main/java/net/momirealms/customfishing/commands/subcmd/StatisticsCommand.java @@ -22,7 +22,7 @@ import net.momirealms.customfishing.commands.AbstractSubCommand; import net.momirealms.customfishing.fishing.loot.Loot; import net.momirealms.customfishing.manager.ConfigManager; import net.momirealms.customfishing.manager.MessageManager; -import net.momirealms.customfishing.util.AdventureUtil; +import net.momirealms.customfishing.util.AdventureUtils; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -56,18 +56,18 @@ public class StatisticsCommand extends AbstractSubCommand { ) return true; int amount = Integer.parseInt(args.get(2)); if (amount < 0) { - AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.negativeStatistics); + AdventureUtils.sendMessage(sender, MessageManager.prefix + MessageManager.negativeStatistics); return true; } Loot loot = CustomFishing.getInstance().getLootManager().getLoot(args.get(1)); if (loot == null || loot.isDisableStats()) { - AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.statisticsNotExists); + AdventureUtils.sendMessage(sender, MessageManager.prefix + MessageManager.statisticsNotExists); return true; } Player player = Bukkit.getPlayer(args.get(0)); assert player != null; CustomFishing.getInstance().getStatisticsManager().setData(player.getUniqueId(), args.get(1), amount); - AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.setStatistics.replace("{Player}", args.get(0)).replace("{Amount}", args.get(2)).replace("{Loot}", args.get(1))); + AdventureUtils.sendMessage(sender, MessageManager.prefix + MessageManager.setStatistics.replace("{Player}", args.get(0)).replace("{Amount}", args.get(2)).replace("{Loot}", args.get(1))); return true; } @@ -105,8 +105,8 @@ public class StatisticsCommand extends AbstractSubCommand { ) return true; Player player = Bukkit.getPlayer(args.get(0)); assert player != null; - if (CustomFishing.getInstance().getStatisticsManager().reset(player.getUniqueId())) AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.resetStatistics.replace("{Player}", args.get(0))); - else AdventureUtil.sendMessage(sender, MessageManager.prefix + "Internal Error, player's data is not loaded"); + if (CustomFishing.getInstance().getStatisticsManager().reset(player.getUniqueId())) AdventureUtils.sendMessage(sender, MessageManager.prefix + MessageManager.resetStatistics.replace("{Player}", args.get(0))); + else AdventureUtils.sendMessage(sender, MessageManager.prefix + "Internal Error, player's data is not loaded"); return true; } diff --git a/src/main/java/net/momirealms/customfishing/commands/subcmd/item/BaitCommand.java b/src/main/java/net/momirealms/customfishing/commands/subcmd/item/BaitCommand.java index ece3853c..bd1e6771 100644 --- a/src/main/java/net/momirealms/customfishing/commands/subcmd/item/BaitCommand.java +++ b/src/main/java/net/momirealms/customfishing/commands/subcmd/item/BaitCommand.java @@ -20,8 +20,8 @@ package net.momirealms.customfishing.commands.subcmd.item; import net.momirealms.customfishing.CustomFishing; import net.momirealms.customfishing.commands.AbstractSubCommand; import net.momirealms.customfishing.manager.MessageManager; -import net.momirealms.customfishing.util.AdventureUtil; -import net.momirealms.customfishing.util.ItemStackUtil; +import net.momirealms.customfishing.util.AdventureUtils; +import net.momirealms.customfishing.util.ItemStackUtils; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -54,14 +54,14 @@ public class BaitCommand extends AbstractSubCommand { || super.itemNotExist(sender, "bait", args.get(0)) ) return true; if (args.size() == 1){ - ItemStackUtil.givePlayerBait((Player) sender, args.get(0), 1); + ItemStackUtils.givePlayerBait((Player) sender, args.get(0), 0); super.getItemMsg(sender, args.get(0), 1); } else { if (Integer.parseInt(args.get(1)) < 1){ - AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.wrongAmount); + AdventureUtils.sendMessage(sender, MessageManager.prefix + MessageManager.wrongAmount); return true; } - ItemStackUtil.givePlayerBait((Player) sender, args.get(0), Integer.parseInt(args.get(1))); + ItemStackUtils.givePlayerBait((Player) sender, args.get(0), Integer.parseInt(args.get(1))); super.getItemMsg(sender, args.get(0), Integer.parseInt(args.get(1))); } return true; @@ -93,15 +93,15 @@ public class BaitCommand extends AbstractSubCommand { || itemNotExist(sender, "bait", args.get(1)) ) return true; if (args.size() == 2){ - ItemStackUtil.givePlayerBait(Bukkit.getPlayer(args.get(0)), args.get(1), 1); + ItemStackUtils.givePlayerBait(Bukkit.getPlayer(args.get(0)), args.get(1), 0); super.giveItemMsg(sender, args.get(0), args.get(1), 1); } else if (args.size() == 3) { if (Integer.parseInt(args.get(2)) < 1) { - AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.wrongAmount); + AdventureUtils.sendMessage(sender, MessageManager.prefix + MessageManager.wrongAmount); return true; } - ItemStackUtil.givePlayerBait(Bukkit.getPlayer(args.get(0)), args.get(1), Integer.parseInt(args.get(2))); + ItemStackUtils.givePlayerBait(Bukkit.getPlayer(args.get(0)), args.get(1), Integer.parseInt(args.get(2))); super.giveItemMsg(sender, args.get(0), args.get(1), Integer.parseInt(args.get(2))); } return true; diff --git a/src/main/java/net/momirealms/customfishing/commands/subcmd/item/LootCommand.java b/src/main/java/net/momirealms/customfishing/commands/subcmd/item/LootCommand.java index caf88a90..46021797 100644 --- a/src/main/java/net/momirealms/customfishing/commands/subcmd/item/LootCommand.java +++ b/src/main/java/net/momirealms/customfishing/commands/subcmd/item/LootCommand.java @@ -20,8 +20,8 @@ package net.momirealms.customfishing.commands.subcmd.item; import net.momirealms.customfishing.CustomFishing; import net.momirealms.customfishing.commands.AbstractSubCommand; import net.momirealms.customfishing.manager.MessageManager; -import net.momirealms.customfishing.util.AdventureUtil; -import net.momirealms.customfishing.util.ItemStackUtil; +import net.momirealms.customfishing.util.AdventureUtils; +import net.momirealms.customfishing.util.ItemStackUtils; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -56,15 +56,16 @@ public class LootCommand extends AbstractSubCommand { || itemNotExist(sender, "loot", args.get(1)) ) return true; if (args.size() == 2){ - ItemStackUtil.givePlayerLoot(Bukkit.getPlayer(args.get(0)), args.get(1), 1); - super.giveItemMsg(sender, args.get(0), args.get(1), 1); + int amount = ItemStackUtils.givePlayerLoot(Bukkit.getPlayer(args.get(0)), args.get(1), 0); + if (amount > 0) + super.giveItemMsg(sender, args.get(0), args.get(1), amount); } else if (args.size() == 3) { if (Integer.parseInt(args.get(2)) < 1) { - AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.wrongAmount); + AdventureUtils.sendMessage(sender, MessageManager.prefix + MessageManager.wrongAmount); return true; } - ItemStackUtil.givePlayerLoot(Bukkit.getPlayer(args.get(0)), args.get(1), Integer.parseInt(args.get(2))); + ItemStackUtils.givePlayerLoot(Bukkit.getPlayer(args.get(0)), args.get(1), Integer.parseInt(args.get(2))); super.giveItemMsg(sender, args.get(0), args.get(1), Integer.parseInt(args.get(2))); } return true; @@ -98,14 +99,15 @@ public class LootCommand extends AbstractSubCommand { || super.itemNotExist(sender, "loot", args.get(0)) ) return true; if (args.size() == 1){ - ItemStackUtil.givePlayerLoot((Player) sender, args.get(0), 1); - super.getItemMsg(sender, args.get(0), 1); + int amount = ItemStackUtils.givePlayerLoot((Player) sender, args.get(0), 0); + if (amount > 0) + super.getItemMsg(sender, args.get(0), amount); } else { if (Integer.parseInt(args.get(1)) < 1){ - AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.wrongAmount); + AdventureUtils.sendMessage(sender, MessageManager.prefix + MessageManager.wrongAmount); return true; } - ItemStackUtil.givePlayerLoot((Player) sender, args.get(0), Integer.parseInt(args.get(1))); + ItemStackUtils.givePlayerLoot((Player) sender, args.get(0), Integer.parseInt(args.get(1))); super.getItemMsg(sender, args.get(0), Integer.parseInt(args.get(1))); } return true; @@ -136,8 +138,8 @@ public class LootCommand extends AbstractSubCommand { || lackArgs(sender, 1, args.size()) ) return true; Player player = (Player) sender; - if (ItemStackUtil.saveToFile(player.getInventory().getItemInMainHand(), args.get(0))) AdventureUtil.playerMessage(player, MessageManager.prefix + "Done! File is saved to /CustomFishing/loots/imported.yml"); - else AdventureUtil.playerMessage(player, MessageManager.prefix + "Error. The item can't be null or there already exists loot with that key name"); + if (ItemStackUtils.saveToFile(player.getInventory().getItemInMainHand(), args.get(0))) AdventureUtils.playerMessage(player, MessageManager.prefix + "Done! File is saved to /CustomFishing/loots/imported.yml"); + else AdventureUtils.playerMessage(player, MessageManager.prefix + "Error. The item can't be null or there already exists loot with that key name"); return true; } diff --git a/src/main/java/net/momirealms/customfishing/commands/subcmd/item/RodCommand.java b/src/main/java/net/momirealms/customfishing/commands/subcmd/item/RodCommand.java index b039bd6e..8f502a63 100644 --- a/src/main/java/net/momirealms/customfishing/commands/subcmd/item/RodCommand.java +++ b/src/main/java/net/momirealms/customfishing/commands/subcmd/item/RodCommand.java @@ -20,8 +20,8 @@ package net.momirealms.customfishing.commands.subcmd.item; import net.momirealms.customfishing.CustomFishing; import net.momirealms.customfishing.commands.AbstractSubCommand; import net.momirealms.customfishing.manager.MessageManager; -import net.momirealms.customfishing.util.AdventureUtil; -import net.momirealms.customfishing.util.ItemStackUtil; +import net.momirealms.customfishing.util.AdventureUtils; +import net.momirealms.customfishing.util.ItemStackUtils; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -54,15 +54,15 @@ public class RodCommand extends AbstractSubCommand { || itemNotExist(sender, "rod", args.get(1)) ) return true; if (args.size() == 2){ - ItemStackUtil.givePlayerRod(Bukkit.getPlayer(args.get(0)), args.get(1), 1); + ItemStackUtils.givePlayerRod(Bukkit.getPlayer(args.get(0)), args.get(1), 0); super.giveItemMsg(sender, args.get(0), args.get(1), 1); } else if (args.size() == 3) { if (Integer.parseInt(args.get(2)) < 1) { - AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.wrongAmount); + AdventureUtils.sendMessage(sender, MessageManager.prefix + MessageManager.wrongAmount); return true; } - ItemStackUtil.givePlayerRod(Bukkit.getPlayer(args.get(0)), args.get(1), Integer.parseInt(args.get(2))); + ItemStackUtils.givePlayerRod(Bukkit.getPlayer(args.get(0)), args.get(1), Integer.parseInt(args.get(2))); super.giveItemMsg(sender, args.get(0), args.get(1), Integer.parseInt(args.get(2))); } return true; @@ -96,14 +96,14 @@ public class RodCommand extends AbstractSubCommand { || super.itemNotExist(sender, "rod", args.get(0)) ) return true; if (args.size() == 1){ - ItemStackUtil.givePlayerRod((Player) sender, args.get(0), 1); + ItemStackUtils.givePlayerRod((Player) sender, args.get(0), 0); super.getItemMsg(sender, args.get(0), 1); } else { if (Integer.parseInt(args.get(1)) < 1){ - AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.wrongAmount); + AdventureUtils.sendMessage(sender, MessageManager.prefix + MessageManager.wrongAmount); return true; } - ItemStackUtil.givePlayerRod((Player) sender, args.get(0), Integer.parseInt(args.get(1))); + ItemStackUtils.givePlayerRod((Player) sender, args.get(0), Integer.parseInt(args.get(1))); super.getItemMsg(sender, args.get(0), Integer.parseInt(args.get(1))); } return true; diff --git a/src/main/java/net/momirealms/customfishing/commands/subcmd/item/UtilCommand.java b/src/main/java/net/momirealms/customfishing/commands/subcmd/item/UtilCommand.java index d47ddc15..13444c90 100644 --- a/src/main/java/net/momirealms/customfishing/commands/subcmd/item/UtilCommand.java +++ b/src/main/java/net/momirealms/customfishing/commands/subcmd/item/UtilCommand.java @@ -20,8 +20,8 @@ package net.momirealms.customfishing.commands.subcmd.item; import net.momirealms.customfishing.CustomFishing; import net.momirealms.customfishing.commands.AbstractSubCommand; import net.momirealms.customfishing.manager.MessageManager; -import net.momirealms.customfishing.util.AdventureUtil; -import net.momirealms.customfishing.util.ItemStackUtil; +import net.momirealms.customfishing.util.AdventureUtils; +import net.momirealms.customfishing.util.ItemStackUtils; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -54,14 +54,14 @@ public class UtilCommand extends AbstractSubCommand { || super.itemNotExist(sender, "util", args.get(0)) ) return true; if (args.size() == 1){ - ItemStackUtil.givePlayerUtil((Player) sender, args.get(0), 1); + ItemStackUtils.givePlayerUtil((Player) sender, args.get(0), 0); super.getItemMsg(sender, args.get(0), 1); } else { if (Integer.parseInt(args.get(1)) < 1){ - AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.wrongAmount); + AdventureUtils.sendMessage(sender, MessageManager.prefix + MessageManager.wrongAmount); return true; } - ItemStackUtil.givePlayerUtil((Player) sender, args.get(0), Integer.parseInt(args.get(1))); + ItemStackUtils.givePlayerUtil((Player) sender, args.get(0), Integer.parseInt(args.get(1))); super.getItemMsg(sender, args.get(0), Integer.parseInt(args.get(1))); } return true; @@ -93,15 +93,15 @@ public class UtilCommand extends AbstractSubCommand { || itemNotExist(sender, "util", args.get(1)) ) return true; if (args.size() == 2){ - ItemStackUtil.givePlayerUtil(Bukkit.getPlayer(args.get(0)), args.get(1), 1); + ItemStackUtils.givePlayerUtil(Bukkit.getPlayer(args.get(0)), args.get(1), 0); super.giveItemMsg(sender, args.get(0), args.get(1), 1); } else if (args.size() == 3) { if (Integer.parseInt(args.get(2)) < 1) { - AdventureUtil.sendMessage(sender, MessageManager.prefix + MessageManager.wrongAmount); + AdventureUtils.sendMessage(sender, MessageManager.prefix + MessageManager.wrongAmount); return true; } - ItemStackUtil.givePlayerUtil(Bukkit.getPlayer(args.get(0)), args.get(1), Integer.parseInt(args.get(2))); + ItemStackUtils.givePlayerUtil(Bukkit.getPlayer(args.get(0)), args.get(1), Integer.parseInt(args.get(2))); super.giveItemMsg(sender, args.get(0), args.get(1), Integer.parseInt(args.get(2))); } return true; diff --git a/src/main/java/net/momirealms/customfishing/data/storage/FileStorageImpl.java b/src/main/java/net/momirealms/customfishing/data/storage/FileStorageImpl.java index 8f150f0f..b99cf574 100644 --- a/src/main/java/net/momirealms/customfishing/data/storage/FileStorageImpl.java +++ b/src/main/java/net/momirealms/customfishing/data/storage/FileStorageImpl.java @@ -20,8 +20,8 @@ package net.momirealms.customfishing.data.storage; import net.momirealms.customfishing.CustomFishing; import net.momirealms.customfishing.data.PlayerSellData; import net.momirealms.customfishing.data.PlayerStatisticsData; -import net.momirealms.customfishing.util.ConfigUtil; -import net.momirealms.customfishing.util.InventoryUtil; +import net.momirealms.customfishing.util.ConfigUtils; +import net.momirealms.customfishing.util.InventoryUtils; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.configuration.file.YamlConfiguration; @@ -54,10 +54,10 @@ public class FileStorageImpl implements DataStorageInterface { @Override public Inventory loadBagData(UUID uuid, boolean force) { - YamlConfiguration config = ConfigUtil.readData(new File(plugin.getDataFolder(), "fishingbag_data" + File.separator + uuid + ".yml")); + YamlConfiguration config = ConfigUtils.readData(new File(plugin.getDataFolder(), "fishingbag_data" + File.separator + uuid + ".yml")); String contents = config.getString("contents"); int size = config.getInt("size", 9); - ItemStack[] itemStacks = InventoryUtil.getInventoryItems(contents); + ItemStack[] itemStacks = InventoryUtils.getInventoryItems(contents); OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(uuid); Inventory inventory = Bukkit.createInventory(null, size, "{CustomFishing_Bag_" + offlinePlayer.getName() + "}"); if (itemStacks != null) inventory.setContents(itemStacks); @@ -67,7 +67,7 @@ public class FileStorageImpl implements DataStorageInterface { @Override public void saveBagData(UUID uuid, Inventory inventory, boolean unlock) { YamlConfiguration data = new YamlConfiguration(); - String contents = InventoryUtil.toBase64(inventory.getContents()); + String contents = InventoryUtils.toBase64(inventory.getContents()); data.set("contents", contents); data.set("size", inventory.getSize()); try { @@ -88,7 +88,7 @@ public class FileStorageImpl implements DataStorageInterface { @Override public PlayerSellData loadSellData(UUID uuid, boolean force) { - YamlConfiguration data = ConfigUtil.readData(new File(plugin.getDataFolder(), "sell_data" + File.separator + uuid + ".yml")); + YamlConfiguration data = ConfigUtils.readData(new File(plugin.getDataFolder(), "sell_data" + File.separator + uuid + ".yml")); int date = data.getInt("date"); double money = data.getDouble("earnings"); return new PlayerSellData(money, date); @@ -142,7 +142,7 @@ public class FileStorageImpl implements DataStorageInterface { @Override public PlayerStatisticsData loadStatistics(UUID uuid, boolean force) { - YamlConfiguration data = ConfigUtil.readData(new File(plugin.getDataFolder(), "statistics_data" + File.separator + uuid + ".yml")); + YamlConfiguration data = ConfigUtils.readData(new File(plugin.getDataFolder(), "statistics_data" + File.separator + uuid + ".yml")); return new PlayerStatisticsData(data); } } diff --git a/src/main/java/net/momirealms/customfishing/data/storage/MySQLStorageImpl.java b/src/main/java/net/momirealms/customfishing/data/storage/MySQLStorageImpl.java index c64298a3..f3a21e1c 100644 --- a/src/main/java/net/momirealms/customfishing/data/storage/MySQLStorageImpl.java +++ b/src/main/java/net/momirealms/customfishing/data/storage/MySQLStorageImpl.java @@ -21,8 +21,8 @@ import net.momirealms.customfishing.CustomFishing; import net.momirealms.customfishing.data.PlayerSellData; import net.momirealms.customfishing.data.PlayerStatisticsData; import net.momirealms.customfishing.manager.ConfigManager; -import net.momirealms.customfishing.util.AdventureUtil; -import net.momirealms.customfishing.util.InventoryUtil; +import net.momirealms.customfishing.util.AdventureUtils; +import net.momirealms.customfishing.util.InventoryUtils; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.inventory.Inventory; @@ -79,16 +79,16 @@ public class MySQLStorageImpl implements DataStorageInterface { } int size = rs.getInt(3); String contents = rs.getString(4); - ItemStack[] itemStacks = InventoryUtil.getInventoryItems(contents); - if (plugin.getVersionHelper().isSpigot()) inventory = Bukkit.createInventory(null, size, AdventureUtil.replaceMiniMessage(ConfigManager.fishingBagTitle.replace("{player}", Optional.ofNullable(offlinePlayer.getName()).orElse("")))); + ItemStack[] itemStacks = InventoryUtils.getInventoryItems(contents); + if (plugin.getVersionHelper().isSpigot()) inventory = Bukkit.createInventory(null, size, AdventureUtils.replaceMiniMessage(ConfigManager.fishingBagTitle.replace("{player}", Optional.ofNullable(offlinePlayer.getName()).orElse("")))); else inventory = Bukkit.createInventory(null, size, "{CustomFishing_Bag_" + offlinePlayer.getName() + "}"); if (itemStacks != null) inventory.setContents(itemStacks); lockData(uuid, "fishingbag"); } else { - if (plugin.getVersionHelper().isSpigot()) inventory = Bukkit.createInventory(null, 9, AdventureUtil.replaceMiniMessage(ConfigManager.fishingBagTitle.replace("{player}", Optional.ofNullable(offlinePlayer.getName()).orElse("")))); + if (plugin.getVersionHelper().isSpigot()) inventory = Bukkit.createInventory(null, 9, AdventureUtils.replaceMiniMessage(ConfigManager.fishingBagTitle.replace("{player}", Optional.ofNullable(offlinePlayer.getName()).orElse("")))); else inventory = Bukkit.createInventory(null, 9, "{CustomFishing_Bag_" + offlinePlayer.getName() + "}"); - insertBagData(uuid, InventoryUtil.toBase64(inventory.getContents())); + insertBagData(uuid, InventoryUtils.toBase64(inventory.getContents())); } } catch (SQLException e) { e.printStackTrace(); @@ -98,7 +98,7 @@ public class MySQLStorageImpl implements DataStorageInterface { @Override public void saveBagData(UUID uuid, Inventory inventory, boolean unlock) { - updateBagData(uuid, inventory.getSize(), InventoryUtil.toBase64(inventory.getContents()), unlock); + updateBagData(uuid, inventory.getSize(), InventoryUtils.toBase64(inventory.getContents()), unlock); } @Override @@ -110,7 +110,7 @@ public class MySQLStorageImpl implements DataStorageInterface { for (Map.Entry entry : set) { statement.setInt(1, unlock ? 0 : 1); statement.setInt(2, entry.getValue().getSize()); - statement.setString(3, InventoryUtil.toBase64(entry.getValue().getContents())); + statement.setString(3, InventoryUtils.toBase64(entry.getValue().getContents())); statement.setString(4, entry.getKey().toString()); statement.addBatch(); } @@ -119,10 +119,10 @@ public class MySQLStorageImpl implements DataStorageInterface { } catch (SQLException ex) { connection.rollback(); - AdventureUtil.consoleMessage("[CustomFishing] Failed to update bag data for online players"); + AdventureUtils.consoleMessage("[CustomFishing] Failed to update bag data for online players"); } } catch (SQLException ex) { - AdventureUtil.consoleMessage("[CustomFishing] Failed to get connection"); + AdventureUtils.consoleMessage("[CustomFishing] Failed to get connection"); } } @@ -179,10 +179,10 @@ public class MySQLStorageImpl implements DataStorageInterface { } catch (SQLException ex) { connection.rollback(); - AdventureUtil.consoleMessage("[CustomFishing] Failed to update sell data for all the players"); + AdventureUtils.consoleMessage("[CustomFishing] Failed to update sell data for all the players"); } } catch (SQLException ex) { - AdventureUtil.consoleMessage("[CustomFishing] Failed to get connection"); + AdventureUtils.consoleMessage("[CustomFishing] Failed to get connection"); } } @@ -236,10 +236,10 @@ public class MySQLStorageImpl implements DataStorageInterface { } catch (SQLException ex) { connection.rollback(); - AdventureUtil.consoleMessage("[CustomFishing] Failed to update statistics data for online players"); + AdventureUtils.consoleMessage("[CustomFishing] Failed to update statistics data for online players"); } } catch (SQLException ex) { - AdventureUtil.consoleMessage("[CustomFishing] Failed to get connection"); + AdventureUtils.consoleMessage("[CustomFishing] Failed to get connection"); } } @@ -248,7 +248,7 @@ public class MySQLStorageImpl implements DataStorageInterface { try (Connection connection = sqlConnection.getConnectionAndCheck(); PreparedStatement statement = connection.prepareStatement(sql)) { statement.executeUpdate(); } catch (SQLException ex) { - AdventureUtil.consoleMessage("[CustomFishing] Failed to create table"); + AdventureUtils.consoleMessage("[CustomFishing] Failed to create table"); } } @@ -261,7 +261,7 @@ public class MySQLStorageImpl implements DataStorageInterface { statement.setString(4, contents); statement.executeUpdate(); } catch (SQLException ex) { - AdventureUtil.consoleMessage("[CustomFishing] Failed to insert data for " + uuid); + AdventureUtils.consoleMessage("[CustomFishing] Failed to insert data for " + uuid); } } @@ -274,7 +274,7 @@ public class MySQLStorageImpl implements DataStorageInterface { statement.setInt(4, 0); statement.executeUpdate(); } catch (SQLException ex) { - AdventureUtil.consoleMessage("[CustomFishing] Failed to insert data for " + uuid); + AdventureUtils.consoleMessage("[CustomFishing] Failed to insert data for " + uuid); } } @@ -286,7 +286,7 @@ public class MySQLStorageImpl implements DataStorageInterface { statement.setString(3, ""); statement.executeUpdate(); } catch (SQLException ex) { - AdventureUtil.consoleMessage("[CustomFishing] Failed to insert data for " + uuid); + AdventureUtils.consoleMessage("[CustomFishing] Failed to insert data for " + uuid); } } @@ -299,7 +299,7 @@ public class MySQLStorageImpl implements DataStorageInterface { statement.setString(4, uuid.toString()); statement.executeUpdate(); } catch (SQLException ex) { - AdventureUtil.consoleMessage("[CustomFishing] Failed to update data for " + uuid); + AdventureUtils.consoleMessage("[CustomFishing] Failed to update data for " + uuid); } } @@ -312,7 +312,7 @@ public class MySQLStorageImpl implements DataStorageInterface { statement.setString(4, uuid.toString()); statement.executeUpdate(); } catch (SQLException ex) { - AdventureUtil.consoleMessage("[CustomFishing] Failed to update data for " + uuid); + AdventureUtils.consoleMessage("[CustomFishing] Failed to update data for " + uuid); } } @@ -324,7 +324,7 @@ public class MySQLStorageImpl implements DataStorageInterface { statement.setString(3, uuid.toString()); statement.executeUpdate(); } catch (SQLException ex) { - AdventureUtil.consoleMessage("[CustomFishing] Failed to update data for " + uuid); + AdventureUtils.consoleMessage("[CustomFishing] Failed to update data for " + uuid); } } @@ -332,18 +332,18 @@ public class MySQLStorageImpl implements DataStorageInterface { String sql_1 = String.format(SqlConstants.SQL_ALTER_TABLE, sqlConnection.getTablePrefix() + "_" + "fishingbag"); try (Connection connection = sqlConnection.getConnectionAndCheck(); PreparedStatement statement = connection.prepareStatement(sql_1)) { statement.executeUpdate(); - AdventureUtil.consoleMessage("[CustomFishing] Tables updated"); + AdventureUtils.consoleMessage("[CustomFishing] Tables updated"); } catch (SQLException ex) { - AdventureUtil.consoleMessage(ex.getSQLState()); - AdventureUtil.consoleMessage("[CustomFishing] Failed to migrate data"); + AdventureUtils.consoleMessage(ex.getSQLState()); + AdventureUtils.consoleMessage("[CustomFishing] Failed to migrate data"); } String sql_2 = String.format(SqlConstants.SQL_DROP_TABLE, sqlConnection.getTablePrefix() + "_" + "sellcache"); try (Connection connection = sqlConnection.getConnectionAndCheck(); PreparedStatement statement = connection.prepareStatement(sql_2)) { statement.executeUpdate(); - AdventureUtil.consoleMessage("[CustomFishing] Outdated table deleted"); + AdventureUtils.consoleMessage("[CustomFishing] Outdated table deleted"); } catch (SQLException ex) { - AdventureUtil.consoleMessage(ex.getSQLState()); - AdventureUtil.consoleMessage("[CustomFishing] Failed to migrate data"); + AdventureUtils.consoleMessage(ex.getSQLState()); + AdventureUtils.consoleMessage("[CustomFishing] Failed to migrate data"); } } @@ -353,7 +353,7 @@ public class MySQLStorageImpl implements DataStorageInterface { statement.setString(1, uuid.toString()); statement.executeUpdate(); } catch (SQLException ex) { - AdventureUtil.consoleMessage("[CustomFishing] Failed to lock data for " + uuid); + AdventureUtils.consoleMessage("[CustomFishing] Failed to lock data for " + uuid); } } } diff --git a/src/main/java/net/momirealms/customfishing/data/storage/SqlConnection.java b/src/main/java/net/momirealms/customfishing/data/storage/SqlConnection.java index 04d5c878..ff1d8082 100644 --- a/src/main/java/net/momirealms/customfishing/data/storage/SqlConnection.java +++ b/src/main/java/net/momirealms/customfishing/data/storage/SqlConnection.java @@ -21,8 +21,8 @@ import com.zaxxer.hikari.HikariConfig; import com.zaxxer.hikari.HikariDataSource; import com.zaxxer.hikari.pool.HikariPool; import net.momirealms.customfishing.CustomFishing; -import net.momirealms.customfishing.util.AdventureUtil; -import net.momirealms.customfishing.util.ConfigUtil; +import net.momirealms.customfishing.util.AdventureUtils; +import net.momirealms.customfishing.util.ConfigUtils; import org.bukkit.configuration.file.YamlConfiguration; import java.io.File; @@ -43,8 +43,8 @@ public class SqlConnection { } public void createNewHikariConfiguration() { - ConfigUtil.update("database.yml"); - YamlConfiguration config = ConfigUtil.getConfig("database.yml"); + ConfigUtils.update("database.yml"); + YamlConfiguration config = ConfigUtils.getConfig("database.yml"); String storageMode = config.getString("data-storage-method", "MySQL"); HikariConfig hikariConfig = new HikariConfig(); @@ -74,7 +74,7 @@ public class SqlConnection { try { hikariDataSource = new HikariDataSource(hikariConfig); } catch (HikariPool.PoolInitializationException e) { - AdventureUtil.consoleMessage("[CustomFishing] Failed to create sql connection"); + AdventureUtils.consoleMessage("[CustomFishing] Failed to create sql connection"); } if (config.getBoolean("migration", false)) { @@ -84,7 +84,7 @@ public class SqlConnection { config.save(new File(CustomFishing.getInstance().getDataFolder(), "database.yml")); } catch (IOException e) { - AdventureUtil.consoleMessage("[CustomFishing] Error occurred when saving database config"); + AdventureUtils.consoleMessage("[CustomFishing] Error occurred when saving database config"); } } } @@ -95,13 +95,13 @@ public class SqlConnection { Connection connection = getConnection(); connection.close(); if (secondTry) { - AdventureUtil.consoleMessage("[CustomFishing] Successfully reconnect to SQL!"); + AdventureUtils.consoleMessage("[CustomFishing] Successfully reconnect to SQL!"); } else { secondTry = true; } return true; } catch (SQLException e) { - AdventureUtil.consoleMessage("[CustomFishing] Error! Failed to connect to SQL!"); + AdventureUtils.consoleMessage("[CustomFishing] Error! Failed to connect to SQL!"); e.printStackTrace(); close(); return false; @@ -145,7 +145,7 @@ public class SqlConnection { return getConnectionAndCheck(); } else { firstTry = true; - AdventureUtil.consoleMessage("[CustomFishing] Error! Failed to connect to SQL!"); + AdventureUtils.consoleMessage("[CustomFishing] Error! Failed to connect to SQL!"); close(); e.printStackTrace(); return null; diff --git a/src/main/java/net/momirealms/customfishing/fishing/BobberCheckTask.java b/src/main/java/net/momirealms/customfishing/fishing/BobberCheckTask.java index 014e5b73..b1489081 100644 --- a/src/main/java/net/momirealms/customfishing/fishing/BobberCheckTask.java +++ b/src/main/java/net/momirealms/customfishing/fishing/BobberCheckTask.java @@ -23,9 +23,9 @@ import net.momirealms.customfishing.CustomFishing; import net.momirealms.customfishing.fishing.loot.Loot; import net.momirealms.customfishing.manager.ConfigManager; import net.momirealms.customfishing.manager.FishingManager; -import net.momirealms.customfishing.util.AdventureUtil; -import net.momirealms.customfishing.util.ArmorStandUtil; -import net.momirealms.customfishing.util.FakeItemUtil; +import net.momirealms.customfishing.util.AdventureUtils; +import net.momirealms.customfishing.util.ArmorStandUtils; +import net.momirealms.customfishing.util.FakeItemUtils; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; @@ -80,8 +80,8 @@ public class BobberCheckTask extends BukkitRunnable { public void run() { timer ++; if (!land && entityID != 0) { - CustomFishing.getProtocolManager().sendServerPacket(player, FakeItemUtil.getVelocity(entityID, fishHook.getVelocity())); - CustomFishing.getProtocolManager().sendServerPacket(player, FakeItemUtil.getTpPacket(entityID, fishHook.getLocation())); + CustomFishing.getProtocolManager().sendServerPacket(player, FakeItemUtils.getVelocity(entityID, fishHook.getVelocity())); + CustomFishing.getProtocolManager().sendServerPacket(player, FakeItemUtils.getTpPacket(entityID, fishHook.getLocation())); } if (timer > 3600) { stop(); @@ -103,7 +103,7 @@ public class BobberCheckTask extends BukkitRunnable { } if (first) { sendRemovePacket(); - ArmorStandUtil.sendAnimationToPlayer(fishHook.getLocation(), player, ConfigManager.lava_item, ConfigManager.lava_time); + ArmorStandUtils.sendAnimationToPlayer(fishHook.getLocation(), player, ConfigManager.lava_item, ConfigManager.lava_time); first = false; } if (hooked) { @@ -136,7 +136,7 @@ public class BobberCheckTask extends BukkitRunnable { } fishingManager.getNextLoot(player, effect, possibleLoots); if (ConfigManager.enableWaterAnimation) { - ArmorStandUtil.sendAnimationToPlayer(fishHook.getLocation(), player, ConfigManager.water_item, ConfigManager.water_time); + ArmorStandUtils.sendAnimationToPlayer(fishHook.getLocation(), player, ConfigManager.water_item, ConfigManager.water_time); } }); return; @@ -159,7 +159,7 @@ public class BobberCheckTask extends BukkitRunnable { private void sendRemovePacket() { if (entityID == 0) return; - CustomFishing.getProtocolManager().sendServerPacket(player, FakeItemUtil.getDestroyPacket(entityID)); + CustomFishing.getProtocolManager().sendServerPacket(player, FakeItemUtils.getDestroyPacket(entityID)); } public void cancelTask() { @@ -193,7 +193,7 @@ public class BobberCheckTask extends BukkitRunnable { task_1 = Bukkit.getScheduler().runTaskLater(plugin, () -> { hooked = true; if (hookedEntity != null && !hookedEntity.isDead()) hookedEntity.remove(); - AdventureUtil.playerSound(player, Sound.Source.NEUTRAL, Key.key("minecraft:block.pointed_dripstone.drip_lava_into_cauldron"), 1, 1); + AdventureUtils.playerSound(player, Sound.Source.NEUTRAL, Key.key("minecraft:block.pointed_dripstone.drip_lava_into_cauldron"), 1, 1); if (ConfigManager.instantBar) fishingManager.showBar(player); }, random); task_2 = Bukkit.getScheduler().runTaskLater(plugin, () -> { diff --git a/src/main/java/net/momirealms/customfishing/fishing/action/MessageActionImpl.java b/src/main/java/net/momirealms/customfishing/fishing/action/MessageActionImpl.java index 94fd3270..1c229b69 100644 --- a/src/main/java/net/momirealms/customfishing/fishing/action/MessageActionImpl.java +++ b/src/main/java/net/momirealms/customfishing/fishing/action/MessageActionImpl.java @@ -17,7 +17,7 @@ package net.momirealms.customfishing.fishing.action; -import net.momirealms.customfishing.util.AdventureUtil; +import net.momirealms.customfishing.util.AdventureUtils; import org.bukkit.entity.Player; import org.jetbrains.annotations.Nullable; @@ -31,7 +31,7 @@ public record MessageActionImpl(String[] messages, String nick) implements Actio @Override public void doOn(Player player, @Nullable Player anotherPlayer) { for (String message : messages) { - AdventureUtil.playerMessage(player, + AdventureUtils.playerMessage(player, message.replace("{player}", player.getName()) .replace("{world}", player.getWorld().getName()) .replace("{x}", String.valueOf(player.getLocation().getBlockX())) diff --git a/src/main/java/net/momirealms/customfishing/fishing/action/SoundActionImpl.java b/src/main/java/net/momirealms/customfishing/fishing/action/SoundActionImpl.java index 6363d9c1..8176df34 100644 --- a/src/main/java/net/momirealms/customfishing/fishing/action/SoundActionImpl.java +++ b/src/main/java/net/momirealms/customfishing/fishing/action/SoundActionImpl.java @@ -19,13 +19,13 @@ package net.momirealms.customfishing.fishing.action; import net.kyori.adventure.key.Key; import net.kyori.adventure.sound.Sound; -import net.momirealms.customfishing.util.AdventureUtil; +import net.momirealms.customfishing.util.AdventureUtils; import org.bukkit.entity.Player; public record SoundActionImpl(String source, String sound, float volume, float pitch) implements Action { @Override public void doOn(Player player, Player another) { - AdventureUtil.playerSound(player, Sound.Source.valueOf(source.toUpperCase()), Key.key(sound), volume, pitch); + AdventureUtils.playerSound(player, Sound.Source.valueOf(source.toUpperCase()), Key.key(sound), volume, pitch); } } diff --git a/src/main/java/net/momirealms/customfishing/fishing/action/VanillaXPImpl.java b/src/main/java/net/momirealms/customfishing/fishing/action/VanillaXPImpl.java index 8ad105b4..a2020897 100644 --- a/src/main/java/net/momirealms/customfishing/fishing/action/VanillaXPImpl.java +++ b/src/main/java/net/momirealms/customfishing/fishing/action/VanillaXPImpl.java @@ -20,7 +20,7 @@ package net.momirealms.customfishing.fishing.action; import net.kyori.adventure.key.Key; import net.kyori.adventure.sound.Sound; import net.momirealms.customfishing.CustomFishing; -import net.momirealms.customfishing.util.AdventureUtil; +import net.momirealms.customfishing.util.AdventureUtils; import org.bukkit.entity.ExperienceOrb; import org.bukkit.entity.Player; @@ -34,12 +34,12 @@ public record VanillaXPImpl(int amount, boolean mending) implements Action { } else { player.giveExp(amount); - AdventureUtil.playerSound(player, Sound.Source.PLAYER, Key.key("minecraft:entity.experience_orb.pickup"), 1, 1); + AdventureUtils.playerSound(player, Sound.Source.PLAYER, Key.key("minecraft:entity.experience_orb.pickup"), 1, 1); } } else { player.giveExp(amount, mending); - AdventureUtil.playerSound(player, Sound.Source.PLAYER, Key.key("minecraft:entity.experience_orb.pickup"), 1, 1); + AdventureUtils.playerSound(player, Sound.Source.PLAYER, Key.key("minecraft:entity.experience_orb.pickup"), 1, 1); } } } diff --git a/src/main/java/net/momirealms/customfishing/fishing/competition/Competition.java b/src/main/java/net/momirealms/customfishing/fishing/competition/Competition.java index 3dbd5f20..057646ec 100644 --- a/src/main/java/net/momirealms/customfishing/fishing/competition/Competition.java +++ b/src/main/java/net/momirealms/customfishing/fishing/competition/Competition.java @@ -26,7 +26,7 @@ import net.momirealms.customfishing.fishing.competition.ranking.RedisRankingImpl import net.momirealms.customfishing.integration.papi.PlaceholderManager; import net.momirealms.customfishing.manager.ConfigManager; import net.momirealms.customfishing.manager.MessageManager; -import net.momirealms.customfishing.util.AdventureUtil; +import net.momirealms.customfishing.util.AdventureUtils; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; @@ -67,7 +67,7 @@ public class Competition { startTimer(); for (String startMsg : competitionConfig.getStartMessage()) for (Player player : playerCollections) - AdventureUtil.playerMessage(player, startMsg); + AdventureUtils.playerMessage(player, startMsg); for (String startCmd : competitionConfig.getStartCommand()) Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), startCmd); @@ -78,7 +78,7 @@ public class Competition { } else { for (Player player : playerCollections) { - AdventureUtil.playerMessage(player, MessageManager.prefix + MessageManager.notEnoughPlayers); + AdventureUtils.playerMessage(player, MessageManager.prefix + MessageManager.notEnoughPlayers); } currentCompetition = null; } @@ -131,7 +131,7 @@ public class Competition { for (Player player : Bukkit.getOnlinePlayers()) { for (String msg : newMessage) { - AdventureUtil.playerMessage(player, msg); + AdventureUtils.playerMessage(player, msg); } } diff --git a/src/main/java/net/momirealms/customfishing/fishing/competition/bossbar/BossBarManager.java b/src/main/java/net/momirealms/customfishing/fishing/competition/bossbar/BossBarManager.java index c50868f9..de912394 100644 --- a/src/main/java/net/momirealms/customfishing/fishing/competition/bossbar/BossBarManager.java +++ b/src/main/java/net/momirealms/customfishing/fishing/competition/bossbar/BossBarManager.java @@ -22,7 +22,7 @@ import net.momirealms.customfishing.fishing.competition.Competition; import net.momirealms.customfishing.listener.JoinQuitListener; import net.momirealms.customfishing.manager.MessageManager; import net.momirealms.customfishing.object.Function; -import net.momirealms.customfishing.util.AdventureUtil; +import net.momirealms.customfishing.util.AdventureUtils; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.HandlerList; @@ -74,7 +74,7 @@ public class BossBarManager extends Function { } cache.put(player, sender); } else { - AdventureUtil.playerMessage(player, MessageManager.competitionOn); + AdventureUtils.playerMessage(player, MessageManager.competitionOn); } } }, 5); diff --git a/src/main/java/net/momirealms/customfishing/fishing/competition/bossbar/BossBarSender.java b/src/main/java/net/momirealms/customfishing/fishing/competition/bossbar/BossBarSender.java index 247238a4..af031e93 100644 --- a/src/main/java/net/momirealms/customfishing/fishing/competition/bossbar/BossBarSender.java +++ b/src/main/java/net/momirealms/customfishing/fishing/competition/bossbar/BossBarSender.java @@ -27,7 +27,7 @@ import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; import net.momirealms.customfishing.CustomFishing; import net.momirealms.customfishing.fishing.competition.Competition; import net.momirealms.customfishing.object.DynamicText; -import net.momirealms.customfishing.util.AdventureUtil; +import net.momirealms.customfishing.util.AdventureUtils; import org.bukkit.boss.BarColor; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; @@ -75,9 +75,7 @@ public class BossBarSender { public void show() { this.isShown = true; - CustomFishing.getProtocolManager().sendServerPacket(player, getPacket()); - this.bukkitTask = new BukkitRunnable() { @Override public void run() { @@ -113,14 +111,13 @@ public class BossBarSender { try { Method sMethod = MinecraftReflection.getChatSerializerClass().getMethod("a", String.class); sMethod.setAccessible(true); - Object chatComponent = sMethod.invoke(null, GsonComponentSerializer.gson().serialize(MiniMessage.miniMessage().deserialize(AdventureUtil.replaceLegacy(text.getLatestValue())))); + Object chatComponent = sMethod.invoke(null, GsonComponentSerializer.gson().serialize(MiniMessage.miniMessage().deserialize(AdventureUtils.replaceLegacy(text.getLatestValue())))); Class packetBossClass = Class.forName("net.minecraft.network.protocol.game.PacketPlayOutBoss$e"); Constructor packetConstructor = packetBossClass.getDeclaredConstructor(MinecraftReflection.getIChatBaseComponentClass()); packetConstructor.setAccessible(true); Object updatePacket = packetConstructor.newInstance(chatComponent); packet.getModifier().write(1, updatePacket); - } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException | ClassNotFoundException | - InstantiationException e) { + } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException | ClassNotFoundException | InstantiationException e) { throw new RuntimeException(e); } return packet; @@ -136,8 +133,7 @@ public class BossBarSender { packetConstructor.setAccessible(true); Object updatePacket = packetConstructor.newInstance(Competition.currentCompetition.getProgress()); packet.getModifier().write(1, updatePacket); - } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException | ClassNotFoundException | - InstantiationException e) { + } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException | ClassNotFoundException | InstantiationException e) { throw new RuntimeException(e); } return packet; @@ -172,8 +168,8 @@ public class BossBarSender { remove.setAccessible(true); packet.getModifier().write(1, remove.get(null)); CustomFishing.getProtocolManager().sendServerPacket(player, packet); - } catch (ClassNotFoundException e){ - AdventureUtil.consoleMessage("[CustomFishing] Failed to remove bossbar for " + player.getName()); + } catch (ClassNotFoundException e) { + AdventureUtils.consoleMessage("[CustomFishing] Failed to remove bossbar for " + player.getName()); } catch (NoSuchFieldException | IllegalAccessException e) { throw new RuntimeException(e); } diff --git a/src/main/java/net/momirealms/customfishing/fishing/competition/ranking/RedisRankingImpl.java b/src/main/java/net/momirealms/customfishing/fishing/competition/ranking/RedisRankingImpl.java index 968d6839..c2ed82bd 100644 --- a/src/main/java/net/momirealms/customfishing/fishing/competition/ranking/RedisRankingImpl.java +++ b/src/main/java/net/momirealms/customfishing/fishing/competition/ranking/RedisRankingImpl.java @@ -18,7 +18,7 @@ package net.momirealms.customfishing.fishing.competition.ranking; import net.momirealms.customfishing.fishing.competition.CompetitionPlayer; -import net.momirealms.customfishing.util.JedisUtil; +import net.momirealms.customfishing.util.JedisUtils; import redis.clients.jedis.Jedis; import redis.clients.jedis.resps.Tuple; @@ -29,14 +29,14 @@ public class RedisRankingImpl implements RankingInterface { @Override public void clear() { - Jedis jedis = JedisUtil.getJedis(); + Jedis jedis = JedisUtils.getJedis(); jedis.zremrangeByRank("cf_competition",0,-1); jedis.close(); } @Override public CompetitionPlayer getCompetitionPlayer(String player) { - Jedis jedis = JedisUtil.getJedis(); + Jedis jedis = JedisUtils.getJedis(); Double score = jedis.zscore("cf_competition", player); jedis.close(); if (score == null || score == 0) return null; @@ -45,7 +45,7 @@ public class RedisRankingImpl implements RankingInterface { @Override public Iterator getIterator() { - Jedis jedis = JedisUtil.getJedis(); + Jedis jedis = JedisUtils.getJedis(); List players = jedis.zrevrange("cf_competition", 0, -1); jedis.close(); return players.iterator(); @@ -53,7 +53,7 @@ public class RedisRankingImpl implements RankingInterface { @Override public int getSize() { - Jedis jedis = JedisUtil.getJedis(); + Jedis jedis = JedisUtils.getJedis(); long size = jedis.zcard("cf_competition"); jedis.close(); return (int) size; @@ -61,7 +61,7 @@ public class RedisRankingImpl implements RankingInterface { @Override public String getPlayerRank(String player) { - Jedis jedis = JedisUtil.getJedis(); + Jedis jedis = JedisUtils.getJedis(); Long rank = jedis.zrevrank("cf_competition", player); jedis.close(); if(rank == null){ @@ -72,7 +72,7 @@ public class RedisRankingImpl implements RankingInterface { @Override public float getPlayerScore(String player) { - Jedis jedis = JedisUtil.getJedis(); + Jedis jedis = JedisUtils.getJedis(); Double rank = jedis.zscore("cf_competition", player); jedis.close(); if(rank == null) { @@ -83,21 +83,21 @@ public class RedisRankingImpl implements RankingInterface { @Override public void refreshData(String player, float score) { - Jedis jedis = JedisUtil.getJedis(); + Jedis jedis = JedisUtils.getJedis(); jedis.zincrby("cf_competition", score, player); jedis.close(); } @Override public void setData(String player, float score) { - Jedis jedis = JedisUtil.getJedis(); + Jedis jedis = JedisUtils.getJedis(); jedis.zadd("cf_competition", score, player); jedis.close(); } @Override public String getPlayerAt(int rank) { - Jedis jedis = JedisUtil.getJedis(); + Jedis jedis = JedisUtils.getJedis(); List player = jedis.zrevrange("cf_competition", rank - 1, rank -1); jedis.close(); if (player == null) return null; @@ -107,7 +107,7 @@ public class RedisRankingImpl implements RankingInterface { @Override public float getScoreAt(int rank) { - Jedis jedis = JedisUtil.getJedis(); + Jedis jedis = JedisUtils.getJedis(); List players = jedis.zrevrangeWithScores("cf_competition", rank - 1, rank -1); jedis.close(); if (players == null) return 0; diff --git a/src/main/java/net/momirealms/customfishing/fishing/mode/FishingGame.java b/src/main/java/net/momirealms/customfishing/fishing/mode/FishingGame.java index bdab3bf6..14911846 100644 --- a/src/main/java/net/momirealms/customfishing/fishing/mode/FishingGame.java +++ b/src/main/java/net/momirealms/customfishing/fishing/mode/FishingGame.java @@ -22,7 +22,7 @@ import net.momirealms.customfishing.fishing.bar.FishingBar; import net.momirealms.customfishing.manager.FishingManager; import net.momirealms.customfishing.manager.MessageManager; import net.momirealms.customfishing.manager.OffsetManager; -import net.momirealms.customfishing.util.AdventureUtil; +import net.momirealms.customfishing.util.AdventureUtils; import org.bukkit.Material; import org.bukkit.entity.FishHook; import org.bukkit.entity.Player; @@ -68,7 +68,7 @@ public abstract class FishingGame extends BukkitRunnable { protected void timeOutCheck() { if (System.currentTimeMillis() > deadline) { - AdventureUtil.playerMessage(player, MessageManager.prefix + MessageManager.escape); + AdventureUtils.playerMessage(player, MessageManager.prefix + MessageManager.escape); cancel(); fishingManager.removeFishingPlayer(player); fishingManager.removeHook(player); diff --git a/src/main/java/net/momirealms/customfishing/fishing/mode/ModeOneGame.java b/src/main/java/net/momirealms/customfishing/fishing/mode/ModeOneGame.java index aee93e4c..e416fff1 100644 --- a/src/main/java/net/momirealms/customfishing/fishing/mode/ModeOneGame.java +++ b/src/main/java/net/momirealms/customfishing/fishing/mode/ModeOneGame.java @@ -20,7 +20,7 @@ package net.momirealms.customfishing.fishing.mode; import net.momirealms.customfishing.CustomFishing; import net.momirealms.customfishing.fishing.bar.ModeOneBar; import net.momirealms.customfishing.manager.FishingManager; -import net.momirealms.customfishing.util.AdventureUtil; +import net.momirealms.customfishing.util.AdventureUtils; import org.bukkit.entity.Player; public class ModeOneGame extends FishingGame { @@ -57,7 +57,7 @@ public class ModeOneGame extends FishingGame { + "" + offsetManager.getOffsetChars(modeOneBar.getPointerOffset() + progress) + "" + modeOneBar.getPointerImage() + "" + offsetManager.getOffsetChars(modeOneBar.getTotalWidth() - progress - modeOneBar.getPointerWidth()) + ""; - AdventureUtil.playerTitle(player, title, bar,0,500,0); + AdventureUtils.playerTitle(player, title, bar,0,500,0); } @Override diff --git a/src/main/java/net/momirealms/customfishing/fishing/mode/ModeThreeGame.java b/src/main/java/net/momirealms/customfishing/fishing/mode/ModeThreeGame.java index 31b9c5fa..49ee33a3 100644 --- a/src/main/java/net/momirealms/customfishing/fishing/mode/ModeThreeGame.java +++ b/src/main/java/net/momirealms/customfishing/fishing/mode/ModeThreeGame.java @@ -20,7 +20,7 @@ package net.momirealms.customfishing.fishing.mode; import net.momirealms.customfishing.CustomFishing; import net.momirealms.customfishing.fishing.bar.ModeThreeBar; import net.momirealms.customfishing.manager.FishingManager; -import net.momirealms.customfishing.util.AdventureUtil; +import net.momirealms.customfishing.util.AdventureUtils; import org.bukkit.entity.FishHook; import org.bukkit.entity.Player; @@ -103,7 +103,7 @@ public class ModeThreeGame extends FishingGame { + "" + offsetManager.getOffsetChars(modeThreeBar.getBar_effective_width() - fish_position - modeThreeBar.getFish_icon_width()) + "" + ""; strain = Math.max(0, Math.min(strain, modeThreeBar.getUltimate_strain())); - AdventureUtil.playerTitle(player, + AdventureUtils.playerTitle(player, title.replace("{strain}", modeThreeBar.getStrain()[(int) ((strain / modeThreeBar.getUltimate_strain()) * modeThreeBar.getStrain().length)]) , bar,0,500,0 ); diff --git a/src/main/java/net/momirealms/customfishing/fishing/mode/ModeTwoGame.java b/src/main/java/net/momirealms/customfishing/fishing/mode/ModeTwoGame.java index 3d3404d6..11c696da 100644 --- a/src/main/java/net/momirealms/customfishing/fishing/mode/ModeTwoGame.java +++ b/src/main/java/net/momirealms/customfishing/fishing/mode/ModeTwoGame.java @@ -20,7 +20,7 @@ package net.momirealms.customfishing.fishing.mode; import net.momirealms.customfishing.CustomFishing; import net.momirealms.customfishing.fishing.bar.ModeTwoBar; import net.momirealms.customfishing.manager.FishingManager; -import net.momirealms.customfishing.util.AdventureUtil; +import net.momirealms.customfishing.util.AdventureUtils; import org.bukkit.entity.FishHook; import org.bukkit.entity.Player; @@ -96,7 +96,7 @@ public class ModeTwoGame extends FishingGame { + "" + offsetManager.getOffsetChars((int) (modeTwoBar.getBar_effective_width() - fish_position - modeTwoBar.getFish_icon_width() + 1)) + "" + ""; hold_time = Math.max(0, Math.min(hold_time, time_requirement)); - AdventureUtil.playerTitle(player, + AdventureUtils.playerTitle(player, title.replace("{progress}", modeTwoBar.getProgress()[(int) ((hold_time / time_requirement) * modeTwoBar.getProgress().length)]) , bar,0,500,0 ); diff --git a/src/main/java/net/momirealms/customfishing/fishing/requirements/Requirement.java b/src/main/java/net/momirealms/customfishing/fishing/requirements/Requirement.java index 4777ef98..8cbfec66 100644 --- a/src/main/java/net/momirealms/customfishing/fishing/requirements/Requirement.java +++ b/src/main/java/net/momirealms/customfishing/fishing/requirements/Requirement.java @@ -17,7 +17,7 @@ package net.momirealms.customfishing.fishing.requirements; -import net.momirealms.customfishing.util.AdventureUtil; +import net.momirealms.customfishing.util.AdventureUtils; import org.bukkit.entity.Player; import org.jetbrains.annotations.Nullable; @@ -32,7 +32,7 @@ public abstract class Requirement { public void notMetMessage(Player player) { if (msg != null && player != null) { for (String str : msg) { - AdventureUtil.playerMessage(player, str); + AdventureUtils.playerMessage(player, str); } } } diff --git a/src/main/java/net/momirealms/customfishing/fishing/totem/ActivatedTotem.java b/src/main/java/net/momirealms/customfishing/fishing/totem/ActivatedTotem.java index 832567da..fbae7097 100644 --- a/src/main/java/net/momirealms/customfishing/fishing/totem/ActivatedTotem.java +++ b/src/main/java/net/momirealms/customfishing/fishing/totem/ActivatedTotem.java @@ -19,7 +19,7 @@ package net.momirealms.customfishing.fishing.totem; import net.momirealms.customfishing.CustomFishing; import net.momirealms.customfishing.manager.FishingManager; -import net.momirealms.customfishing.util.ArmorStandUtil; +import net.momirealms.customfishing.util.ArmorStandUtils; import net.momirealms.customfishing.util.LocationUtils; import org.bukkit.Location; import org.bukkit.entity.Player; @@ -79,7 +79,7 @@ public class ActivatedTotem extends BukkitRunnable { if (nearbyPlayers.remove(player)) { if (hasHolo) { for (int i = 0; i < entityID.length; i++) { - CustomFishing.getProtocolManager().sendServerPacket(player, ArmorStandUtil.getMetaPacket(entityID[i], + CustomFishing.getProtocolManager().sendServerPacket(player, ArmorStandUtils.getMetaPacket(entityID[i], totem.getHoloText()[entityID.length - 1 - i] .replace("{time}", String.valueOf(totem.getDuration() - timer)) .replace("{max_time}", String.valueOf(totem.getDuration())) @@ -92,7 +92,7 @@ public class ActivatedTotem extends BukkitRunnable { else { if (hasHolo) { for (int j : entityID) { - CustomFishing.getProtocolManager().sendServerPacket(player, ArmorStandUtil.getDestroyPacket(j)); + CustomFishing.getProtocolManager().sendServerPacket(player, ArmorStandUtils.getDestroyPacket(j)); } } nearbyPlayerSet.remove(player); @@ -102,8 +102,8 @@ public class ActivatedTotem extends BukkitRunnable { for (Player newComer : nearbyPlayers) { if (hasHolo) { for (int i = 0; i < entityID.length; i++) { - CustomFishing.getProtocolManager().sendServerPacket(newComer, ArmorStandUtil.getSpawnPacket(entityID[i], bottomLoc.clone().add(0.5, totem.getHoloOffset() + i * 0.4, 0.5))); - CustomFishing.getProtocolManager().sendServerPacket(newComer, ArmorStandUtil.getMetaPacket(entityID[i], + CustomFishing.getProtocolManager().sendServerPacket(newComer, ArmorStandUtils.getSpawnPacket(entityID[i], bottomLoc.clone().add(0.5, totem.getHoloOffset() + i * 0.4, 0.5))); + CustomFishing.getProtocolManager().sendServerPacket(newComer, ArmorStandUtils.getMetaPacket(entityID[i], totem.getHoloText()[entityID.length - 1 - i] .replace("{time}", String.valueOf(totem.getDuration() - timer)) .replace("{max_time}", String.valueOf(totem.getDuration())) @@ -132,7 +132,7 @@ public class ActivatedTotem extends BukkitRunnable { if (hasHolo) { for (Player player : nearbyPlayerSet) { for (int j : entityID) { - CustomFishing.getProtocolManager().sendServerPacket(player, ArmorStandUtil.getDestroyPacket(j)); + CustomFishing.getProtocolManager().sendServerPacket(player, ArmorStandUtils.getDestroyPacket(j)); } } } diff --git a/src/main/java/net/momirealms/customfishing/helper/VersionHelper.java b/src/main/java/net/momirealms/customfishing/helper/VersionHelper.java index f7ed90ad..6d60912c 100644 --- a/src/main/java/net/momirealms/customfishing/helper/VersionHelper.java +++ b/src/main/java/net/momirealms/customfishing/helper/VersionHelper.java @@ -21,7 +21,7 @@ import de.tr7zw.changeme.nbtapi.utils.MinecraftVersion; import de.tr7zw.changeme.nbtapi.utils.VersionChecker; import net.momirealms.customfishing.CustomFishing; import net.momirealms.customfishing.manager.ConfigManager; -import net.momirealms.customfishing.util.AdventureUtil; +import net.momirealms.customfishing.util.AdventureUtils; import org.bukkit.Bukkit; import java.io.BufferedReader; @@ -105,19 +105,19 @@ public class VersionHelper { inputStream.close(); if (!compareVer(newest, current)) { - AdventureUtil.consoleMessage(ConfigManager.lang.equalsIgnoreCase("chinese") ? "[CustomFishing] 当前已是最新版本" : "[CustomFishing] You are using the latest version."); + AdventureUtils.consoleMessage(ConfigManager.lang.equalsIgnoreCase("chinese") ? "[CustomFishing] 当前已是最新版本" : "[CustomFishing] You are using the latest version."); return; } if (ConfigManager.lang.equalsIgnoreCase("chinese")) { - AdventureUtil.consoleMessage("[CustomFishing] 当前版本: " + current); - AdventureUtil.consoleMessage("[CustomFishing] 最新版本: " + newest); - AdventureUtil.consoleMessage("[CustomFishing] 请到 售后群https://polymart.org/resource/customfishing.2723 获取最新版本."); + AdventureUtils.consoleMessage("[CustomFishing] 当前版本: " + current); + AdventureUtils.consoleMessage("[CustomFishing] 最新版本: " + newest); + AdventureUtils.consoleMessage("[CustomFishing] 请到 售后群https://polymart.org/resource/customfishing.2723 获取最新版本."); } else { - AdventureUtil.consoleMessage("[CustomFishing] Current version: " + current); - AdventureUtil.consoleMessage("[CustomFishing] Latest version: " + newest); - AdventureUtil.consoleMessage("[CustomFishing] Update is available: https://polymart.org/resource/customfishing.2723"); + AdventureUtils.consoleMessage("[CustomFishing] Current version: " + current); + AdventureUtils.consoleMessage("[CustomFishing] Latest version: " + newest); + AdventureUtils.consoleMessage("[CustomFishing] Update is available: https://polymart.org/resource/customfishing.2723"); } } catch (Exception exception) { Log.warn("Error occurred when checking update"); diff --git a/src/main/java/net/momirealms/customfishing/integration/block/ItemsAdderBlockImpl.java b/src/main/java/net/momirealms/customfishing/integration/block/ItemsAdderBlockImpl.java index 0e6e6628..1fbfbbb5 100644 --- a/src/main/java/net/momirealms/customfishing/integration/block/ItemsAdderBlockImpl.java +++ b/src/main/java/net/momirealms/customfishing/integration/block/ItemsAdderBlockImpl.java @@ -20,7 +20,7 @@ package net.momirealms.customfishing.integration.block; import dev.lone.itemsadder.api.CustomBlock; import net.momirealms.customfishing.CustomFishing; import net.momirealms.customfishing.integration.BlockInterface; -import net.momirealms.customfishing.util.AdventureUtil; +import net.momirealms.customfishing.util.AdventureUtils; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; @@ -42,7 +42,7 @@ public class ItemsAdderBlockImpl implements BlockInterface { public void placeBlock(String id, Location location) { String blockID = CustomFishing.getInstance().getTotemManager().getInvertedBlock(id); if (blockID == null) { - AdventureUtil.consoleMessage(id + " does not exist in default.yml"); + AdventureUtils.consoleMessage(id + " does not exist in default.yml"); return; } if (BlockInterface.isVanillaItem(blockID)) { diff --git a/src/main/java/net/momirealms/customfishing/integration/block/OraxenBlockImpl.java b/src/main/java/net/momirealms/customfishing/integration/block/OraxenBlockImpl.java index d4df4394..5bba954e 100644 --- a/src/main/java/net/momirealms/customfishing/integration/block/OraxenBlockImpl.java +++ b/src/main/java/net/momirealms/customfishing/integration/block/OraxenBlockImpl.java @@ -22,7 +22,7 @@ import io.th0rgal.oraxen.mechanics.provided.gameplay.noteblock.NoteBlockMechanic import io.th0rgal.oraxen.mechanics.provided.gameplay.noteblock.NoteBlockMechanicFactory; import net.momirealms.customfishing.CustomFishing; import net.momirealms.customfishing.integration.BlockInterface; -import net.momirealms.customfishing.util.AdventureUtil; +import net.momirealms.customfishing.util.AdventureUtils; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; @@ -39,7 +39,7 @@ public class OraxenBlockImpl implements BlockInterface { public void placeBlock(String id, Location location) { String blockID = CustomFishing.getInstance().getTotemManager().getInvertedBlock(id); if (blockID == null) { - AdventureUtil.consoleMessage(id + " does not exist in default.yml"); + AdventureUtils.consoleMessage(id + " does not exist in default.yml"); return; } if (BlockInterface.isVanillaItem(blockID)) { diff --git a/src/main/java/net/momirealms/customfishing/integration/block/VanillaBlockImpl.java b/src/main/java/net/momirealms/customfishing/integration/block/VanillaBlockImpl.java index fa16959b..6a1686dd 100644 --- a/src/main/java/net/momirealms/customfishing/integration/block/VanillaBlockImpl.java +++ b/src/main/java/net/momirealms/customfishing/integration/block/VanillaBlockImpl.java @@ -19,7 +19,7 @@ package net.momirealms.customfishing.integration.block; import net.momirealms.customfishing.CustomFishing; import net.momirealms.customfishing.integration.BlockInterface; -import net.momirealms.customfishing.util.AdventureUtil; +import net.momirealms.customfishing.util.AdventureUtils; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; @@ -35,7 +35,7 @@ public class VanillaBlockImpl implements BlockInterface { public void placeBlock(String id, Location location) { String blockID = CustomFishing.getInstance().getTotemManager().getInvertedBlock(id); if (blockID == null) { - AdventureUtil.consoleMessage(id + " does not exist in default.yml"); + AdventureUtils.consoleMessage(id + " does not exist in default.yml"); return; } BlockInterface.placeVanillaBlock(blockID, location); diff --git a/src/main/java/net/momirealms/customfishing/integration/item/EcoItemRegister.java b/src/main/java/net/momirealms/customfishing/integration/item/EcoItemRegister.java index 625516da..e142966e 100644 --- a/src/main/java/net/momirealms/customfishing/integration/item/EcoItemRegister.java +++ b/src/main/java/net/momirealms/customfishing/integration/item/EcoItemRegister.java @@ -22,7 +22,7 @@ import de.tr7zw.changeme.nbtapi.NBTCompound; import de.tr7zw.changeme.nbtapi.NBTItem; import net.momirealms.customfishing.CustomFishing; import net.momirealms.customfishing.fishing.loot.Item; -import net.momirealms.customfishing.util.ItemStackUtil; +import net.momirealms.customfishing.util.ItemStackUtils; import org.bukkit.NamespacedKey; import java.util.Map; @@ -45,7 +45,7 @@ public class EcoItemRegister { return false; } }, - ItemStackUtil.getFromItem(entry.getValue()) + ItemStackUtils.getFromItem(entry.getValue()) ).register(); } // Baits @@ -63,7 +63,7 @@ public class EcoItemRegister { return false; } }, - ItemStackUtil.getFromItem(entry.getValue()) + ItemStackUtils.getFromItem(entry.getValue()) ).register(); } // Utils @@ -81,7 +81,7 @@ public class EcoItemRegister { return false; } }, - ItemStackUtil.getFromItem(entry.getValue()) + ItemStackUtils.getFromItem(entry.getValue()) ).register(); } } diff --git a/src/main/java/net/momirealms/customfishing/integration/quest/NewBetonQuestCFQuest.java b/src/main/java/net/momirealms/customfishing/integration/quest/NewBetonQuestCFQuest.java index a69e1520..146be5a4 100644 --- a/src/main/java/net/momirealms/customfishing/integration/quest/NewBetonQuestCFQuest.java +++ b/src/main/java/net/momirealms/customfishing/integration/quest/NewBetonQuestCFQuest.java @@ -19,7 +19,7 @@ package net.momirealms.customfishing.integration.quest; import net.momirealms.customfishing.api.event.FishResultEvent; import net.momirealms.customfishing.fishing.FishResult; -import net.momirealms.customfishing.util.AdventureUtil; +import net.momirealms.customfishing.util.AdventureUtils; import org.betonquest.betonquest.BetonQuest; import org.betonquest.betonquest.Instruction; import org.betonquest.betonquest.VariableNumber; @@ -96,7 +96,7 @@ public class NewBetonQuestCFQuest extends CountingObjective implements Listener try { targetLocation = playerLocation.getLocation(profile); } catch (final org.betonquest.betonquest.exceptions.QuestRuntimeException e) { - AdventureUtil.consoleMessage(e.getMessage()); + AdventureUtils.consoleMessage(e.getMessage()); return true; } final int range = rangeVar.getInt(profile); diff --git a/src/main/java/net/momirealms/customfishing/integration/quest/OldBetonQuestCFQuest.java b/src/main/java/net/momirealms/customfishing/integration/quest/OldBetonQuestCFQuest.java index 83a2ef98..0352f184 100644 --- a/src/main/java/net/momirealms/customfishing/integration/quest/OldBetonQuestCFQuest.java +++ b/src/main/java/net/momirealms/customfishing/integration/quest/OldBetonQuestCFQuest.java @@ -19,7 +19,7 @@ package net.momirealms.customfishing.integration.quest; import net.momirealms.customfishing.api.event.FishResultEvent; import net.momirealms.customfishing.fishing.FishResult; -import net.momirealms.customfishing.util.AdventureUtil; +import net.momirealms.customfishing.util.AdventureUtils; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -134,7 +134,7 @@ public class OldBetonQuestCFQuest extends Objective implements Listener { this.amount = Integer.parseInt(instruction); } catch (NumberFormatException e) { - AdventureUtil.consoleMessage("[CustomFishing] NumberFormatException"); + AdventureUtils.consoleMessage("[CustomFishing] NumberFormatException"); this.amount = 1; } } diff --git a/src/main/java/net/momirealms/customfishing/manager/BagDataManager.java b/src/main/java/net/momirealms/customfishing/manager/BagDataManager.java index 50a3bb22..2a194df6 100644 --- a/src/main/java/net/momirealms/customfishing/manager/BagDataManager.java +++ b/src/main/java/net/momirealms/customfishing/manager/BagDataManager.java @@ -29,7 +29,7 @@ import net.momirealms.customfishing.listener.InventoryListener; import net.momirealms.customfishing.listener.JoinQuitListener; import net.momirealms.customfishing.listener.WindowPacketListener; import net.momirealms.customfishing.object.InventoryFunction; -import net.momirealms.customfishing.util.AdventureUtil; +import net.momirealms.customfishing.util.AdventureUtils; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.OfflinePlayer; @@ -59,7 +59,6 @@ public class BagDataManager extends InventoryFunction { this.plugin = plugin; this.dataMap = new ConcurrentHashMap<>(); this.tempData = new HashMap<>(); - this.inventoryListener = new InventoryListener(this); this.windowPacketListener = new WindowPacketListener(this); this.joinQuitListener = new JoinQuitListener(this); @@ -102,9 +101,9 @@ public class BagDataManager extends InventoryFunction { if (owner == null) { Inventory inventory = plugin.getDataManager().getDataStorageInterface().loadBagData(ownerOffline.getUniqueId(), force); if (inventory == null) { - AdventureUtil.playerMessage(viewer, "[CustomFishing] Failed to load bag data for player " + ownerOffline.getName()); - AdventureUtil.playerMessage(viewer, "This might be caused by the target player is online but on another server"); - AdventureUtil.playerMessage(viewer, "Use /fishingbag open [Player] --force to ignore this warning"); + AdventureUtils.playerMessage(viewer, "[CustomFishing] Failed to load bag data for player " + ownerOffline.getName()); + AdventureUtils.playerMessage(viewer, "This might be caused by the target player is online but on another server"); + AdventureUtils.playerMessage(viewer, "Use /fishingbag open [Player] --force to ignore this warning"); return; } tempData.put(ownerOffline.getUniqueId(), inventory); @@ -114,10 +113,10 @@ public class BagDataManager extends InventoryFunction { else { Inventory inventory = dataMap.get(owner.getUniqueId()); if (inventory == null) { - AdventureUtil.consoleMessage("[CustomFishing] Bag data is not loaded for player " + owner.getName()); + AdventureUtils.consoleMessage("[CustomFishing] Bag data is not loaded for player " + owner.getName()); } else { - openGui(owner, viewer, inventory); + openBagGUI(owner, viewer, inventory); } } } @@ -172,7 +171,7 @@ public class BagDataManager extends InventoryFunction { WrappedChatComponent.fromJson( GsonComponentSerializer.gson().serialize( MiniMessage.miniMessage().deserialize( - AdventureUtil.replaceLegacy(text) + AdventureUtils.replaceLegacy(text) ) ) ) @@ -231,7 +230,7 @@ public class BagDataManager extends InventoryFunction { } } - public void openGui(Player owner, Player viewer, Inventory inventory) { + public void openBagGUI(Player owner, Player viewer, Inventory inventory) { int size = 1; for (int i = 6; i > 1; i--) { if (owner.hasPermission("fishingbag.rows." + i)) { @@ -241,7 +240,7 @@ public class BagDataManager extends InventoryFunction { } if (size * 9 != inventory.getSize()) { ItemStack[] itemStacks = inventory.getContents(); - Inventory newInv = plugin.getVersionHelper().isSpigot() ? Bukkit.createInventory(null, size * 9, AdventureUtil.replaceMiniMessage(ConfigManager.fishingBagTitle.replace("{player}", owner.getName()))) : Bukkit.createInventory(null, size * 9, "{CustomFishing_Bag_" + owner.getName() + "}"); + Inventory newInv = plugin.getVersionHelper().isSpigot() ? Bukkit.createInventory(null, size * 9, AdventureUtils.replaceMiniMessage(ConfigManager.fishingBagTitle.replace("{player}", owner.getName()))) : Bukkit.createInventory(null, size * 9, "{CustomFishing_Bag_" + owner.getName() + "}"); newInv.setContents(itemStacks); dataMap.put(owner.getUniqueId(), newInv); viewer.openInventory(newInv); diff --git a/src/main/java/net/momirealms/customfishing/manager/BarMechanicManager.java b/src/main/java/net/momirealms/customfishing/manager/BarMechanicManager.java index e29416f6..261f8b1e 100644 --- a/src/main/java/net/momirealms/customfishing/manager/BarMechanicManager.java +++ b/src/main/java/net/momirealms/customfishing/manager/BarMechanicManager.java @@ -24,7 +24,7 @@ import net.momirealms.customfishing.fishing.bar.ModeOneBar; import net.momirealms.customfishing.fishing.bar.ModeThreeBar; import net.momirealms.customfishing.fishing.bar.ModeTwoBar; import net.momirealms.customfishing.object.Function; -import net.momirealms.customfishing.util.AdventureUtil; +import net.momirealms.customfishing.util.AdventureUtils; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; @@ -75,12 +75,12 @@ public class BarMechanicManager extends Function { fishingBarList.add(bars.get(bar)); } else { - AdventureUtil.consoleMessage("[CustomFishing] Bar " + bar + " doesn't exist"); + AdventureUtils.consoleMessage("[CustomFishing] Bar " + bar + " doesn't exist"); } } int[] difficulties = section.getIntegerList("difficulty").stream().mapToInt(Integer::intValue).toArray(); if (difficulties.length == 0) { - AdventureUtil.consoleMessage("[CustomFishing] Game " + key + " doesn't have difficulties"); + AdventureUtils.consoleMessage("[CustomFishing] Game " + key + " doesn't have difficulties"); continue; } MiniGameConfig miniGameConfig = new MiniGameConfig( @@ -91,7 +91,7 @@ public class BarMechanicManager extends Function { miniGames.put(key, miniGameConfig); } } - AdventureUtil.consoleMessage("[CustomFishing] Loaded " + miniGames.size() + " game(s)"); + AdventureUtils.consoleMessage("[CustomFishing] Loaded " + miniGames.size() + " game(s)"); } private void loadBars() { @@ -123,7 +123,7 @@ public class BarMechanicManager extends Function { } } } - AdventureUtil.consoleMessage("[CustomFishing] Loaded " + bars.size() + " bar(s)"); + AdventureUtils.consoleMessage("[CustomFishing] Loaded " + bars.size() + " bar(s)"); } public MiniGameConfig getGameConfig(String game) { diff --git a/src/main/java/net/momirealms/customfishing/manager/CompetitionManager.java b/src/main/java/net/momirealms/customfishing/manager/CompetitionManager.java index d11bbf6b..e6e8d7cb 100644 --- a/src/main/java/net/momirealms/customfishing/manager/CompetitionManager.java +++ b/src/main/java/net/momirealms/customfishing/manager/CompetitionManager.java @@ -27,7 +27,7 @@ import net.momirealms.customfishing.fishing.competition.CompetitionSchedule; import net.momirealms.customfishing.fishing.competition.bossbar.BossBarConfig; import net.momirealms.customfishing.fishing.competition.bossbar.BossBarOverlay; import net.momirealms.customfishing.object.Function; -import net.momirealms.customfishing.util.AdventureUtil; +import net.momirealms.customfishing.util.AdventureUtils; import org.bukkit.boss.BarColor; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; @@ -128,7 +128,7 @@ public class CompetitionManager extends Function { case "Thursday" -> days.add(5); case "Friday" -> days.add(6); case "Saturday" -> days.add(7); - default -> AdventureUtil.consoleMessage("[CustomFishing] Unknown weekday: " + weekDay); + default -> AdventureUtils.consoleMessage("[CustomFishing] Unknown weekday: " + weekDay); } } competitionConfig.setWeekday(days); @@ -146,7 +146,7 @@ public class CompetitionManager extends Function { amount++; } } - AdventureUtil.consoleMessage("[CustomFishing] Loaded " + amount + " competition(s)"); + AdventureUtils.consoleMessage("[CustomFishing] Loaded " + amount + " competition(s)"); } public HashMap getCompetitionsT() { diff --git a/src/main/java/net/momirealms/customfishing/manager/ConfigManager.java b/src/main/java/net/momirealms/customfishing/manager/ConfigManager.java index 9f4ccc11..daa0188f 100644 --- a/src/main/java/net/momirealms/customfishing/manager/ConfigManager.java +++ b/src/main/java/net/momirealms/customfishing/manager/ConfigManager.java @@ -17,8 +17,8 @@ package net.momirealms.customfishing.manager; -import net.momirealms.customfishing.util.ConfigUtil; -import net.momirealms.customfishing.util.JedisUtil; +import net.momirealms.customfishing.util.ConfigUtils; +import net.momirealms.customfishing.util.JedisUtils; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.World; @@ -80,8 +80,8 @@ public class ConfigManager { public static boolean updateChecker; public static void load() { - ConfigUtil.update("config.yml"); - YamlConfiguration config = ConfigUtil.getConfig("config.yml"); + ConfigUtils.update("config.yml"); + YamlConfiguration config = ConfigUtils.getConfig("config.yml"); lang = config.getString("lang","english"); bStats = config.getBoolean("metrics", true); updateChecker = config.getBoolean("update-checker", true); @@ -169,14 +169,14 @@ public class ConfigManager { private static void redisSettings(YamlConfiguration config) { if (enableCompetition && config.getBoolean("mechanics.fishing-competition.redis", false)) { - if (!JedisUtil.isPoolEnabled()) { - YamlConfiguration configuration = ConfigUtil.getConfig("database.yml"); - JedisUtil.initializeRedis(configuration); + if (!JedisUtils.isPoolEnabled()) { + YamlConfiguration configuration = ConfigUtils.getConfig("database.yml"); + JedisUtils.initializeRedis(configuration); } useRedis = true; } - else if (useRedis && JedisUtil.isPoolEnabled()) { - JedisUtil.closePool(); + else if (useRedis && JedisUtils.isPoolEnabled()) { + JedisUtils.closePool(); useRedis = false; } } diff --git a/src/main/java/net/momirealms/customfishing/manager/DataManager.java b/src/main/java/net/momirealms/customfishing/manager/DataManager.java index f7c89f27..fe1a4f12 100644 --- a/src/main/java/net/momirealms/customfishing/manager/DataManager.java +++ b/src/main/java/net/momirealms/customfishing/manager/DataManager.java @@ -23,8 +23,8 @@ import net.momirealms.customfishing.data.storage.FileStorageImpl; import net.momirealms.customfishing.data.storage.MySQLStorageImpl; import net.momirealms.customfishing.data.storage.StorageType; import net.momirealms.customfishing.object.Function; -import net.momirealms.customfishing.util.AdventureUtil; -import net.momirealms.customfishing.util.ConfigUtil; +import net.momirealms.customfishing.util.AdventureUtils; +import net.momirealms.customfishing.util.ConfigUtils; import org.bukkit.Bukkit; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.scheduler.BukkitTask; @@ -45,7 +45,7 @@ public class DataManager extends Function { } private boolean loadStorageMode() { - YamlConfiguration config = ConfigUtil.getConfig("database.yml"); + YamlConfiguration config = ConfigUtils.getConfig("database.yml"); if (config.getString("data-storage-method","YAML").equalsIgnoreCase("YAML")) { if (storageType != StorageType.YAML) { this.dataStorageInterface = new FileStorageImpl(plugin); @@ -68,22 +68,22 @@ public class DataManager extends Function { this.timerSave = Bukkit.getScheduler().runTaskTimerAsynchronously(plugin, () -> { //long time1 = System.currentTimeMillis(); if (ConfigManager.enableFishingBag) { - AdventureUtil.consoleMessage("[CustomFishing] Saving fishing bag data..."); + AdventureUtils.consoleMessage("[CustomFishing] Saving fishing bag data..."); plugin.getBagDataManager().saveBagDataForOnlinePlayers(false); } if (ConfigManager.enableStatistics) { - AdventureUtil.consoleMessage("[CustomFishing] Saving statistics data..."); + AdventureUtils.consoleMessage("[CustomFishing] Saving statistics data..."); plugin.getStatisticsManager().saveStatisticsDataForOnlinePlayers(false); } //AdventureUtil.consoleMessage("[CustomFishing] Data saved for all online players. Took " + (System.currentTimeMillis() - time1) + " ms."); - AdventureUtil.consoleMessage("[CustomFishing] Data saved for all online players."); + AdventureUtils.consoleMessage("[CustomFishing] Data saved for all online players."); }, 24000, 24000); } @Override public void unload() { if (timerSave != null) timerSave.cancel(); - YamlConfiguration config = ConfigUtil.getConfig("database.yml"); + YamlConfiguration config = ConfigUtils.getConfig("database.yml"); StorageType st = config.getString("data-storage-method","YAML").equalsIgnoreCase("YAML") ? StorageType.YAML : StorageType.SQL; if (this.dataStorageInterface != null && dataStorageInterface.getStorageType() != st) this.dataStorageInterface.disable(); } diff --git a/src/main/java/net/momirealms/customfishing/manager/EffectManager.java b/src/main/java/net/momirealms/customfishing/manager/EffectManager.java index 0a5f49d9..57d85f9f 100644 --- a/src/main/java/net/momirealms/customfishing/manager/EffectManager.java +++ b/src/main/java/net/momirealms/customfishing/manager/EffectManager.java @@ -21,8 +21,8 @@ import net.momirealms.customfishing.CustomFishing; import net.momirealms.customfishing.fishing.Effect; import net.momirealms.customfishing.fishing.loot.Item; import net.momirealms.customfishing.object.Function; -import net.momirealms.customfishing.util.AdventureUtil; -import net.momirealms.customfishing.util.ConfigUtil; +import net.momirealms.customfishing.util.AdventureUtils; +import net.momirealms.customfishing.util.ConfigUtils; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; import org.jetbrains.annotations.NotNull; @@ -94,14 +94,14 @@ public class EffectManager extends Function { Item item = new Item(utilSection, key); item.setCfTag(new String[] {"util", key}); utilItems.put(key, item); - Effect effect = ConfigUtil.getEffect(utilSection.getConfigurationSection("effect")); + Effect effect = ConfigUtils.getEffect(utilSection.getConfigurationSection("effect")); if (utilSection.contains("requirements")) { - effect.setRequirements(ConfigUtil.getRequirements(utilSection.getConfigurationSection("requirements"))); + effect.setRequirements(ConfigUtils.getRequirements(utilSection.getConfigurationSection("requirements"))); } utilEffects.put(key, effect); } } - AdventureUtil.consoleMessage("[CustomFishing] Loaded " + utilItems.size() + " util(s)"); + AdventureUtils.consoleMessage("[CustomFishing] Loaded " + utilItems.size() + " util(s)"); } private void loadEnchant() { @@ -120,16 +120,16 @@ public class EffectManager extends Function { ConfigurationSection levelSection = config.getConfigurationSection(key); if (levelSection == null) continue; for (String level : levelSection.getKeys(false)) { - Effect effect = ConfigUtil.getEffect(levelSection.getConfigurationSection(level + ".effect")); + Effect effect = ConfigUtils.getEffect(levelSection.getConfigurationSection(level + ".effect")); if (levelSection.contains(level + ".requirements")) { - effect.setRequirements(ConfigUtil.getRequirements(levelSection.getConfigurationSection(level + ".requirements"))); + effect.setRequirements(ConfigUtils.getRequirements(levelSection.getConfigurationSection(level + ".requirements"))); } enchantEffects.put((key.startsWith("eco") ? "minecraft" + key.substring(3) : key) + ":" + level, effect); } amount++; } } - AdventureUtil.consoleMessage("[CustomFishing] Loaded " + amount + " enchantment(s)"); + AdventureUtils.consoleMessage("[CustomFishing] Loaded " + amount + " enchantment(s)"); } private void loadBait() { @@ -150,14 +150,14 @@ public class EffectManager extends Function { Item item = new Item(baitSection, key); item.setCfTag(new String[] {"bait", key}); baitItems.put(key, item); - Effect effect = ConfigUtil.getEffect(baitSection.getConfigurationSection("effect")); + Effect effect = ConfigUtils.getEffect(baitSection.getConfigurationSection("effect")); if (baitSection.contains("requirements")) { - effect.setRequirements(ConfigUtil.getRequirements(baitSection.getConfigurationSection("requirements"))); + effect.setRequirements(ConfigUtils.getRequirements(baitSection.getConfigurationSection("requirements"))); } baitEffects.put(key, effect); } } - AdventureUtil.consoleMessage("[CustomFishing] Loaded " + baitItems.size() + " bait(s)"); + AdventureUtils.consoleMessage("[CustomFishing] Loaded " + baitItems.size() + " bait(s)"); } private void loadRod() { @@ -179,14 +179,14 @@ public class EffectManager extends Function { Item item = new Item(rodSection, key); item.setCfTag(new String[] {"rod", key}); rodItems.put(key, item); - Effect effect = ConfigUtil.getEffect(rodSection.getConfigurationSection("effect")); + Effect effect = ConfigUtils.getEffect(rodSection.getConfigurationSection("effect")); if (rodSection.contains("requirements")) { - effect.setRequirements(ConfigUtil.getRequirementsWithMsg(rodSection.getConfigurationSection("requirements"))); + effect.setRequirements(ConfigUtils.getRequirementsWithMsg(rodSection.getConfigurationSection("requirements"))); } rodEffects.put(key, effect); } } - AdventureUtil.consoleMessage("[CustomFishing] Loaded " + rodItems.size() + " rod(s)"); + AdventureUtils.consoleMessage("[CustomFishing] Loaded " + rodItems.size() + " rod(s)"); } @Nullable diff --git a/src/main/java/net/momirealms/customfishing/manager/FishingManager.java b/src/main/java/net/momirealms/customfishing/manager/FishingManager.java index 4709714a..008e61fe 100644 --- a/src/main/java/net/momirealms/customfishing/manager/FishingManager.java +++ b/src/main/java/net/momirealms/customfishing/manager/FishingManager.java @@ -49,9 +49,9 @@ import net.momirealms.customfishing.integration.item.McMMOTreasure; import net.momirealms.customfishing.listener.*; import net.momirealms.customfishing.object.Function; import net.momirealms.customfishing.object.SimpleLocation; -import net.momirealms.customfishing.util.AdventureUtil; -import net.momirealms.customfishing.util.FakeItemUtil; -import net.momirealms.customfishing.util.ItemStackUtil; +import net.momirealms.customfishing.util.AdventureUtils; +import net.momirealms.customfishing.util.FakeItemUtils; +import net.momirealms.customfishing.util.ItemStackUtils; import net.momirealms.customfishing.util.LocationUtils; import org.bukkit.Bukkit; import org.bukkit.GameMode; @@ -310,8 +310,8 @@ public class FishingManager extends Function { if (baitItem != null) { baitItem.setAmount(1); entityID = new Random().nextInt(Integer.MAX_VALUE); - CustomFishing.getProtocolManager().sendServerPacket(player, FakeItemUtil.getSpawnPacket(entityID, fishHook.getLocation())); - CustomFishing.getProtocolManager().sendServerPacket(player, FakeItemUtil.getMetaPacket(entityID, baitItem)); + CustomFishing.getProtocolManager().sendServerPacket(player, FakeItemUtils.getSpawnPacket(entityID, fishHook.getLocation())); + CustomFishing.getProtocolManager().sendServerPacket(player, FakeItemUtils.getMetaPacket(entityID, baitItem)); } BobberCheckTask bobberCheckTask = new BobberCheckTask(plugin, player, initialEffect, fishHook, this, lureLevel, entityID); @@ -426,7 +426,7 @@ public class FishingManager extends Function { if (loot == null) { item.remove(); event.setExpToDrop(0); - AdventureUtil.playerMessage(player, MessageManager.prefix + MessageManager.noLoot); + AdventureUtils.playerMessage(player, MessageManager.prefix + MessageManager.noLoot); } else { if (loot.isDisableBar()) { @@ -485,7 +485,7 @@ public class FishingManager extends Function { fishingGame.cancel(); nextEffect.remove(player); nextLoot.remove(player); - AdventureUtil.playerMessage(player, MessageManager.prefix + MessageManager.hookOther); + AdventureUtils.playerMessage(player, MessageManager.prefix + MessageManager.hookOther); } } } @@ -597,12 +597,12 @@ public class FishingManager extends Function { ItemStack drop = plugin.getIntegrationManager().build(droppedItem.getMaterial()); if (drop.getType() != Material.AIR) { if (droppedItem.getRandomEnchants() != null) - ItemStackUtil.addRandomEnchants(drop, droppedItem.getRandomEnchants()); + ItemStackUtils.addRandomEnchants(drop, droppedItem.getRandomEnchants()); if (droppedItem.isRandomDurability()) - ItemStackUtil.addRandomDamage(drop); + ItemStackUtils.addRandomDamage(drop); if (ConfigManager.preventPickUp && player != null) - ItemStackUtil.addOwner(drop, player.getName()); - ItemStackUtil.addExtraMeta(drop, droppedItem, sizeMultiplier); + ItemStackUtils.addOwner(drop, player.getName()); + ItemStackUtils.addExtraMeta(drop, droppedItem, sizeMultiplier); } return drop; } @@ -654,7 +654,7 @@ public class FishingManager extends Function { for (Action action : vanilla.getSuccessActions()) action.doOn(player, null); - AdventureUtil.playerSound(player, Sound.Source.PLAYER, Key.key("minecraft:entity.experience_orb.pickup"), 1, 1); + AdventureUtils.playerSound(player, Sound.Source.PLAYER, Key.key("minecraft:entity.experience_orb.pickup"), 1, 1); dropItem(player, location, isDouble, itemStack); sendSuccessTitle(player, itemStack); } @@ -708,18 +708,18 @@ public class FishingManager extends Function { int lootIndex; while ((lootIndex = text.indexOf("{loot}", startIndex)) != -1) { String before = text.substring(startIndex, lootIndex); - titleComponent = titleComponent.append(AdventureUtil.getComponentFromMiniMessage(before)); + titleComponent = titleComponent.append(AdventureUtils.getComponentFromMiniMessage(before)); startIndex = lootIndex + 6; titleComponent = titleComponent.append(getDisplayName(itemStack)); } String after = text.substring(startIndex); - titleComponent = titleComponent.append(AdventureUtil.getComponentFromMiniMessage(after)); + titleComponent = titleComponent.append(AdventureUtils.getComponentFromMiniMessage(after)); return titleComponent; } private void sendSuccessTitle(Player player, String loot) { if (!ConfigManager.enableSuccessTitle) return; - Bukkit.getScheduler().runTaskLater(plugin, () -> AdventureUtil.playerTitle( + Bukkit.getScheduler().runTaskLater(plugin, () -> AdventureUtils.playerTitle( player, ConfigManager.successTitle[new Random().nextInt(ConfigManager.successTitle.length)] .replace("{loot}", loot) @@ -739,7 +739,7 @@ public class FishingManager extends Function { Component titleComponent = getTitleComponent(itemStack, title); String subTitle = ConfigManager.successSubTitle[new Random().nextInt(ConfigManager.successSubTitle.length)]; Component subtitleComponent = getTitleComponent(itemStack, subTitle); - Bukkit.getScheduler().runTaskLater(plugin, () -> AdventureUtil.playerTitle( + Bukkit.getScheduler().runTaskLater(plugin, () -> AdventureUtils.playerTitle( player, titleComponent, subtitleComponent, @@ -784,7 +784,7 @@ public class FishingManager extends Function { } if (!ConfigManager.enableFailureTitle) return; - Bukkit.getScheduler().runTaskLater(plugin, () -> AdventureUtil.playerTitle( + Bukkit.getScheduler().runTaskLater(plugin, () -> AdventureUtils.playerTitle( player, ConfigManager.failureTitle[new Random().nextInt(ConfigManager.failureTitle.length)], ConfigManager.failureSubTitle[new Random().nextInt(ConfigManager.failureSubTitle.length)], @@ -814,7 +814,7 @@ public class FishingManager extends Function { if(itemStack.getType() != Material.FISHING_ROD) return; NBTItem nbtItem = new NBTItem(itemStack); if (nbtItem.getCompound("CustomFishing") != null || !nbtItem.hasTag("MMOITEMS_ITEM_ID")) return; - ItemStackUtil.addIdentifier(itemStack, "rod", nbtItem.getString("MMOITEMS_ITEM_ID")); + ItemStackUtils.addIdentifier(itemStack, "rod", nbtItem.getString("MMOITEMS_ITEM_ID")); } public boolean isCoolDown(Player player, long delay) { @@ -931,12 +931,12 @@ public class FishingManager extends Function { } if (possibleLoots.size() == 0) { - AdventureUtil.playerMessage(player, MessageManager.prefix + MessageManager.noLoot); + AdventureUtils.playerMessage(player, MessageManager.prefix + MessageManager.noLoot); return; } StringJoiner stringJoiner = new StringJoiner(MessageManager.splitChar); possibleLoots.forEach(loot -> stringJoiner.add(loot.getNick())); - AdventureUtil.playerMessage(player, MessageManager.prefix + MessageManager.possibleLoots + stringJoiner); + AdventureUtils.playerMessage(player, MessageManager.prefix + MessageManager.possibleLoots + stringJoiner); } private void showFishingBar(Player player, @NotNull Loot loot) { diff --git a/src/main/java/net/momirealms/customfishing/manager/IntegrationManager.java b/src/main/java/net/momirealms/customfishing/manager/IntegrationManager.java index 22056814..af14e6b9 100644 --- a/src/main/java/net/momirealms/customfishing/manager/IntegrationManager.java +++ b/src/main/java/net/momirealms/customfishing/manager/IntegrationManager.java @@ -41,8 +41,8 @@ import net.momirealms.customfishing.integration.skill.EcoSkillsImpl; import net.momirealms.customfishing.integration.skill.MMOCoreImpl; import net.momirealms.customfishing.integration.skill.mcMMOImpl; import net.momirealms.customfishing.object.Function; -import net.momirealms.customfishing.util.AdventureUtil; -import net.momirealms.customfishing.util.ConfigUtil; +import net.momirealms.customfishing.util.AdventureUtils; +import net.momirealms.customfishing.util.ConfigUtils; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -145,7 +145,7 @@ public class IntegrationManager extends Function { this.skillInterface = new mcMMOImpl(); hookMessage("mcMMO"); } else if (pluginManager.isPluginEnabled("MMOCore")) { - this.skillInterface = new MMOCoreImpl(ConfigUtil.getConfig("config.yml").getString("other-settings.MMOCore-profession-name", "fishing")); + this.skillInterface = new MMOCoreImpl(ConfigUtils.getConfig("config.yml").getString("other-settings.MMOCore-profession-name", "fishing")); hookMessage("MMOCore"); } else if (pluginManager.isPluginEnabled("AureliumSkills")) { this.skillInterface = new AureliumsImpl(); @@ -282,7 +282,7 @@ public class IntegrationManager extends Function { } private void hookMessage(String plugin){ - AdventureUtil.consoleMessage("[CustomFishing] " + plugin + " hooked!"); + AdventureUtils.consoleMessage("[CustomFishing] " + plugin + " hooked!"); } @Nullable diff --git a/src/main/java/net/momirealms/customfishing/manager/LootManager.java b/src/main/java/net/momirealms/customfishing/manager/LootManager.java index 4f296694..68d98ad3 100644 --- a/src/main/java/net/momirealms/customfishing/manager/LootManager.java +++ b/src/main/java/net/momirealms/customfishing/manager/LootManager.java @@ -23,9 +23,9 @@ import net.momirealms.customfishing.fishing.action.Action; import net.momirealms.customfishing.fishing.loot.*; import net.momirealms.customfishing.object.Function; import net.momirealms.customfishing.object.LeveledEnchantment; -import net.momirealms.customfishing.util.AdventureUtil; -import net.momirealms.customfishing.util.ConfigUtil; -import net.momirealms.customfishing.util.ItemStackUtil; +import net.momirealms.customfishing.util.AdventureUtils; +import net.momirealms.customfishing.util.ConfigUtils; +import net.momirealms.customfishing.util.ItemStackUtils; import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; import org.bukkit.Material; @@ -60,7 +60,7 @@ public class LootManager extends Function { @Nullable public ItemStack build(String key) { Item item = lootItems.get(key); - return item == null || item.getMaterial() == Material.AIR ? new ItemStack(Material.AIR) : ItemStackUtil.getFromItem(item); + return item == null || item.getMaterial() == Material.AIR ? new ItemStack(Material.AIR) : ItemStackUtils.getFromItem(item); } @Override @@ -78,8 +78,8 @@ public class LootManager extends Function { this.loadItems(); this.loadMobs(); this.loadCategories(); - AdventureUtil.consoleMessage("[CustomFishing] Loaded " + (this.lavaLoots.size() + this.waterLoots.size()) + " loot(s)"); - AdventureUtil.consoleMessage("[CustomFishing] Loaded " + (this.category.size()) + " category(s)"); + AdventureUtils.consoleMessage("[CustomFishing] Loaded " + (this.lavaLoots.size() + this.waterLoots.size()) + " loot(s)"); + AdventureUtils.consoleMessage("[CustomFishing] Loaded " + (this.category.size()) + " category(s)"); } @Override @@ -124,7 +124,7 @@ public class LootManager extends Function { List fishIDs = config.getStringList(key); for (String id : fishIDs) { if (!waterLoots.containsKey(id) && !lavaLoots.containsKey(id)) { - AdventureUtil.consoleMessage("[CustomFishing] Fish ID " + id + " doesn't exist in category " + key); + AdventureUtils.consoleMessage("[CustomFishing] Fish ID " + id + " doesn't exist in category " + key); continue outer; } } @@ -152,7 +152,7 @@ public class LootManager extends Function { if (!mobSection.getBoolean("enable", true)) continue; Mob loot = new Mob( key, - mobSection.contains("nick") ? mobSection.getString("nick") : AdventureUtil.replaceLegacy(mobSection.getString("mobID", key)), + mobSection.contains("nick") ? mobSection.getString("nick") : AdventureUtils.replaceLegacy(mobSection.getString("mobID", key)), getMiniGames(mobSection), mobSection.getInt("weight",10), mobSection.getBoolean("show-in-fishfinder", true), @@ -168,7 +168,7 @@ public class LootManager extends Function { ); setActions(mobSection, loot); - loot.setRequirements(ConfigUtil.getRequirements(mobSection.getConfigurationSection("requirements"))); + loot.setRequirements(ConfigUtils.getRequirements(mobSection.getConfigurationSection("requirements"))); if (mobSection.getBoolean("in-lava", false)) lavaLoots.put(key, loot); else waterLoots.put(key, loot); @@ -196,7 +196,7 @@ public class LootManager extends Function { String material = lootSection.getString("material","COD"); DroppedItem loot = new DroppedItem( key, - lootSection.contains("nick") ? lootSection.getString("nick") : AdventureUtil.replaceLegacy(lootSection.getString("display.name", key)), + lootSection.contains("nick") ? lootSection.getString("nick") : AdventureUtils.replaceLegacy(lootSection.getString("display.name", key)), material.contains(":") ? material : key, getMiniGames(lootSection), lootSection.getInt("weight",10), @@ -210,7 +210,7 @@ public class LootManager extends Function { if (lootSection.contains("size")) { String[] size = StringUtils.split(lootSection.getString("size", "1~10"), "~"); if (size.length != 2) { - AdventureUtil.consoleMessage("[CustomFishing] Wrong size found at " + key); + AdventureUtils.consoleMessage("[CustomFishing] Wrong size found at " + key); continue; } loot.setSize(size); @@ -238,7 +238,7 @@ public class LootManager extends Function { } setActions(lootSection, loot); - loot.setRequirements(ConfigUtil.getRequirements(lootSection.getConfigurationSection("requirements"))); + loot.setRequirements(ConfigUtils.getRequirements(lootSection.getConfigurationSection("requirements"))); if (key.equals("vanilla")) { vanilla_loot = loot; continue; @@ -255,10 +255,10 @@ public class LootManager extends Function { } private void setActions(ConfigurationSection section, Loot loot) { - loot.setSuccessActions(ConfigUtil.getActions(section.getConfigurationSection("action.success"), loot.getNick())); - loot.setFailureActions(ConfigUtil.getActions(section.getConfigurationSection("action.failure"), loot.getNick())); - loot.setHookActions(ConfigUtil.getActions(section.getConfigurationSection("action.hook"), loot.getNick())); - loot.setConsumeActions(ConfigUtil.getActions(section.getConfigurationSection("action.consume"), loot.getNick())); + loot.setSuccessActions(ConfigUtils.getActions(section.getConfigurationSection("action.success"), loot.getNick())); + loot.setFailureActions(ConfigUtils.getActions(section.getConfigurationSection("action.failure"), loot.getNick())); + loot.setHookActions(ConfigUtils.getActions(section.getConfigurationSection("action.hook"), loot.getNick())); + loot.setConsumeActions(ConfigUtils.getActions(section.getConfigurationSection("action.consume"), loot.getNick())); setSuccessAmountAction(section.getConfigurationSection("action.success-times"), loot); } @@ -266,7 +266,7 @@ public class LootManager extends Function { if (section != null) { HashMap actionMap = new HashMap<>(); for (String amount : section.getKeys(false)) { - actionMap.put(Integer.parseInt(amount), ConfigUtil.getActions(section.getConfigurationSection(amount), loot.getNick())); + actionMap.put(Integer.parseInt(amount), ConfigUtils.getActions(section.getConfigurationSection(amount), loot.getNick())); } loot.setSuccessTimesActions(actionMap); } @@ -281,7 +281,7 @@ public class LootManager extends Function { } MiniGameConfig gameConfig = plugin.getBarMechanicManager().getGameConfig(games[i]); if (gameConfig == null) { - AdventureUtil.consoleMessage("[CustomFishing] Mini game " + games[i] + " doesn't exist"); + AdventureUtils.consoleMessage("[CustomFishing] Mini game " + games[i] + " doesn't exist"); return null; } gameConfigs[i] = gameConfig; diff --git a/src/main/java/net/momirealms/customfishing/manager/MessageManager.java b/src/main/java/net/momirealms/customfishing/manager/MessageManager.java index 89c9aed7..b39df4be 100644 --- a/src/main/java/net/momirealms/customfishing/manager/MessageManager.java +++ b/src/main/java/net/momirealms/customfishing/manager/MessageManager.java @@ -18,7 +18,7 @@ package net.momirealms.customfishing.manager; import net.momirealms.customfishing.CustomFishing; -import net.momirealms.customfishing.util.ConfigUtil; +import net.momirealms.customfishing.util.ConfigUtils; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; @@ -62,7 +62,7 @@ public class MessageManager { public static String statisticsNotExists; public static void load() { - YamlConfiguration config = ConfigUtil.getConfig("messages" + File.separator + "messages_" + ConfigManager.lang +".yml"); + YamlConfiguration config = ConfigUtils.getConfig("messages" + File.separator + "messages_" + ConfigManager.lang +".yml"); prefix = getOrSet(config, "prefix", "[CustomFishing] "); reload = getOrSet(config, "reload", "Reloaded. Took {time}ms."); nonArgs = getOrSet(config, "none-args", "Arguments cannot be none."); diff --git a/src/main/java/net/momirealms/customfishing/manager/OffsetManager.java b/src/main/java/net/momirealms/customfishing/manager/OffsetManager.java index afa21718..47bf75a2 100644 --- a/src/main/java/net/momirealms/customfishing/manager/OffsetManager.java +++ b/src/main/java/net/momirealms/customfishing/manager/OffsetManager.java @@ -2,7 +2,7 @@ package net.momirealms.customfishing.manager; import net.momirealms.customfishing.CustomFishing; import net.momirealms.customfishing.object.Function; -import net.momirealms.customfishing.util.ConfigUtil; +import net.momirealms.customfishing.util.ConfigUtils; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; @@ -29,7 +29,7 @@ public class OffsetManager extends Function { } private void loadConfig() { - YamlConfiguration config = ConfigUtil.getConfig("config.yml"); + YamlConfiguration config = ConfigUtils.getConfig("config.yml"); ConfigurationSection section = config.getConfigurationSection("other-settings.offset-characters"); if (section != null) { font = section.getString("font", "customfishing:offset_chars"); diff --git a/src/main/java/net/momirealms/customfishing/manager/SellManager.java b/src/main/java/net/momirealms/customfishing/manager/SellManager.java index 5ded8185..793765ca 100644 --- a/src/main/java/net/momirealms/customfishing/manager/SellManager.java +++ b/src/main/java/net/momirealms/customfishing/manager/SellManager.java @@ -34,9 +34,9 @@ import net.momirealms.customfishing.listener.InventoryListener; import net.momirealms.customfishing.listener.JoinQuitListener; import net.momirealms.customfishing.listener.WindowPacketListener; import net.momirealms.customfishing.object.InventoryFunction; -import net.momirealms.customfishing.util.AdventureUtil; -import net.momirealms.customfishing.util.ConfigUtil; -import net.momirealms.customfishing.util.ItemStackUtil; +import net.momirealms.customfishing.util.AdventureUtils; +import net.momirealms.customfishing.util.ConfigUtils; +import net.momirealms.customfishing.util.ItemStackUtils; import net.objecthunter.exp4j.Expression; import net.objecthunter.exp4j.ExpressionBuilder; import org.bukkit.Bukkit; @@ -167,7 +167,7 @@ public class SellManager extends InventoryFunction { } private void loadConfig() { - YamlConfiguration config = ConfigUtil.getConfig("sell-fish.yml"); + YamlConfiguration config = ConfigUtils.getConfig("sell-fish.yml"); formula = config.getString("price-formula", "{base} + {bonus} * {size}"); sellLimitation = config.getBoolean("sell-limitation.enable", false); upperLimit = config.getInt("sell-limitation.upper-limit", 10000); @@ -185,7 +185,7 @@ public class SellManager extends InventoryFunction { ConfigurationSection item_section = dec_section.getConfigurationSection(key); if (item_section == null) continue; Item item = new Item(item_section, key); - ItemStack itemStack = ItemStackUtil.getFromItem(item); + ItemStack itemStack = ItemStackUtils.getFromItem(item); if (item_section.contains("slots")) { for (int slot : item_section.getIntegerList("slots")) { guiItems.put(slot - 1, itemStack); @@ -200,18 +200,18 @@ public class SellManager extends InventoryFunction { sellIcon = new Item(sellIconSection, "sellIcon"); } else { - AdventureUtil.consoleMessage("[CustomFishing] Sell icon is missing"); + AdventureUtils.consoleMessage("[CustomFishing] Sell icon is missing"); } ConfigurationSection denyIconSection = config.getConfigurationSection("functional-icons.deny"); if (denyIconSection != null) { denyIcon = new Item(denyIconSection, "denyIcon"); } else { - AdventureUtil.consoleMessage("[CustomFishing] Deny icon is missing"); + AdventureUtils.consoleMessage("[CustomFishing] Deny icon is missing"); } for (int slot : config.getIntegerList("functional-icons.slots")) { - guiItems.put(slot - 1, ItemStackUtil.getFromItem(sellIcon)); + guiItems.put(slot - 1, ItemStackUtils.getFromItem(sellIcon)); functionIconSlots.add(slot - 1); } @@ -243,19 +243,19 @@ public class SellManager extends InventoryFunction { public void openGuiForPlayer(Player player) { player.closeInventory(); if (!sellDataMap.containsKey(player.getUniqueId())) { - AdventureUtil.consoleMessage("Sell cache is not loaded for player " + player.getName()); + AdventureUtils.consoleMessage("Sell cache is not loaded for player " + player.getName()); return; } - Inventory inventory = plugin.getVersionHelper().isSpigot() ? Bukkit.createInventory(player, guiSize, AdventureUtil.replaceMiniMessage(SellManager.title.replace("{player}", player.getName()))) : Bukkit.createInventory(player, guiSize, "{CustomFishing_Sell}"); + Inventory inventory = plugin.getVersionHelper().isSpigot() ? Bukkit.createInventory(player, guiSize, AdventureUtils.replaceMiniMessage(SellManager.title.replace("{player}", player.getName()))) : Bukkit.createInventory(player, guiSize, "{CustomFishing_Sell}"); for (Map.Entry entry : guiItems.entrySet()) { inventory.setItem(entry.getKey(), entry.getValue()); } for (int slot : functionIconSlots) { - inventory.setItem(slot, ItemStackUtil.getFromItem(sellIcon.cloneWithPrice(getTotalPrice(getPlayerItems(inventory))))); + inventory.setItem(slot, ItemStackUtils.getFromItem(sellIcon.cloneWithPrice(getTotalPrice(getPlayerItems(inventory))))); } inventoryMap.put(player, inventory); player.openInventory(inventory); - if (openKey != null) AdventureUtil.playerSound(player, soundSource, openKey, 1, 1); + if (openKey != null) AdventureUtils.playerSound(player, soundSource, openKey, 1, 1); } @Override @@ -279,9 +279,9 @@ public class SellManager extends InventoryFunction { if (sellData == null) { inventory.close(); - AdventureUtil.playerMessage(player, MessageManager.prefix + "Your data is not loaded! Try to rejoin the server"); - AdventureUtil.consoleMessage("[CustomFishing] Unexpected issue, " + player.getName() + "'s sell-cache is not loaded!"); - if (denyKey != null) AdventureUtil.playerSound(player, soundSource, denyKey, 1, 1); + AdventureUtils.playerMessage(player, MessageManager.prefix + "Your data is not loaded! Try to rejoin the server"); + AdventureUtils.consoleMessage("[CustomFishing] Unexpected issue, " + player.getName() + "'s sell-cache is not loaded!"); + if (denyKey != null) AdventureUtils.playerSound(player, soundSource, denyKey, 1, 1); return; } @@ -296,8 +296,8 @@ public class SellManager extends InventoryFunction { if (sellLimitation && sell + totalPrice > upperLimit) { inventory.close(); - AdventureUtil.playerMessage(player, MessageManager.prefix + MessageManager.reachSellLimit); - if (denyKey != null) AdventureUtil.playerSound(player, soundSource, denyKey, 1, 1); + AdventureUtils.playerMessage(player, MessageManager.prefix + MessageManager.reachSellLimit); + if (denyKey != null) AdventureUtils.playerSound(player, soundSource, denyKey, 1, 1); return; } @@ -319,16 +319,16 @@ public class SellManager extends InventoryFunction { } else { for (int slot : functionIconSlots) { - inventory.setItem(slot, ItemStackUtil.getFromItem(denyIcon)); + inventory.setItem(slot, ItemStackUtils.getFromItem(denyIcon)); } update = false; - if (denyKey != null) AdventureUtil.playerSound(player, soundSource, denyKey, 1, 1); + if (denyKey != null) AdventureUtils.playerSound(player, soundSource, denyKey, 1, 1); } } } if (update) { Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> { - ItemStack icon = ItemStackUtil.getFromItem(sellIcon.cloneWithPrice(getTotalPrice(getPlayerItems(inventory)))); + ItemStack icon = ItemStackUtils.getFromItem(sellIcon.cloneWithPrice(getTotalPrice(getPlayerItems(inventory)))); for (int slot : functionIconSlots) { inventory.setItem(slot, icon); } @@ -342,7 +342,7 @@ public class SellManager extends InventoryFunction { Inventory inventory = inventoryMap.get(player); if (inventory == null) return; Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> { - ItemStack icon = ItemStackUtil.getFromItem(sellIcon.cloneWithPrice(getTotalPrice(getPlayerItems(inventory)))); + ItemStack icon = ItemStackUtils.getFromItem(sellIcon.cloneWithPrice(getTotalPrice(getPlayerItems(inventory)))); for (int slot : functionIconSlots) { inventory.setItem(slot, icon); } @@ -356,7 +356,7 @@ public class SellManager extends InventoryFunction { if (inventory == null) return; if (event.getInventory() == inventory) { returnItems(getPlayerItems(event.getInventory()), player); - if (closeKey != null) AdventureUtil.playerSound(player, soundSource, closeKey, 1, 1); + if (closeKey != null) AdventureUtils.playerSound(player, soundSource, closeKey, 1, 1); } } @@ -421,11 +421,11 @@ public class SellManager extends InventoryFunction { } private void doActions(Player player, float earnings, double remains) { - if (titleNotification != null) AdventureUtil.playerTitle(player, titleNotification.replace("{money}", String.format("%.2f", earnings)).replace("{remains}", sellLimitation ? String.format("%.2f", remains) : "unlimited"), subtitleNotification.replace("{money}", String.format("%.2f", earnings)).replace("{remains}", sellLimitation ? String.format("%.2f", remains) : "unlimited"), titleIn * 50, titleStay * 50, titleOut * 50); - if (msgNotification != null) AdventureUtil.playerMessage(player, msgNotification.replace("{money}", String.format("%.2f", earnings)).replace("{remains}", sellLimitation ? String.format("%.2f", remains) : "unlimited")); - if (actionbarNotification != null) AdventureUtil.playerActionbar(player, actionbarNotification.replace("{money}", String.format("%.2f", earnings)).replace("{remains}", sellLimitation ? String.format("%.2f", remains) : "unlimited")); - if (ConfigManager.logEarning) AdventureUtil.consoleMessage("[CustomFishing] Log: " + player.getName() + " earns " + String.format("%.2f", earnings) + " from selling fish"); - if (successKey != null) AdventureUtil.playerSound(player, soundSource, successKey, 1, 1); + if (titleNotification != null) AdventureUtils.playerTitle(player, titleNotification.replace("{money}", String.format("%.2f", earnings)).replace("{remains}", sellLimitation ? String.format("%.2f", remains) : "unlimited"), subtitleNotification.replace("{money}", String.format("%.2f", earnings)).replace("{remains}", sellLimitation ? String.format("%.2f", remains) : "unlimited"), titleIn * 50, titleStay * 50, titleOut * 50); + if (msgNotification != null) AdventureUtils.playerMessage(player, msgNotification.replace("{money}", String.format("%.2f", earnings)).replace("{remains}", sellLimitation ? String.format("%.2f", remains) : "unlimited")); + if (actionbarNotification != null) AdventureUtils.playerActionbar(player, actionbarNotification.replace("{money}", String.format("%.2f", earnings)).replace("{remains}", sellLimitation ? String.format("%.2f", remains) : "unlimited")); + if (ConfigManager.logEarning) AdventureUtils.consoleMessage("[CustomFishing] Log: " + player.getName() + " earns " + String.format("%.2f", earnings) + " from selling fish"); + if (successKey != null) AdventureUtils.playerSound(player, soundSource, successKey, 1, 1); if (plugin.getIntegrationManager().getVaultHook() != null) plugin.getIntegrationManager().getVaultHook().getEconomy().depositPlayer(player, earnings); if (commands != null) for (String cmd : commands) @@ -453,7 +453,7 @@ public class SellManager extends InventoryFunction { WrappedChatComponent.fromJson( GsonComponentSerializer.gson().serialize( MiniMessage.miniMessage().deserialize( - AdventureUtil.replaceLegacy(plugin.getIntegrationManager().getPlaceholderManager().parse(player, SellManager.title)) + AdventureUtils.replaceLegacy(plugin.getIntegrationManager().getPlaceholderManager().parse(player, SellManager.title)) ) ) ) diff --git a/src/main/java/net/momirealms/customfishing/manager/TotemManager.java b/src/main/java/net/momirealms/customfishing/manager/TotemManager.java index edafa46d..719deb4c 100644 --- a/src/main/java/net/momirealms/customfishing/manager/TotemManager.java +++ b/src/main/java/net/momirealms/customfishing/manager/TotemManager.java @@ -27,8 +27,8 @@ import net.momirealms.customfishing.fishing.totem.OriginalModel; import net.momirealms.customfishing.fishing.totem.TotemConfig; import net.momirealms.customfishing.integration.BlockInterface; import net.momirealms.customfishing.object.Function; -import net.momirealms.customfishing.util.AdventureUtil; -import net.momirealms.customfishing.util.ConfigUtil; +import net.momirealms.customfishing.util.AdventureUtils; +import net.momirealms.customfishing.util.ConfigUtils; import net.momirealms.customfishing.util.LocationUtils; import org.apache.commons.lang.StringUtils; import org.bukkit.Location; @@ -111,13 +111,13 @@ public class TotemManager extends Function { } private void loadBlocks() { - YamlConfiguration config = ConfigUtil.getConfig("totem_blocks/default.yml"); + YamlConfiguration config = ConfigUtils.getConfig("totem_blocks/default.yml"); config.getKeys(false).forEach(key -> blockIDs.put(key, config.getString(key))); config.getKeys(false).forEach(key -> invertedIDs.put(config.getString(key), key)); } private void loadTotems() { - YamlConfiguration config = ConfigUtil.getConfig("totems/default.yml"); + YamlConfiguration config = ConfigUtils.getConfig("totems/default.yml"); for (String key : config.getKeys(false)) { List cores = config.getStringList(key + ".core"); List flat = config.getStringList(key + ".layer.1"); @@ -130,13 +130,13 @@ public class TotemManager extends Function { for (int k = 0; k < height; k++) { List layer = config.getStringList(key + ".layer." + (k+1)); if (layer.size() != width) { - AdventureUtil.consoleMessage("[CustomFishing] Each layer should have the same size! Error exists in totem:" + key + " layer:" + (k + 1)); + AdventureUtils.consoleMessage("[CustomFishing] Each layer should have the same size! Error exists in totem:" + key + " layer:" + (k + 1)); return; } for (int j = 0; j < width; j++) { String[] args = layer.get(j).split("\\s+"); if (args.length != length) { - AdventureUtil.consoleMessage("[CustomFishing] Each layer should have the same size! Error exists in totem:" + key + " layer:" + (k + 1) + " line:" + (k + 1)); + AdventureUtils.consoleMessage("[CustomFishing] Each layer should have the same size! Error exists in totem:" + key + " layer:" + (k + 1) + " line:" + (k + 1)); return; } for (int i = 0; i < length; i++) { @@ -166,7 +166,7 @@ public class TotemManager extends Function { } } if(corePos == null) { - AdventureUtil.consoleMessage("[CustomTotems] No core block set for totem:" + key); + AdventureUtils.consoleMessage("[CustomTotems] No core block set for totem:" + key); return; } else { @@ -180,7 +180,7 @@ public class TotemManager extends Function { config.getInt(key + ".radius", 16), config.getInt(key + ".duration", 300), Particle.valueOf(config.getString(key + ".particle", "SPELL_MOB").toUpperCase()), - ConfigUtil.getEffect(config.getConfigurationSection(key + ".effect")) + ConfigUtils.getEffect(config.getConfigurationSection(key + ".effect")) ); List actionList = new ArrayList<>(); @@ -198,7 +198,7 @@ public class TotemManager extends Function { totem.setActivatorActions(actionList.toArray(new Action[0])); totem.setNearbyActions(nearActionList.toArray(new Action[0])); - totem.setRequirements(ConfigUtil.getRequirementsWithMsg(config.getConfigurationSection(key + ".requirements"))); + totem.setRequirements(ConfigUtils.getRequirementsWithMsg(config.getConfigurationSection(key + ".requirements"))); if (config.getBoolean(key + ".hologram.enable", false)) { totem.setHoloText(config.getStringList(key + ".hologram.text").toArray(new String[0])); @@ -234,7 +234,7 @@ public class TotemManager extends Function { } } } - AdventureUtil.consoleMessage("[CustomFishing] Loaded " + totems.size() + " totem(s)"); + AdventureUtils.consoleMessage("[CustomFishing] Loaded " + totems.size() + " totem(s)"); } private CorePos getCorePos(List cores, CorePos corePos, OriginalModel originalModel, int k, int j, int i, String content) { diff --git a/src/main/java/net/momirealms/customfishing/util/AdventureUtils.java b/src/main/java/net/momirealms/customfishing/util/AdventureUtils.java new file mode 100644 index 00000000..e61a1a92 --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/util/AdventureUtils.java @@ -0,0 +1,225 @@ +/* + * Copyright (C) <2022> + * + * 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 + * 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.momirealms.customfishing.util; + +import net.kyori.adventure.audience.Audience; +import net.kyori.adventure.key.Key; +import net.kyori.adventure.sound.Sound; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.minimessage.MiniMessage; +import net.kyori.adventure.title.Title; +import net.momirealms.customfishing.CustomFishing; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import java.time.Duration; +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class AdventureUtils { + + /** + * Get component from text + * @param text text + * @return component + */ + public static Component getComponentFromMiniMessage(String text) { + return MiniMessage.miniMessage().deserialize(replaceLegacy(text)); + } + + /** + * Send a message to a command sender + * @param sender sender + * @param s message + */ + public static void sendMessage(CommandSender sender, String s) { + if (s == null) return; + if (sender instanceof Player player) playerMessage(player, s); + else consoleMessage(s); + } + + /** + * Send a message to console + * @param s message + */ + public static void consoleMessage(String s) { + if (s == null) return; + Audience au = CustomFishing.getAdventure().sender(Bukkit.getConsoleSender()); + au.sendMessage(getComponentFromMiniMessage(s)); + } + + /** + * Send a message to a player + * @param player player + * @param s message + */ + public static void playerMessage(Player player, String s) { + if (s == null) return; + Audience au = CustomFishing.getAdventure().player(player); + au.sendMessage(getComponentFromMiniMessage(s)); + } + + /** + * Send a title to a player + * @param player player + * @param s1 title + * @param s2 subtitle + * @param in in (ms) + * @param duration duration (ms) + * @param out out (ms) + */ + public static void playerTitle(Player player, String s1, String s2, int in, int duration, int out) { + Audience au = CustomFishing.getAdventure().player(player); + Title.Times times = Title.Times.times(Duration.ofMillis(in), Duration.ofMillis(duration), Duration.ofMillis(out)); + Title title = Title.title(getComponentFromMiniMessage(s1), getComponentFromMiniMessage(s2), times); + au.showTitle(title); + } + + /** + * Send a title to a player + * @param player player + * @param s1 title + * @param s2 subtitle + * @param in in (ms) + * @param duration duration (ms) + * @param out out (ms) + */ + public static void playerTitle(Player player, Component s1, Component s2, int in, int duration, int out) { + Audience au = CustomFishing.getAdventure().player(player); + Title.Times times = Title.Times.times(Duration.ofMillis(in), Duration.ofMillis(duration), Duration.ofMillis(out)); + Title title = Title.title(s1, s2, times); + au.showTitle(title); + } + + /** + * Send an actionbar to a player + * @param player player + * @param s actionbar + */ + public static void playerActionbar(Player player, String s) { + Audience au = CustomFishing.getAdventure().player(player); + au.sendActionBar(getComponentFromMiniMessage(s)); + } + + /** + * Play a sound to a player + * @param player player + * @param source sound source + * @param key sound key + * @param volume volume + * @param pitch pitch + */ + public static void playerSound(Player player, Sound.Source source, Key key, float volume, float pitch) { + Sound sound = Sound.sound(key, source, volume, pitch); + Audience au = CustomFishing.getAdventure().player(player); + au.playSound(sound); + } + + /** + * Replace the legacy codes with MiniMessage Format + * @param str text + * @return MiniMessage format text + */ + public static String replaceLegacy(String str) { + StringBuilder stringBuilder = new StringBuilder(); + char[] chars = str.replace("&","§").toCharArray(); + for (int i = 0; i < chars.length; i++) { + if (chars[i] == '§') { + if (i + 1 < chars.length) { + switch (chars[i+1]) { + case '0' -> {i++;stringBuilder.append("");} + case '1' -> {i++;stringBuilder.append("");} + case '2' -> {i++;stringBuilder.append("");} + case '3' -> {i++;stringBuilder.append("");} + case '4' -> {i++;stringBuilder.append("");} + case '5' -> {i++;stringBuilder.append("");} + case '6' -> {i++;stringBuilder.append("");} + case '7' -> {i++;stringBuilder.append("");} + case '8' -> {i++;stringBuilder.append("");} + case '9' -> {i++;stringBuilder.append("");} + case 'a' -> {i++;stringBuilder.append("");} + case 'b' -> {i++;stringBuilder.append("");} + case 'c' -> {i++;stringBuilder.append("");} + case 'd' -> {i++;stringBuilder.append("");} + case 'e' -> {i++;stringBuilder.append("");} + case 'f' -> {i++;stringBuilder.append("");} + case 'r' -> {i++;stringBuilder.append("");} + case 'l' -> {i++;stringBuilder.append("");} + case 'm' -> {i++;stringBuilder.append("");} + case 'o' -> {i++;stringBuilder.append("");} + case 'n' -> {i++;stringBuilder.append("");} + case 'k' -> {i++;stringBuilder.append("");} + case 'x' -> {stringBuilder.append("<#").append(chars[i+3]).append(chars[i+5]).append(chars[i+7]).append(chars[i+9]).append(chars[i+11]).append(chars[i+13]).append(">");i += 13;} + } + } + } + else { + stringBuilder.append(chars[i]); + } + } + return stringBuilder.toString(); + } + + public static String replaceMiniMessage(String str) { + String result = str.replace("&","§"); + List miniFormat = new ArrayList<>(); + Pattern pattern = Pattern.compile("<.*?>"); + Matcher matcher = pattern.matcher(str); + while (matcher.find()) miniFormat.add(matcher.group()); + for (String mini : miniFormat) { + StringBuilder replacer = new StringBuilder(); + switch (mini) { + case "" -> replacer = new StringBuilder("§0"); + case "" -> replacer = new StringBuilder("§1"); + case "" -> replacer = new StringBuilder("§2"); + case "" -> replacer = new StringBuilder("§3"); + case "" -> replacer = new StringBuilder("§4"); + case "" -> replacer = new StringBuilder("§5"); + case "" -> replacer = new StringBuilder("§6"); + case "" -> replacer = new StringBuilder("§7"); + case "" -> replacer = new StringBuilder("§8"); + case "" -> replacer = new StringBuilder("§9"); + case "" -> replacer = new StringBuilder("§a"); + case "" -> replacer = new StringBuilder("§b"); + case "" -> replacer = new StringBuilder("§c"); + case "" -> replacer = new StringBuilder("§d"); + case "" -> replacer = new StringBuilder("§e"); + case "" -> replacer = new StringBuilder("§f"); + case "" -> replacer = new StringBuilder("§r"); + case "" -> replacer = new StringBuilder("§l"); + case "" -> replacer = new StringBuilder("§m"); + case "" -> replacer = new StringBuilder("§o"); + case "" -> replacer = new StringBuilder("§n"); + case "" -> replacer = new StringBuilder("§k"); + default -> { + if (mini.length() == 9 && mini.charAt(1) == '#') { + replacer = new StringBuilder("§x"); + for (int i = 2; i < 8; i++) { + replacer.append("§").append(mini.charAt(i)); + } + } + } + } + result = result.replace(mini, replacer.toString()); + } + return result; + } +} diff --git a/src/main/java/net/momirealms/customfishing/util/ArmorStandUtils.java b/src/main/java/net/momirealms/customfishing/util/ArmorStandUtils.java new file mode 100644 index 00000000..bb4a199a --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/util/ArmorStandUtils.java @@ -0,0 +1,131 @@ +/* + * Copyright (C) <2022> + * + * 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 + * 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.momirealms.customfishing.util; + +import com.comphenix.protocol.PacketType; +import com.comphenix.protocol.events.PacketContainer; +import com.comphenix.protocol.wrappers.*; +import com.google.common.collect.Lists; +import net.kyori.adventure.text.minimessage.MiniMessage; +import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; +import net.momirealms.customfishing.CustomFishing; +import net.momirealms.customfishing.fishing.loot.Item; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +import java.util.*; + +public class ArmorStandUtils { + + public static PacketContainer getDestroyPacket(int id) { + PacketContainer destroyPacket = new PacketContainer(PacketType.Play.Server.ENTITY_DESTROY); + destroyPacket.getIntLists().write(0, List.of(id)); + return destroyPacket; + } + + public static PacketContainer getSpawnPacket(int id, Location location) { + PacketContainer entityPacket = new PacketContainer(PacketType.Play.Server.SPAWN_ENTITY); + entityPacket.getModifier().write(0, id); + entityPacket.getModifier().write(1, UUID.randomUUID()); + entityPacket.getEntityTypeModifier().write(0, EntityType.ARMOR_STAND); + entityPacket.getDoubles().write(0, location.getX()); + entityPacket.getDoubles().write(1, location.getY()); + entityPacket.getDoubles().write(2, location.getZ()); + return entityPacket; + } + + public static PacketContainer getMetaPacket(int id) { + PacketContainer metaPacket = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA); + metaPacket.getIntegers().write(0, id); + if (CustomFishing.getInstance().getVersionHelper().isVersionNewerThan1_19_R2()) { + WrappedDataWatcher wrappedDataWatcher = createDataWatcher(); + setValueList(metaPacket, wrappedDataWatcher); + } else { + metaPacket.getWatchableCollectionModifier().write(0, createDataWatcher().getWatchableObjects()); + } + return metaPacket; + } + + static void setValueList(PacketContainer metaPacket, WrappedDataWatcher wrappedDataWatcher) { + List wrappedDataValueList = Lists.newArrayList(); + wrappedDataWatcher.getWatchableObjects().stream().filter(Objects::nonNull).forEach(entry -> { + final WrappedDataWatcher.WrappedDataWatcherObject dataWatcherObject = entry.getWatcherObject(); + wrappedDataValueList.add(new WrappedDataValue(dataWatcherObject.getIndex(), dataWatcherObject.getSerializer(), entry.getRawValue())); + }); + metaPacket.getDataValueCollectionModifier().write(0, wrappedDataValueList); + } + + public static PacketContainer getMetaPacket(int id, String text) { + PacketContainer metaPacket = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA); + metaPacket.getIntegers().write(0, id); + if (CustomFishing.getInstance().getVersionHelper().isVersionNewerThan1_19_R2()) { + WrappedDataWatcher wrappedDataWatcher = createDataWatcher(text); + setValueList(metaPacket, wrappedDataWatcher); + } else { + metaPacket.getWatchableCollectionModifier().write(0, createDataWatcher(text).getWatchableObjects()); + } + return metaPacket; + } + + public static WrappedDataWatcher createDataWatcher() { + WrappedDataWatcher wrappedDataWatcher = new WrappedDataWatcher(); + WrappedDataWatcher.Serializer serializer1 = WrappedDataWatcher.Registry.get(Boolean.class); + WrappedDataWatcher.Serializer serializer2 = WrappedDataWatcher.Registry.get(Byte.class); + wrappedDataWatcher.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(3, serializer1), false); + byte flag = 0x20; + wrappedDataWatcher.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(0, serializer2), flag); + return wrappedDataWatcher; + } + + public static WrappedDataWatcher createDataWatcher(String text) { + WrappedDataWatcher wrappedDataWatcher = new WrappedDataWatcher(); + WrappedDataWatcher.Serializer serializer1 = WrappedDataWatcher.Registry.get(Boolean.class); + WrappedDataWatcher.Serializer serializer2 = WrappedDataWatcher.Registry.get(Byte.class); + wrappedDataWatcher.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(2, WrappedDataWatcher.Registry.getChatComponentSerializer(true)), Optional.of(WrappedChatComponent.fromJson(GsonComponentSerializer.gson().serialize(MiniMessage.miniMessage().deserialize(text))).getHandle())); + wrappedDataWatcher.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(3, serializer1), true); + wrappedDataWatcher.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(15, serializer2), (byte) 0x01); + byte flag = 0x20; + wrappedDataWatcher.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(0, serializer2), flag); + wrappedDataWatcher.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(3, serializer1), true); + return wrappedDataWatcher; + } + + public static PacketContainer getEquipPacket(int id, ItemStack itemStack) { + PacketContainer equipPacket = new PacketContainer(PacketType.Play.Server.ENTITY_EQUIPMENT); + equipPacket.getIntegers().write(0, id); + List> pairs = new ArrayList<>(); + pairs.add(new Pair<>(EnumWrappers.ItemSlot.HEAD, itemStack)); + equipPacket.getSlotStackPairLists().write(0, pairs); + return equipPacket; + } + + public static void sendAnimationToPlayer(Location location, Player player, String key, int time) { + int id = new Random().nextInt(Integer.MAX_VALUE); + Item item = CustomFishing.getInstance().getEffectManager().getUtilItem(key); + if (item == null) return; + CustomFishing.getProtocolManager().sendServerPacket(player, getSpawnPacket(id, location.clone().subtract(0,1,0))); + CustomFishing.getProtocolManager().sendServerPacket(player, getMetaPacket(id)); + CustomFishing.getProtocolManager().sendServerPacket(player, getEquipPacket(id, ItemStackUtils.getFromItem(item))); + Bukkit.getScheduler().runTaskLaterAsynchronously(CustomFishing.getInstance(), () -> { + CustomFishing.getProtocolManager().sendServerPacket(player, getDestroyPacket(id)); + }, time); + } +} \ No newline at end of file diff --git a/src/main/java/net/momirealms/customfishing/util/ConfigUtils.java b/src/main/java/net/momirealms/customfishing/util/ConfigUtils.java new file mode 100644 index 00000000..b7971c3a --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/util/ConfigUtils.java @@ -0,0 +1,197 @@ +/* + * Copyright (C) <2022> + * + * 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 + * 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.momirealms.customfishing.util; + +import dev.dejvokep.boostedyaml.YamlDocument; +import dev.dejvokep.boostedyaml.dvs.versioning.BasicVersioning; +import dev.dejvokep.boostedyaml.settings.dumper.DumperSettings; +import dev.dejvokep.boostedyaml.settings.general.GeneralSettings; +import dev.dejvokep.boostedyaml.settings.loader.LoaderSettings; +import dev.dejvokep.boostedyaml.settings.updater.UpdaterSettings; +import net.momirealms.customfishing.CustomFishing; +import net.momirealms.customfishing.fishing.Effect; +import net.momirealms.customfishing.fishing.action.*; +import net.momirealms.customfishing.fishing.requirements.*; +import net.momirealms.customfishing.helper.Log; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Objects; + +public class ConfigUtils { + + /** + * Get a config by name + * @param configName config's name + * @return yaml + */ + public static YamlConfiguration getConfig(String configName) { + File file = new File(CustomFishing.getInstance().getDataFolder(), configName); + if (!file.exists()) CustomFishing.getInstance().saveResource(configName, false); + return YamlConfiguration.loadConfiguration(file); + } + + /** + * Update config + * @param fileName config + */ + public static void update(String fileName){ + try { + YamlDocument.create(new File(CustomFishing.getInstance().getDataFolder(), fileName), Objects.requireNonNull(CustomFishing.getInstance().getResource(fileName)), GeneralSettings.DEFAULT, LoaderSettings.builder().setAutoUpdate(true).build(), DumperSettings.DEFAULT, UpdaterSettings.builder().setVersioning(new BasicVersioning("config-version")).build()); + } catch (IOException e){ + Log.warn(e.getMessage()); + } + } + + /** + * Create a data file if not exists + * @param file file path + * @return yaml data + */ + public static YamlConfiguration readData(File file) { + if (!file.exists()) { + try { + file.getParentFile().mkdirs(); + file.createNewFile(); + } catch (IOException e) { + e.printStackTrace(); + AdventureUtils.consoleMessage("[CustomFishing] Failed to generate data files!"); + } + } + return YamlConfiguration.loadConfiguration(file); + } + + public static RequirementInterface[] getRequirements(ConfigurationSection section) { + if (section != null) { + List requirements = new ArrayList<>(); + for (String type : section.getKeys(false)) { + switch (type) { + case "biome" -> requirements.add(new BiomeImpl(null, section.getStringList(type))); + case "weather" -> requirements.add(new WeatherImpl(null, section.getStringList(type))); + case "ypos" -> requirements.add(new YPosImpl(null, section.getStringList(type))); + case "season" -> requirements.add(new SeasonImpl(null, section.getStringList(type))); + case "world" -> requirements.add(new WorldImpl(null, section.getStringList(type))); + case "permission" -> requirements.add(new PermissionImpl(null, section.getString(type))); + case "time" -> requirements.add(new TimeImpl(null, section.getStringList(type))); + case "skill-level" -> requirements.add(new SkillLevelImpl(null, section.getInt(type))); + case "job-level" -> requirements.add(new JobLevelImpl(null, section.getInt(type))); + case "papi-condition" -> requirements.add(new CustomPapi(null, Objects.requireNonNull(section.getConfigurationSection(type)).getValues(false))); + } + } + return requirements.toArray(new RequirementInterface[0]); + } + return null; + } + + public static RequirementInterface[] getRequirementsWithMsg(ConfigurationSection section) { + if (section != null) { + List requirements = new ArrayList<>(); + for (String id : section.getKeys(false)) { + ConfigurationSection innerSec = section.getConfigurationSection(id); + if (innerSec == null) continue; + String type = innerSec.getString("type"); + if (type == null) continue; + String[] msg = innerSec.getStringList("message").size() == 0 ? (innerSec.getString("message") == null ? null : new String[]{innerSec.getString("message")}) : innerSec.getStringList("message").toArray(new String[0]); + switch (type) { + case "biome" -> requirements.add(new BiomeImpl(msg, innerSec.getStringList("value"))); + case "weather" -> requirements.add(new WeatherImpl(msg, innerSec.getStringList("value"))); + case "ypos" -> requirements.add(new YPosImpl(msg, innerSec.getStringList("value"))); + case "season" -> requirements.add(new SeasonImpl(msg, innerSec.getStringList("value"))); + case "world" -> requirements.add(new WorldImpl(msg, innerSec.getStringList("value"))); + case "permission" -> requirements.add(new PermissionImpl(msg, innerSec.getString("value"))); + case "time" -> requirements.add(new TimeImpl(msg, innerSec.getStringList("value"))); + case "skill-level" -> requirements.add(new SkillLevelImpl(msg, innerSec.getInt("value"))); + case "job-level" -> requirements.add(new JobLevelImpl(msg, innerSec.getInt("value"))); + case "papi-condition" -> requirements.add(new CustomPapi(msg, Objects.requireNonNull(innerSec.getConfigurationSection("value")).getValues(false))); + } + } + return requirements.toArray(new RequirementInterface[0]); + } + return null; + } + + public static Action[] getActions(ConfigurationSection section, String nick) { + if (section != null) { + List actions = new ArrayList<>(); + for (String action : section.getKeys(false)) { + switch (action) { + case "message" -> actions.add(new MessageActionImpl(section.getStringList(action).toArray(new String[0]), nick)); + case "command" -> actions.add(new CommandActionImpl(section.getStringList(action).toArray(new String[0]), nick)); + case "exp" -> actions.add(new VanillaXPImpl(section.getInt(action), false)); + case "mending" -> actions.add(new VanillaXPImpl(section.getInt(action), true)); + case "skill-xp" -> actions.add(new SkillXPImpl(section.getDouble(action))); + case "job-xp" -> actions.add(new JobXPImpl(section.getDouble(action))); + case "sound" -> actions.add(new SoundActionImpl( + section.getString(action + ".source"), + section.getString(action + ".key"), + (float) section.getDouble(action + ".volume"), + (float) section.getDouble(action + ".pitch") + )); + case "potion-effect" -> { + List potionEffectList = new ArrayList<>(); + for (String key : section.getConfigurationSection(action).getKeys(false)) { + PotionEffectType type = PotionEffectType.getByName(section.getString(action + "." + key + ".type", "BLINDNESS").toUpperCase()); + if (type == null) AdventureUtils.consoleMessage("[CustomFishing] Potion effect " + section.getString(action + "." + key + ".type", "BLINDNESS") + " doesn't exists"); + potionEffectList.add(new PotionEffect( + type == null ? PotionEffectType.LUCK : type, + section.getInt(action + "." + key + ".duration"), + section.getInt(action + "." + key + ".amplifier") + )); + } + actions.add(new PotionEffectImpl(potionEffectList.toArray(new PotionEffect[0]))); + } + } + } + return actions.toArray(new Action[0]); + } + return null; + } + + public static Effect getEffect(ConfigurationSection section) { + Effect effect = new Effect(); + if (section == null) return effect; + for (String modifier : section.getKeys(false)) { + switch (modifier) { + case "weight-add" -> { + HashMap as = new HashMap<>(); + Objects.requireNonNull(section.getConfigurationSection(modifier)).getValues(false).forEach((group, value) -> as.put(group, (Integer) value)); + effect.setWeightAS(as); + } + case "weight-multiply" -> { + HashMap md = new HashMap<>(); + Objects.requireNonNull(section.getConfigurationSection(modifier)).getValues(false).forEach((group, value) -> md.put(group, Double.parseDouble(String.valueOf(value))-1)); + effect.setWeightMD(md); + } + case "time" -> effect.setTimeModifier(section.getDouble(modifier)); + case "difficulty" -> effect.setDifficulty(section.getInt(modifier)); + case "double-loot" -> effect.setDoubleLootChance(section.getDouble(modifier)); + case "score" -> effect.setScoreMultiplier(section.getDouble(modifier)); + case "size-multiply" -> effect.setSizeMultiplier(section.getDouble(modifier)); + case "lava-fishing" -> effect.setCanLavaFishing(section.getBoolean(modifier, false)); + } + } + return effect; + } +} diff --git a/src/main/java/net/momirealms/customfishing/util/FakeItemUtils.java b/src/main/java/net/momirealms/customfishing/util/FakeItemUtils.java new file mode 100644 index 00000000..faa07533 --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/util/FakeItemUtils.java @@ -0,0 +1,70 @@ +package net.momirealms.customfishing.util; + +import com.comphenix.protocol.PacketType; +import com.comphenix.protocol.events.PacketContainer; +import com.comphenix.protocol.wrappers.WrappedDataWatcher; +import net.momirealms.customfishing.CustomFishing; +import org.bukkit.Location; +import org.bukkit.entity.EntityType; +import org.bukkit.inventory.ItemStack; +import org.bukkit.util.Vector; + +import java.util.List; +import java.util.UUID; + +public class FakeItemUtils { + + public static PacketContainer getDestroyPacket(int id) { + PacketContainer destroyPacket = new PacketContainer(PacketType.Play.Server.ENTITY_DESTROY); + destroyPacket.getIntLists().write(0, List.of(id)); + return destroyPacket; + } + + public static PacketContainer getSpawnPacket(int id, Location location) { + PacketContainer entityPacket = new PacketContainer(PacketType.Play.Server.SPAWN_ENTITY); + entityPacket.getModifier().write(0, id); + entityPacket.getModifier().write(1, UUID.randomUUID()); + entityPacket.getEntityTypeModifier().write(0, EntityType.DROPPED_ITEM); + entityPacket.getDoubles().write(0, location.getX()); + entityPacket.getDoubles().write(1, location.getY() - 0.5); + entityPacket.getDoubles().write(2, location.getZ()); + return entityPacket; + } + + public static PacketContainer getMetaPacket(int id, ItemStack itemStack) { + PacketContainer metaPacket = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA); + metaPacket.getIntegers().write(0, id); + if (CustomFishing.getInstance().getVersionHelper().isVersionNewerThan1_19_R2()) { + WrappedDataWatcher wrappedDataWatcher = createDataWatcher(itemStack); + ArmorStandUtils.setValueList(metaPacket, wrappedDataWatcher); + } else { + metaPacket.getWatchableCollectionModifier().write(0, createDataWatcher(itemStack).getWatchableObjects()); + } + return metaPacket; + } + + public static PacketContainer getTpPacket(int id, Location location) { + PacketContainer tpPacket = new PacketContainer(PacketType.Play.Server.ENTITY_TELEPORT); + tpPacket.getModifier().write(0, id); + tpPacket.getDoubles().write(0, location.getX()); + tpPacket.getDoubles().write(1, location.getY() - 0.5); + tpPacket.getDoubles().write(2, location.getZ()); + return tpPacket; + } + + public static PacketContainer getVelocity(int id, Vector vector) { + PacketContainer entityPacket = new PacketContainer(PacketType.Play.Server.ENTITY_VELOCITY); + entityPacket.getModifier().write(0, id); + entityPacket.getIntegers().write(1, (int) (vector.getX() * 8000)); + entityPacket.getIntegers().write(2, (int) (vector.getY() * 8000)); + entityPacket.getIntegers().write(3, (int) (vector.getZ() * 8000)); + return entityPacket; + } + + public static WrappedDataWatcher createDataWatcher(ItemStack itemStack) { + WrappedDataWatcher wrappedDataWatcher = new WrappedDataWatcher(); + wrappedDataWatcher.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(8, WrappedDataWatcher.Registry.getItemStackSerializer(false)), itemStack); + wrappedDataWatcher.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(5, WrappedDataWatcher.Registry.get(Boolean.class)), true); + return wrappedDataWatcher; + } +} diff --git a/src/main/java/net/momirealms/customfishing/util/InventoryUtils.java b/src/main/java/net/momirealms/customfishing/util/InventoryUtils.java new file mode 100644 index 00000000..a147ca91 --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/util/InventoryUtils.java @@ -0,0 +1,118 @@ +/* + * Copyright (C) <2022> + * + * 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 + * 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.momirealms.customfishing.util; + +import org.bukkit.inventory.ItemStack; +import org.bukkit.util.io.BukkitObjectInputStream; +import org.bukkit.util.io.BukkitObjectOutputStream; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; + +public class InventoryUtils { + + /** + * Converts itemStacks to base64 + * @param contents items + * @return base64 + */ + public static @NotNull String toBase64(ItemStack[] contents) { + boolean convert = false; + for (ItemStack content : contents) { + if (content != null) { + convert = true; + break; + } + } + if (convert) { + try { + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + BukkitObjectOutputStream dataOutput = new BukkitObjectOutputStream(outputStream); + dataOutput.writeInt(contents.length); + for (ItemStack itemStack : contents) { + dataOutput.writeObject(itemStack); + } + dataOutput.close(); + byte[] byteArr = outputStream.toByteArray(); + outputStream.close(); + return Base64Coder.encodeLines(byteArr); + } catch (IOException e) { + throw new RuntimeException("[CustomFishing] Data save error", e); + } + } + return ""; + } + + /** + * Get itemStacks from base64 + * @param base64 base64 + * @return itemStacks + */ + @Nullable + public static ItemStack[] getInventoryItems(String base64) { + ItemStack[] itemStacks = null; + try { + itemStacks = stacksFromBase64(base64); + } catch (IllegalArgumentException exception) { + exception.printStackTrace(); + } + return itemStacks; + } + + private static ItemStack[] stacksFromBase64(String data) { + if (data == null || data.equals("")) return new ItemStack[]{}; + + ByteArrayInputStream inputStream; + try { + inputStream = new ByteArrayInputStream(Base64Coder.decodeLines(data)); + } catch (IllegalArgumentException e) { + return new ItemStack[]{}; + } + BukkitObjectInputStream dataInput = null; + ItemStack[] stacks = null; + try { + dataInput = new BukkitObjectInputStream(inputStream); + stacks = new ItemStack[dataInput.readInt()]; + } catch (IOException e) { + e.printStackTrace(); + } + if (stacks == null) return new ItemStack[]{}; + for (int i = 0; i < stacks.length; i++) { + try { + stacks[i] = (ItemStack) dataInput.readObject(); + } + catch (IOException | ClassNotFoundException | NullPointerException e) { + try { + dataInput.close(); + } catch (IOException exception) { + AdventureUtils.consoleMessage("[CustomFishing] Error! Failed to read fishing bag data"); + } + return null; + } + } + try { + dataInput.close(); + } catch (IOException ignored) { + } + return stacks; + } +} diff --git a/src/main/java/net/momirealms/customfishing/util/ItemStackUtils.java b/src/main/java/net/momirealms/customfishing/util/ItemStackUtils.java new file mode 100644 index 00000000..919b2ecb --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/util/ItemStackUtils.java @@ -0,0 +1,260 @@ +/* + * Copyright (C) <2022> + * + * 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 + * 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.momirealms.customfishing.util; + +import de.tr7zw.changeme.nbtapi.NBTCompound; +import de.tr7zw.changeme.nbtapi.NBTItem; +import de.tr7zw.changeme.nbtapi.NBTListCompound; +import net.kyori.adventure.text.minimessage.MiniMessage; +import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; +import net.momirealms.customfishing.CustomFishing; +import net.momirealms.customfishing.fishing.loot.DroppedItem; +import net.momirealms.customfishing.fishing.loot.Item; +import net.momirealms.customfishing.fishing.loot.Loot; +import net.momirealms.customfishing.object.LeveledEnchantment; +import org.bukkit.Material; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.Damageable; +import org.bukkit.inventory.meta.EnchantmentStorageMeta; +import org.bukkit.inventory.meta.ItemMeta; + +import java.io.File; +import java.io.IOException; +import java.util.*; + +public class ItemStackUtils { + + /** + * Build itemStack from item's config + * @param item item + * @return itemStack + */ + public static ItemStack getFromItem(Item item) { + ItemStack itemStack = new ItemStack(item.getMaterial()); + itemStack.setAmount(item.getAmount()); + ItemMeta itemMeta = itemStack.getItemMeta(); + if (item.getCustomModelData() != 0) itemMeta.setCustomModelData(item.getCustomModelData()); + if (item.isUnbreakable()) itemMeta.setUnbreakable(true); + if (item.getItemFlags() != null) item.getItemFlags().forEach(itemMeta::addItemFlags); + if (item.getEnchantment() != null) { + if (itemStack.getType() == Material.ENCHANTED_BOOK){ + EnchantmentStorageMeta meta = (EnchantmentStorageMeta) itemMeta; + item.getEnchantment().forEach(enchantment -> meta.addStoredEnchant(Objects.requireNonNull(Enchantment.getByKey(enchantment.key())),enchantment.level(),true)); + itemStack.setItemMeta(meta); + } + else { + item.getEnchantment().forEach(enchantment -> itemMeta.addEnchant(Objects.requireNonNull(Enchantment.getByKey(enchantment.key())),enchantment.level(),true)); + itemStack.setItemMeta(itemMeta); + } + } + else { + itemStack.setItemMeta(itemMeta); + } + NBTItem nbtItem = new NBTItem(itemStack); + if (item.getName() != null) { + NBTCompound display = nbtItem.addCompound("display"); + String name = item.getName(); + if (name.contains("&") || name.contains("§")){ + name = AdventureUtils.replaceLegacy(name); + } + display.setString("Name", GsonComponentSerializer.gson().serialize(MiniMessage.miniMessage().deserialize("" + name))); + } + if (item.getLore() != null) { + NBTCompound display = nbtItem.addCompound("display"); + List lore = display.getStringList("Lore"); + item.getLore().forEach(line -> { + if (line.contains("&") || line.contains("§")){ + line = AdventureUtils.replaceLegacy(line); + } + lore.add(GsonComponentSerializer.gson().serialize(MiniMessage.miniMessage().deserialize("" + line))); + }); + } + if (item.getCfTag() != null) { + NBTCompound cfCompound = nbtItem.addCompound("CustomFishing"); + cfCompound.setString("type", item.getCfTag()[0]); + cfCompound.setString("id", item.getCfTag()[1]); + } + if (item.getHead64() != null) { + NBTCompound nbtCompound = nbtItem.addCompound("SkullOwner"); + nbtCompound.setUUID("Id", item.isHeadStackable() ? UUID.nameUUIDFromBytes(item.getKey().getBytes()) : UUID.randomUUID()); + NBTListCompound texture = nbtCompound.addCompound("Properties").getCompoundList("textures").addCompound(); + texture.setString("Value", item.getHead64()); + } + if (item.getTotem() != null) { + nbtItem.setString("Totem", item.getTotem()); + } + if (item.getNbt() != null) NBTUtils.setTags(item.getNbt(), nbtItem); + return nbtItem.getItem(); + } + + /** + * Get an itemStack with random durability + * @param itemStack itemStack + */ + public static void addRandomDamage(ItemStack itemStack){ + if (itemStack.getItemMeta() instanceof Damageable damageable){ + damageable.setDamage((int) (itemStack.getType().getMaxDurability() * Math.random())); + itemStack.setItemMeta(damageable); + } + } + + /** + * Adds owner tag + * @param itemStack itemStack + * @param name owner + */ + public static void addOwner(ItemStack itemStack, String name){ + NBTItem nbtItem = new NBTItem(itemStack); + nbtItem.setString("TempOwner", name); + itemStack.setItemMeta(nbtItem.getItem().getItemMeta()); + } + + /** + * Add random enchantments + * @param itemStack itemStack + * @param enchantments enchantments + */ + public static void addRandomEnchants(ItemStack itemStack, LeveledEnchantment[] enchantments){ + ItemMeta itemMeta = itemStack.getItemMeta(); + if (itemStack.getType() == Material.ENCHANTED_BOOK){ + EnchantmentStorageMeta meta = (EnchantmentStorageMeta)itemMeta; + for (LeveledEnchantment enchantment : enchantments) { + if (enchantment.chance() > Math.random()) meta.addStoredEnchant(Objects.requireNonNull(Enchantment.getByKey(enchantment.key())),enchantment.level(),true); + } + itemStack.setItemMeta(meta); + } + else { + for (LeveledEnchantment enchantment : enchantments) { + if (enchantment.chance() > Math.random()) itemMeta.addEnchant(Objects.requireNonNull(Enchantment.getByKey(enchantment.key())),enchantment.level(),true); + } + itemStack.setItemMeta(itemMeta); + } + } + + /** + * Add customFishing tags + * + * @param itemStack itemStack + * @param type type + * @param id id + */ + public static void addIdentifier(ItemStack itemStack, String type, String id){ + NBTItem nbtItem = new NBTItem(itemStack); + NBTCompound nbtCompound = nbtItem.addCompound("CustomFishing"); + nbtCompound.setString("type", type); + nbtCompound.setString("id", id); + itemStack.setItemMeta(nbtItem.getItem().getItemMeta()); + } + + public static int givePlayerLoot(Player player, String key, int amount){ + Loot loot = CustomFishing.getInstance().getLootManager().getLoot(key); + if (!(loot instanceof DroppedItem droppedItem)) return 0; + ItemStack itemStack = CustomFishing.getInstance().getFishingManager().getCustomFishingLootItemStack(droppedItem, player); + if (itemStack.getType() == Material.AIR) return 0; + if (amount != 0) itemStack.setAmount(amount); + player.getInventory().addItem(itemStack); + return itemStack.getAmount(); + } + + public static void givePlayerRod(Player player, String rodKey, int amount){ + Item item = CustomFishing.getInstance().getEffectManager().getRodItem(rodKey); + if (item == null) return; + ItemStack itemStack = getFromItem(item); + if (amount != 0) + for (int i = 0; i < amount; i++) { + player.getInventory().addItem(itemStack); + } + else { + player.getInventory().addItem(itemStack); + } + } + + public static void givePlayerBait(Player player, String baitKey, int amount){ + Item item = CustomFishing.getInstance().getEffectManager().getBaitItem(baitKey); + if (item == null) return; + ItemStack itemStack = getFromItem(item); + if (amount != 0) itemStack.setAmount(amount); + player.getInventory().addItem(itemStack); + } + + public static void givePlayerUtil(Player player, String utilKey, int amount){ + Item item = CustomFishing.getInstance().getEffectManager().getUtilItem(utilKey); + if (item == null) return; + ItemStack itemStack = getFromItem(item); + if (amount != 0) itemStack.setAmount(amount); + player.getInventory().addItem(itemStack); + } + + public static boolean saveToFile(ItemStack itemStack, String key){ + if (itemStack == null || itemStack.getType() == Material.AIR || CustomFishing.getInstance().getLootManager().hasLoot(key)) return false; + File file = new File(CustomFishing.getInstance().getDataFolder(), File.separator + "loots" + File.separator + "imported.yml"); + YamlConfiguration data = ConfigUtils.readData(file); + data.set(key + ".material", itemStack.getType().toString()); + data.set(key + ".amount", itemStack.getAmount()); + NBTItem nbtItem = new NBTItem(itemStack); + Map map0 = NBTUtils.compoundToMap(nbtItem); + if (map0.size() != 0) { + data.createSection(key + ".nbt", map0); + } + try { + data.save(file); + CustomFishing.getInstance().getLootManager().unload(); + CustomFishing.getInstance().getLootManager().load(); + } catch (IOException e) { + e.printStackTrace(); + } + return true; + } + + public static void addExtraMeta(ItemStack itemStack, DroppedItem droppedItem, double sizeMultiplier) { + NBTItem nbtItem = new NBTItem(itemStack); + boolean changed = replaceSizeLore(droppedItem.getSize(), nbtItem, sizeMultiplier); + if (droppedItem.getBasicPrice() != 0) { + NBTCompound fishMetaCompound = nbtItem.addCompound("FishMeta"); + fishMetaCompound.setFloat("base", droppedItem.getBasicPrice()); + changed = true; + } + if (droppedItem.getSizeBonus() != 0) { + NBTCompound fishMetaCompound = nbtItem.addCompound("FishMeta"); + fishMetaCompound.setFloat("bonus", droppedItem.getSizeBonus()); + changed = true; + } + if (changed) { + itemStack.setItemMeta(nbtItem.getItem().getItemMeta()); + } + } + + private static boolean replaceSizeLore(String[] sizes, NBTItem nbtItem, double sizeMultiplier) { + if (sizes == null) return false; + float min = Float.parseFloat(sizes[0]); + float max = Float.parseFloat(sizes[1]); + if (max - min < 0) return false; + float size = (float) ((min + Math.random() * (max - min)) * sizeMultiplier); + String sizeText = String.format("%.1f", size); + NBTCompound nbtCompound = nbtItem.getCompound("display"); + if (nbtCompound == null || !nbtCompound.hasTag("Lore")) return false; + List lore = nbtCompound.getStringList("Lore"); + lore.replaceAll(s -> s.replace("{size}", sizeText)); + NBTCompound fishMetaCompound = nbtItem.addCompound("FishMeta"); + fishMetaCompound.setFloat("size", size); + return true; + } +} diff --git a/src/main/java/net/momirealms/customfishing/util/JedisUtils.java b/src/main/java/net/momirealms/customfishing/util/JedisUtils.java new file mode 100644 index 00000000..7cbcb33f --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/util/JedisUtils.java @@ -0,0 +1,89 @@ +/* + * Copyright (C) <2022> + * + * 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 + * 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.momirealms.customfishing.util; + +import net.momirealms.customfishing.helper.Log; +import org.bukkit.configuration.file.YamlConfiguration; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.JedisPool; +import redis.clients.jedis.JedisPoolConfig; + +import java.util.ArrayList; +import java.util.List; + +public class JedisUtils { + + private static JedisPool jedisPool; + + public static Jedis getJedis(){ + return jedisPool.getResource(); + } + + public static void initializeRedis(YamlConfiguration configuration){ + JedisPoolConfig jedisPoolConfig = new JedisPoolConfig(); + jedisPoolConfig.setTestWhileIdle(true); + jedisPoolConfig.setTimeBetweenEvictionRunsMillis(30000); + jedisPoolConfig.setNumTestsPerEvictionRun(-1); + jedisPoolConfig.setMinEvictableIdleTimeMillis(configuration.getInt("Redis.MinEvictableIdleTimeMillis",1800000)); + jedisPoolConfig.setMaxTotal(configuration.getInt("Redis.MaxTotal",8)); + jedisPoolConfig.setMaxIdle(configuration.getInt("Redis.MaxIdle",8)); + jedisPoolConfig.setMinIdle(configuration.getInt("Redis.MinIdle",1)); + jedisPoolConfig.setMaxWaitMillis(configuration.getInt("redis.MaxWaitMillis",30000)); + if (configuration.getString("Redis.password") != null) { + jedisPool = new JedisPool(jedisPoolConfig, configuration.getString("Redis.host","localhost"), configuration.getInt("Redis.port",6379), 2000, configuration.getString("Redis.password")); + } + else { + jedisPool = new JedisPool(jedisPoolConfig, configuration.getString("Redis.host","localhost"), configuration.getInt("Redis.port",6379)); + } + + AdventureUtils.consoleMessage("[CustomFishing] Redis Server Connected!"); + + List minIdleJedisList = new ArrayList<>(jedisPoolConfig.getMinIdle()); + for (int i = 0; i < jedisPoolConfig.getMinIdle(); i++) { + Jedis jedis; + try { + jedis = jedisPool.getResource(); + minIdleJedisList.add(jedis); + jedis.ping(); + } catch (Exception e) { + Log.warn(e.getMessage()); + } + } + + for (int i = 0; i < jedisPoolConfig.getMinIdle(); i++) { + Jedis jedis; + try { + jedis = minIdleJedisList.get(i); + jedis.close(); + } catch (Exception e) { + Log.warn(e.getMessage()); + } + } + } + + public static void closePool() { + if (jedisPool != null) { + jedisPool.close(); + jedisPool = null; + } + } + + public static boolean isPoolEnabled() { + return jedisPool != null && !jedisPool.isClosed(); + } +} diff --git a/src/main/java/net/momirealms/customfishing/util/NBTUtils.java b/src/main/java/net/momirealms/customfishing/util/NBTUtils.java new file mode 100644 index 00000000..841fe9a9 --- /dev/null +++ b/src/main/java/net/momirealms/customfishing/util/NBTUtils.java @@ -0,0 +1,158 @@ +/* + * Copyright (C) <2022> + * + * 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 + * 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.momirealms.customfishing.util; + +import de.tr7zw.changeme.nbtapi.NBTCompound; +import de.tr7zw.changeme.nbtapi.NBTItem; +import de.tr7zw.changeme.nbtapi.NBTListCompound; +import de.tr7zw.changeme.nbtapi.iface.ReadWriteNBT; +import org.bukkit.configuration.MemorySection; +import org.bukkit.inventory.ItemStack; + +import java.util.*; + +public class NBTUtils { + + public static NBTItem setNBTToItemStack(Map nbt, ItemStack itemStack){ + NBTItem nbtItem = new NBTItem(itemStack); + setTags(nbt, nbtItem); + return nbtItem; + } + + @SuppressWarnings("unchecked") + public static void setTags(Map map, NBTCompound nbtCompound) { + for (Map.Entry entry : map.entrySet()) { + String key = entry.getKey(); + Object value = entry.getValue(); + if (value instanceof MemorySection memorySection) { + setTags(memorySection.getValues(false), nbtCompound.addCompound(key)); + } else if (value instanceof List list) { + for (Object o : list) { + if (o instanceof String stringValue) { + setListValue(key, stringValue, nbtCompound); + } else if (o instanceof Map mapValue) { + NBTListCompound nbtListCompound = nbtCompound.getCompoundList(key).addCompound(); + setTags((Map) mapValue, nbtListCompound); + } + } + } else if (value instanceof String stringValue) { + setSingleValue(key, stringValue, nbtCompound); + } + } + } + + private static void setListValue(String key, String value, NBTCompound nbtCompound) { + String[] parts = getTypeAndData(value); + String type = parts[0]; String data = parts[1]; + switch (type) { + case "String" -> nbtCompound.getStringList(key).add(data); + case "UUID" -> nbtCompound.getUUIDList(key).add(UUID.fromString(data)); + case "Double" -> nbtCompound.getDoubleList(key).add(Double.valueOf(data)); + case "Long" -> nbtCompound.getLongList(key).add(Long.valueOf(data)); + case "Float" -> nbtCompound.getFloatList(key).add(Float.valueOf(data)); + case "Int" -> nbtCompound.getIntegerList(key).add(Integer.valueOf(data)); + case "IntArray" -> { + String[] split = data.replace("[", "").replace("]", "").replaceAll("\\s", "").split(","); + int[] array = Arrays.stream(split).mapToInt(Integer::parseInt).toArray(); + nbtCompound.getIntArrayList(key).add(array); + } + default -> throw new IllegalArgumentException("Invalid value type: " + type); + } + } + + private static void setSingleValue(String key, String value, NBTCompound nbtCompound) { + String[] parts = getTypeAndData(value); + String type = parts[0]; String data = parts[1]; + switch (type) { + case "Int" -> nbtCompound.setInteger(key, Integer.valueOf(data)); + case "String" -> nbtCompound.setString(key, data); + case "Long" -> nbtCompound.setLong(key, Long.valueOf(data)); + case "Float" -> nbtCompound.setFloat(key, Float.valueOf(data)); + case "Double" -> nbtCompound.setDouble(key, Double.valueOf(data)); + case "Short" -> nbtCompound.setShort(key, Short.valueOf(data)); + case "Boolean" -> nbtCompound.setBoolean(key, Boolean.valueOf(data)); + case "UUID" -> nbtCompound.setUUID(key, UUID.nameUUIDFromBytes(data.getBytes())); + case "Byte" -> nbtCompound.setByte(key, Byte.valueOf(data)); + case "ByteArray" -> { + String[] split = splitValue(value); + byte[] bytes = new byte[split.length]; + for (int i = 0; i < split.length; i++){ + bytes[i] = Byte.parseByte(split[i]); + } + nbtCompound.setByteArray(key, bytes); + } + case "IntArray" -> { + String[] split = splitValue(value); + int[] array = Arrays.stream(split).mapToInt(Integer::parseInt).toArray(); + nbtCompound.setIntArray(key, array); + } + default -> throw new IllegalArgumentException("Invalid value type: " + type); + } + } + + public static Map compoundToMap(ReadWriteNBT nbtCompound){ + Map map = new HashMap<>(); + for (String key : nbtCompound.getKeys()) { + switch (nbtCompound.getType(key)){ + case NBTTagByte -> map.put(key, "(Byte) " + nbtCompound.getByte(key)); + case NBTTagInt -> map.put(key, "(Int) " + nbtCompound.getInteger(key)); + case NBTTagDouble -> map.put(key, "(Double) " + nbtCompound.getDouble(key)); + case NBTTagLong -> map.put(key, "(Long) " + nbtCompound.getLong(key)); + case NBTTagFloat -> map.put(key, "(Float) " + nbtCompound.getFloat(key)); + case NBTTagShort -> map.put(key, "(Short) " + nbtCompound.getShort(key)); + case NBTTagString -> map.put(key, "(String) " + nbtCompound.getString(key)); + case NBTTagByteArray -> map.put(key, "(ByteArray) " + Arrays.toString(nbtCompound.getByteArray(key))); + case NBTTagIntArray -> map.put(key, "(IntArray) " + Arrays.toString(nbtCompound.getIntArray(key))); + case NBTTagCompound -> { + Map map1 = compoundToMap(nbtCompound.getCompound(key)); + if (map1.size() != 0) map.put(key, map1); + } + case NBTTagList -> { + List list = new ArrayList<>(); + switch (nbtCompound.getListType(key)) { + case NBTTagCompound -> nbtCompound.getCompoundList(key).forEach(a -> list.add(compoundToMap(a))); + case NBTTagInt -> nbtCompound.getIntegerList(key).forEach(a -> list.add("(Int) " + a)); + case NBTTagDouble -> nbtCompound.getDoubleList(key).forEach(a -> list.add("(Double) " + a)); + case NBTTagString -> nbtCompound.getStringList(key).forEach(a -> list.add("(String) " + a)); + case NBTTagFloat -> nbtCompound.getFloatList(key).forEach(a -> list.add("(Float) " + a)); + case NBTTagLong -> nbtCompound.getLongList(key).forEach(a -> list.add("(Long) " + a)); + case NBTTagIntArray -> nbtCompound.getIntArrayList(key).forEach(a -> list.add("(IntArray) " + Arrays.toString(a))); + } + if (list.size() != 0) map.put(key, list); + } + } + } + return map; + } + + private static String[] getTypeAndData(String str) { + String[] parts = str.split("\\s+", 2); + if (parts.length != 2) { + throw new IllegalArgumentException("Invalid value format: " + str); + } + String type = parts[0].substring(1, parts[0].length() - 1); + String data = parts[1]; + return new String[]{type, data}; + } + + private static String[] splitValue(String value) { + return value.substring(value.indexOf('[') + 1, value.lastIndexOf(']')) + .replaceAll("\\s", "") + .split(","); + } +} \ No newline at end of file diff --git a/src/main/resources/loots/default.yml b/src/main/resources/loots/default.yml index 9d1a0d3b..3fc1bee7 100644 --- a/src/main/resources/loots/default.yml +++ b/src/main/resources/loots/default.yml @@ -19,6 +19,7 @@ rubbish: obsidian: nick: '<#4B0082>Obsidian' material: obsidian + show-in-fishfinder: false in-lava: true disable-stats: true action: @@ -27,6 +28,7 @@ obsidian: wither_skeleton_skull: nick: 'Wither Skeleton Skull' material: wither_skeleton_skull + show-in-fishfinder: false in-lava: true disable-stats: true weight: 1