diff --git a/build.gradle.kts b/build.gradle.kts index f076b138..5776c1fa 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -25,6 +25,7 @@ dependencies { implementation(project(path = ":eco-core:core-nms:v1_18_R1", configuration = "reobf")) implementation(project(path = ":eco-core:core-nms:v1_18_R2", configuration = "reobf")) implementation(project(path = ":eco-core:core-nms:v1_19_R1", configuration = "reobf")) + implementation(project(path = ":eco-core:core-nms:v1_19_R2", configuration = "reobf")) } allprojects { diff --git a/eco-api/src/main/java/com/willfp/eco/core/price/CombinedDisplayPrice.java b/eco-api/src/main/java/com/willfp/eco/core/price/CombinedDisplayPrice.java new file mode 100644 index 00000000..12036e3f --- /dev/null +++ b/eco-api/src/main/java/com/willfp/eco/core/price/CombinedDisplayPrice.java @@ -0,0 +1,156 @@ +package com.willfp.eco.core.price; + +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * A group of {@link ConfiguredPrice}s in order to show them + * to players in one go. + */ +public final class CombinedDisplayPrice { + /** + * Maps configured prices to multipliers. + */ + private final Map prices; + + /** + * The player to format for. + */ + private final Player player; + + /** + * Initialize a new combined price mapping formatters to multipliers. + * + * @param player The player. + * @param prices The prices. + */ + private CombinedDisplayPrice(@NotNull final Player player, + @NotNull final Map prices) { + this.player = player; + this.prices = prices; + } + + /** + * Get the display strings. + * + * @return The display strings. + */ + @NotNull + public String[] getDisplayStrings() { + List displayStrings = new ArrayList<>(); + + for (Map.Entry entry : prices.entrySet()) { + displayStrings.add(entry.getKey().getDisplay(player, entry.getValue())); + } + + return displayStrings.toArray(new String[0]); + } + + /** + * The builder. + */ + public static class Builder { + /** + * All multiplied prices. + */ + private final List prices = new ArrayList<>(); + + /** + * The player. + */ + private final Player player; + + /** + * Create a new builder. + * + * @param player The player. + */ + Builder(@NotNull final Player player) { + this.player = player; + } + + /** + * Add a new price with a certain multiplier. + * + * @param price The price. + * @param multiplier The multiplier. + * @return The builder. + */ + @NotNull + public Builder add(@NotNull final ConfiguredPrice price, + final double multiplier) { + prices.add(new MultipliedPrice(price, multiplier)); + return this; + } + + + /** + * Add a new price. + * + * @param price The price. + * @return The builder. + */ + @NotNull + public Builder add(@NotNull final ConfiguredPrice price) { + return this.add(price, 1D); + } + + /** + * Build into a {@link CombinedDisplayPrice}. + * + * @return The combined price. + */ + @NotNull + public CombinedDisplayPrice build() { + Map unitPrices = new HashMap<>(); + + // Take first configured price at each ID as the format for all prices with that ID. + for (MultipliedPrice price : prices) { + // Find the base price. + ConfiguredPrice base = unitPrices.keySet() + .stream() + .filter(it -> it.getIdentifier().equals(price.price().getIdentifier())) + .findFirst() + .orElse(price.price()); + + // Find the multiplier for a value of 1, e.g. a price that's worth 20 will be 0.05. + double unitMultiplier = 1 / base.getValue(player); + + double currentMultiplier = unitPrices.getOrDefault(base, 0D); + currentMultiplier += unitMultiplier * price.price().getValue(player, price.multiplier()); + unitPrices.put(base, currentMultiplier); + } + + return new CombinedDisplayPrice(player, unitPrices); + } + + /** + * A price with a multiplier. + * + * @param price The price. + * @param multiplier The multiplier. + */ + private record MultipliedPrice( + @NotNull ConfiguredPrice price, + double multiplier + ) { + + } + } + + /** + * Create a new builder for a player. + * + * @param player The player. + * @return The builder. + */ + @NotNull + public static Builder builder(@NotNull final Player player) { + return new Builder(player); + } +} diff --git a/eco-api/src/main/java/com/willfp/eco/core/price/ConfiguredPrice.java b/eco-api/src/main/java/com/willfp/eco/core/price/ConfiguredPrice.java index 8944ddd6..d455de8d 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/price/ConfiguredPrice.java +++ b/eco-api/src/main/java/com/willfp/eco/core/price/ConfiguredPrice.java @@ -86,6 +86,11 @@ public final class ConfiguredPrice implements Price { this.price.setMultiplier(player, multiplier); } + @Override + public String getIdentifier() { + return this.price.getIdentifier(); + } + /** * Get the price that this delegates to. * diff --git a/eco-api/src/main/java/com/willfp/eco/core/price/Price.java b/eco-api/src/main/java/com/willfp/eco/core/price/Price.java index b7ed5559..deae9227 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/price/Price.java +++ b/eco-api/src/main/java/com/willfp/eco/core/price/Price.java @@ -132,6 +132,21 @@ public interface Price { throw new NotImplementedException("Override setMultiplier(Player, double) in your Price implementation!"); } + /** + * Get the identifier of this price (as type/instance checks break with delegation, + * this is used for combining prices, etc.) + *

+ * By default, this uses the class name, but it's good practice to override this. + *

+ * It's also good practice to prefix your identifiers with some kind of namespace or + * internal ID, in order to prevent conflicts. + * + * @return The identifier. + */ + default String getIdentifier() { + return this.getClass().getName(); + } + /** * If the price is backed by a value, get it here. * diff --git a/eco-api/src/main/java/com/willfp/eco/core/price/impl/PriceEconomy.java b/eco-api/src/main/java/com/willfp/eco/core/price/impl/PriceEconomy.java index c853871a..36a6dcef 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/price/impl/PriceEconomy.java +++ b/eco-api/src/main/java/com/willfp/eco/core/price/impl/PriceEconomy.java @@ -85,4 +85,9 @@ public final class PriceEconomy implements Price { final double multiplier) { this.multipliers.put(player.getUniqueId(), multiplier); } + + @Override + public String getIdentifier() { + return "eco:economy"; + } } diff --git a/eco-api/src/main/java/com/willfp/eco/core/price/impl/PriceFree.java b/eco-api/src/main/java/com/willfp/eco/core/price/impl/PriceFree.java index 1e2568f5..2f709032 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/price/impl/PriceFree.java +++ b/eco-api/src/main/java/com/willfp/eco/core/price/impl/PriceFree.java @@ -49,4 +49,9 @@ public final class PriceFree implements Price { final double multiplier) { return 0; } + + @Override + public String getIdentifier() { + return "eco:free"; + } } diff --git a/eco-api/src/main/java/com/willfp/eco/core/price/impl/PriceItem.java b/eco-api/src/main/java/com/willfp/eco/core/price/impl/PriceItem.java index ac7e2c77..894b827f 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/price/impl/PriceItem.java +++ b/eco-api/src/main/java/com/willfp/eco/core/price/impl/PriceItem.java @@ -1,6 +1,7 @@ package com.willfp.eco.core.price.impl; import com.willfp.eco.core.drops.DropQueue; +import com.willfp.eco.core.items.HashedItem; import com.willfp.eco.core.items.TestableItem; import com.willfp.eco.core.math.MathContext; import com.willfp.eco.core.price.Price; @@ -151,4 +152,9 @@ public final class PriceItem implements Price { final double multiplier) { this.multipliers.put(player.getUniqueId(), multiplier); } + + @Override + public String getIdentifier() { + return "eco:item-" + HashedItem.of(this.item.getItem()).getHash(); + } } diff --git a/eco-api/src/main/java/com/willfp/eco/core/proxy/ProxyConstants.java b/eco-api/src/main/java/com/willfp/eco/core/proxy/ProxyConstants.java index aa428d37..03ebef1c 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/proxy/ProxyConstants.java +++ b/eco-api/src/main/java/com/willfp/eco/core/proxy/ProxyConstants.java @@ -21,7 +21,8 @@ public final class ProxyConstants { "v1_17_R1", "v1_18_R1", "v1_18_R2", - "v1_19_R1" + "v1_19_R1", + "v1_19_R2" ); private ProxyConstants() { diff --git a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/price/PriceFactoryXP.kt b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/price/PriceFactoryXP.kt index 3033a237..8f6874f0 100644 --- a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/price/PriceFactoryXP.kt +++ b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/price/PriceFactoryXP.kt @@ -46,5 +46,9 @@ object PriceFactoryXP : PriceFactory { override fun setMultiplier(player: Player, multiplier: Double) { multipliers[player.uniqueId] = multiplier.roundToInt().toDouble() } + + override fun getIdentifier(): String { + return "eco:xp" + } } } diff --git a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/price/PriceFactoryXPLevels.kt b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/price/PriceFactoryXPLevels.kt index 2f22c39e..ed7b2895 100644 --- a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/price/PriceFactoryXPLevels.kt +++ b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/price/PriceFactoryXPLevels.kt @@ -47,5 +47,9 @@ object PriceFactoryXPLevels : PriceFactory { override fun setMultiplier(player: Player, multiplier: Double) { multipliers[player.uniqueId] = multiplier.roundToInt().toDouble() } + + override fun getIdentifier(): String { + return "eco:xp-levels" + } } } diff --git a/eco-core/core-nms/nms-common/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/common/NMSCommons.kt b/eco-core/core-nms/nms-common/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/common/NMSCommons.kt index 91b046ed..40a473e4 100644 --- a/eco-core/core-nms/nms-common/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/common/NMSCommons.kt +++ b/eco-core/core-nms/nms-common/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/common/NMSCommons.kt @@ -4,7 +4,6 @@ import com.willfp.eco.core.entities.ai.EntityGoal import com.willfp.eco.core.entities.ai.TargetGoal import com.willfp.eco.internal.spigot.proxy.common.ai.EntityGoalFactory import com.willfp.eco.internal.spigot.proxy.common.ai.TargetGoalFactory -import net.minecraft.core.Registry import net.minecraft.nbt.CompoundTag import net.minecraft.resources.ResourceLocation import net.minecraft.world.entity.LivingEntity @@ -48,17 +47,14 @@ private val MATERIAL_TO_ITEM = mutableMapOf() fun Material.toItem(): Item = MATERIAL_TO_ITEM.getOrPut(this) { - Registry.ITEM.getOptional(this.key.toResourceLocation()) - .orElseThrow { IllegalArgumentException("Material is not item!") } + impl.materialToItem(this) } private val ITEM_TO_MATERIAL = mutableMapOf() fun Item.toMaterial(): Material = ITEM_TO_MATERIAL.getOrPut(this) { - val material = Material.getMaterial(Registry.ITEM.getKey(this).path.uppercase()) - ?: throw IllegalArgumentException("Invalid material!") - material + impl.itemToMaterial(this) } fun CompoundTag.makePdc(base: Boolean = false): PersistentDataContainer = @@ -94,6 +90,10 @@ interface CommonsProvider { return null } + fun materialToItem(material: Material): Item + + fun itemToMaterial(item: Item): Material + companion object { fun setIfNeeded(provider: CommonsProvider) { if (::impl.isInitialized) { diff --git a/eco-core/core-nms/v1_17_R1/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_17_R1/CommonsInitializer.kt b/eco-core/core-nms/v1_17_R1/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_17_R1/CommonsInitializer.kt index ea983725..a6f43af9 100644 --- a/eco-core/core-nms/v1_17_R1/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_17_R1/CommonsInitializer.kt +++ b/eco-core/core-nms/v1_17_R1/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_17_R1/CommonsInitializer.kt @@ -2,11 +2,15 @@ package com.willfp.eco.internal.spigot.proxy.v1_17_R1 import com.willfp.eco.internal.spigot.proxy.CommonsInitializerProxy import com.willfp.eco.internal.spigot.proxy.common.CommonsProvider +import com.willfp.eco.internal.spigot.proxy.common.toResourceLocation +import net.minecraft.core.Registry import net.minecraft.nbt.CompoundTag import net.minecraft.nbt.Tag import net.minecraft.resources.ResourceLocation import net.minecraft.world.entity.PathfinderMob +import net.minecraft.world.item.Item import org.bukkit.Bukkit +import org.bukkit.Material import org.bukkit.NamespacedKey import org.bukkit.craftbukkit.v1_17_R1.CraftServer import org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity @@ -131,5 +135,13 @@ class CommonsInitializer : CommonsInitializerProxy { } } } + + override fun materialToItem(material: Material): Item = + Registry.ITEM.getOptional(material.key.toResourceLocation()) + .orElseThrow { IllegalArgumentException("Material is not item!") } + + override fun itemToMaterial(item: Item) = + Material.getMaterial(Registry.ITEM.getKey(item).path.uppercase()) + ?: throw IllegalArgumentException("Invalid material!") } } diff --git a/eco-core/core-nms/v1_18_R1/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_18_R1/CommonsInitializer.kt b/eco-core/core-nms/v1_18_R1/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_18_R1/CommonsInitializer.kt index 4d786a3e..142d0a78 100644 --- a/eco-core/core-nms/v1_18_R1/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_18_R1/CommonsInitializer.kt +++ b/eco-core/core-nms/v1_18_R1/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_18_R1/CommonsInitializer.kt @@ -2,11 +2,15 @@ package com.willfp.eco.internal.spigot.proxy.v1_18_R1 import com.willfp.eco.internal.spigot.proxy.CommonsInitializerProxy import com.willfp.eco.internal.spigot.proxy.common.CommonsProvider +import com.willfp.eco.internal.spigot.proxy.common.toResourceLocation +import net.minecraft.core.Registry import net.minecraft.nbt.CompoundTag import net.minecraft.nbt.Tag import net.minecraft.resources.ResourceLocation import net.minecraft.world.entity.PathfinderMob +import net.minecraft.world.item.Item import org.bukkit.Bukkit +import org.bukkit.Material import org.bukkit.NamespacedKey import org.bukkit.craftbukkit.v1_18_R1.CraftServer import org.bukkit.craftbukkit.v1_18_R1.entity.CraftEntity @@ -131,5 +135,13 @@ class CommonsInitializer : CommonsInitializerProxy { } } } + + override fun materialToItem(material: Material): Item = + Registry.ITEM.getOptional(material.key.toResourceLocation()) + .orElseThrow { IllegalArgumentException("Material is not item!") } + + override fun itemToMaterial(item: Item) = + Material.getMaterial(Registry.ITEM.getKey(item).path.uppercase()) + ?: throw IllegalArgumentException("Invalid material!") } } diff --git a/eco-core/core-nms/v1_18_R2/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_18_R2/CommonsInitializer.kt b/eco-core/core-nms/v1_18_R2/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_18_R2/CommonsInitializer.kt index 259a465f..fc026f4b 100644 --- a/eco-core/core-nms/v1_18_R2/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_18_R2/CommonsInitializer.kt +++ b/eco-core/core-nms/v1_18_R2/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_18_R2/CommonsInitializer.kt @@ -2,11 +2,15 @@ package com.willfp.eco.internal.spigot.proxy.v1_18_R2 import com.willfp.eco.internal.spigot.proxy.CommonsInitializerProxy import com.willfp.eco.internal.spigot.proxy.common.CommonsProvider +import com.willfp.eco.internal.spigot.proxy.common.toResourceLocation +import net.minecraft.core.Registry import net.minecraft.nbt.CompoundTag import net.minecraft.nbt.Tag import net.minecraft.resources.ResourceLocation import net.minecraft.world.entity.PathfinderMob +import net.minecraft.world.item.Item import org.bukkit.Bukkit +import org.bukkit.Material import org.bukkit.NamespacedKey import org.bukkit.craftbukkit.v1_18_R2.CraftServer import org.bukkit.craftbukkit.v1_18_R2.entity.CraftEntity @@ -131,5 +135,13 @@ class CommonsInitializer : CommonsInitializerProxy { } } } + + override fun materialToItem(material: Material): Item = + Registry.ITEM.getOptional(material.key.toResourceLocation()) + .orElseThrow { IllegalArgumentException("Material is not item!") } + + override fun itemToMaterial(item: Item) = + Material.getMaterial(Registry.ITEM.getKey(item).path.uppercase()) + ?: throw IllegalArgumentException("Invalid material!") } } diff --git a/eco-core/core-nms/v1_19_R1/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_19_R1/CommonsInitializer.kt b/eco-core/core-nms/v1_19_R1/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_19_R1/CommonsInitializer.kt index 084fb7bd..c3f1222d 100644 --- a/eco-core/core-nms/v1_19_R1/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_19_R1/CommonsInitializer.kt +++ b/eco-core/core-nms/v1_19_R1/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_19_R1/CommonsInitializer.kt @@ -2,11 +2,15 @@ package com.willfp.eco.internal.spigot.proxy.v1_19_R1 import com.willfp.eco.internal.spigot.proxy.CommonsInitializerProxy import com.willfp.eco.internal.spigot.proxy.common.CommonsProvider +import com.willfp.eco.internal.spigot.proxy.common.toResourceLocation +import net.minecraft.core.Registry import net.minecraft.nbt.CompoundTag import net.minecraft.nbt.Tag import net.minecraft.resources.ResourceLocation import net.minecraft.world.entity.PathfinderMob +import net.minecraft.world.item.Item import org.bukkit.Bukkit +import org.bukkit.Material import org.bukkit.NamespacedKey import org.bukkit.craftbukkit.v1_19_R1.CraftServer import org.bukkit.craftbukkit.v1_19_R1.entity.CraftEntity @@ -131,5 +135,13 @@ class CommonsInitializer : CommonsInitializerProxy { } } } + + override fun materialToItem(material: Material): Item = + Registry.ITEM.getOptional(material.key.toResourceLocation()) + .orElseThrow { IllegalArgumentException("Material is not item!") } + + override fun itemToMaterial(item: Item) = + Material.getMaterial(Registry.ITEM.getKey(item).path.uppercase()) + ?: throw IllegalArgumentException("Invalid material!") } } diff --git a/eco-core/core-nms/v1_19_R2/build.gradle.kts b/eco-core/core-nms/v1_19_R2/build.gradle.kts new file mode 100644 index 00000000..1889163a --- /dev/null +++ b/eco-core/core-nms/v1_19_R2/build.gradle.kts @@ -0,0 +1,39 @@ +plugins { + id("io.papermc.paperweight.userdev") version "1.3.6" +} + +group = "com.willfp" +version = rootProject.version + +dependencies { + implementation(project(":eco-core:core-nms:nms-common")) + paperDevBundle("1.19.3-R0.1-SNAPSHOT") + + implementation("net.kyori:adventure-text-minimessage:4.11.0") { + version { + strictly("4.11.0") + } + exclude(group = "net.kyori", module = "adventure-api") + } +} + +tasks { + build { + dependsOn(reobfJar) + } + + reobfJar { + mustRunAfter(shadowJar) + } + + shadowJar { + relocate( + "com.willfp.eco.internal.spigot.proxy.common", + "com.willfp.eco.internal.spigot.proxy.v1_19_R2.common" + ) + relocate( + "net.kyori.adventure.text.minimessage", + "com.willfp.eco.internal.spigot.proxy.v1_19_R2.minimessage" + ) + } +} diff --git a/eco-core/core-nms/v1_19_R2/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_19_R2/AutoCraft.kt b/eco-core/core-nms/v1_19_R2/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_19_R2/AutoCraft.kt new file mode 100644 index 00000000..46e08cbc --- /dev/null +++ b/eco-core/core-nms/v1_19_R2/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_19_R2/AutoCraft.kt @@ -0,0 +1,15 @@ +package com.willfp.eco.internal.spigot.proxy.v1_19_R2 + +import com.willfp.eco.internal.spigot.proxy.AutoCraftProxy +import net.minecraft.network.protocol.game.ClientboundPlaceGhostRecipePacket +import net.minecraft.resources.ResourceLocation + +class AutoCraft : AutoCraftProxy { + override fun modifyPacket(packet: Any) { + val recipePacket = packet as ClientboundPlaceGhostRecipePacket + val fKey = recipePacket.javaClass.getDeclaredField("b") + fKey.isAccessible = true + val key = fKey[recipePacket] as ResourceLocation + fKey[recipePacket] = ResourceLocation(key.namespace, key.path + "_displayed") + } +} \ No newline at end of file diff --git a/eco-core/core-nms/v1_19_R2/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_19_R2/BukkitCommands.kt b/eco-core/core-nms/v1_19_R2/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_19_R2/BukkitCommands.kt new file mode 100644 index 00000000..d7eb6631 --- /dev/null +++ b/eco-core/core-nms/v1_19_R2/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_19_R2/BukkitCommands.kt @@ -0,0 +1,35 @@ +package com.willfp.eco.internal.spigot.proxy.v1_19_R2 + +import com.willfp.eco.core.command.impl.PluginCommand +import com.willfp.eco.internal.spigot.proxy.BukkitCommandsProxy +import org.bukkit.Bukkit +import org.bukkit.command.Command +import org.bukkit.command.SimpleCommandMap +import org.bukkit.craftbukkit.v1_19_R2.CraftServer +import java.lang.reflect.Field + +class BukkitCommands : BukkitCommandsProxy { + private val knownCommandsField: Field by lazy { + SimpleCommandMap::class.java.getDeclaredField("knownCommands") + .apply { + isAccessible = true + } + } + + @Suppress("UNCHECKED_CAST") + private val knownCommands: MutableMap + get() = knownCommandsField.get(getCommandMap()) as MutableMap + + override fun getCommandMap(): SimpleCommandMap { + return (Bukkit.getServer() as CraftServer).commandMap + } + + override fun syncCommands() { + (Bukkit.getServer() as CraftServer).syncCommands() + } + + override fun unregisterCommand(command: PluginCommand) { + knownCommands.remove(command.name) + knownCommands.remove("${command.plugin.name.lowercase()}:${command.name}") + } +} diff --git a/eco-core/core-nms/v1_19_R2/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_19_R2/ChatComponent.kt b/eco-core/core-nms/v1_19_R2/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_19_R2/ChatComponent.kt new file mode 100644 index 00000000..7871866e --- /dev/null +++ b/eco-core/core-nms/v1_19_R2/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_19_R2/ChatComponent.kt @@ -0,0 +1,93 @@ +package com.willfp.eco.internal.spigot.proxy.v1_19_R2 + +import com.willfp.eco.core.display.Display +import com.willfp.eco.internal.spigot.proxy.ChatComponentProxy +import net.kyori.adventure.nbt.api.BinaryTagHolder +import net.kyori.adventure.text.BuildableComponent +import net.kyori.adventure.text.Component +import net.kyori.adventure.text.TranslatableComponent +import net.kyori.adventure.text.event.HoverEvent +import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer +import net.minecraft.nbt.TagParser +import org.bukkit.Material +import org.bukkit.craftbukkit.v1_19_R2.inventory.CraftItemStack +import org.bukkit.entity.Player +import org.bukkit.inventory.ItemStack + +@Suppress("UNCHECKED_CAST") +class ChatComponent : ChatComponentProxy { + private val gsonComponentSerializer = GsonComponentSerializer.gson() + + override fun modifyComponent(obj: Any, player: Player): Any { + if (obj !is net.minecraft.network.chat.Component) { + return obj + } + + val component = gsonComponentSerializer.deserialize( + net.minecraft.network.chat.Component.Serializer.toJson( + obj + ) + ).asComponent() as BuildableComponent<*, *> + + val newComponent = modifyBaseComponent(component, player) + + return net.minecraft.network.chat.Component.Serializer.fromJson( + gsonComponentSerializer.serialize(newComponent.asComponent()) + ) ?: obj + } + + private fun modifyBaseComponent(baseComponent: Component, player: Player): Component { + var component = baseComponent + + if (component is TranslatableComponent) { + val args = mutableListOf() + for (arg in component.args()) { + args.add(modifyBaseComponent(arg, player)) + } + component = component.args(args) + } + + val children = mutableListOf() + for (child in component.children()) { + children.add(modifyBaseComponent(child, player)) + } + component = component.children(children) + + val hoverEvent: HoverEvent = component.style().hoverEvent() as HoverEvent? ?: return component + + val showItem = hoverEvent.value() + + if (showItem !is HoverEvent.ShowItem) { + return component + } + + val newShowItem = showItem.nbt( + BinaryTagHolder.binaryTagHolder( + CraftItemStack.asNMSCopy( + Display.display( + CraftItemStack.asBukkitCopy( + CraftItemStack.asNMSCopy( + ItemStack( + Material.matchMaterial( + showItem.item() + .toString() + ) ?: return component, + showItem.count() + ) + ).apply { + this.tag = TagParser.parseTag( + showItem.nbt()?.string() ?: return component + ) ?: return component + } + ), + player + ) + ).orCreateTag.toString() + ) + ) + + val newHover = hoverEvent.value(newShowItem) + val style = component.style().hoverEvent(newHover) + return component.style(style) + } +} \ No newline at end of file diff --git a/eco-core/core-nms/v1_19_R2/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_19_R2/CommonsInitializer.kt b/eco-core/core-nms/v1_19_R2/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_19_R2/CommonsInitializer.kt new file mode 100644 index 00000000..1d4c7db3 --- /dev/null +++ b/eco-core/core-nms/v1_19_R2/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_19_R2/CommonsInitializer.kt @@ -0,0 +1,148 @@ +package com.willfp.eco.internal.spigot.proxy.v1_19_R2 + +import com.willfp.eco.internal.spigot.proxy.CommonsInitializerProxy +import com.willfp.eco.internal.spigot.proxy.common.CommonsProvider +import com.willfp.eco.internal.spigot.proxy.common.toResourceLocation +import net.minecraft.core.registries.BuiltInRegistries +import net.minecraft.core.registries.Registries +import net.minecraft.nbt.CompoundTag +import net.minecraft.nbt.Tag +import net.minecraft.resources.ResourceLocation +import net.minecraft.world.entity.PathfinderMob +import net.minecraft.world.item.Item +import org.bukkit.Bukkit +import org.bukkit.Material +import org.bukkit.NamespacedKey +import org.bukkit.craftbukkit.v1_19_R2.CraftServer +import org.bukkit.craftbukkit.v1_19_R2.entity.CraftEntity +import org.bukkit.craftbukkit.v1_19_R2.entity.CraftMob +import org.bukkit.craftbukkit.v1_19_R2.inventory.CraftItemStack +import org.bukkit.craftbukkit.v1_19_R2.persistence.CraftPersistentDataContainer +import org.bukkit.craftbukkit.v1_19_R2.persistence.CraftPersistentDataTypeRegistry +import org.bukkit.craftbukkit.v1_19_R2.util.CraftMagicNumbers +import org.bukkit.craftbukkit.v1_19_R2.util.CraftNamespacedKey +import org.bukkit.entity.LivingEntity +import org.bukkit.entity.Mob +import org.bukkit.inventory.ItemStack +import org.bukkit.persistence.PersistentDataContainer +import java.lang.reflect.Field + +class CommonsInitializer : CommonsInitializerProxy { + override fun init() { + CommonsProvider.setIfNeeded(CommonsProviderImpl) + } + + object CommonsProviderImpl : CommonsProvider { + private val cisHandle: Field = CraftItemStack::class.java.getDeclaredField("handle").apply { + isAccessible = true + } + + private val pdcRegsitry = Class.forName("org.bukkit.craftbukkit.v1_19_R2.inventory.CraftMetaItem") + .getDeclaredField("DATA_TYPE_REGISTRY") + .apply { isAccessible = true } + .get(null) as CraftPersistentDataTypeRegistry + + override val nbtTagString = CraftMagicNumbers.NBT.TAG_STRING + + override fun toPathfinderMob(mob: Mob): PathfinderMob? { + val craft = mob as? CraftMob ?: return null + return craft.handle as? PathfinderMob + } + + override fun toResourceLocation(namespacedKey: NamespacedKey): ResourceLocation = + CraftNamespacedKey.toMinecraft(namespacedKey) + + override fun asNMSStack(itemStack: ItemStack): net.minecraft.world.item.ItemStack { + return if (itemStack !is CraftItemStack) { + CraftItemStack.asNMSCopy(itemStack) + } else { + cisHandle[itemStack] as net.minecraft.world.item.ItemStack? ?: CraftItemStack.asNMSCopy(itemStack) + } + } + + override fun asBukkitStack(itemStack: net.minecraft.world.item.ItemStack): ItemStack { + return CraftItemStack.asBukkitCopy(itemStack) + } + + override fun mergeIfNeeded(itemStack: ItemStack, nmsStack: net.minecraft.world.item.ItemStack) { + if (itemStack !is CraftItemStack) { + itemStack.itemMeta = CraftItemStack.asCraftMirror(nmsStack).itemMeta + } + } + + override fun toBukkitEntity(entity: net.minecraft.world.entity.LivingEntity): LivingEntity? = + CraftEntity.getEntity(Bukkit.getServer() as CraftServer, entity) as? LivingEntity + + override fun makePdc(tag: CompoundTag, base: Boolean): PersistentDataContainer { + fun emptyPdc(): CraftPersistentDataContainer = CraftPersistentDataContainer(pdcRegsitry) + + fun CompoundTag?.toPdc(): PersistentDataContainer { + val pdc = emptyPdc() + this ?: return pdc + val keys = this.allKeys + for (key in keys) { + pdc.put(key, this[key]) + } + + return pdc + } + + return if (base) { + tag.toPdc() + } else { + if (tag.contains("PublicBukkitValues")) { + tag.getCompound("PublicBukkitValues").toPdc() + } else { + emptyPdc() + } + } + } + + override fun setPdc( + tag: CompoundTag, + pdc: PersistentDataContainer?, + item: net.minecraft.world.item.ItemStack? + ) { + fun CraftPersistentDataContainer.toTag(): CompoundTag { + val compound = CompoundTag() + val rawPublicMap: Map = this.raw + for ((key, value) in rawPublicMap) { + compound.put(key, value) + } + + return compound + } + + val container = when (pdc) { + is CraftPersistentDataContainer? -> pdc + else -> null + } + + if (item != null) { + if (container != null && !container.isEmpty) { + for (key in tag.allKeys.toSet()) { + tag.remove(key) + } + + tag.merge(container.toTag()) + } else { + item.setTag(null) + } + } else { + if (container != null && !container.isEmpty) { + tag.put("PublicBukkitValues", container.toTag()) + } else { + tag.remove("PublicBukkitValues") + } + } + } + + override fun materialToItem(material: Material): Item = + BuiltInRegistries.ITEM.getOptional(material.key.toResourceLocation()) + .orElseThrow { IllegalArgumentException("Material is not item!") } + + override fun itemToMaterial(item: Item) = + Material.getMaterial(BuiltInRegistries.ITEM.getKey(item).path.uppercase()) + ?: throw IllegalArgumentException("Invalid material!") + } +} diff --git a/eco-core/core-nms/v1_19_R2/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_19_R2/DummyEntityFactory.kt b/eco-core/core-nms/v1_19_R2/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_19_R2/DummyEntityFactory.kt new file mode 100644 index 00000000..8053c0bb --- /dev/null +++ b/eco-core/core-nms/v1_19_R2/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_19_R2/DummyEntityFactory.kt @@ -0,0 +1,16 @@ +package com.willfp.eco.internal.spigot.proxy.v1_19_R2 + +import com.willfp.eco.internal.entities.EcoDummyEntity +import com.willfp.eco.internal.spigot.proxy.DummyEntityFactoryProxy +import org.bukkit.Location +import org.bukkit.craftbukkit.v1_19_R2.CraftWorld +import org.bukkit.entity.Entity +import org.bukkit.entity.EntityType + +class DummyEntityFactory : DummyEntityFactoryProxy { + override fun createDummyEntity(location: Location): Entity { + val world = location.world as CraftWorld + @Suppress("UsePropertyAccessSyntax") + return EcoDummyEntity(world.createEntity(location, EntityType.ZOMBIE.entityClass).getBukkitEntity()) + } +} diff --git a/eco-core/core-nms/v1_19_R2/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_19_R2/EntityControllerFactory.kt b/eco-core/core-nms/v1_19_R2/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_19_R2/EntityControllerFactory.kt new file mode 100644 index 00000000..fd542d9d --- /dev/null +++ b/eco-core/core-nms/v1_19_R2/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_19_R2/EntityControllerFactory.kt @@ -0,0 +1,12 @@ +package com.willfp.eco.internal.spigot.proxy.v1_19_R2 + +import com.willfp.eco.core.entities.ai.EntityController +import com.willfp.eco.internal.spigot.proxy.EntityControllerFactoryProxy +import com.willfp.eco.internal.spigot.proxy.common.ai.EcoEntityController +import org.bukkit.entity.Mob + +class EntityControllerFactory : EntityControllerFactoryProxy { + override fun createEntityController(entity: T): EntityController { + return EcoEntityController(entity) + } +} diff --git a/eco-core/core-nms/v1_19_R2/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_19_R2/ExtendedPersistentDataContainerFactory.kt b/eco-core/core-nms/v1_19_R2/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_19_R2/ExtendedPersistentDataContainerFactory.kt new file mode 100644 index 00000000..ce011f14 --- /dev/null +++ b/eco-core/core-nms/v1_19_R2/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_19_R2/ExtendedPersistentDataContainerFactory.kt @@ -0,0 +1,83 @@ +package com.willfp.eco.internal.spigot.proxy.v1_19_R2 + +import com.willfp.eco.core.data.ExtendedPersistentDataContainer +import com.willfp.eco.internal.spigot.proxy.ExtendedPersistentDataContainerFactoryProxy +import net.minecraft.nbt.Tag +import org.bukkit.Material +import org.bukkit.craftbukkit.v1_19_R2.inventory.CraftItemStack +import org.bukkit.craftbukkit.v1_19_R2.persistence.CraftPersistentDataContainer +import org.bukkit.craftbukkit.v1_19_R2.persistence.CraftPersistentDataTypeRegistry +import org.bukkit.inventory.ItemStack +import org.bukkit.persistence.PersistentDataContainer +import org.bukkit.persistence.PersistentDataType + +class ExtendedPersistentDataContainerFactory : ExtendedPersistentDataContainerFactoryProxy { + @Suppress("UNCHECKED_CAST") + private val registry: CraftPersistentDataTypeRegistry + + init { + /* + Can't grab actual instance since it's in CraftMetaItem (which is package-private) + And getting it would mean more janky reflection + */ + val item = CraftItemStack.asCraftCopy(ItemStack(Material.STONE)) + val pdc = item.itemMeta!!.persistentDataContainer + this.registry = CraftPersistentDataContainer::class.java.getDeclaredField("registry") + .apply { isAccessible = true }.get(pdc) as CraftPersistentDataTypeRegistry + } + + override fun adapt(pdc: PersistentDataContainer): ExtendedPersistentDataContainer { + return when (pdc) { + is CraftPersistentDataContainer -> EcoPersistentDataContainer(pdc) + else -> throw IllegalArgumentException("Custom PDC instance ims not supported!") + } + } + + override fun newPdc(): PersistentDataContainer { + return CraftPersistentDataContainer(registry) + } + + inner class EcoPersistentDataContainer( + val handle: CraftPersistentDataContainer + ) : ExtendedPersistentDataContainer { + @Suppress("UNCHECKED_CAST") + private val customDataTags: MutableMap = + CraftPersistentDataContainer::class.java.getDeclaredField("customDataTags") + .apply { isAccessible = true }.get(handle) as MutableMap + + override fun set(key: String, dataType: PersistentDataType, value: Z) { + customDataTags[key] = + registry.wrap(dataType.primitiveType, dataType.toPrimitive(value, handle.adapterContext)) + } + + override fun has(key: String, dataType: PersistentDataType): Boolean { + val value = customDataTags[key] ?: return false + return registry.isInstanceOf(dataType.primitiveType, value) + } + + override fun get(key: String, dataType: PersistentDataType): Z? { + val value = customDataTags[key] ?: return null + return dataType.fromPrimitive(registry.extract(dataType.primitiveType, value), handle.adapterContext) + } + + override fun getOrDefault( + key: String, + dataType: PersistentDataType, + defaultValue: Z + ): Z { + return get(key, dataType) ?: defaultValue + } + + override fun remove(key: String) { + customDataTags.remove(key) + } + + override fun getAllKeys(): MutableSet { + return customDataTags.keys + } + + override fun getBase(): PersistentDataContainer { + return handle + } + } +} diff --git a/eco-core/core-nms/v1_19_R2/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_19_R2/FastItemStackFactory.kt b/eco-core/core-nms/v1_19_R2/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_19_R2/FastItemStackFactory.kt new file mode 100644 index 00000000..6df8247a --- /dev/null +++ b/eco-core/core-nms/v1_19_R2/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_19_R2/FastItemStackFactory.kt @@ -0,0 +1,12 @@ +package com.willfp.eco.internal.spigot.proxy.v1_19_R2 + +import com.willfp.eco.core.fast.FastItemStack +import com.willfp.eco.internal.spigot.proxy.FastItemStackFactoryProxy +import com.willfp.eco.internal.spigot.proxy.common.item.EcoFastItemStack +import org.bukkit.inventory.ItemStack + +class FastItemStackFactory : FastItemStackFactoryProxy { + override fun create(itemStack: ItemStack): FastItemStack { + return EcoFastItemStack(itemStack) + } +} \ No newline at end of file diff --git a/eco-core/core-nms/v1_19_R2/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_19_R2/MiniMessageTranslator.kt b/eco-core/core-nms/v1_19_R2/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_19_R2/MiniMessageTranslator.kt new file mode 100644 index 00000000..dfc9f6ba --- /dev/null +++ b/eco-core/core-nms/v1_19_R2/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_19_R2/MiniMessageTranslator.kt @@ -0,0 +1,33 @@ +package com.willfp.eco.internal.spigot.proxy.v1_19_R2 + +import com.willfp.eco.core.display.Display +import com.willfp.eco.internal.spigot.proxy.MiniMessageTranslatorProxy +import com.willfp.eco.util.toLegacy +import net.kyori.adventure.text.minimessage.MiniMessage + +class MiniMessageTranslator : MiniMessageTranslatorProxy { + override fun format(message: String): String { + var mut = message + + val startsWithPrefix = mut.startsWith(Display.PREFIX) + if (startsWithPrefix) { + mut = mut.substring(2) + } + + mut = mut.replace('ยง', '&') + + val miniMessage = runCatching { + MiniMessage.miniMessage().deserialize( + mut + ).toLegacy() + }.getOrNull() ?: mut + + mut = if (startsWithPrefix) { + Display.PREFIX + miniMessage + } else { + miniMessage + } + + return mut + } +} diff --git a/eco-core/core-nms/v1_19_R2/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_19_R2/SNBTConverter.kt b/eco-core/core-nms/v1_19_R2/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_19_R2/SNBTConverter.kt new file mode 100644 index 00000000..bf94e70d --- /dev/null +++ b/eco-core/core-nms/v1_19_R2/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_19_R2/SNBTConverter.kt @@ -0,0 +1,52 @@ +package com.willfp.eco.internal.spigot.proxy.v1_19_R2 + +import com.willfp.eco.core.items.TestableItem +import com.willfp.eco.core.recipe.parts.EmptyTestableItem +import com.willfp.eco.internal.spigot.proxy.SNBTConverterProxy +import net.minecraft.nbt.CompoundTag +import net.minecraft.nbt.SnbtPrinterTagVisitor +import net.minecraft.nbt.TagParser +import org.bukkit.craftbukkit.v1_19_R2.inventory.CraftItemStack +import org.bukkit.inventory.ItemStack + +class SNBTConverter : SNBTConverterProxy { + override fun fromSNBT(snbt: String): ItemStack? { + val nbt = runCatching { TagParser.parseTag(snbt) }.getOrNull() ?: return null + val nms = net.minecraft.world.item.ItemStack.of(nbt) + return CraftItemStack.asBukkitCopy(nms) + } + + override fun toSNBT(itemStack: ItemStack): String { + val nms = CraftItemStack.asNMSCopy(itemStack) + return SnbtPrinterTagVisitor().visit(nms.save(CompoundTag())) + } + + override fun makeSNBTTestable(snbt: String): TestableItem { + val nbt = runCatching { TagParser.parseTag(snbt) }.getOrNull() ?: return EmptyTestableItem() + val nms = net.minecraft.world.item.ItemStack.of(nbt) + if (nms == net.minecraft.world.item.ItemStack.EMPTY) { + return EmptyTestableItem() + } + + nbt.remove("Count") + return SNBTTestableItem(CraftItemStack.asBukkitCopy(nms), nbt) + } + + class SNBTTestableItem( + private val item: ItemStack, + private val tag: CompoundTag + ) : TestableItem { + override fun matches(itemStack: ItemStack?): Boolean { + if (itemStack == null) { + return false + } + + val nms = CraftItemStack.asNMSCopy(itemStack) + val nmsTag = nms.save(CompoundTag()) + nmsTag.remove("Count") + return tag.copy().merge(nmsTag) == nmsTag + } + + override fun getItem(): ItemStack = item + } +} diff --git a/eco-core/core-nms/v1_19_R2/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_19_R2/Skull.kt b/eco-core/core-nms/v1_19_R2/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_19_R2/Skull.kt new file mode 100644 index 00000000..f0850f2e --- /dev/null +++ b/eco-core/core-nms/v1_19_R2/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_19_R2/Skull.kt @@ -0,0 +1,18 @@ +package com.willfp.eco.internal.spigot.proxy.v1_19_R2 + +import com.willfp.eco.internal.spigot.proxy.SkullProxy +import com.willfp.eco.internal.spigot.proxy.common.texture +import org.bukkit.inventory.meta.SkullMeta + +class Skull : SkullProxy { + override fun setSkullTexture( + meta: SkullMeta, + base64: String + ) { + meta.texture = base64 + } + + override fun getSkullTexture( + meta: SkullMeta + ): String? = meta.texture +} diff --git a/eco-core/core-nms/v1_19_R2/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_19_R2/TPS.kt b/eco-core/core-nms/v1_19_R2/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_19_R2/TPS.kt new file mode 100644 index 00000000..0d9c830f --- /dev/null +++ b/eco-core/core-nms/v1_19_R2/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_19_R2/TPS.kt @@ -0,0 +1,11 @@ +package com.willfp.eco.internal.spigot.proxy.v1_19_R2 + +import com.willfp.eco.internal.spigot.proxy.TPSProxy +import org.bukkit.Bukkit +import org.bukkit.craftbukkit.v1_19_R2.CraftServer + +class TPS : TPSProxy { + override fun getTPS(): Double { + return (Bukkit.getServer() as CraftServer).handle.server.recentTps[0] + } +} \ No newline at end of file diff --git a/eco-core/core-nms/v1_19_R2/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_19_R2/VillagerTrade.kt b/eco-core/core-nms/v1_19_R2/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_19_R2/VillagerTrade.kt new file mode 100644 index 00000000..7532943f --- /dev/null +++ b/eco-core/core-nms/v1_19_R2/src/main/kotlin/com/willfp/eco/internal/spigot/proxy/v1_19_R2/VillagerTrade.kt @@ -0,0 +1,41 @@ +package com.willfp.eco.internal.spigot.proxy.v1_19_R2 + +import com.willfp.eco.core.display.Display +import com.willfp.eco.internal.spigot.proxy.VillagerTradeProxy +import net.minecraft.nbt.CompoundTag +import net.minecraft.world.item.ItemStack +import net.minecraft.world.item.trading.MerchantOffer +import org.bukkit.craftbukkit.v1_19_R2.inventory.CraftItemStack +import org.bukkit.craftbukkit.v1_19_R2.inventory.CraftMerchantRecipe +import org.bukkit.entity.Player +import org.bukkit.inventory.MerchantRecipe +import java.lang.reflect.Field + +class VillagerTrade : VillagerTradeProxy { + private val handle: Field = CraftMerchantRecipe::class.java.getDeclaredField("handle") + + override fun displayTrade( + recipe: MerchantRecipe, + player: Player + ): MerchantRecipe { + recipe as CraftMerchantRecipe + + val nbt = getHandle(recipe).createTag() + for (tag in arrayOf("buy", "buyB", "sell")) { + val nms = ItemStack.of(nbt.getCompound(tag)) + val displayed = Display.display(CraftItemStack.asBukkitCopy(nms), player) + val itemNBT = CraftItemStack.asNMSCopy(displayed).save(CompoundTag()) + nbt.put(tag, itemNBT) + } + + return CraftMerchantRecipe(MerchantOffer(nbt)) + } + + private fun getHandle(recipe: CraftMerchantRecipe): MerchantOffer { + return handle[recipe] as MerchantOffer + } + + init { + handle.isAccessible = true + } +} \ No newline at end of file diff --git a/eco-core/core-plugin/build.gradle b/eco-core/core-plugin/build.gradle index 36eb6aa9..1f7fdf4a 100644 --- a/eco-core/core-plugin/build.gradle +++ b/eco-core/core-plugin/build.gradle @@ -51,10 +51,11 @@ dependencies { compileOnly 'com.github.N0RSKA:ScytherAPI:55a' compileOnly 'com.ticxo.modelengine:api:R3.0.1' compileOnly 'me.TechsCode:UltraEconomyAPI:1.0.0' + compileOnly 'com.github.Ssomar-Developement:SCore:3.4.7' // MythicMobs - compileOnly 'io.lumine:Mythic:5.0.1' - compileOnly 'io.lumine:LumineUtils:1.16.1-SNAPSHOT' + compileOnly 'io.lumine:Mythic:5.2.1' + compileOnly 'io.lumine:LumineUtils:1.19-SNAPSHOT' // CombatLogX V10 + NewbieHelper Expansion compileOnly 'com.SirBlobman.combatlogx:CombatLogX-API:10.0.0.0-SNAPSHOT' diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/integrations/customentities/CustomEntitiesMythicMobs.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/integrations/customentities/CustomEntitiesMythicMobs.kt index 9621768e..4bb44224 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/integrations/customentities/CustomEntitiesMythicMobs.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/integrations/customentities/CustomEntitiesMythicMobs.kt @@ -17,7 +17,7 @@ class CustomEntitiesMythicMobs : CustomEntitiesIntegration { CustomEntity( key, { - val entityId = api.getMythicMobInstance(it)?.type?.entityType ?: return@CustomEntity false + val entityId = api.getMythicMobInstance(it)?.type?.entityType?.name ?: return@CustomEntity false entityId.equals(id, ignoreCase = true) }, { diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/integrations/customitems/CustomItemsExecutableItems.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/integrations/customitems/CustomItemsExecutableItems.kt index 0fa86149..a302d7d4 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/integrations/customitems/CustomItemsExecutableItems.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/integrations/customitems/CustomItemsExecutableItems.kt @@ -1,6 +1,6 @@ package com.willfp.eco.internal.spigot.integrations.customitems -import com.ssomar.executableitems.api.ExecutableItemsAPI +import com.ssomar.score.api.executableitems.ExecutableItemsAPI import com.willfp.eco.core.integrations.customitems.CustomItemsIntegration import com.willfp.eco.core.items.CustomItem import com.willfp.eco.core.items.Items @@ -8,6 +8,7 @@ import com.willfp.eco.core.items.TestableItem import com.willfp.eco.core.items.provider.ItemProvider import com.willfp.eco.util.NamespacedKeyUtils import org.bukkit.inventory.ItemStack +import java.util.Optional import java.util.function.Predicate class CustomItemsExecutableItems : CustomItemsIntegration { @@ -21,15 +22,15 @@ class CustomItemsExecutableItems : CustomItemsIntegration { private class ExecutableItemsProvider : ItemProvider("executableitems") { override fun provideForKey(key: String): TestableItem? { - val item = ExecutableItemsAPI.getExecutableItem(key) ?: return null + val item = ExecutableItemsAPI.getExecutableItemsManager().getExecutableItem(key).orElse(null) ?: return null val namespacedKey = NamespacedKeyUtils.create("executableitems", key) return CustomItem( namespacedKey, Predicate { test: ItemStack -> - val customStack = ExecutableItemsAPI.getExecutableItemConfig(test) ?: return@Predicate false + val customStack = ExecutableItemsAPI.getExecutableItemsManager().getExecutableItem(test).orElse(null) ?: return@Predicate false customStack.id.equals(key, ignoreCase = true) }, - item + item.buildItem(1, Optional.empty()) ) } } diff --git a/gradle.properties b/gradle.properties index fa723f55..9c2fe539 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ -version = 6.47.0 +version = 6.48.3 plugin-name = eco kotlin.code.style = official \ No newline at end of file diff --git a/lib/ExecutableItems-4.1.3.3.jar b/lib/ExecutableItems-4.1.3.3.jar deleted file mode 100644 index 863a46cc..00000000 Binary files a/lib/ExecutableItems-4.1.3.3.jar and /dev/null differ diff --git a/lib/SCore-1.6.4.3.jar b/lib/SCore-1.6.4.3.jar deleted file mode 100644 index bc2422da..00000000 Binary files a/lib/SCore-1.6.4.3.jar and /dev/null differ diff --git a/settings.gradle.kts b/settings.gradle.kts index f528f307..3ae0770e 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -16,6 +16,7 @@ include(":eco-core:core-nms:v1_17_R1") include(":eco-core:core-nms:v1_18_R1") include(":eco-core:core-nms:v1_18_R2") include(":eco-core:core-nms:v1_19_R1") +include(":eco-core:core-nms:v1_19_R2") include(":eco-core:core-proxy") include(":eco-core:core-plugin") include(":eco-core:core-backend") \ No newline at end of file