diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index a50cacd..8c4a93c 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -26,7 +26,7 @@ jobs: contents: write env: - MODRINTH_VERSIONS: '["1.18.x", "1.19.x", "1.20.x", "1.21.x", "26.1.x", "26.2.x"]' + MODRINTH_VERSIONS: '["1.18.x", "1.19.x", "1.20.x", "1.21.x", "26.1.x"]' MODRINTH_PLATFORMS: '["spigot", "paper", "purpur", "folia"]' steps: @@ -157,7 +157,7 @@ jobs: webhook-url: ${{ secrets.RELEASE_WEBHOOK_URL }} content: | ${{ github.event.release.prerelease == false && '<@&1338546156325568642>' || '<@&1352296092989001768>' }} - # New ${{ github.event.release.prerelease && 'beta ' || '' }}version of custom anvil ! <:CustomAnvil:1262550667986342001>([Modrinth](https://modrinth.com/plugin/customanvil), [Hangar](https://hangar.papermc.io/alexcrea/CustomAnvil) and [GitHub](${{ github.event.release.html_url }}) links) + # New ${{ github.event.release.prerelease && 'beta' || '' }} version of custom anvil ! <:CustomAnvil:1262550667986342001>([Modrinth](https://modrinth.com/plugin/customanvil), [Hangar](https://hangar.papermc.io/alexcrea/CustomAnvil) and [GitHub](${{ github.event.release.html_url }}) links) -# note: automated release. spigot is not uploaded yet. ${{ github.event.release.body }} diff --git a/COMPATIBILITY.md b/COMPATIBILITY.md index 9d37521..66ac561 100644 --- a/COMPATIBILITY.md +++ b/COMPATIBILITY.md @@ -6,55 +6,54 @@ This is cannot be fixed on geyser or my side. Here is various plugins that had issues with CustomAnvil where efforts was made for compatibility and should be working right: -some if not all of them are cool ! I recommend checking them out ! +some of them are cool I recommend checking them out ! ## Supported By CustomAnvil These plugins have compatibility handled by custom anvil. seek help on custom anvil and do not bother these developers #### Enchantment Plugins -- [ExcellentEnchants](https://www.spigotmc.org/resources/excellentenchants-%E2%AD%90-75-vanilla-like-enchantments.61693/) by NightExpress: - Use ExcellentEnchants item type \ - Also use ExcellentEnchant max enchant limit +- [ExcellentEnchants](https://www.spigotmc.org/resources/excellentenchants-%E2%AD%90-75-vanilla-like-enchantments.61693/): + Use ExcellentEnchants item type -- [EcoEnchant](https://www.spigotmc.org/resources/ecoenchants-%E2%AD%95-250-enchantments-%E2%9C%85-create-custom-enchants-%E2%9C%A8-essentials-cmi-support.79573/) by Auxilor: +- [EcoEnchant](https://www.spigotmc.org/resources/ecoenchants-%E2%AD%95-250-enchantments-%E2%9C%85-create-custom-enchants-%E2%9C%A8-essentials-cmi-support.79573/): Need to use /anvilconfigreload or a server restart to add newly added enchantment. Use EcoEnchant restriction system but new restriction can be added in custom anvil -- [Enchantment²](https://www.spigotmc.org/resources/enchants-squared-the-enchantsplus-rewrite-custom-enchantments-that-act-like-vanilla-ones.86747/) by Athlaeos: +- [Enchantment²](https://www.spigotmc.org/resources/enchants-squared-the-enchantsplus-rewrite-custom-enchantments-that-act-like-vanilla-ones.86747/): Support by Custom Anvil but still experimental. Automatic configuration. Plugin is not actively developed anymore -- [SuperEnchants](https://modrinth.com/plugin/superenchants) by Aznos: +- [SuperEnchants](https://modrinth.com/plugin/superenchants) Use SuperEnchant restrictions system but new restriction can be added in custom anvil #### Custom Items Plugins Custom Items support is considered unstable. If you find issue please report it ! -- [EcoItem](https://www.spigotmc.org/resources/30-sale%E2%8F%B3-ecoitems-%E2%AD%95-create-custom-items-%E2%9C%85-weapons-armors-tools-charms-%E2%9C%A8-item-levels-rarities.94601/) by Exanthiax: +- [EcoItem](https://www.spigotmc.org/resources/30-sale%E2%8F%B3-ecoitems-%E2%AD%95-create-custom-items-%E2%9C%85-weapons-armors-tools-charms-%E2%9C%A8-item-levels-rarities.94601/) May have some issue. but should partially work I hope -- [ItemAdder](https://www.spigotmc.org/resources/%E2%9C%A8itemsadder%E2%AD%90emotes-mobs-items-armors-hud-gui-emojis-blocks-wings-hats-liquids.73355/) by LoneDev: +- [ItemAdder](https://www.spigotmc.org/resources/%E2%9C%A8itemsadder%E2%AD%90emotes-mobs-items-armors-hud-gui-emojis-blocks-wings-hats-liquids.73355/) Need to fix unit item not working completly correctly as in can't have twice same base item #### Anvil Mechanics Plugins -- [Disenchantment](https://www.spigotmc.org/resources/disenchantment-1-21-1-1-20-6-new-book-splitting-mechanics.110741/) by H7KZ +- [Disenchantment](https://www.spigotmc.org/resources/disenchantment-1-21-1-1-20-6-new-book-splitting-mechanics.110741/) Partially use Custom Anvil maximum XP settings (>= 6.1.5) -- [HavenBags](https://www.spigotmc.org/resources/havenbags-shulker-like-player-bound-bags-1-17-1-21-4.110420/) by hyperdefined +- [HavenBags](https://www.spigotmc.org/resources/havenbags-shulker-like-player-bound-bags-1-17-1-21-4.110420/) For bag upgrade and skin via anvil. (version >= 1.31.0) -- [AxPlayerWarp](https://modrinth.com/project/QDJHDKvi) by ArtillexStudios +- [AxPlayerWarp](https://modrinth.com/project/QDJHDKvi) For its anvil inventory usage -- [ToolsStats](https://modrinth.com/project/oBZj9E15) by Valorless +- [ToolsStats](https://modrinth.com/project/oBZj9E15) For token application using anvil ### Known Partially Incompatible -- [UberEnchant](https://modrinth.com/plugin/uberenchant) by coltonj96 +- [UberEnchant](https://modrinth.com/plugin/uberenchant) Anvil handling as they are doing something similar to CustomAnvil. -It is by no mean there faults and I recommend checking them out especially if custom anvil do not work for your use case ! +It is by no mean there faults and I recomend checking them out -- [AdvencedEnchantments](https://ae.advancedplugins.net/) by Advanced Plugins +- [AdvencedEnchantments](https://ae.advancedplugins.net/) Paid plugin I do not own as I did not get commissioned for support. may be able to use api but cannot test on my side diff --git a/CREDITS.md b/CREDITS.md index 56409f5..528ad15 100644 --- a/CREDITS.md +++ b/CREDITS.md @@ -5,7 +5,7 @@ Thanks for all the contributors of bukkit, spigot, the paper team and the advent Thanks JetBrain for making IntelliJ ### Dependencies -These dependencies (or a modified version of) are used by custom anvil +Here dependencies are used by custom anvil - [IF](https://github.com/stefvanschie/IF) an inventory framework by stefvanschie - [Mockbukkit](https://github.com/MockBukkit/MockBukkit) for unit testing - [CentralPortalPlus](https://github.com/lalakii/central-portal-plus) by lalakii @@ -17,18 +17,23 @@ These dependencies (or a modified version of) are used by custom anvil - [ModrinthUpdateChecker](https://github.com/Clickism/ModrinthUpdateChecker) by Clickism and thanks to the modrinth team ### Compatibility -Thanks to all the cool creator making the minecraft plugin's ecosystem works ! \ -See [Compatibility list](https://github.com/alexcrea/CustomAnvil/blob/v1.x.x/COMPATIBILITY.md) for details - -but especially, Big Thanks for H7KZ maker of [Disenchantment](https://github.com/H7KZ/Disenchantment) +Here is to credits all the author of plugins +It partially repeat the the [Compatibility list](https://github.com/alexcrea/CustomAnvil/blob/v1.x.x/COMPATIBILITY.md) +- Big Thanks for H7KZ for [Disenchantment](https://github.com/H7KZ/Disenchantment) +- [Enchantment²](https://www.spigotmc.org/resources/enchants-squared-the-enchantsplus-rewrite-custom-enchantments-that-act-like-vanilla-ones.86747/) by Athlaeos +- [EcoEnchant](https://www.spigotmc.org/resources/ecoenchants-%E2%AD%95-250-enchantments-%E2%9C%85-create-custom-enchants-%E2%9C%A8-essentials-cmi-support.79573/) by Auxilor +- [ExcellentEnchants](https://www.spigotmc.org/resources/excellentenchants-%E2%AD%90-75-vanilla-like-enchantments.61693/) by NightExpress +- [HavenBags](https://www.spigotmc.org/resources/havenbags-shulker-like-player-bound-bags-1-17-1-21-4.110420/) by hyperdefined +- [AxPlayerWarp](https://modrinth.com/project/QDJHDKvi) by ArtillexStudios +- [ToolsStats](https://modrinth.com/project/oBZj9E15) by Valorless ### Special Thanks +Thanks for Microsoft leading me into using a better operating system \ Thanks for all the users trying my plugin for these niche use cases -, reporting issues and giving ideas ! +and for reporting issues and giving ideas ! Thanks coltonj96 for [UberEnchant](https://modrinth.com/plugin/uberenchant). we may be incompatible with the anvil, but I do think it is a good alternative ! \ -I wish one day to work on cross compatibiltiy \ -* If custom anvil do not work well for you or your use case give it a try ! * +I wish one day to work on cross compatibiltiy diff --git a/README.md b/README.md index 9d9e678..22d9da1 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ # Custom Anvil **Custom Anvil** is a plugin that allows server administrators to customize every aspect of the anvil's mechanics. +It is expected to work on 1.18 to 1.21.7 minecraft servers running spigot or paper. +(the plugin support of 1.16.5 to 1.17.1 is experimental and may encounter issues) ### Download Locations: @@ -14,7 +16,7 @@ the plugin can be downloaded on - Vanilla like default configuration. - Custom enchantment level limit. - Custom anvil recipes. -- Custom enchant restrictions (allows unsafe enchantment only for a group of item or create new restriction). +- Custom enchant restrictions (allow unsafe enchantment only for a group of item or create new restriction). - Custom items of unit repairs (repair damaged with unit of "material", for example the repair of diamond sword by diamonds). - Custom XP cost for every aspect of the anvil. - Permissions to bypass level limit or enchantment restriction. @@ -23,14 +25,8 @@ the plugin can be downloaded on - Gui to configure the plugin in game. - Support use of color code, hexadecimal color and minimessage for color/decoration - (Experimental) Folia support (gui do not work) -- (Experimental) Dialog rename (allows longer rename) -- (Experimental) Anvil with monetary cost (using vault) (require dialog rename) - -And more ! - --- ### Permissions: -Note that for most of them you also need to enable feature and in most case enable use of permission for the specfic feature (indicated with `(toggleable)`) ```yml # Generic and bypass permissions ca.affected: Player with this permission will be affected by the plugin @@ -48,22 +44,17 @@ ca.config.edit: Allow administrator to edit the plugin's config in game # ----------------------------------------------------------------------------- # Permissions related to use of color and minimessage ca.color.code: Allow player to use color code on rename if enabled (toggleable) -ca.color.code.[thecode] (for example ca.color.code.a): Allows usage of only certain color code (toggleable) ca.color.hex: Allow player to use hexadecimal color on rename if enabled (toggleable) -ca.rename.minimessage: Allow player to use minimessage formating on rename if enabled (toggleable) +ca.rename.minimessage: Allow player to use minimessage formating on rename if enabled (toggleable) (only legacy compatible at the time) # Permissions related to edition of the lore ca.lore_edit.book: Allow player to edit lore via book and quil if enabled (toggleable) ca.lore_edit.paper: Allow player to edit lore via paper if enabled (toggleable) - -# Others -ca.rename.dialog: Allow player to use the rename dialog (toggleable) ``` ### Commands -run `/customanvil help` to get information about available commands \ -this only show subcommands you have permission for +run `customanvil help` to get information about available commands (need permissions to use them) ### Supported Plugins See the [Compatibility list](https://github.com/alexcrea/CustomAnvil/blob/v1.x.x/COMPATIBILITY.md) @@ -72,10 +63,13 @@ See the [Compatibility list](https://github.com/alexcrea/CustomAnvil/blob/v1.x.x One of the configurations allow displaying price about 40 and removing Too Expensive. \ By how the minecraft client work: price above 40 can only be displayed green, even if the player does not own enough experience level. -spigot version 1.18 to 1.21.11 do not need any ProtocoLib dependency. (26.1.0 or above requires it) \ +Minecraft version 1.18 to latest marked as supported do not need any ProtocoLib dependency. \ Any recent paper version also are supported for this feature. -But you should wait for update for new version containing new enchantable item or new enchantments if any of this got added. -Else it is, likely, fine to use the current version you are ussing on a new paper version +But you should wait for update for new version containing new enchantable item or new enchantments. +Other version need ProtocoLib enabled on your server for this feature. \ +You can also wait for an update of the plugin to support a newer version. + +Please note that 1.16.5 to 1.17.1 are not officially supported. Run at your own risk. ### For custom enchantment plugin developers For information about the API, please refer to [the Wiki](https://github.com/alexcrea/CustomAnvil/wiki) \ @@ -106,6 +100,3 @@ Credits and thanks can be seen [here](https://github.com/alexcrea/CustomAnvil/bl ### Known issue: Most unknown registered enchantments (by unsupported custom enchantment plugin & datapacks) will not have restriction by default. Planned but no eta. - -### Do you need help with the plugin, or have any issue or suggestion? -You can ask on the discussion page, create a [GitHub issue](https://github.com/alexcrea/CustomAnvil/issues) or join my [discord](https://discord.gg/KHUNsUfRYJ)​ diff --git a/build.gradle.kts b/build.gradle.kts index a5dc7c3..fedeb77 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -22,7 +22,7 @@ plugins { } group = "xyz.alexcrea" -version = "1.17.5" +version = "1.17.0" val isDevBuild = System.getenv("SMALL_COMMIT_HASH") != null val isPreRelease = System.getenv("IS_GITHUB_PRERELEASE") == "true" @@ -58,7 +58,7 @@ dependencies { compileOnly("org.spigotmc:spigot-api:1.18-R0.1-SNAPSHOT") // fast stats - implementation("dev.faststats.metrics:bukkit:0.27.0") + implementation("dev.faststats.metrics:bukkit:0.25.1") // minimessage implementation("net.kyori:adventure-text-minimessage:4.25.0") diff --git a/defaultconfigs/README.md b/defaultconfigs/README.md index daa2088..a413b66 100644 --- a/defaultconfigs/README.md +++ b/defaultconfigs/README.md @@ -1,5 +1,5 @@ ### Default Plugin's Configurations From 1.18 to 1.20.6 use [1.18 configurations](https://github.com/alexcrea/CustomAnvil/tree/master/defaultconfigs/1.18) \ -From 1.21 to 1.21.8 use [1.21 configurations](https://github.com/alexcrea/CustomAnvil/tree/master/defaultconfigs/1.21) \ -From 1.21.9 to 1.21.10 use [1.21.9 configurations](https://github.com/alexcrea/CustomAnvil/tree/master/defaultconfigs/1.21.9) \ -From 1.21.11 use [1.21.11 configurations](https://github.com/alexcrea/CustomAnvil/tree/master/defaultconfigs/1.21.11) +From 1.21 to 1.21.8 use [1.21 configurations](https://github.com/alexcrea/CustomAnvil/tree/master/defaultconfigs/1.21) +From 1.21.9 to 1.21.10 use [1.21.9 configurations](https://github.com/alexcrea/CustomAnvil/tree/master/defaultconfigs/1.21.9) +From 1.21.11 use [1.21.11 configurations](https://github.com/alexcrea/CustomAnvil/tree/master/defaultconfigs/1.21.11) \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 4397d2e..19e22ef 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,5 +9,5 @@ kotlin.daemon.jvmargs=-Xmx8G subprojects.reobfnms=v1_17R1,v1_18R1,v1_18R2,v1_19R1,v1_19R2,v1_19R3,v1_20R1,v1_20R2,v1_20R3,v1_20R4,v1_21R1,v1_21R2,v1_21R3,v1_21R4,v1_21R5,v1_21R6,v1_21R7 # list of version for hangar release -paperVersion=1.18-26.2 +paperVersion=1.18-26.1.2 diff --git a/impl/ExcellentEnchant5_4/build.gradle.kts b/impl/ExcellentEnchant5_4/build.gradle.kts index 9fe598b..87694be 100644 --- a/impl/ExcellentEnchant5_4/build.gradle.kts +++ b/impl/ExcellentEnchant5_4/build.gradle.kts @@ -12,6 +12,6 @@ repositories { dependencies { // Excellent Enchant - compileOnly("su.nightexpress.excellentenchants:Core:5.4.3") - compileOnly("su.nightexpress.nightcore:main:2.16.2") + compileOnly("su.nightexpress.excellentenchants:Core:5.4.1") + compileOnly("su.nightexpress.nightcore:main:2.14.1") } \ No newline at end of file diff --git a/nms/nms-paper/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/PaperPacketManager.kt b/nms/nms-paper/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/PaperPacketManager.kt index ee0c101..7e248e1 100644 --- a/nms/nms-paper/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/PaperPacketManager.kt +++ b/nms/nms-paper/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/versions/PaperPacketManager.kt @@ -24,8 +24,8 @@ class PaperPacketManager : PacketManagerBase(), PacketManager { sendedAbilities.mayfly = playerAbilities.mayfly sendedAbilities.instabuild = instantBuild sendedAbilities.mayBuild = playerAbilities.mayBuild - sendedAbilities.setFlyingSpeed(playerAbilities.getFlyingSpeed()) - sendedAbilities.setWalkingSpeed(playerAbilities.getWalkingSpeed()) + sendedAbilities.flyingSpeed = playerAbilities.flyingSpeed + sendedAbilities.walkingSpeed = playerAbilities.walkingSpeed } val packet = ClientboundPlayerAbilitiesPacket(sendedAbilities) nmsPlayer.connection.send(packet) diff --git a/nms/v1_21R1/src/main/kotlin/xyz/alexcrea/cuanvil/util/ModernPrepareAnvilCreator.kt b/nms/v1_21R1/src/main/kotlin/xyz/alexcrea/cuanvil/util/ModernPrepareAnvilCreator.kt new file mode 100644 index 0000000..0c51e0a --- /dev/null +++ b/nms/v1_21R1/src/main/kotlin/xyz/alexcrea/cuanvil/util/ModernPrepareAnvilCreator.kt @@ -0,0 +1,12 @@ +package xyz.alexcrea.cuanvil.util + +import org.bukkit.event.inventory.PrepareAnvilEvent +import org.bukkit.inventory.InventoryView +import org.bukkit.inventory.ItemStack +import org.bukkit.inventory.view.AnvilView + +object ModernPrepareAnvilCreator { + fun createPrepareAnvil(view: InventoryView, item: ItemStack?): PrepareAnvilEvent { + return PrepareAnvilEvent(view as AnvilView, item) + } +} diff --git a/src/main/java/xyz/alexcrea/cuanvil/enchant/wrapped/CASuperEnchantEnchantment.java b/src/main/java/xyz/alexcrea/cuanvil/enchant/wrapped/CASuperEnchantEnchantment.java index 6039dc8..f5943be 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/enchant/wrapped/CASuperEnchantEnchantment.java +++ b/src/main/java/xyz/alexcrea/cuanvil/enchant/wrapped/CASuperEnchantEnchantment.java @@ -5,7 +5,6 @@ import com.maddoxh.superEnchants.enchants.EnchantManager; import com.maddoxh.superEnchants.items.EnchantApplicator; import com.maddoxh.superEnchants.items.EnchantReader; import com.maddoxh.superEnchants.util.ConflictChecker; -import org.bukkit.Material; import org.bukkit.NamespacedKey; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; @@ -69,8 +68,6 @@ public class CASuperEnchantEnchantment extends CAEnchantmentBase implements Addi @Override public boolean isItemConflict(@NotNull Map enchantments, @NotNull NamespacedKey itemType, @NotNull ItemStack item) { - if(Material.ENCHANTED_BOOK.equals(item.getType())) return false; - return !enchant.canApplyTo(item.getType()); } } diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/BasicConfigGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/BasicConfigGui.java index 51936c7..97f8e54 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/BasicConfigGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/global/BasicConfigGui.java @@ -283,9 +283,15 @@ public class BasicConfigGui extends ChestGui implements ValueUpdatableGui { lore.add("§7If the player do not have the required xp level, the action will not be completable."); if(!this.packetManager.getCanSetInstantBuild()){ - lore.add(""); - lore.add("§4/!\\§cCaution§4/!\\ §cYou need ProtocoLib installed and working or a paper server."); - lore.add("§cCurrently ProtocoLib is not detected."); + if(MinecraftVersionUtil.INSTANCE.isTooNewForSpigot()){ + lore.add(""); + lore.add("§4/!\\§cCaution§4/!\\ §cYou need ProtocoLib installed and working or a paper server."); + lore.add("§cCurrently ProtocoLib is not detected."); + } else { + lore.add(""); + lore.add("§4/!\\§cCaution§4/!\\ §cYou need ProtocoLib installed and working or a newer version of this plugin for this to work."); + lore.add("§cCurrently ProtocoLib is not detected."); + } } String[] loreAsArray = new String[lore.size()]; diff --git a/src/main/java/xyz/alexcrea/cuanvil/update/UpdateUtils.java b/src/main/java/xyz/alexcrea/cuanvil/update/UpdateUtils.java index 2907fef..c13515f 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/update/UpdateUtils.java +++ b/src/main/java/xyz/alexcrea/cuanvil/update/UpdateUtils.java @@ -15,6 +15,22 @@ public class UpdateUtils { return Version.fromString(versionString); } + @Deprecated + public static int[] currentMinecraftVersionArray() { + String versionString = Bukkit.getServer().getBukkitVersion().split("-")[0]; + return UpdateUtils.readVersionFromString(versionString); + } + + public static int[] readVersionFromString(String versionString) { + String[] partialVersion = versionString.split("\\."); + int[] versionParts = new int[]{0, 0, 0}; + + for (int i = 0; i < Math.min(3, partialVersion.length); i++) { + versionParts[i] = Integer.parseInt(partialVersion[i]); + } + return versionParts; + } + public static void addToStringList(FileConfiguration config, String path, String... toAdd) { List groups = new ArrayList<>(config.getStringList(path)); groups.addAll(Arrays.asList(toAdd)); diff --git a/src/main/java/xyz/alexcrea/cuanvil/update/Version.java b/src/main/java/xyz/alexcrea/cuanvil/update/Version.java index a49fbdd..15476f5 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/update/Version.java +++ b/src/main/java/xyz/alexcrea/cuanvil/update/Version.java @@ -21,11 +21,7 @@ public record Version(int major, int minor, int patch) { int[] versionParts = new int[]{0, 0, 0}; for (int i = 0; i < Math.min(3, partialVersion.length); i++) { - try { - versionParts[i] = Integer.parseInt(partialVersion[i]); - } catch (NumberFormatException e) { - break; - } + versionParts[i] = Integer.parseInt(partialVersion[i]); } return new Version(versionParts[0], versionParts[1], versionParts[2]); } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/anvil/AnvilCost.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/anvil/AnvilCost.kt index 710687c..f8ff89c 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/anvil/AnvilCost.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/anvil/AnvilCost.kt @@ -1,8 +1,6 @@ package xyz.alexcrea.cuanvil.anvil -import io.delilaheve.util.ConfigOptions import java.math.BigDecimal -import kotlin.math.min import io.delilaheve.util.ConfigOptions.getMonetaryMultiplier as moneyMultiplier open class AnvilCost { @@ -32,21 +30,6 @@ open class AnvilCost { return generic + enchantment + repair + rename + lore + illegalPenalty + workPenalty + recipe } - fun filteredXpCost(ignoreRules: Boolean = false): Int { - val original = asXpCost() - - // Test repair cost limit - return if ( - !ignoreRules && - !ConfigOptions.doRemoveCostLimit && - ConfigOptions.doCapCost - ) { - min(original, ConfigOptions.maxAnvilCost) - } else { - original - } - } - open fun asMonetaryCost(): BigDecimal { // multiply by per use type multipliers return BigDecimal(generic) diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/MinecraftVersionUtil.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/MinecraftVersionUtil.kt index cbd2209..d981f81 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/MinecraftVersionUtil.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/MinecraftVersionUtil.kt @@ -6,29 +6,29 @@ object MinecraftVersionUtil { val craftbukkitVersion: String? get() { - val version = UpdateUtils.currentMinecraftVersion() - if (version.major != 1) return null + val versionParts = UpdateUtils.currentMinecraftVersionArray() + if (versionParts[0] != 1) return null - return when (version.minor) { - 17 -> when (version.patch) { + return when (versionParts[1]) { + 17 -> when (versionParts[2]) { 0, 1 -> "1_17R1" else -> null } - 18 -> when (version.patch) { + 18 -> when (versionParts[2]) { 0, 1 -> "1_18R1" 2 -> "1_18R2" else -> null } - 19 -> when (version.patch) { + 19 -> when (versionParts[2]) { 0, 1, 2 -> "1_19R1" 3 -> "1_19R2" 4 -> "1_19R3" else -> null } - 20 -> when (version.patch) { + 20 -> when (versionParts[2]) { 0, 1 -> "1_20R1" 2 -> "1_20R2" 3, 4 -> "1_20R3" @@ -36,7 +36,7 @@ object MinecraftVersionUtil { else -> null } - 21 -> when (version.patch) { + 21 -> when (versionParts[2]) { 0, 1 -> "1_21R1" 2, 3 -> "1_21R2" 4 -> "1_21R3" @@ -52,7 +52,8 @@ object MinecraftVersionUtil { } val isTooNewForSpigot: Boolean get() { - return UpdateUtils.currentMinecraftVersion().major != 1 + val versionParts = UpdateUtils.currentMinecraftVersionArray() + return versionParts[0] != 1 } } \ No newline at end of file diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/PacketManagerSelector.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/PacketManagerSelector.kt index d74ef08..6c18a75 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/PacketManagerSelector.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/packet/PacketManagerSelector.kt @@ -38,8 +38,8 @@ object PacketManagerSelector { // Reobfuscated packet manager for spigot or paper as it remap private val reobfPacketManager: PacketManagerBase? get() { - val versionParts = UpdateUtils.currentMinecraftVersion() - if (versionParts.major != 1) return null + val versionParts = UpdateUtils.currentMinecraftVersionArray() + if (versionParts[0] != 1) return null try { val clazz = Class.forName("xyz.alexcrea.cuanvil.dependency.packet.versions." + @@ -47,7 +47,7 @@ object PacketManagerSelector { val manager = clazz.getConstructor().newInstance() return manager as PacketManagerBase - } catch (_: ClassNotFoundException) { + } catch (e: ClassNotFoundException) { return null } } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/ExcellentEnchantsDependency.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/ExcellentEnchantsDependency.kt index 816a4df..c2d3019 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/ExcellentEnchantsDependency.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/dependency/plugins/ExcellentEnchantsDependency.kt @@ -13,7 +13,7 @@ import xyz.alexcrea.cuanvil.enchant.wrapped.CAEEPreV5Enchantment import xyz.alexcrea.cuanvil.enchant.wrapped.CAEEV5Enchantment import xyz.alexcrea.cuanvil.enchant.wrapped.CAEEV5_4Enchantment import xyz.alexcrea.cuanvil.enchant.wrapped.CALegacyEEEnchantment -import java.lang.reflect.Constructor +import xyz.alexcrea.cuanvil.util.ModernPrepareAnvilCreator import java.lang.reflect.Method import su.nightexpress.excellentenchants.api.EnchantRegistry as V5EnchantRegistry import su.nightexpress.excellentenchants.enchantment.impl.universal.CurseOfFragilityEnchant as LegacyCurseOfFragilityEnchant @@ -118,8 +118,6 @@ class ExcellentEnchantsDependency { private lateinit var handleRechargeMethod: Method private lateinit var handleCombineMethod: Method - private val prepareAnvilConstructor = PrepareAnvilEvent::class.java.constructors.first() as Constructor - fun redirectListeners() { val toUnregister = ArrayList() // get required PrepareAnvilEvent listener @@ -226,8 +224,12 @@ class ExcellentEnchantsDependency { val first: ItemStack = treatInput(event.leftItem) val second: ItemStack = treatInput(event.rightItem) - val fakeEvent = prepareAnvilConstructor.newInstance(event.view, result) - + val fakeEvent: PrepareAnvilEvent = try { + //TODO remove this on legacy removal + PrepareAnvilEvent(event.view, result) + } catch (_: NoSuchMethodError) { + ModernPrepareAnvilCreator.createPrepareAnvil(event.view, result) + } handleCombineMethod.invoke(this.usedAnvilListener, fakeEvent, first, second, result) event.result = fakeEvent.result diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/listener/AnvilResultListener.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/listener/AnvilResultListener.kt index e393dbd..feee833 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/listener/AnvilResultListener.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/listener/AnvilResultListener.kt @@ -121,7 +121,7 @@ class AnvilResultListener : Listener { view, inventory, player, leftItem, rightItem ) - if (!unitRepairResult.isEmpty()) { + if (unitRepairResult.isEmpty()) { onUnitRepairExtract( rightItem, event, player, inventory, unitRepairResult @@ -270,19 +270,13 @@ class AnvilResultListener : Listener { } - private fun tryRemoveCost(player: Player, result: AnvilResult): Boolean { + private fun tryRemoveCost(player: Player, cost: AnvilCost): Boolean { if (player.gameMode == GameMode.CREATIVE) return true - - val cost = result.cost if (cost.isMonetary) { val result = EconomyManager.economy!!.remove(player, cost.asMonetaryCost()) if (!result) return false } else { - val xpCost = cost.filteredXpCost() - if (xpCost > AnvilXpUtil.maximumXpCost(result.ignoreXpRules)) return false - if (player.level < xpCost) return false - - player.level -= xpCost + player.level -= cost.asXpCost() } return true @@ -314,7 +308,7 @@ class AnvilResultListener : Listener { // If not creative middle click... if (event.click != ClickType.MIDDLE) { - if (!tryRemoveCost(player, result)) return false + if (!tryRemoveCost(player, cost)) return false // We remove what should be removed if (leftItem != null) leftItem.amount -= leftRemoveCount diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/util/anvil/AnvilXpUtil.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/util/anvil/AnvilXpUtil.kt index 4846f31..f6ee12f 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/util/anvil/AnvilXpUtil.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/util/anvil/AnvilXpUtil.kt @@ -22,6 +22,7 @@ import xyz.alexcrea.cuanvil.dependency.economy.EconomyManager import xyz.alexcrea.cuanvil.group.ConflictType import xyz.alexcrea.cuanvil.util.AnvilTitleUtil import xyz.alexcrea.cuanvil.util.dialog.AnvilRenameDialogUtil +import kotlin.math.min object AnvilXpUtil { @@ -41,15 +42,7 @@ object AnvilXpUtil { cost.isMonetary = true setAnvilPrice(inventory, view, player, cost) } else - setAnvilInvXp(inventory, view, player, cost.filteredXpCost(ignoreRules), ignoreRules) - } - - fun maximumXpCost(ignoreRules: Boolean = false): Int { - return if (ConfigOptions.doRemoveCostLimit || ignoreRules) { - Int.MAX_VALUE - } else { - ConfigOptions.maxAnvilCost + 1 - } + setAnvilInvXp(inventory, view, player, cost.asXpCost(), ignoreRules) } /** @@ -62,11 +55,28 @@ object AnvilXpUtil { anvilCost: Int, ignoreRules: Boolean = false ) { - val maximumRepairCost = maximumXpCost(ignoreRules) + + // Test repair cost limit + val finalAnvilCost = if ( + !ignoreRules && + !ConfigOptions.doRemoveCostLimit && + ConfigOptions.doCapCost + ) { + min(anvilCost, ConfigOptions.maxAnvilCost) + } else { + anvilCost + } + + val maximumRepairCost = + if (ConfigOptions.doRemoveCostLimit || ignoreRules) { + Int.MAX_VALUE + } else { + ConfigOptions.maxAnvilCost + 1 + } // Try first just in case another plugin, or the test need this inventory.maximumRepairCost = maximumRepairCost - inventory.repairCost = anvilCost + inventory.repairCost = finalAnvilCost // TODO for 2.x.x use anvil view & set directly there /* Because Minecraft likes to have the final say in the repair cost displayed @@ -77,15 +87,15 @@ object AnvilXpUtil { ) { // retry after a tick inventory.maximumRepairCost = maximumRepairCost - inventory.repairCost = anvilCost + inventory.repairCost = finalAnvilCost // TODO for 2.x.x use anvil view & set directly there if (player !is Player) return@scheduleOnEntity if (player.gameMode != GameMode.CREATIVE) { val bypassToExpensive = (ConfigOptions.doReplaceTooExpensive) && - (anvilCost >= 40) && - anvilCost < inventory.maximumRepairCost + (finalAnvilCost >= 40) && + finalAnvilCost < inventory.maximumRepairCost DependencyManager.packetManager.setInstantBuild(player, bypassToExpensive) }