diff --git a/build.gradle.kts b/build.gradle.kts index d0d70116..b4219b74 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -7,7 +7,7 @@ plugins { allprojects { - version = "2.0.4" + version = "2.0.5" apply() apply(plugin = "java") diff --git a/plugin/src/main/java/net/momirealms/customfishing/adventure/component/Languages.java b/plugin/src/main/java/net/momirealms/customfishing/adventure/component/Languages.java index 35c93436..ed3399d5 100644 --- a/plugin/src/main/java/net/momirealms/customfishing/adventure/component/Languages.java +++ b/plugin/src/main/java/net/momirealms/customfishing/adventure/component/Languages.java @@ -1,3 +1,9 @@ +/* + * This file is part of InvUI, licensed under the MIT License. + * + * Copyright (c) 2021 NichtStudioCode + */ + package net.momirealms.customfishing.adventure.component; import com.google.gson.stream.JsonReader; diff --git a/plugin/src/main/java/net/momirealms/customfishing/adventure/component/ShadedAdventureComponentUtils.java b/plugin/src/main/java/net/momirealms/customfishing/adventure/component/ShadedAdventureComponentUtils.java index 12bc0c1e..9709b287 100644 --- a/plugin/src/main/java/net/momirealms/customfishing/adventure/component/ShadedAdventureComponentUtils.java +++ b/plugin/src/main/java/net/momirealms/customfishing/adventure/component/ShadedAdventureComponentUtils.java @@ -1,3 +1,9 @@ +/* + * This file is part of InvUI, licensed under the MIT License. + * + * Copyright (c) 2021 NichtStudioCode + */ + package net.momirealms.customfishing.adventure.component; import net.kyori.adventure.text.Component; diff --git a/plugin/src/main/java/net/momirealms/customfishing/adventure/component/ShadedAdventureComponentWrapper.java b/plugin/src/main/java/net/momirealms/customfishing/adventure/component/ShadedAdventureComponentWrapper.java index b3e4dd68..46e56122 100644 --- a/plugin/src/main/java/net/momirealms/customfishing/adventure/component/ShadedAdventureComponentWrapper.java +++ b/plugin/src/main/java/net/momirealms/customfishing/adventure/component/ShadedAdventureComponentWrapper.java @@ -1,3 +1,9 @@ +/* + * This file is part of InvUI, licensed under the MIT License. + * + * Copyright (c) 2021 NichtStudioCode + */ + package net.momirealms.customfishing.adventure.component; import net.kyori.adventure.text.Component; diff --git a/plugin/src/main/java/net/momirealms/customfishing/adventure/component/ShadedAdventureShadedComponentLocalizer.java b/plugin/src/main/java/net/momirealms/customfishing/adventure/component/ShadedAdventureShadedComponentLocalizer.java index 63c13aae..5fcebf65 100644 --- a/plugin/src/main/java/net/momirealms/customfishing/adventure/component/ShadedAdventureShadedComponentLocalizer.java +++ b/plugin/src/main/java/net/momirealms/customfishing/adventure/component/ShadedAdventureShadedComponentLocalizer.java @@ -1,3 +1,9 @@ +/* + * This file is part of InvUI, licensed under the MIT License. + * + * Copyright (c) 2021 NichtStudioCode + */ + package net.momirealms.customfishing.adventure.component; import net.kyori.adventure.text.*; diff --git a/plugin/src/main/java/net/momirealms/customfishing/adventure/component/ShadedComponentLocalizer.java b/plugin/src/main/java/net/momirealms/customfishing/adventure/component/ShadedComponentLocalizer.java index d9ad9500..418c7d94 100644 --- a/plugin/src/main/java/net/momirealms/customfishing/adventure/component/ShadedComponentLocalizer.java +++ b/plugin/src/main/java/net/momirealms/customfishing/adventure/component/ShadedComponentLocalizer.java @@ -1,3 +1,9 @@ +/* + * This file is part of InvUI, licensed under the MIT License. + * + * Copyright (c) 2021 NichtStudioCode + */ + package net.momirealms.customfishing.adventure.component; import java.util.ArrayList; diff --git a/plugin/src/main/java/net/momirealms/customfishing/command/sub/CompetitionCommand.java b/plugin/src/main/java/net/momirealms/customfishing/command/sub/CompetitionCommand.java index 42b3e887..d5b63d10 100644 --- a/plugin/src/main/java/net/momirealms/customfishing/command/sub/CompetitionCommand.java +++ b/plugin/src/main/java/net/momirealms/customfishing/command/sub/CompetitionCommand.java @@ -35,7 +35,6 @@ public class CompetitionCommand { public CommandAPICommand getCompetitionCommand() { return new CommandAPICommand("competition") - .withPermission("customfishing.command.competition") .withSubcommands( getCompetitionStartCommand(), getCompetitionEndCommand(), diff --git a/plugin/src/main/java/net/momirealms/customfishing/command/sub/ItemCommand.java b/plugin/src/main/java/net/momirealms/customfishing/command/sub/ItemCommand.java index 1dbc6c45..27583bd3 100644 --- a/plugin/src/main/java/net/momirealms/customfishing/command/sub/ItemCommand.java +++ b/plugin/src/main/java/net/momirealms/customfishing/command/sub/ItemCommand.java @@ -51,7 +51,6 @@ public class ItemCommand { public CommandAPICommand getItemCommand() { return new CommandAPICommand("items") - .withPermission("customfishing.command.items") .withSubcommands( getSubCommand("item"), getSubCommand("util"), diff --git a/plugin/src/main/java/net/momirealms/customfishing/mechanic/fishing/FishingManagerImpl.java b/plugin/src/main/java/net/momirealms/customfishing/mechanic/fishing/FishingManagerImpl.java index fa372768..1edef21f 100644 --- a/plugin/src/main/java/net/momirealms/customfishing/mechanic/fishing/FishingManagerImpl.java +++ b/plugin/src/main/java/net/momirealms/customfishing/mechanic/fishing/FishingManagerImpl.java @@ -678,7 +678,7 @@ public class FishingManagerImpl implements Listener, FishingManager { private void doSuccessActions(Loot loot, Effect effect, FishingPreparation fishingPreparation, Player player) { FishingCompetition competition = plugin.getCompetitionManager().getOnGoingCompetition(); if (competition != null) { - String scoreStr = fishingPreparation.getArg("{SCORE}"); + String scoreStr = fishingPreparation.getArg("{CUSTOM_SCORE}"); if (scoreStr != null) { competition.refreshData(player, Double.parseDouble(scoreStr)); } else { @@ -686,15 +686,18 @@ public class FishingManagerImpl implements Listener, FishingManager { case CATCH_AMOUNT -> { fishingPreparation.insertArg("{score}", "1.00"); competition.refreshData(player, 1); + fishingPreparation.insertArg("{SCORE}", "1"); } case MAX_SIZE, TOTAL_SIZE -> { - String size = fishingPreparation.getArg("{size}"); + String size = fishingPreparation.getArg("{SIZE}"); if (size != null) { double score = Double.parseDouble(size); fishingPreparation.insertArg("{score}", String.format("%.2f", score)); competition.refreshData(player, score); + fishingPreparation.insertArg("{SCORE}", size); } else { - fishingPreparation.insertArg("{score}", "0.00"); + fishingPreparation.insertArg("{score}", String.format("%.2f", 0.00)); + fishingPreparation.insertArg("{SCORE}", "0"); } } case TOTAL_SCORE -> { @@ -703,8 +706,10 @@ public class FishingManagerImpl implements Listener, FishingManager { double finalScore = score * effect.getScoreMultiplier() + effect.getScore(); fishingPreparation.insertArg("{score}", String.format("%.2f", finalScore)); competition.refreshData(player, finalScore); + fishingPreparation.insertArg("{SCORE}", String.valueOf(finalScore)); } else { fishingPreparation.insertArg("{score}", "0.00"); + fishingPreparation.insertArg("{SCORE}", "0"); } } } diff --git a/plugin/src/main/java/net/momirealms/customfishing/mechanic/item/ItemManagerImpl.java b/plugin/src/main/java/net/momirealms/customfishing/mechanic/item/ItemManagerImpl.java index 5732a947..fef9eebe 100644 --- a/plugin/src/main/java/net/momirealms/customfishing/mechanic/item/ItemManagerImpl.java +++ b/plugin/src/main/java/net/momirealms/customfishing/mechanic/item/ItemManagerImpl.java @@ -122,6 +122,7 @@ public class ItemManagerImpl implements ItemManager, Listener { } public void disable() { + HandlerList.unregisterAll(this); this.buildableItemMap.clear(); this.itemLibraryMap.clear(); } @@ -587,14 +588,14 @@ public class ItemManagerImpl implements ItemManager, Listener { @Override public ItemBuilder nbt(Map nbt) { if (nbt.size() == 0) return this; - editors.put("nbt", (player, nbtItem, placeholders) -> NBTUtils.setTagsFromBukkitYAML(nbtItem, nbt)); + editors.put("nbt", (player, nbtItem, placeholders) -> NBTUtils.setTagsFromBukkitYAML(player, placeholders, nbtItem, nbt)); return this; } @Override public ItemBuilder nbt(ConfigurationSection section) { if (section == null) return this; - editors.put("nbt", (player, nbtItem, placeholders) -> NBTUtils.setTagsFromBukkitYAML(nbtItem, section.getValues(false))); + editors.put("nbt", (player, nbtItem, placeholders) -> NBTUtils.setTagsFromBukkitYAML(player, placeholders, nbtItem, section.getValues(false))); return this; } diff --git a/plugin/src/main/java/net/momirealms/customfishing/util/NBTUtils.java b/plugin/src/main/java/net/momirealms/customfishing/util/NBTUtils.java index d98c8a82..f448d056 100644 --- a/plugin/src/main/java/net/momirealms/customfishing/util/NBTUtils.java +++ b/plugin/src/main/java/net/momirealms/customfishing/util/NBTUtils.java @@ -20,7 +20,10 @@ package net.momirealms.customfishing.util; import de.tr7zw.changeme.nbtapi.NBTCompound; import de.tr7zw.changeme.nbtapi.NBTListCompound; import de.tr7zw.changeme.nbtapi.iface.ReadWriteNBT; +import net.momirealms.customfishing.api.util.LogUtils; +import net.momirealms.customfishing.compatibility.papi.PlaceholderManagerImpl; import org.bukkit.configuration.MemorySection; +import org.bukkit.entity.Player; import java.util.*; @@ -51,7 +54,7 @@ public class NBTUtils { * @param map The source map from Bukkit YAML */ @SuppressWarnings("unchecked") - public static void setTagsFromBukkitYAML(NBTCompound nbtCompound, Map map) { + public static void setTagsFromBukkitYAML(Player player, Map placeholders, NBTCompound nbtCompound, Map map) { Deque stack = new ArrayDeque<>(); stack.push(new StackElement(map, nbtCompound)); @@ -70,31 +73,31 @@ public class NBTUtils { } else if (value instanceof List list) { for (Object o : list) { if (o instanceof String stringValue) { - setListValue(key, stringValue, currentNbtCompound); + setListValue(player, placeholders, key, stringValue, currentNbtCompound); } else if (o instanceof Map mapValue) { NBTListCompound nbtListCompound = currentNbtCompound.getCompoundList(key).addCompound(); stack.push(new StackElement((Map) mapValue, nbtListCompound)); } } } else if (value instanceof String stringValue) { - setSingleValue(key, stringValue, currentNbtCompound); + setSingleValue(player, placeholders, key, stringValue, currentNbtCompound); } } } } // Private helper method - private static void setListValue(String key, String value, NBTCompound nbtCompound) { + private static void setListValue(Player player, Map placeholders, String key, String value, NBTCompound nbtCompound) { String[] parts = getTypeAndData(value); String type = parts[0]; - String data = parts[1]; + String data = getParsedData(player, placeholders, 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 "Double" -> nbtCompound.getDoubleList(key).add(Double.parseDouble(data)); + case "Long" -> nbtCompound.getLongList(key).add(Long.parseLong(data)); + case "Float" -> nbtCompound.getFloatList(key).add(Float.parseFloat(data)); + case "Int" -> nbtCompound.getIntegerList(key).add(Integer.parseInt(data)); case "IntArray" -> { String[] split = data.replace("[", "").replace("]", "").replaceAll("\\s", "").split(","); int[] array = Arrays.stream(split).mapToInt(Integer::parseInt).toArray(); @@ -105,20 +108,20 @@ public class NBTUtils { } // Private helper method - private static void setSingleValue(String key, String value, NBTCompound nbtCompound) { + private static void setSingleValue(Player player, Map placeholders, String key, String value, NBTCompound nbtCompound) { String[] parts = getTypeAndData(value); String type = parts[0]; - String data = parts[1]; + String data = getParsedData(player, placeholders, parts[1]); switch (type) { - case "Int" -> nbtCompound.setInteger(key, Integer.valueOf(data)); + case "Int" -> nbtCompound.setInteger(key, Integer.parseInt(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 "Long" -> nbtCompound.setLong(key, Long.parseLong(data)); + case "Float" -> nbtCompound.setFloat(key, Float.parseFloat(data)); + case "Double" -> nbtCompound.setDouble(key, Double.parseDouble(data)); + case "Short" -> nbtCompound.setShort(key, Short.parseShort(data)); + case "Boolean" -> nbtCompound.setBoolean(key, Boolean.parseBoolean(data)); case "UUID" -> nbtCompound.setUUID(key, UUID.nameUUIDFromBytes(data.getBytes())); - case "Byte" -> nbtCompound.setByte(key, Byte.valueOf(data)); + case "Byte" -> nbtCompound.setByte(key, Byte.parseByte(data)); case "ByteArray" -> { String[] split = splitValue(value); byte[] bytes = new byte[split.length]; @@ -136,6 +139,23 @@ public class NBTUtils { } } + public static String getParsedData(Player player, Map placeholders, String data) { + if (data.length() >= 3) + switch (data.substring(0,3)) { + case "-P:" -> data = PlaceholderManagerImpl.getInstance().parse(player, data.substring(3), placeholders); + case "-E:" -> { + data = PlaceholderManagerImpl.getInstance().parse(player, data.substring(3), placeholders); + double value = ConfigUtils.getExpressionValue(player, data, new HashMap<>()); + if (value % 1 == 0) { + data = Long.toString((long) value); + } else { + data = Double.toString(value); + } + } + } + return data; + } + /** * Converts an NBT compound to a map of key-value pairs. * diff --git a/plugin/src/main/resources/config.yml b/plugin/src/main/resources/config.yml index 98a6bd3b..8478bf7f 100644 --- a/plugin/src/main/resources/config.yml +++ b/plugin/src/main/resources/config.yml @@ -130,7 +130,7 @@ mechanics: # Fishing wait time # This section would take effect if you set "override-vanilla" to true # That also means vanilla mechanics for example lure enchantment - # would not longer take effect, so you have to configurate its effect + # would no longer take effect, so you have to configurate its effect # in enchantment effects. fishing-wait-time: # override vanilla mechanic