diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 6528028b..0eb7b97e 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -4,9 +4,10 @@ plugins { } dependencies { - implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.0") + implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.0") } repositories { // Use the plugin portal to apply community plugins in convention plugins. gradlePluginPortal() + mavenCentral() } \ No newline at end of file diff --git a/even-more-fish-addons-j17/build.gradle.kts b/even-more-fish-addons-j17/build.gradle.kts index 1fec25dc..1de60b40 100644 --- a/even-more-fish-addons-j17/build.gradle.kts +++ b/even-more-fish-addons-j17/build.gradle.kts @@ -16,6 +16,8 @@ dependencies { compileOnly(libs.ecoitems.eco) compileOnly(libs.denizen.api) compileOnly(libs.commons.lang3) + compileOnly(libs.itemsadder.api) + compileOnly(libs.headdatabase.api) compileOnly(project(":even-more-fish-api")) } diff --git a/even-more-fish-addons-j17/src/main/java/com/oheers/evenmorefish/addons/DenizenItemAddon.java b/even-more-fish-addons-j17/src/main/java/com/oheers/evenmorefish/addons/DenizenItemAddon.java index 2a85cf1b..639e0929 100644 --- a/even-more-fish-addons-j17/src/main/java/com/oheers/evenmorefish/addons/DenizenItemAddon.java +++ b/even-more-fish-addons-j17/src/main/java/com/oheers/evenmorefish/addons/DenizenItemAddon.java @@ -3,7 +3,6 @@ import com.denizenscript.denizen.objects.ItemTag; import com.oheers.fish.api.addons.ItemAddon; -import org.apache.commons.lang3.JavaVersion; import org.bukkit.inventory.ItemStack; public class DenizenItemAddon extends ItemAddon { @@ -33,8 +32,4 @@ public ItemStack getItemStack(String id) { return itemTag.getItemStack(); } - @Override - public JavaVersion getRequiredJavaVersion() { - return JavaVersion.JAVA_17; - } } diff --git a/even-more-fish-addons-j17/src/main/java/com/oheers/evenmorefish/addons/EcoItemsItemAddon.java b/even-more-fish-addons-j17/src/main/java/com/oheers/evenmorefish/addons/EcoItemsItemAddon.java index b16896d6..f0194426 100644 --- a/even-more-fish-addons-j17/src/main/java/com/oheers/evenmorefish/addons/EcoItemsItemAddon.java +++ b/even-more-fish-addons-j17/src/main/java/com/oheers/evenmorefish/addons/EcoItemsItemAddon.java @@ -3,7 +3,6 @@ import com.oheers.fish.api.addons.ItemAddon; import com.willfp.ecoitems.items.EcoItem; import com.willfp.ecoitems.items.EcoItems; -import org.apache.commons.lang3.JavaVersion; import org.bukkit.inventory.ItemStack; public class EcoItemsItemAddon extends ItemAddon { @@ -34,8 +33,4 @@ public ItemStack getItemStack(String id) { return item.getItemStack(); } - @Override - public JavaVersion getRequiredJavaVersion() { - return JavaVersion.JAVA_17; - } } diff --git a/even-more-fish-addons-j8/src/main/java/com/oheers/evenmorefish/addons/HeadDatabaseItemAddon.java b/even-more-fish-addons-j17/src/main/java/com/oheers/evenmorefish/addons/HeadDatabaseItemAddon.java similarity index 100% rename from even-more-fish-addons-j8/src/main/java/com/oheers/evenmorefish/addons/HeadDatabaseItemAddon.java rename to even-more-fish-addons-j17/src/main/java/com/oheers/evenmorefish/addons/HeadDatabaseItemAddon.java diff --git a/even-more-fish-addons-j8/src/main/java/com/oheers/evenmorefish/addons/ItemsAdderItemAddon.java b/even-more-fish-addons-j17/src/main/java/com/oheers/evenmorefish/addons/ItemsAdderItemAddon.java similarity index 100% rename from even-more-fish-addons-j8/src/main/java/com/oheers/evenmorefish/addons/ItemsAdderItemAddon.java rename to even-more-fish-addons-j17/src/main/java/com/oheers/evenmorefish/addons/ItemsAdderItemAddon.java diff --git a/even-more-fish-addons-j17/src/main/java/com/oheers/evenmorefish/addons/OraxenItemAddon.java b/even-more-fish-addons-j17/src/main/java/com/oheers/evenmorefish/addons/OraxenItemAddon.java index d8fc88ba..003f19a7 100644 --- a/even-more-fish-addons-j17/src/main/java/com/oheers/evenmorefish/addons/OraxenItemAddon.java +++ b/even-more-fish-addons-j17/src/main/java/com/oheers/evenmorefish/addons/OraxenItemAddon.java @@ -4,7 +4,6 @@ import com.oheers.fish.api.addons.ItemAddon; import io.th0rgal.oraxen.api.OraxenItems; import io.th0rgal.oraxen.items.ItemBuilder; -import org.apache.commons.lang3.JavaVersion; import org.bukkit.inventory.ItemStack; public class OraxenItemAddon extends ItemAddon { @@ -34,8 +33,4 @@ public ItemStack getItemStack(String id) { return item.build(); } - @Override - public JavaVersion getRequiredJavaVersion() { - return JavaVersion.JAVA_17; - } } diff --git a/even-more-fish-addons-j8/build.gradle.kts b/even-more-fish-addons-j8/build.gradle.kts deleted file mode 100644 index 1707d918..00000000 --- a/even-more-fish-addons-j8/build.gradle.kts +++ /dev/null @@ -1,21 +0,0 @@ -plugins { - id("com.oheers.evenmorefish.java-conventions") -} - -repositories {} - -dependencies { - compileOnly(libs.spigot.api) - compileOnly(libs.commons.lang3) - compileOnly(libs.itemsadder.api) - compileOnly(libs.headdatabase.api) - - compileOnly(project(":even-more-fish-api")) -} - -java { - toolchain { - languageVersion.set(JavaLanguageVersion.of(8)) - vendor.set(JvmVendorSpec.ADOPTIUM) - } -} diff --git a/even-more-fish-api/build.gradle.kts b/even-more-fish-api/build.gradle.kts index 99d548e4..56ad903b 100644 --- a/even-more-fish-api/build.gradle.kts +++ b/even-more-fish-api/build.gradle.kts @@ -12,7 +12,7 @@ dependencies { java { toolchain { - languageVersion.set(JavaLanguageVersion.of(8)) + languageVersion.set(JavaLanguageVersion.of(17)) vendor.set(JvmVendorSpec.ADOPTIUM) } } diff --git a/even-more-fish-api/src/main/java/com/oheers/fish/api/addons/Addon.java b/even-more-fish-api/src/main/java/com/oheers/fish/api/addons/Addon.java index bce63c73..8cdf51b9 100644 --- a/even-more-fish-api/src/main/java/com/oheers/fish/api/addons/Addon.java +++ b/even-more-fish-api/src/main/java/com/oheers/fish/api/addons/Addon.java @@ -24,7 +24,7 @@ public interface Addon { /** - * Can this addon be registered. + * This should check if the addon can be registered. I.e., required java version + required plugin. */ default boolean canRegister() throws JavaVersionException, RequiredPluginException { final boolean hasRequiredPlugin = Bukkit.getPluginManager().getPlugin(getPluginName()) != null; @@ -44,7 +44,7 @@ default boolean canRegister() throws JavaVersionException, RequiredPluginExcepti String getAuthor(); default JavaVersion getRequiredJavaVersion() { - return JavaVersion.JAVA_1_8; + return JavaVersion.JAVA_17; } default Logger getLogger() { diff --git a/even-more-fish-plugin/build.gradle.kts b/even-more-fish-plugin/build.gradle.kts index d1239ca9..18ba6f21 100644 --- a/even-more-fish-plugin/build.gradle.kts +++ b/even-more-fish-plugin/build.gradle.kts @@ -6,15 +6,14 @@ import net.minecrell.pluginyml.bukkit.BukkitPluginDescription plugins { `java-library` - id("maven-publish") - id("net.minecrell.plugin-yml.bukkit") version "0.6.0" - id("com.github.johnrengelman.shadow") version "8.1.1" - + `maven-publish` + alias(libs.plugins.bukkit.yml) + alias(libs.plugins.shadow) alias(libs.plugins.grgit) } group = "com.oheers.evenmorefish" -version = "1.7.2" +version = "1.7.3" description = "A fishing extension bringing an exciting new experience to fishing." @@ -88,9 +87,7 @@ dependencies { implementation(libs.universalscheduler) implementation(libs.acf) implementation(libs.inventorygui) - implementation(libs.adventure.api) - implementation(libs.adventure.minimessage) - implementation(libs.adventure.legacy) + implementation(libs.bundles.adventure) library(libs.friendlyid) library(libs.flyway.core) @@ -253,14 +250,13 @@ tasks { compileJava { options.compilerArgs.add("-parameters") options.isFork = true - - + options.encoding = "UTF-8" } } java { toolchain { - languageVersion.set(JavaLanguageVersion.of(8)) + languageVersion.set(JavaLanguageVersion.of(17)) vendor.set(JvmVendorSpec.ADOPTIUM) } } diff --git a/even-more-fish-plugin/src/main/java/com/oheers/fish/Economy.java b/even-more-fish-plugin/src/main/java/com/oheers/fish/Economy.java index cdb33e94..e929e9a4 100644 --- a/even-more-fish-plugin/src/main/java/com/oheers/fish/Economy.java +++ b/even-more-fish-plugin/src/main/java/com/oheers/fish/Economy.java @@ -96,43 +96,33 @@ public boolean withdraw(@NotNull OfflinePlayer player, double amount) { } public boolean has(@NotNull OfflinePlayer player, double amount) { - switch (economyType) { - case VAULT: - return vaultEconomy.has(player, amount); - case PLAYER_POINTS: + return switch (economyType) { + case VAULT -> vaultEconomy.has(player, amount); + case PLAYER_POINTS -> // PlayerPoints doesn't seem to have a method to check this - return playerPointsEconomy.look(player.getUniqueId()) >= amount; - case GRIEF_PREVENTION: - return griefPreventionEconomy.dataStore.getPlayerData(player.getUniqueId()).getBonusClaimBlocks() >= amount; - default: - return true; - } + playerPointsEconomy.look(player.getUniqueId()) >= amount; + case GRIEF_PREVENTION -> griefPreventionEconomy.dataStore.getPlayerData(player.getUniqueId()).getBonusClaimBlocks() >= amount; + default -> true; + }; } public double get(@NotNull OfflinePlayer player) { - switch (economyType) { - case VAULT: - return vaultEconomy.getBalance(player); - case PLAYER_POINTS: + return switch (economyType) { + case VAULT -> vaultEconomy.getBalance(player); + case PLAYER_POINTS -> // PlayerPoints doesn't seem to have a method to check this - return playerPointsEconomy.look(player.getUniqueId()); - case GRIEF_PREVENTION: - return griefPreventionEconomy.dataStore.getPlayerData(player.getUniqueId()).getBonusClaimBlocks(); - default: - return 0; - } + playerPointsEconomy.look(player.getUniqueId()); + case GRIEF_PREVENTION -> griefPreventionEconomy.dataStore.getPlayerData(player.getUniqueId()).getBonusClaimBlocks(); + default -> 0; + }; } public static double prepareValue(double value) { - switch (economyType) { - case VAULT: - return value; - case PLAYER_POINTS: - case GRIEF_PREVENTION: - return Math.floor(value); - default: - return 0; - } + return switch (economyType) { + case VAULT -> value; + case PLAYER_POINTS, GRIEF_PREVENTION -> Math.floor(value); + default -> 0; + }; } public enum EconomyType { diff --git a/even-more-fish-plugin/src/main/java/com/oheers/fish/EvenMoreFish.java b/even-more-fish-plugin/src/main/java/com/oheers/fish/EvenMoreFish.java index ba89bfe5..c199734f 100644 --- a/even-more-fish-plugin/src/main/java/com/oheers/fish/EvenMoreFish.java +++ b/even-more-fish-plugin/src/main/java/com/oheers/fish/EvenMoreFish.java @@ -36,7 +36,6 @@ import com.oheers.fish.fishing.items.Names; import com.oheers.fish.fishing.items.Rarity; import com.oheers.fish.gui.FillerStyle; -import com.oheers.fish.gui.SellGUI; import com.oheers.fish.utils.AntiCraft; import com.oheers.fish.utils.HeadDBIntegration; import com.oheers.fish.utils.ItemFactory; @@ -262,7 +261,7 @@ private void saveAdditionalDefaultAddons() { for (final String fileName : Arrays.stream(DefaultAddons.values()) .map(DefaultAddons::getFullFileName) - .collect(Collectors.toList())) { + .toList()) { final File addonFile = new File(getDataFolder(), "addons/" + fileName); final File jarFile = new File(getDataFolder(), "addons/" + fileName.replace(".addon", ".jar")); if (!jarFile.exists()) { @@ -418,7 +417,7 @@ private void loadCommandManager() { Optional potentialRarity = EvenMoreFish.getInstance().getFishCollection().keySet().stream() .filter(rarity -> rarity.getValue().equalsIgnoreCase(rarityId)) .findFirst(); - if (!potentialRarity.isPresent()) { + if (potentialRarity.isEmpty()) { throw new InvalidCommandArgument("No such rarity: " + rarityId); } @@ -431,7 +430,7 @@ private void loadCommandManager() { .filter(f -> f.getName().equalsIgnoreCase(fishId.replace("_", " ")) || f.getName().equalsIgnoreCase(fishId)) .findFirst(); - if (!potentialFish.isPresent()) { + if (potentialFish.isEmpty()) { throw new InvalidCommandArgument("No such fish: " + fishId); } @@ -853,8 +852,7 @@ public List getOnlinePlayersExcludingVanish() { // Check Essentials if (Bukkit.getPluginManager().isPluginEnabled("Essentials")) { Plugin plugin = Bukkit.getPluginManager().getPlugin("Essentials"); - if (plugin instanceof Essentials) { - Essentials essentials = (Essentials) plugin; + if (plugin instanceof Essentials essentials) { players = players.stream().filter(player -> !essentials.getUser(player).isVanished()).collect(Collectors.toList()); } } diff --git a/even-more-fish-plugin/src/main/java/com/oheers/fish/FishUtils.java b/even-more-fish-plugin/src/main/java/com/oheers/fish/FishUtils.java index ca9252ac..5e1b5eb3 100644 --- a/even-more-fish-plugin/src/main/java/com/oheers/fish/FishUtils.java +++ b/even-more-fish-plugin/src/main/java/com/oheers/fish/FishUtils.java @@ -30,11 +30,7 @@ import org.bukkit.block.Skull; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.SkullMeta; -import org.bukkit.profile.PlayerProfile; -import org.bukkit.profile.PlayerTextures; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.util.List; import java.util.UUID; @@ -44,7 +40,7 @@ public class FishUtils { private static final Pattern HEX_PATTERN = Pattern.compile("&#" + "([A-Fa-f0-9]{6})"); - private static final char COLOR_CHAR = '\u00A7'; + private static final char COLOR_CHAR = '§'; // checks for the "emf-fish-name" nbt tag, to determine if this ItemStack is a fish or not. public static boolean isFish(ItemStack item) { @@ -270,7 +266,7 @@ public static String translateColorCodes(String message) { } Matcher matcher = HEX_PATTERN.matcher(message); - StringBuffer buffer = new StringBuffer(message.length() + 4 * 8); + StringBuilder buffer = new StringBuilder(message.length() + 4 * 8); while (matcher.find()) { String group = matcher.group(1); matcher.appendReplacement(buffer, COLOR_CHAR + "x" diff --git a/even-more-fish-plugin/src/main/java/com/oheers/fish/addons/AddonManager.java b/even-more-fish-plugin/src/main/java/com/oheers/fish/addons/AddonManager.java index 629c83f9..262184d4 100644 --- a/even-more-fish-plugin/src/main/java/com/oheers/fish/addons/AddonManager.java +++ b/even-more-fish-plugin/src/main/java/com/oheers/fish/addons/AddonManager.java @@ -21,7 +21,6 @@ import java.util.*; import java.util.concurrent.CompletableFuture; import java.util.logging.Level; -import java.util.stream.Collectors; public class AddonManager { private static final String ADDON_FOLDER = "addons"; @@ -53,10 +52,9 @@ public ItemStack getItemStack(final String prefix, final String id) throws NoPre } final Addon addon = addonMap.get(prefix); - if (!(addon instanceof ItemAddon)) { + if (!(addon instanceof ItemAddon itemAddon)) { return new ItemStack(Material.AIR); } - ItemAddon itemAddon = (ItemAddon) addon; return itemAddon.getItemStack(id); } @@ -76,8 +74,7 @@ public boolean registerAddon(final @NotNull Addon addon) { this.loadingMap.put(prefix, false); this.addonMap.put(prefix, addon); - if (addon instanceof Listener) { - Listener listener = (Listener) addon; + if (addon instanceof Listener listener) { Bukkit.getPluginManager().registerEvents(listener, plugin); } return true; @@ -107,8 +104,7 @@ public Optional registerAddon(final @NotNull Class addon return Optional.empty(); } - if (addonInstance instanceof Listener) { - final Listener listener = (Listener) addonInstance; + if (addonInstance instanceof Listener listener) { Bukkit.getPluginManager().registerEvents(listener, plugin); } @@ -174,7 +170,7 @@ private void registerAll() { .map(this::registerAddon) .filter(Optional::isPresent) .map(Optional::get) - .collect(Collectors.toList()); + .toList(); final String message = String.format("%s new addons registered! (%s total)", registered.size(), addonMap.keySet().size()); @@ -190,8 +186,7 @@ public void load() { registerAll(); for (Map.Entry entry : addonMap.entrySet()) { - if (entry.getValue() instanceof Listener) { - final Listener listener = (Listener) entry.getValue(); + if (entry.getValue() instanceof Listener listener) { Bukkit.getPluginManager().registerEvents(listener, plugin); } } diff --git a/even-more-fish-plugin/src/main/java/com/oheers/fish/baits/BaitListener.java b/even-more-fish-plugin/src/main/java/com/oheers/fish/baits/BaitListener.java index d0cf09d1..44c04604 100644 --- a/even-more-fish-plugin/src/main/java/com/oheers/fish/baits/BaitListener.java +++ b/even-more-fish-plugin/src/main/java/com/oheers/fish/baits/BaitListener.java @@ -32,10 +32,10 @@ public void onClickEvent(InventoryClickEvent event) { return; } - ItemStack clickedItem = event.getCurrentItem(); + ItemStack potentialFishingRod = event.getCurrentItem(); ItemStack cursor = event.getCursor(); - if (clickedItem.getType() != Material.FISHING_ROD) + if (potentialFishingRod.getType() != Material.FISHING_ROD) return; if (!BaitNBTManager.isBaitObject(cursor)) { @@ -48,21 +48,20 @@ public void onClickEvent(InventoryClickEvent event) { return; } - ApplicationResult result = null; + ApplicationResult result; Bait bait = EvenMoreFish.getInstance().getBaits().get(BaitNBTManager.getBaitName(event.getCursor())); - ItemStack fishingRod = clickedItem; - NbtVersion nbtVersion = NbtVersion.getVersion(clickedItem); + NbtVersion nbtVersion = NbtVersion.getVersion(potentialFishingRod); if (nbtVersion != NbtVersion.COMPAT) { - fishingRod = convertToCompatNbtItem(nbtVersion, fishingRod); + convertToCompatNbtItem(nbtVersion, potentialFishingRod); } try { if (event.getAction() == InventoryAction.MOVE_TO_OTHER_INVENTORY) { - result = BaitNBTManager.applyBaitedRodNBT(fishingRod, bait, event.getCursor().getAmount()); + result = BaitNBTManager.applyBaitedRodNBT(potentialFishingRod, bait, event.getCursor().getAmount()); EvenMoreFish.getInstance().incrementMetricBaitsApplied(event.getCursor().getAmount()); } else { - result = BaitNBTManager.applyBaitedRodNBT(fishingRod, bait, 1); + result = BaitNBTManager.applyBaitedRodNBT(potentialFishingRod, bait, 1); EvenMoreFish.getInstance().incrementMetricBaitsApplied(1); } @@ -94,7 +93,7 @@ public void onClickEvent(InventoryClickEvent event) { } } - private ItemStack convertToCompatNbtItem(final NbtVersion nbtVersion, final ItemStack fishingRod) { + private void convertToCompatNbtItem(final NbtVersion nbtVersion, final ItemStack fishingRod) { final String appliedBaitString = NbtUtils.getString(fishingRod, NbtKeys.EMF_APPLIED_BAIT); if (nbtVersion == NbtVersion.LEGACY) { @@ -123,15 +122,12 @@ private ItemStack convertToCompatNbtItem(final NbtVersion nbtVersion, final Item nbt.getOrCreateCompound(NbtKeys.EMF_COMPOUND).setString(NbtKeys.EMF_APPLIED_BAIT, appliedBaitString); }); - return fishingRod; } private boolean anvilCheck(InventoryClickEvent event) { - if (!(event.getClickedInventory() instanceof AnvilInventory) || !(event.getWhoClicked() instanceof Player)) { + if (!(event.getClickedInventory() instanceof AnvilInventory inv) || !(event.getWhoClicked() instanceof Player player)) { return false; } - Player player = (Player) event.getWhoClicked(); - AnvilInventory inv = (AnvilInventory) event.getClickedInventory(); if (event.getSlot() == 2 && BaitNBTManager.isBaitedRod(inv.getItem(1))) { event.setCancelled(true); player.closeInventory(); diff --git a/even-more-fish-plugin/src/main/java/com/oheers/fish/baits/BaitNBTManager.java b/even-more-fish-plugin/src/main/java/com/oheers/fish/baits/BaitNBTManager.java index 6dcb46ea..2647915b 100644 --- a/even-more-fish-plugin/src/main/java/com/oheers/fish/baits/BaitNBTManager.java +++ b/even-more-fish-plugin/src/main/java/com/oheers/fish/baits/BaitNBTManager.java @@ -171,13 +171,13 @@ public static ApplicationResult applyBaitedRodNBT(ItemStack item, Bait bait, int cursorModifier.set(-quantity); } } else { - if (combined.length() > 0) { + if (!combined.isEmpty()) { combined.deleteCharAt(combined.length() - 1); } } NBT.modify(item, nbt -> { ReadWriteNBT emfCompound = nbt.getOrCreateCompound(NbtKeys.EMF_COMPOUND); - if (combined.length() > 0) { + if (!combined.isEmpty()) { emfCompound.setString(NbtKeys.EMF_APPLIED_BAIT, combined.toString()); } else { emfCompound.removeKey(NbtKeys.EMF_APPLIED_BAIT); @@ -199,7 +199,7 @@ public static ApplicationResult applyBaitedRodNBT(ItemStack item, Bait bait, int }); } - if (doingLoreStuff && combined.length() >= 1) { + if (doingLoreStuff && !combined.isEmpty()) { ItemMeta meta = item.getItemMeta(); meta.setLore(newApplyLore(item)); item.setItemMeta(meta); @@ -401,9 +401,6 @@ public static List deleteOldLore(ItemStack itemStack) throws IndexOutOfB int maxBaits = BaitFile.getInstance().getMaxBaits() + BaitFile.getInstance().getRodLoreFormat().size(); //todo, to help this be compliant with java:S5413, we should iterate in reverse order, this should be done in another pr, left here for reference //compliant version - // for (int i = lore.size() - 1; i >= maxBaits; i--) { - // lore.remove(i); - // } for (int i = 1; i < maxBaits; i++) { lore.remove(lore.size() - 1); } @@ -411,9 +408,6 @@ public static List deleteOldLore(ItemStack itemStack) throws IndexOutOfB // starting at 1, because at least one bait replacing {baits} is repeated. int numBaitsApplied = getNumBaitsApplied(itemStack) + BaitFile.getInstance().getRodLoreFormat().size(); //compliant version - // for (int i = lore.size() - 1; i >= numBaitsApplied; i--) { - // lore.remove(i); - // } for (int i = 1; i < numBaitsApplied; i++) { lore.remove(lore.size() - 1); } diff --git a/even-more-fish-plugin/src/main/java/com/oheers/fish/commands/AdminCommand.java b/even-more-fish-plugin/src/main/java/com/oheers/fish/commands/AdminCommand.java index eda7c720..4a1858bc 100644 --- a/even-more-fish-plugin/src/main/java/com/oheers/fish/commands/AdminCommand.java +++ b/even-more-fish-plugin/src/main/java/com/oheers/fish/commands/AdminCommand.java @@ -12,10 +12,7 @@ import com.oheers.fish.baits.BaitNBTManager; import com.oheers.fish.competition.Competition; import com.oheers.fish.competition.CompetitionType; -import com.oheers.fish.config.BaitFile; -import com.oheers.fish.config.FishFile; import com.oheers.fish.config.MainConfig; -import com.oheers.fish.config.RaritiesFile; import com.oheers.fish.config.messages.ConfigMessage; import com.oheers.fish.config.messages.Message; import com.oheers.fish.config.messages.Messages; diff --git a/even-more-fish-plugin/src/main/java/com/oheers/fish/competition/Bar.java b/even-more-fish-plugin/src/main/java/com/oheers/fish/competition/Bar.java index c63216c5..8362da5d 100644 --- a/even-more-fish-plugin/src/main/java/com/oheers/fish/competition/Bar.java +++ b/even-more-fish-plugin/src/main/java/com/oheers/fish/competition/Bar.java @@ -41,27 +41,14 @@ public void setProgress(long timeLeft, long totalTime) { } public void setPrefix(String prefix, CompetitionType type) { - String typeString = ""; - switch (type) { - case SPECIFIC_RARITY: - typeString = "Specific Rarity"; - break; - case MOST_FISH: - typeString = "Most Fish"; - break; - case LARGEST_FISH: - typeString = "Largest Fish"; - break; - case LARGEST_TOTAL: - typeString = "Largest Total"; - break; - case SPECIFIC_FISH: - typeString = "Specific Fish"; - break; - case RANDOM: - typeString = "Random"; - break; - } + String typeString = switch (type) { + case SPECIFIC_RARITY -> "Specific Rarity"; + case MOST_FISH -> "Most Fish"; + case LARGEST_FISH -> "Largest Fish"; + case LARGEST_TOTAL -> "Largest Total"; + case SPECIFIC_FISH -> "Specific Fish"; + case RANDOM -> "Random"; + }; this.prefix = prefix.replace("{type}", typeString); } diff --git a/even-more-fish-plugin/src/main/java/com/oheers/fish/competition/Competition.java b/even-more-fish-plugin/src/main/java/com/oheers/fish/competition/Competition.java index a5e12a4a..bbcf30eb 100644 --- a/even-more-fish-plugin/src/main/java/com/oheers/fish/competition/Competition.java +++ b/even-more-fish-plugin/src/main/java/com/oheers/fish/competition/Competition.java @@ -26,7 +26,6 @@ import java.time.Instant; import java.util.*; import java.util.logging.Level; -import java.util.stream.Collectors; public class Competition { @@ -408,162 +407,96 @@ public void announceBegin() { public void sendPlayerLeaderboard(Player player) { boolean reachingCount = true; - if (active) { - if (leaderboard.getSize() != 0) { - - List competitionColours = CompetitionConfig.getInstance().getPositionColours(); - StringBuilder builder = new StringBuilder(); - int pos = 0; - - for (CompetitionEntry entry : leaderboard.getEntries()) { - pos++; - if (reachingCount) { - leaderboardMembers.add(entry.getPlayer()); - Message message = new Message(ConfigMessage.LEADERBOARD_LARGEST_FISH); - message.setPlayer(Bukkit.getOfflinePlayer(entry.getPlayer()).getName()); - message.setPosition(Integer.toString(pos)); - if (pos > competitionColours.size()) { - Random r = EvenMoreFish.getInstance().getRandom(); - int s = r.nextInt(3); - switch (s) { - case 0: - message.setPositionColour("&c\u00bb &r"); - break; - case 1: - message.setPositionColour("&c_ &r"); - break; - case 2: - message.setPositionColour("&c&ko &r"); - break; - } - } else { - message.setPositionColour(competitionColours.get(pos - 1)); - } + if (!active) { + new Message(ConfigMessage.NO_COMPETITION_RUNNING).broadcast(player, true); + return; + } - if (competitionType == CompetitionType.LARGEST_FISH) { - Fish fish = entry.getFish(); - message.setRarityColour(fish.getRarity().getColour()); - message.setLength(Float.toString(entry.getValue())); - - if (fish.getRarity().getDisplayName() != null) { - message.setRarity(fish.getRarity().getDisplayName()); - } else { - message.setRarity(fish.getRarity().getValue()); - } - - if (fish.getDisplayName() != null) { - message.setFishCaught(fish.getDisplayName()); - } else { - message.setFishCaught(fish.getName()); - } - } else { - if (competitionType == CompetitionType.LARGEST_TOTAL) { - message.setMessage(ConfigMessage.LEADERBOARD_LARGEST_TOTAL); - // Clearing floating point .00000003 error not-cool stuff. - message.setAmount(Double.toString(Math.floor(entry.getValue() * 10) / 10)); - } else { - message.setMessage(ConfigMessage.LEADERBOARD_MOST_FISH); - message.setAmount(Integer.toString((int) entry.getValue())); - } + if (leaderboard.getSize() == 0) { + new Message(ConfigMessage.NO_FISH_CAUGHT).broadcast(player, false); + return; + } - } - builder.append(message.getRawMessage(true)); - - if (pos == Messages.getInstance().getConfig().getInt("leaderboard-count")) { - if (Messages.getInstance().getConfig().getBoolean("always-show-pos")) { - if (leaderboardMembers.contains(player.getUniqueId())) { - break; - } else { - reachingCount = false; - } - } else { - break; - } - } else { - builder.append("\n"); - } - } else { - if (entry.getPlayer() == player.getUniqueId()) { - Message message = new Message(ConfigMessage.LEADERBOARD_LARGEST_FISH); - message.setPosition(Integer.toString(pos)); - message.setPlayer(Bukkit.getOfflinePlayer(entry.getPlayer()).getName()); - message.setPositionColour("&f"); - - if (competitionType == CompetitionType.LARGEST_FISH) { - Fish fish = entry.getFish(); - message.setRarityColour(fish.getRarity().getColour()); - message.setLength(Float.toString(entry.getValue())); - - if (fish.getRarity().getDisplayName() != null) { - message.setRarity(fish.getRarity().getDisplayName()); - } else { - message.setRarity(fish.getRarity().getValue()); - } - - if (fish.getDisplayName() != null) { - message.setFishCaught(fish.getDisplayName()); - } else { - message.setFishCaught(fish.getName()); - } - } else { - message.setAmount(Integer.toString((int) entry.getValue())); - if (competitionType == CompetitionType.LARGEST_TOTAL) { - message.setMessage(ConfigMessage.LEADERBOARD_LARGEST_TOTAL); - } else { - message.setMessage(ConfigMessage.LEADERBOARD_MOST_FISH); - } - } - - builder.append("\n").append(message.getRawMessage(true)); - } + + List competitionColours = CompetitionConfig.getInstance().getPositionColours(); + StringBuilder builder = new StringBuilder(); + int pos = 0; + + for (CompetitionEntry entry : leaderboard.getEntries()) { + pos++; + if (reachingCount) { + leaderboardMembers.add(entry.getPlayer()); + Message message = new Message(ConfigMessage.LEADERBOARD_LARGEST_FISH); + message.setPlayer(Bukkit.getOfflinePlayer(entry.getPlayer()).getName()); + message.setPosition(Integer.toString(pos)); + if (pos > competitionColours.size()) { + Random r = EvenMoreFish.getInstance().getRandom(); + int s = r.nextInt(3); + switch (s) { + case 0: + message.setPositionColour("&c» &r"); + break; + case 1: + message.setPositionColour("&c_ &r"); + break; + case 2: + message.setPositionColour("&c&ko &r"); + break; } + + } else { + message.setPositionColour(competitionColours.get(pos - 1)); } - player.sendMessage(builder.toString()); - Message message = new Message(ConfigMessage.LEADERBOARD_TOTAL_PLAYERS); - message.setAmount(Integer.toString(leaderboard.getSize())); - message.broadcast(player, true); - } else { - new Message(ConfigMessage.NO_FISH_CAUGHT).broadcast(player, false); - } - } else { - new Message(ConfigMessage.NO_COMPETITION_RUNNING).broadcast(player, true); - } - } - public void sendConsoleLeaderboard(ConsoleCommandSender console) { - boolean reachingCount = true; - if (active) { - if (leaderboard.getSize() != 0) { + if (competitionType == CompetitionType.LARGEST_FISH) { + Fish fish = entry.getFish(); + message.setRarityColour(fish.getRarity().getColour()); + message.setLength(Float.toString(entry.getValue())); - List competitionColours = CompetitionConfig.getInstance().getPositionColours(); - StringBuilder builder = new StringBuilder(); - int pos = 0; + if (fish.getRarity().getDisplayName() != null) { + message.setRarity(fish.getRarity().getDisplayName()); + } else { + message.setRarity(fish.getRarity().getValue()); + } - for (CompetitionEntry entry : leaderboard.getEntries()) { - pos++; - leaderboardMembers.add(entry.getPlayer()); - Message message = new Message(ConfigMessage.LEADERBOARD_LARGEST_FISH); - message.setPlayer(Bukkit.getOfflinePlayer(entry.getPlayer()).getName()); - message.setPosition(Integer.toString(pos)); - if (pos > competitionColours.size()) { - Random r = new Random(); - int s = r.nextInt(3); - switch (s) { - case 0: - message.setPositionColour("&c\u00bb &r"); - break; - case 1: - message.setPositionColour("&c_ &r"); - break; - case 2: - message.setPositionColour("&c&ko &r"); - break; - } + if (fish.getDisplayName() != null) { + message.setFishCaught(fish.getDisplayName()); + } else { + message.setFishCaught(fish.getName()); + } + } else { + if (competitionType == CompetitionType.LARGEST_TOTAL) { + message.setMessage(ConfigMessage.LEADERBOARD_LARGEST_TOTAL); + // Clearing floating point .00000003 error not-cool stuff. + message.setAmount(Double.toString(Math.floor(entry.getValue() * 10) / 10)); + } else { + message.setMessage(ConfigMessage.LEADERBOARD_MOST_FISH); + message.setAmount(Integer.toString((int) entry.getValue())); + } + + } + builder.append(message.getRawMessage(true)); + if (pos == Messages.getInstance().getConfig().getInt("leaderboard-count")) { + if (Messages.getInstance().getConfig().getBoolean("always-show-pos")) { + if (leaderboardMembers.contains(player.getUniqueId())) { + break; + } else { + reachingCount = false; + } } else { - message.setPositionColour(competitionColours.get(pos - 1)); + break; } + } else { + builder.append("\n"); + } + } else { + if (entry.getPlayer() == player.getUniqueId()) { + Message message = new Message(ConfigMessage.LEADERBOARD_LARGEST_FISH); + message.setPosition(Integer.toString(pos)); + message.setPlayer(Bukkit.getOfflinePlayer(entry.getPlayer()).getName()); + message.setPositionColour("&f"); if (competitionType == CompetitionType.LARGEST_FISH) { Fish fish = entry.getFish(); @@ -582,29 +515,104 @@ public void sendConsoleLeaderboard(ConsoleCommandSender console) { message.setFishCaught(fish.getName()); } } else { + message.setAmount(Integer.toString((int) entry.getValue())); if (competitionType == CompetitionType.LARGEST_TOTAL) { message.setMessage(ConfigMessage.LEADERBOARD_LARGEST_TOTAL); - // Clearing floating point .00000003 error not-cool stuff. - message.setAmount(Double.toString(Math.floor(entry.getValue() * 10) / 10)); } else { message.setMessage(ConfigMessage.LEADERBOARD_MOST_FISH); - message.setAmount(Integer.toString((int) entry.getValue())); } - } - builder.append(message.getRawMessage(true)); + builder.append("\n").append(message.getRawMessage(true)); } - console.sendMessage(builder.toString()); - Message message = new Message(ConfigMessage.LEADERBOARD_TOTAL_PLAYERS); - message.setAmount(Integer.toString(leaderboard.getSize())); - message.broadcast(console, true); - } else { - new Message(ConfigMessage.NO_FISH_CAUGHT).broadcast(console, false); } - } else { + } + player.sendMessage(builder.toString()); + Message message = new Message(ConfigMessage.LEADERBOARD_TOTAL_PLAYERS); + message.setAmount(Integer.toString(leaderboard.getSize())); + message.broadcast(player, true); + + + } + + public void sendConsoleLeaderboard(ConsoleCommandSender console) { + if (!active) { new Message(ConfigMessage.NO_COMPETITION_RUNNING).broadcast(console, true); + return; + } + if (leaderboard.getSize() == 0) { + new Message(ConfigMessage.NO_FISH_CAUGHT).broadcast(console, false); + return; + } + + + List competitionColours = CompetitionConfig.getInstance().getPositionColours(); + StringBuilder builder = new StringBuilder(); + int pos = 0; + + for (CompetitionEntry entry : leaderboard.getEntries()) { + pos++; + leaderboardMembers.add(entry.getPlayer()); + Message message = new Message(ConfigMessage.LEADERBOARD_LARGEST_FISH); + message.setPlayer(Bukkit.getOfflinePlayer(entry.getPlayer()).getName()); + message.setPosition(Integer.toString(pos)); + if (pos > competitionColours.size()) { + Random r = EvenMoreFish.getInstance().getRandom(); + int s = r.nextInt(3); + switch (s) { + case 0: + message.setPositionColour("&c» &r"); + break; + case 1: + message.setPositionColour("&c_ &r"); + break; + case 2: + message.setPositionColour("&c&ko &r"); + break; + default: + break; + } + + } else { + message.setPositionColour(competitionColours.get(pos - 1)); + } + + if (competitionType == CompetitionType.LARGEST_FISH) { + Fish fish = entry.getFish(); + message.setRarityColour(fish.getRarity().getColour()); + message.setLength(Float.toString(entry.getValue())); + + if (fish.getRarity().getDisplayName() != null) { + message.setRarity(fish.getRarity().getDisplayName()); + } else { + message.setRarity(fish.getRarity().getValue()); + } + + if (fish.getDisplayName() != null) { + message.setFishCaught(fish.getDisplayName()); + } else { + message.setFishCaught(fish.getName()); + } + } else { + if (competitionType == CompetitionType.LARGEST_TOTAL) { + message.setMessage(ConfigMessage.LEADERBOARD_LARGEST_TOTAL); + // Clearing floating point .00000003 error not-cool stuff. + message.setAmount(Double.toString(Math.floor(entry.getValue() * 10) / 10)); + } else { + message.setMessage(ConfigMessage.LEADERBOARD_MOST_FISH); + message.setAmount(Integer.toString((int) entry.getValue())); + } + + } + builder.append(message.getRawMessage(true)); + } + console.sendMessage(builder.toString()); + Message message = new Message(ConfigMessage.LEADERBOARD_TOTAL_PLAYERS); + message.setAmount(Integer.toString(leaderboard.getSize())); + message.broadcast(console, true); + + } public boolean chooseFish(String competitionName, boolean adminStart) { @@ -630,7 +638,7 @@ public boolean chooseFish(String competitionName, boolean adminStart) { if (allowedRarities.isEmpty()) { EvenMoreFish.getInstance().getLogger().severe("The allowed-rarities list found in the " + competitionName + " competition config contains no loaded rarities!"); EvenMoreFish.getInstance().getLogger().severe("Configured Rarities: " + configRarities); - EvenMoreFish.getInstance().getLogger().severe("Loaded Rarities: " + EvenMoreFish.getInstance().getFishCollection().keySet().stream().map(Rarity::getValue).collect(Collectors.toList())); + EvenMoreFish.getInstance().getLogger().severe("Loaded Rarities: " + EvenMoreFish.getInstance().getFishCollection().keySet().stream().map(Rarity::getValue).toList()); return false; } @@ -654,7 +662,7 @@ public boolean chooseFish(String competitionName, boolean adminStart) { } this.selectedFish = selectedFish; return true; - } catch (IllegalArgumentException|IndexOutOfBoundsException exception) { + } catch (IllegalArgumentException | IndexOutOfBoundsException exception) { EvenMoreFish.getInstance() .getLogger() .severe("Could not load: " + competitionName + " because a random fish could not be chosen. \nIf you need support, please provide the following information:"); @@ -752,48 +760,49 @@ public void initRewards(String competitionName, boolean adminStart) { } private void handleRewards() { + if (leaderboard.getSize() == 0) { + if (!((competitionType == CompetitionType.SPECIFIC_FISH || competitionType == CompetitionType.SPECIFIC_RARITY) && numberNeeded == 1)) { + new Message(ConfigMessage.NO_WINNERS).broadcast(false); + } + return; + } + boolean databaseEnabled = MainConfig.getInstance().databaseEnabled(); - if (leaderboard.getSize() != 0) { - int rewardPlace = 1; - CompetitionEntry topEntry = leaderboard.getTopEntry(); - if (topEntry != null && databaseEnabled) { - UserReport topReport = DataManager.getInstance().getUserReportIfExists(topEntry.getPlayer()); - if (topReport == null) { - EvenMoreFish.getInstance().getLogger().severe("Could not fetch User Report for " + topEntry.getPlayer() + ", their data has not been modified."); - } else { - topReport.incrementCompetitionsWon(1); - } + int rewardPlace = 1; + CompetitionEntry topEntry = leaderboard.getTopEntry(); + if (topEntry != null && databaseEnabled) { + UserReport topReport = DataManager.getInstance().getUserReportIfExists(topEntry.getPlayer()); + if (topReport == null) { + EvenMoreFish.getInstance().getLogger().severe("Could not fetch User Report for " + topEntry.getPlayer() + ", their data has not been modified."); + } else { + topReport.incrementCompetitionsWon(1); } + } - boolean participationRewardsExist = (participationRewards != null && !participationRewards.isEmpty()); - Iterator competitionEntryIterator = leaderboard.getIterator(); + boolean participationRewardsExist = (participationRewards != null && !participationRewards.isEmpty()); + Iterator competitionEntryIterator = leaderboard.getIterator(); - while (competitionEntryIterator.hasNext()) { - CompetitionEntry entry = competitionEntryIterator.next(); - if (rewardPlace <= rewards.size()) { - Player player = Bukkit.getPlayer(entry.getPlayer()); - if (player != null) { - rewards.get(rewardPlace).forEach(reward -> reward.rewardPlayer(player, null)); - } - rewardPlace++; - } else { - if (participationRewardsExist) { - Player participationPlayer = Bukkit.getPlayer(entry.getPlayer()); - if (participationPlayer != null) { - participationRewards.forEach(reward -> reward.rewardPlayer(participationPlayer, null)); - } - } + while (competitionEntryIterator.hasNext()) { + CompetitionEntry entry = competitionEntryIterator.next(); + if (rewardPlace <= rewards.size()) { + Player player = Bukkit.getPlayer(entry.getPlayer()); + if (player != null) { + rewards.get(rewardPlace).forEach(reward -> reward.rewardPlayer(player, null)); } - if (databaseEnabled) { - incrementCompetitionsJoined(entry); + rewardPlace++; + } else { + if (participationRewardsExist) { + Player participationPlayer = Bukkit.getPlayer(entry.getPlayer()); + if (participationPlayer != null) { + participationRewards.forEach(reward -> reward.rewardPlayer(participationPlayer, null)); + } } } - - } else { - if (!((competitionType == CompetitionType.SPECIFIC_FISH || competitionType == CompetitionType.SPECIFIC_RARITY) && numberNeeded == 1)) { - new Message(ConfigMessage.NO_WINNERS).broadcast(false); + if (databaseEnabled) { + incrementCompetitionsJoined(entry); } } + } public void singleReward(Player player) { @@ -837,7 +846,7 @@ public void initStartSound(String competitionName) { private CompetitionType getRandomType() { // -1 from the length so that the RANDOM isn't chosen as the random value. - int type = new Random().nextInt(CompetitionType.values().length - 1); + int type = EvenMoreFish.getInstance().getRandom().nextInt(CompetitionType.values().length - 1); return CompetitionType.values()[type]; } diff --git a/even-more-fish-plugin/src/main/java/com/oheers/fish/competition/JoinChecker.java b/even-more-fish-plugin/src/main/java/com/oheers/fish/competition/JoinChecker.java index e6287789..839d7d5f 100644 --- a/even-more-fish-plugin/src/main/java/com/oheers/fish/competition/JoinChecker.java +++ b/even-more-fish-plugin/src/main/java/com/oheers/fish/competition/JoinChecker.java @@ -27,7 +27,7 @@ public class JoinChecker implements Listener { public void databaseRegistration(UUID userUUID, String userName) { if (MainConfig.getInstance().isDatabaseOnline()) { EvenMoreFish.getScheduler().runTaskAsynchronously(() -> { - List fishReports = new ArrayList<>(); + List fishReports; if (EvenMoreFish.getInstance().getDatabaseV3().hasUserLog(userUUID)) { diff --git a/even-more-fish-plugin/src/main/java/com/oheers/fish/config/GUIConfig.java b/even-more-fish-plugin/src/main/java/com/oheers/fish/config/GUIConfig.java index 52ad3a37..8fbea164 100644 --- a/even-more-fish-plugin/src/main/java/com/oheers/fish/config/GUIConfig.java +++ b/even-more-fish-plugin/src/main/java/com/oheers/fish/config/GUIConfig.java @@ -22,11 +22,6 @@ public GUIConfig() { public static GUIConfig getInstance() { return instance; } - - @Override - public void reload() { - super.reload(); - } public String getToggle(boolean toggleState) { if (toggleState) return getConfig().getString("enabled-msg", "&a&l✔"); diff --git a/even-more-fish-plugin/src/main/java/com/oheers/fish/config/MainConfig.java b/even-more-fish-plugin/src/main/java/com/oheers/fish/config/MainConfig.java index 96e090f9..059a64d3 100644 --- a/even-more-fish-plugin/src/main/java/com/oheers/fish/config/MainConfig.java +++ b/even-more-fish-plugin/src/main/java/com/oheers/fish/config/MainConfig.java @@ -2,7 +2,6 @@ import com.oheers.fish.Economy; import com.oheers.fish.EvenMoreFish; -import org.bukkit.Material; import java.util.List; @@ -67,16 +66,12 @@ public boolean isEconomyDisabled() { public Economy.EconomyType economyType() { String economyString = getConfig().getString("economy-type", "Vault"); - switch (economyString) { - case "Vault": - return Economy.EconomyType.VAULT; - case "PlayerPoints": - return Economy.EconomyType.PLAYER_POINTS; - case "GriefPrevention": - return Economy.EconomyType.GRIEF_PREVENTION; - default: - return Economy.EconomyType.NONE; - } + return switch (economyString) { + case "Vault" -> Economy.EconomyType.VAULT; + case "PlayerPoints" -> Economy.EconomyType.PLAYER_POINTS; + case "GriefPrevention" -> Economy.EconomyType.GRIEF_PREVENTION; + default -> Economy.EconomyType.NONE; + }; } public boolean shouldRespectVanish() { return getConfig().getBoolean("respect-vanished", true); } diff --git a/even-more-fish-plugin/src/main/java/com/oheers/fish/config/messages/Message.java b/even-more-fish-plugin/src/main/java/com/oheers/fish/config/messages/Message.java index 4c9b7cdb..ee0f7565 100644 --- a/even-more-fish-plugin/src/main/java/com/oheers/fish/config/messages/Message.java +++ b/even-more-fish-plugin/src/main/java/com/oheers/fish/config/messages/Message.java @@ -4,12 +4,7 @@ import com.oheers.fish.FishUtils; import com.oheers.fish.competition.CompetitionType; import me.clip.placeholderapi.PlaceholderAPI; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.minimessage.MiniMessage; -import net.kyori.adventure.text.minimessage.ParsingException; -import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import org.bukkit.Bukkit; -import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; diff --git a/even-more-fish-plugin/src/main/java/com/oheers/fish/database/DataManager.java b/even-more-fish-plugin/src/main/java/com/oheers/fish/database/DataManager.java index a4c10b34..993ff78c 100644 --- a/even-more-fish-plugin/src/main/java/com/oheers/fish/database/DataManager.java +++ b/even-more-fish-plugin/src/main/java/com/oheers/fish/database/DataManager.java @@ -19,7 +19,7 @@ public class DataManager { private Cache> fishReportCache; private void setup() { - Expiry userReportExpiry = new Expiry() { + Expiry userReportExpiry = new Expiry<>() { @Override public long expireAfterCreate(@NotNull UUID uuid, @NotNull UserReport userReport, long l) { return getCacheDuration(uuid); @@ -38,7 +38,7 @@ public long expireAfterRead(@NotNull UUID uuid, @NotNull UserReport userReport, userReportCache = Caffeine.newBuilder().expireAfter(userReportExpiry).build(); - Expiry> fishReportExpiry = new Expiry>() { + Expiry> fishReportExpiry = new Expiry<>() { @Override public long expireAfterCreate(@NotNull UUID uuid, @NotNull List fishReports, long l) { return getCacheDuration(uuid); diff --git a/even-more-fish-plugin/src/main/java/com/oheers/fish/database/Transaction.java b/even-more-fish-plugin/src/main/java/com/oheers/fish/database/Transaction.java index 28262c45..f0804128 100644 --- a/even-more-fish-plugin/src/main/java/com/oheers/fish/database/Transaction.java +++ b/even-more-fish-plugin/src/main/java/com/oheers/fish/database/Transaction.java @@ -2,27 +2,9 @@ import java.sql.Timestamp; -public class Transaction { - private final String id; //special class for this - private final int userId; - private final Timestamp timestamp; - - public Transaction(String id, int userId, Timestamp timestamp) { - this.id = id; - this.userId = userId; - this.timestamp = timestamp; - } - - public String getId() { - return id; - } - - public int getUserId() { - return userId; - } - - public Timestamp getTimestamp() { - return timestamp; - } +/** + * @param id special class for this + */ +public record Transaction(String id, int userId, Timestamp timestamp) { } diff --git a/even-more-fish-plugin/src/main/java/com/oheers/fish/database/connection/ConnectionFactory.java b/even-more-fish-plugin/src/main/java/com/oheers/fish/database/connection/ConnectionFactory.java index 6099846b..9969c240 100644 --- a/even-more-fish-plugin/src/main/java/com/oheers/fish/database/connection/ConnectionFactory.java +++ b/even-more-fish-plugin/src/main/java/com/oheers/fish/database/connection/ConnectionFactory.java @@ -1,7 +1,6 @@ package com.oheers.fish.database.connection; -import com.google.common.collect.ImmutableMap; import com.oheers.fish.config.MainConfig; import com.oheers.fish.database.DatabaseUtil; import com.zaxxer.hikari.HikariConfig; @@ -167,7 +166,7 @@ public Connection getConnection() throws SQLException { private FluentConfiguration getBaseFlywayConfiguration() { return Flyway.configure(getClass().getClassLoader()) .dataSource(dataSource) - .placeholders(ImmutableMap.of( + .placeholders(Map.of( "table.prefix", MainConfig.getInstance().getPrefix(), "auto.increment", MainConfig.getInstance().getDatabaseType().equalsIgnoreCase("mysql") ? "AUTO_INCREMENT" : "", "primary.key", MainConfig.getInstance().getDatabaseType().equalsIgnoreCase("mysql") ? "PRIMARY KEY (id)" : "PRIMARY KEY (id AUTOINCREMENT)", diff --git a/even-more-fish-plugin/src/main/java/com/oheers/fish/fishing/FishingProcessor.java b/even-more-fish-plugin/src/main/java/com/oheers/fish/fishing/FishingProcessor.java index cf574409..52509e29 100644 --- a/even-more-fish-plugin/src/main/java/com/oheers/fish/fishing/FishingProcessor.java +++ b/even-more-fish-plugin/src/main/java/com/oheers/fish/fishing/FishingProcessor.java @@ -351,21 +351,7 @@ public static Rarity randomWeightedRarity(Player fisher, double boostRate, Set fishList, double boostRate, List boostedFish) { - double totalWeight = 0; - - for (Fish fish : fishList) { - // when boostRate is -1, we need to guarantee a fish, so the fishList has already been moderated to only contain - // boosted fish. The other 2 check that the plugin wants the bait calculations too. - if (boostRate != -1 && boostedFish != null && boostedFish.contains(fish)) { - - if (fish.getWeight() == 0.0d) totalWeight += (1 * boostRate); - else - totalWeight += fish.getWeight() * boostRate; - } else { - if (fish.getWeight() == 0.0d) totalWeight += 1; - else totalWeight += fish.getWeight(); - } - } + final double totalWeight = getTotalWeight(fishList, boostRate, boostedFish); int idx = 0; for (double r = Math.random() * totalWeight; idx < fishList.size() - 1; ++idx) { @@ -390,6 +376,25 @@ private static Fish randomWeightedFish(List fishList, double boostRate, Li return fishList.get(idx); } + private static double getTotalWeight(List fishList, double boostRate, List boostedFish) { + double totalWeight = 0; + + for (Fish fish : fishList) { + // when boostRate is -1, we need to guarantee a fish, so the fishList has already been moderated to only contain + // boosted fish. The other 2 check that the plugin wants the bait calculations too. + if (boostRate != -1 && boostedFish != null && boostedFish.contains(fish)) { + + if (fish.getWeight() == 0.0d) totalWeight += (1 * boostRate); + else + totalWeight += fish.getWeight() * boostRate; + } else { + if (fish.getWeight() == 0.0d) totalWeight += 1; + else totalWeight += fish.getWeight(); + } + } + return totalWeight; + } + public static Fish getFish(Rarity r, Location l, Player p, double boostRate, List boostedFish, boolean doRequirementChecks) { if (r == null) return null; // will store all the fish that match the player's biome or don't discriminate biomes diff --git a/even-more-fish-plugin/src/main/java/com/oheers/fish/gui/SellGUI.java b/even-more-fish-plugin/src/main/java/com/oheers/fish/gui/SellGUI.java index 5b0a9969..1c4128d1 100644 --- a/even-more-fish-plugin/src/main/java/com/oheers/fish/gui/SellGUI.java +++ b/even-more-fish-plugin/src/main/java/com/oheers/fish/gui/SellGUI.java @@ -9,10 +9,8 @@ import com.oheers.fish.selling.SellHelper; import com.oheers.fish.selling.WorthNBT; import com.oheers.fish.utils.GUIUtils; -import de.themoep.inventorygui.DynamicGuiElement; import de.themoep.inventorygui.GuiStorageElement; import de.themoep.inventorygui.InventoryGui; -import de.themoep.inventorygui.StaticGuiElement; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; @@ -44,11 +42,7 @@ public SellGUI(@NotNull Player player, @NotNull SellState sellState, @Nullable I } else { section = GUIConfig.getInstance().getConfig().getConfigurationSection("sell-menu-confirm"); } - if (fishInventory == null) { - this.fishInventory = Bukkit.createInventory(null, 54); - } else { - this.fishInventory = fishInventory; - } + this.fishInventory = Objects.requireNonNullElseGet(fishInventory, () -> Bukkit.createInventory(null, 54)); gui = GUIUtils.createGUI(section); if (section == null) { EvenMoreFish.getInstance().getLogger().log(Level.SEVERE, "Could not find the config for the Sell Menu GUI!"); diff --git a/even-more-fish-plugin/src/main/java/com/oheers/fish/selling/SellHelper.java b/even-more-fish-plugin/src/main/java/com/oheers/fish/selling/SellHelper.java index 323dce9c..cbdacba8 100644 --- a/even-more-fish-plugin/src/main/java/com/oheers/fish/selling/SellHelper.java +++ b/even-more-fish-plugin/src/main/java/com/oheers/fish/selling/SellHelper.java @@ -37,15 +37,13 @@ public class SellHelper { private int fishCount; public static void sellInventoryGui(@NotNull InventoryGui gui, @NotNull HumanEntity humanEntity) { - if (!(humanEntity instanceof Player)) { + if (!(humanEntity instanceof Player player)) { return; } - Player player = (Player) humanEntity; gui.getElements().forEach(element -> { - if (!(element instanceof GuiStorageElement)) { + if (!(element instanceof GuiStorageElement storageElement)) { return; } - GuiStorageElement storageElement = (GuiStorageElement) element; new SellHelper(storageElement.getStorage(), player).sellFish(); }); } diff --git a/even-more-fish-plugin/src/main/java/com/oheers/fish/utils/GUIUtils.java b/even-more-fish-plugin/src/main/java/com/oheers/fish/utils/GUIUtils.java index 961e971e..c8e4aeb2 100644 --- a/even-more-fish-plugin/src/main/java/com/oheers/fish/utils/GUIUtils.java +++ b/even-more-fish-plugin/src/main/java/com/oheers/fish/utils/GUIUtils.java @@ -229,10 +229,10 @@ public static Map getActionMap(@Nullable EMFGUI gui) // The shop action should just open the shop menu newActionMap.put("open-shop", click -> { HumanEntity humanEntity = click.getWhoClicked(); - if (!(humanEntity instanceof Player)) { + + if (!(humanEntity instanceof Player player)) { return true; } - Player player = (Player) humanEntity; new SellGUI(player, SellGUI.SellState.NORMAL, null).open(); return true; }); @@ -242,12 +242,10 @@ public static Map getActionMap(@Nullable EMFGUI gui) }); newActionMap.put("sell-inventory", click -> { HumanEntity humanEntity = click.getWhoClicked(); - if (!(humanEntity instanceof Player)) { + if (!(humanEntity instanceof Player player)) { return true; } - Player player = (Player) humanEntity; - if (gui instanceof SellGUI) { - SellGUI sellGUI = (SellGUI) gui; + if (gui instanceof SellGUI sellGUI) { new SellGUI(player, SellGUI.SellState.CONFIRM, sellGUI.getFishInventory()).open(); return true; } @@ -257,9 +255,7 @@ public static Map getActionMap(@Nullable EMFGUI gui) }); newActionMap.put("sell-shop", click -> { HumanEntity humanEntity = click.getWhoClicked(); - if (gui instanceof SellGUI && humanEntity instanceof Player) { - SellGUI sellGUI = (SellGUI) gui; - Player player = (Player) humanEntity; + if (gui instanceof SellGUI sellGUI && humanEntity instanceof Player player) { new SellGUI(player, SellGUI.SellState.CONFIRM, sellGUI.getFishInventory()).open(); return true; } @@ -269,10 +265,9 @@ public static Map getActionMap(@Nullable EMFGUI gui) }); newActionMap.put("sell-inventory-confirm", click -> { HumanEntity humanEntity = click.getWhoClicked(); - if (!(humanEntity instanceof Player)) { + if (!(humanEntity instanceof Player player)) { return true; } - Player player = (Player) humanEntity; new SellHelper(click.getWhoClicked().getInventory(), player).sellFish(); click.getGui().close(); return true; diff --git a/even-more-fish-plugin/src/main/java/com/oheers/fish/utils/ItemFactory.java b/even-more-fish-plugin/src/main/java/com/oheers/fish/utils/ItemFactory.java index 06b28c32..edb7e884 100644 --- a/even-more-fish-plugin/src/main/java/com/oheers/fish/utils/ItemFactory.java +++ b/even-more-fish-plugin/src/main/java/com/oheers/fish/utils/ItemFactory.java @@ -20,7 +20,6 @@ import org.bukkit.inventory.meta.*; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; -import org.checkerframework.checker.units.qual.N; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -517,8 +516,7 @@ public void applyDyeColour() { public void applyDamage() { ItemMeta meta = product.getItemMeta(); - if (meta instanceof Damageable) { - Damageable nonDamaged = (Damageable) meta; + if (meta instanceof Damageable nonDamaged) { int predefinedDamage = this.configurationFile.getInt(configLocation + "durability"); if (predefinedDamage >= 0 && predefinedDamage <= 100) { @@ -599,14 +597,13 @@ private void applyPotionMeta() { String potionSettings = this.configurationFile.getString(configLocation + "item.potion"); if (potionSettings == null) return; - if (!(product.getItemMeta() instanceof PotionMeta)) return; + if (!(product.getItemMeta() instanceof PotionMeta meta)) return; String[] split = potionSettings.split(":"); if (split.length != 3) { EvenMoreFish.getInstance().getLogger().severe(configLocation + "item.potion: is formatted incorrectly in the fish.yml file. Use \"potion:duration:amplifier\"."); } - PotionMeta meta = ((PotionMeta) product.getItemMeta()); try { meta.addCustomEffect(new PotionEffect(Objects.requireNonNull(PotionEffectType.getByName(split[0])), Integer.parseInt(split[1]) * 20, Integer.parseInt(split[2]) - 1, false), true); } catch (NumberFormatException exception) { diff --git a/even-more-fish-plugin/src/main/java/com/oheers/fish/utils/nbt/NbtUtils.java b/even-more-fish-plugin/src/main/java/com/oheers/fish/utils/nbt/NbtUtils.java index 9da703c4..2febcaea 100644 --- a/even-more-fish-plugin/src/main/java/com/oheers/fish/utils/nbt/NbtUtils.java +++ b/even-more-fish-plugin/src/main/java/com/oheers/fish/utils/nbt/NbtUtils.java @@ -34,43 +34,36 @@ public static boolean hasKey(final BlockState skull, final String key) { } private static boolean hasKey(final @NotNull NbtVersion nbtVersion, final NamespacedKey namespacedKey, final ReadableNBT nbt) { - switch (nbtVersion) { - case NBTAPI: - return nbt.hasTag(namespacedKey.toString()); - case LEGACY: + return switch (nbtVersion) { + case NBTAPI -> nbt.hasTag(namespacedKey.toString()); + case LEGACY -> { if (nbt.hasTag(NbtKeys.PUBLIC_BUKKIT_VALUES)) { - return nbt.getCompound(NbtKeys.PUBLIC_BUKKIT_VALUES) + yield nbt.getCompound(NbtKeys.PUBLIC_BUKKIT_VALUES) .hasTag(namespacedKey.toString()); } - return false; - case COMPAT: - return nbt.getCompound(namespacedKey.getNamespace()).hasTag(namespacedKey.getKey()); - default: - return false; - } + yield false; + } + case COMPAT -> nbt.getCompound(namespacedKey.getNamespace()).hasTag(namespacedKey.getKey()); + }; } private static @Nullable String getNbtString(NamespacedKey namespacedKey, @NotNull NbtVersion nbtVersion, ReadableItemNBT nbt) { - switch (nbtVersion) { - case NBTAPI: { + return switch (nbtVersion) { + case NBTAPI -> { if (nbt.hasTag(namespacedKey.toString())) { - return nbt.getString(namespacedKey.toString()); + yield nbt.getString(namespacedKey.toString()); } - return null; - } - case COMPAT: { - return nbt.getCompound(namespacedKey.getNamespace()).getString(namespacedKey.getKey()); + yield null; } - case LEGACY: { + case COMPAT -> nbt.getCompound(namespacedKey.getNamespace()).getString(namespacedKey.getKey()); + case LEGACY -> { if (nbt.hasTag(NbtKeys.PUBLIC_BUKKIT_VALUES)) { - return nbt.getCompound(NbtKeys.PUBLIC_BUKKIT_VALUES).getString(namespacedKey.toString()); + yield nbt.getCompound(NbtKeys.PUBLIC_BUKKIT_VALUES).getString(namespacedKey.toString()); } - return null; + yield null; } - default: - return null; - } + }; } @@ -92,25 +85,19 @@ public static String[] getBaitArray(final ItemStack item) { public static @Nullable Float getFloat(final ItemStack item, final String key) { final NbtVersion nbtVersion = NbtVersion.getVersion(item); final NamespacedKey namespacedKey = NbtUtils.getNamespacedKey(key); - return NBT.get(item, nbt -> { - switch (nbtVersion) { - case NBTAPI: { - if (nbt.hasTag(namespacedKey.toString())) { - return nbt.getFloat(namespacedKey.toString()); - } - return null; - } - case COMPAT: { - return nbt.getCompound(namespacedKey.getNamespace()).getFloat(namespacedKey.getKey()); + return NBT.get(item, nbt -> switch (nbtVersion) { + case NBTAPI -> { + if (nbt.hasTag(namespacedKey.toString())) { + yield nbt.getFloat(namespacedKey.toString()); } - case LEGACY: { - if (nbt.hasTag(NbtKeys.PUBLIC_BUKKIT_VALUES)) { - return nbt.getCompound(NbtKeys.PUBLIC_BUKKIT_VALUES).getFloat(namespacedKey.toString()); - } - return null; + yield null; + } + case COMPAT -> nbt.getCompound(namespacedKey.getNamespace()).getFloat(namespacedKey.getKey()); + case LEGACY -> { + if (nbt.hasTag(NbtKeys.PUBLIC_BUKKIT_VALUES)) { + yield nbt.getCompound(NbtKeys.PUBLIC_BUKKIT_VALUES).getFloat(namespacedKey.toString()); } - default: - return null; + yield null; } }); } @@ -118,25 +105,19 @@ public static String[] getBaitArray(final ItemStack item) { public static @Nullable Integer getInteger(final ItemStack item, final String key) { final NbtVersion nbtVersion = NbtVersion.getVersion(item); final NamespacedKey namespacedKey = NbtUtils.getNamespacedKey(key); - return NBT.get(item, nbt -> { - switch (nbtVersion) { - case NBTAPI: { - if (nbt.hasTag(namespacedKey.toString())) { - return nbt.getInteger(namespacedKey.toString()); - } - return null; - } - case COMPAT: { - return nbt.getCompound(namespacedKey.getNamespace()).getInteger(namespacedKey.getKey()); + return NBT.get(item, nbt -> switch (nbtVersion) { + case NBTAPI -> { + if (nbt.hasTag(namespacedKey.toString())) { + yield nbt.getInteger(namespacedKey.toString()); } - case LEGACY: { - if (nbt.hasTag(NbtKeys.PUBLIC_BUKKIT_VALUES)) { - return nbt.getCompound(NbtKeys.PUBLIC_BUKKIT_VALUES).getInteger(namespacedKey.toString()); - } - return null; + yield null; + } + case COMPAT -> nbt.getCompound(namespacedKey.getNamespace()).getInteger(namespacedKey.getKey()); + case LEGACY -> { + if (nbt.hasTag(NbtKeys.PUBLIC_BUKKIT_VALUES)) { + yield nbt.getCompound(NbtKeys.PUBLIC_BUKKIT_VALUES).getInteger(namespacedKey.toString()); } - default: - return null; + yield null; } }); } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 2d511d6c..e1ab7f4b 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip networkTimeout=10000 zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/settings.gradle.kts b/settings.gradle.kts index 8efd46e5..c9a367e7 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -11,44 +11,54 @@ dependencyResolutionManagement { create("libs") { library("spigot-api", "org.spigotmc:spigot-api:1.16.5-R0.1-SNAPSHOT") library("vault-api", "com.github.MilkBowl:VaultAPI:1.7.1") - library("placeholder-api", "me.clip:placeholderapi:2.11.3") + library("placeholder-api", "me.clip:placeholderapi:2.11.6") library("authlib", "com.mojang:authlib:1.5.21") library("bstats", "org.bstats:bstats-bukkit:3.0.2") + version("worldguard", "7.0.5")//We must use 7.0.5 until we upgrade to java 17 library("worldguard-core", "com.sk89q.worldguard","worldguard-core").versionRef("worldguard") library("worldguard-bukkit", "com.sk89q.worldguard","worldguard-bukkit").versionRef("worldguard") + bundle("worldguard", listOf("worldguard-core", "worldguard-bukkit")) + version("worldedit", "7.2.15") library("worldedit-core", "com.sk89q.worldedit","worldedit-core").versionRef("worldedit") library("worldedit-bukkit", "com.sk89q.worldedit","worldedit-bukkit").versionRef("worldedit") + bundle("worldedit", listOf("worldedit-core", "worldedit-bukkit")) + version("redprotect", "7.7.3") library("redprotect-core", "br.net.fabiozumbi12.RedProtect","RedProtect-Core").versionRef("redprotect") library("redprotect-spigot", "br.net.fabiozumbi12.RedProtect","RedProtect-Spigot-1.13").versionRef("redprotect") + bundle("redprotect", listOf("redprotect-core", "redprotect-spigot")) + library("mcmmo", "com.gmail.nossr50.mcMMO:mcMMO:2.1.196") library("aurelium-skills", "com.github.Archy-X:AureliumSkills:Beta1.2.8") library("aura-skills", "dev.aurelium:auraskills-api-bukkit:2.0.7") library("headdatabase-api", "com.arcaniax:HeadDatabase-API:1.3.1") - library("griefprevention", "com.github.TechFortress:GriefPrevention:16.17.1")//We must use 16.17.1 until we upgrade to java 17 - library("caffeine", "com.github.ben-manes.caffeine:caffeine:2.9.3")//We must use 2.9.3 until we upgrade to java 17 + library("griefprevention", "com.github.TechFortress:GriefPrevention:16.17.1") + library("itemsadder-api", "com.github.LoneDev6:API-ItemsAdder:3.6.1") library("nbt-api", "de.tr7zw:item-nbt-api:2.13.1") - library("denizen-api", "com.denizenscript:denizen:1.3.0-SNAPSHOT") // Java 17 addon + library("denizen-api", "com.denizenscript:denizen:1.3.0-SNAPSHOT") library("oraxen", "com.github.oraxen:oraxen:1.171.0") library("ecoitems-api", "com.willfp:EcoItems:5.6.1") library("ecoitems-libreforge", "com.willfp:libreforge:4.21.1") library("ecoitems-eco", "com.willfp:eco:6.65.1") + bundle("ecoitems", listOf("ecoitems-api", "ecoitems-libreforge", "ecoitems-eco")) - library("commons-lang3", "org.apache.commons:commons-lang3:3.13.0") - library("commons-codec", "commons-codec:commons-codec:1.16.0") + library("commons-lang3", "org.apache.commons:commons-lang3:3.14.0") + library("commons-codec", "commons-codec:commons-codec:1.17.0") + library("caffeine", "com.github.ben-manes.caffeine:caffeine:3.1.8") library("annotations", "org.jetbrains:annotations:24.0.1") - version("flyway", "9.19.4") + version("flyway", "10.15.0") library("flyway-core", "org.flywaydb","flyway-core").versionRef("flyway") library("flyway-mysql", "org.flywaydb","flyway-mysql").versionRef("flyway") + bundle("flyway", listOf("flyway-core", "flyway-mysql")) library("friendlyid", "com.devskiller.friendly-id:friendly-id:1.1.0") - library("hikaricp", "com.zaxxer:HikariCP:4.0.3") //We must use 4.0.3 until we upgrade to java 17 + library("hikaricp", "com.zaxxer:HikariCP:5.1.0") library("json-simple", "com.googlecode.json-simple:json-simple:1.1.1") library("universalscheduler", "com.github.Anon8281:UniversalScheduler:0.1.6") @@ -59,9 +69,14 @@ dependencyResolutionManagement { library("acf", "co.aikar:acf-paper:0.5.1-SNAPSHOT") library("inventorygui", "de.themoep:inventorygui:1.6.2-SNAPSHOT") - library("adventure-api", "net.kyori:adventure-api:4.17.0") - library("adventure-minimessage", "net.kyori:adventure-text-minimessage:4.17.0") - library("adventure-legacy", "net.kyori:adventure-text-serializer-legacy:4.17.0") + plugin("shadow", "io.github.goooler.shadow").version("8.1.7") + plugin("bukkit-yml", "net.minecrell.plugin-yml.bukkit").version("0.6.0") + + version("adventure", "4.17.0") + library("adventure-api", "net.kyori","adventure-api").versionRef("adventure") + library("adventure-minimessage", "net.kyori","adventure-text-minimessage").versionRef("adventure") + library("adventure-legacy", "net.kyori","adventure-text-serializer-legacy").versionRef("adventure") + bundle("adventure", listOf("adventure-api", "adventure-minimessage", "adventure-legacy")) plugin("grgit", "org.ajoberstar.grgit").version("5.2.2")