Compare commits
22 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3f8759b08a | ||
|
|
abecaa6e9f | ||
|
|
4744bfc78b | ||
|
|
487e68221a | ||
|
|
1c68992a8e | ||
|
|
c5b7d0b644 | ||
|
|
0f91aec3b7 | ||
|
|
d2bf38c5c9 | ||
|
|
2c96b79aba | ||
|
|
d539b9e59e | ||
|
|
b0b06ef402 | ||
|
|
7a84c3de3b | ||
|
|
9431321e1c | ||
|
|
4816284fba | ||
|
|
a9874c9386 | ||
|
|
fe68760184 | ||
|
|
5ae8e72a98 | ||
|
|
15fc6053c8 | ||
|
|
1f7cf78491 | ||
|
|
fc3c80f633 | ||
|
|
2bcbf181a9 | ||
|
|
7adcdd572d |
@@ -24,6 +24,7 @@ dependencies {
|
||||
implementation(project(path = ":eco-core:core-nms:v1_17_R1", configuration = "reobf"))
|
||||
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"))
|
||||
}
|
||||
|
||||
allprojects {
|
||||
|
||||
@@ -15,6 +15,7 @@ import com.willfp.eco.core.factory.RunnableFactory;
|
||||
import com.willfp.eco.core.fast.FastItemStack;
|
||||
import com.willfp.eco.core.gui.GUIFactory;
|
||||
import com.willfp.eco.core.integrations.placeholder.PlaceholderIntegration;
|
||||
import com.willfp.eco.core.items.SNBTHandler;
|
||||
import com.willfp.eco.core.proxy.Cleaner;
|
||||
import com.willfp.eco.core.proxy.ProxyFactory;
|
||||
import com.willfp.eco.core.scheduling.Scheduler;
|
||||
@@ -282,8 +283,7 @@ public interface Handler {
|
||||
* @param <T> The mob type.
|
||||
* @return The controlled entity.
|
||||
*/
|
||||
@NotNull
|
||||
<T extends Mob> EntityController<T> createEntityController(@NotNull T mob);
|
||||
@NotNull <T extends Mob> EntityController<T> createEntityController(@NotNull T mob);
|
||||
|
||||
/**
|
||||
* Adapt base PDC to extended PDC.
|
||||
@@ -301,4 +301,12 @@ public interface Handler {
|
||||
*/
|
||||
@NotNull
|
||||
PersistentDataContainer newPdc();
|
||||
|
||||
/**
|
||||
* Get SNBT handler.
|
||||
*
|
||||
* @return The SNBT handler.
|
||||
*/
|
||||
@NotNull
|
||||
SNBTHandler getSNBTHandler();
|
||||
}
|
||||
|
||||
@@ -28,6 +28,26 @@ public interface Slot {
|
||||
*/
|
||||
boolean isCaptive();
|
||||
|
||||
/**
|
||||
* If the slot is not captive for a player.
|
||||
*
|
||||
* @param player The player.
|
||||
* @return If not captive for the player.
|
||||
*/
|
||||
default boolean isNotCaptiveFor(@NotNull Player player) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the slot is captive from empty.
|
||||
* If true, a captive item will be returned even if the item is the same as the rendered item.
|
||||
*
|
||||
* @return If captive from empty.
|
||||
*/
|
||||
default boolean isCaptiveFromEmpty() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a builder for an ItemStack.
|
||||
*
|
||||
|
||||
@@ -3,10 +3,12 @@ package com.willfp.eco.core.gui.slot;
|
||||
import com.willfp.eco.core.gui.slot.functional.SlotHandler;
|
||||
import com.willfp.eco.core.gui.slot.functional.SlotModifier;
|
||||
import com.willfp.eco.core.gui.slot.functional.SlotUpdater;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/**
|
||||
* Builder to create slots.
|
||||
@@ -102,6 +104,14 @@ public interface SlotBuilder {
|
||||
*/
|
||||
SlotBuilder onMiddleClick(@NotNull SlotHandler handler);
|
||||
|
||||
/**
|
||||
* Prevent captive for players that match a predicate.
|
||||
*
|
||||
* @param predicate The predicate. Returns true when the slot should not be captive.
|
||||
* @return The builder.
|
||||
*/
|
||||
SlotBuilder notCaptiveFor(@NotNull Predicate<Player> predicate);
|
||||
|
||||
/**
|
||||
* Modify the ItemStack.
|
||||
*
|
||||
@@ -130,7 +140,17 @@ public interface SlotBuilder {
|
||||
*
|
||||
* @return The builder.
|
||||
*/
|
||||
SlotBuilder setCaptive();
|
||||
default SlotBuilder setCaptive() {
|
||||
return setCaptive(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set slot to be a captive slot.
|
||||
*
|
||||
* @param fromEmpty If an item with the same output as the rendered item counts as captive.
|
||||
* @return The builder.
|
||||
*/
|
||||
SlotBuilder setCaptive(boolean fromEmpty);
|
||||
|
||||
/**
|
||||
* Build the slot.
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.willfp.eco.core.items;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Exact testable items use the default .equals() method.
|
||||
* This class is package-private as it more or less defeats the point of TestableItem.
|
||||
* It's only for NBT lookups.
|
||||
*/
|
||||
class ExactTestableItem implements TestableItem {
|
||||
/**
|
||||
* The ItemStack.
|
||||
*/
|
||||
private final ItemStack item;
|
||||
|
||||
/**
|
||||
* Create a new ExactTestableItem.
|
||||
*
|
||||
* @param itemStack The ItemStack.
|
||||
*/
|
||||
ExactTestableItem(@NotNull final ItemStack itemStack) {
|
||||
this.item = itemStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(@Nullable final ItemStack itemStack) {
|
||||
return item.equals(itemStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem() {
|
||||
return item.clone();
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package com.willfp.eco.core.items;
|
||||
|
||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import com.github.benmanes.caffeine.cache.LoadingCache;
|
||||
import com.willfp.eco.core.Eco;
|
||||
import com.willfp.eco.core.fast.FastItemStack;
|
||||
import com.willfp.eco.core.items.args.LookupArgParser;
|
||||
import com.willfp.eco.core.items.provider.ItemProvider;
|
||||
@@ -185,6 +186,15 @@ public final class Items {
|
||||
*/
|
||||
@NotNull
|
||||
public static TestableItem lookup(@NotNull final String key) {
|
||||
if (key.startsWith("{")) {
|
||||
ItemStack generated = fromSNBT(key);
|
||||
if (generated != null) {
|
||||
return new ExactTestableItem(generated);
|
||||
} else {
|
||||
return new EmptyTestableItem();
|
||||
}
|
||||
}
|
||||
|
||||
return ITEMS_LOOKUP_HANDLER.parseKey(key);
|
||||
}
|
||||
|
||||
@@ -520,6 +530,28 @@ public final class Items {
|
||||
return fis.unwrap();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert item to SNBT.
|
||||
*
|
||||
* @param itemStack The item.
|
||||
* @return The NBT string.
|
||||
*/
|
||||
@NotNull
|
||||
public static String toSNBT(@NotNull final ItemStack itemStack) {
|
||||
return Eco.getHandler().getSNBTHandler().toSNBT(itemStack);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get item from SNBT.
|
||||
*
|
||||
* @param snbt The NBT string.
|
||||
* @return The ItemStack, or null if invalid.
|
||||
*/
|
||||
@Nullable
|
||||
public static ItemStack fromSNBT(@NotNull final String snbt) {
|
||||
return Eco.getHandler().getSNBTHandler().fromSNBT(snbt);
|
||||
}
|
||||
|
||||
private Items() {
|
||||
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.willfp.eco.core.items;
|
||||
|
||||
import com.willfp.eco.core.Eco;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* API to handle SNBT conversion.
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
@Eco.HandlerComponent
|
||||
public interface SNBTHandler {
|
||||
/**
|
||||
* Get item from SNBT.
|
||||
*
|
||||
* @param snbt The NBT string.
|
||||
* @return The ItemStack, or null if invalid.
|
||||
*/
|
||||
@Nullable
|
||||
ItemStack fromSNBT(@NotNull String snbt);
|
||||
|
||||
/**
|
||||
* Convert item to SNBT.
|
||||
*
|
||||
* @param itemStack The item.
|
||||
* @return The NBT string.
|
||||
*/
|
||||
@NotNull
|
||||
String toSNBT(@NotNull ItemStack itemStack);
|
||||
}
|
||||
@@ -20,7 +20,8 @@ public final class ProxyConstants {
|
||||
public static final List<String> SUPPORTED_VERSIONS = Arrays.asList(
|
||||
"v1_17_R1",
|
||||
"v1_18_R1",
|
||||
"v1_18_R2"
|
||||
"v1_18_R2",
|
||||
"v1_19_R1"
|
||||
);
|
||||
|
||||
private ProxyConstants() {
|
||||
|
||||
@@ -20,6 +20,17 @@ public final class MenuUtils {
|
||||
return new Pair<>(row + 1, column + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert row and column to 0-53 slot.
|
||||
*
|
||||
* @param row The row.
|
||||
* @param column The column.
|
||||
* @return The slot.
|
||||
*/
|
||||
public static int rowColumnToSlot(final int row, final int column) {
|
||||
return (column - 1) + ((row - 1) * 9);
|
||||
}
|
||||
|
||||
private MenuUtils() {
|
||||
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
|
||||
}
|
||||
|
||||
@@ -32,6 +32,10 @@ fun SlotBuilder.onShiftRightClick(action: (InventoryClickEvent, Slot, Menu) -> U
|
||||
fun SlotBuilder.onMiddleClick(action: (InventoryClickEvent, Slot, Menu) -> Unit): SlotBuilder =
|
||||
this.onMiddleClick { a, b, c -> action(a, b, c) }
|
||||
|
||||
/** @see SlotBuilder.notCaptiveFor */
|
||||
fun SlotBuilder.notCaptiveFor(test: (Player) -> Boolean): SlotBuilder =
|
||||
this.notCaptiveFor { test(it) }
|
||||
|
||||
/**
|
||||
* @see SlotBuilder.setModifier
|
||||
* @deprecated Use SlotUpdater instead.
|
||||
|
||||
@@ -49,11 +49,13 @@ class EcoMenu(
|
||||
|
||||
player.openInventory(inventory)
|
||||
MenuHandler.registerInventory(inventory, this, player)
|
||||
inventory.asRenderedInventory()?.generateCaptive()
|
||||
return inventory
|
||||
}
|
||||
|
||||
fun handleClose(event: InventoryCloseEvent) {
|
||||
onClose.handle(event, this)
|
||||
event.inventory.asRenderedInventory()?.generateCaptive()
|
||||
MenuHandler.unregisterInventory(event.inventory)
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ class MenuRenderedInventory(
|
||||
menu.runOnRender(player)
|
||||
}
|
||||
|
||||
private fun generateCaptive() {
|
||||
fun generateCaptive() {
|
||||
captiveItems.clear()
|
||||
for (i in 0 until inventory.size) {
|
||||
val (row, column) = MenuUtils.convertSlotToRowColumn(i)
|
||||
@@ -43,7 +43,17 @@ class MenuRenderedInventory(
|
||||
val renderedItem = slot.getItemStack(player)
|
||||
val itemStack = inventory.getItem(i) ?: continue
|
||||
|
||||
if (itemStack == renderedItem || itemStack.type.isAir || itemStack.amount == 0) {
|
||||
if (slot.isNotCaptiveFor(player)) {
|
||||
continue
|
||||
}
|
||||
|
||||
if (!slot.isCaptiveFromEmpty) {
|
||||
if (itemStack == renderedItem) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
if (itemStack.type.isAir || itemStack.amount == 0) {
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
@@ -2,23 +2,36 @@ package com.willfp.eco.internal.gui.slot
|
||||
|
||||
import com.willfp.eco.core.gui.slot.functional.SlotHandler
|
||||
import com.willfp.eco.core.gui.slot.functional.SlotProvider
|
||||
import org.bukkit.entity.Player
|
||||
|
||||
class EcoCaptiveSlot(
|
||||
provider: SlotProvider
|
||||
provider: SlotProvider,
|
||||
private val captiveFromEmpty: Boolean,
|
||||
private val notCaptiveFor: (Player) -> Boolean
|
||||
) : EcoSlot(
|
||||
provider,
|
||||
allowMovingItem,
|
||||
allowMovingItem,
|
||||
allowMovingItem,
|
||||
allowMovingItem,
|
||||
allowMovingItem,
|
||||
captiveWithTest(notCaptiveFor),
|
||||
captiveWithTest(notCaptiveFor),
|
||||
captiveWithTest(notCaptiveFor),
|
||||
captiveWithTest(notCaptiveFor),
|
||||
captiveWithTest(notCaptiveFor),
|
||||
{ _, _, prev -> prev }
|
||||
) {
|
||||
override fun isCaptive(): Boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
override fun isCaptiveFromEmpty(): Boolean {
|
||||
return captiveFromEmpty
|
||||
}
|
||||
|
||||
override fun isNotCaptiveFor(player: Player): Boolean {
|
||||
return notCaptiveFor(player)
|
||||
}
|
||||
}
|
||||
|
||||
private val allowMovingItem = SlotHandler { event, _, _ ->
|
||||
event.isCancelled = false
|
||||
}
|
||||
private fun captiveWithTest(test: (Player) -> Boolean): SlotHandler {
|
||||
return SlotHandler { event, _, _ ->
|
||||
event.isCancelled = test(event.whoClicked as Player)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +1,39 @@
|
||||
package com.willfp.eco.internal.gui.slot
|
||||
|
||||
import com.willfp.eco.core.gui.menu.Menu
|
||||
import com.willfp.eco.core.gui.slot.Slot
|
||||
import com.willfp.eco.core.gui.slot.SlotBuilder
|
||||
import com.willfp.eco.core.gui.slot.functional.SlotHandler
|
||||
import com.willfp.eco.core.gui.slot.functional.SlotProvider
|
||||
import com.willfp.eco.core.gui.slot.functional.SlotUpdater
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.event.inventory.InventoryClickEvent
|
||||
import java.util.function.Predicate
|
||||
|
||||
internal object NoOpSlot : SlotHandler {
|
||||
override fun handle(event: InventoryClickEvent, slot: Slot, menu: Menu) {
|
||||
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
return other is NoOpSlot
|
||||
}
|
||||
}
|
||||
|
||||
internal class NoOpForPlayer
|
||||
|
||||
class EcoSlotBuilder(private val provider: SlotProvider) : SlotBuilder {
|
||||
private var captive = false
|
||||
private var captiveFromEmpty = false
|
||||
private var updater: SlotUpdater = SlotUpdater { player, menu, _ -> provider.provide(player, menu) }
|
||||
|
||||
private var onLeftClick =
|
||||
SlotHandler { _, _, _ -> run { } }
|
||||
private var onRightClick =
|
||||
SlotHandler { _, _, _ -> run { } }
|
||||
private var onShiftLeftClick =
|
||||
SlotHandler { _, _, _ -> run { } }
|
||||
private var onShiftRightClick =
|
||||
SlotHandler { _, _, _ -> run { } }
|
||||
private var onMiddleClick =
|
||||
SlotHandler { _, _, _ -> run { } }
|
||||
private var onLeftClick: SlotHandler = NoOpSlot
|
||||
private var onRightClick: SlotHandler = NoOpSlot
|
||||
private var onShiftLeftClick: SlotHandler = NoOpSlot
|
||||
private var onShiftRightClick: SlotHandler = NoOpSlot
|
||||
private var onMiddleClick: SlotHandler = NoOpSlot
|
||||
|
||||
private var notCaptiveFor: (Player) -> Boolean = { false }
|
||||
|
||||
override fun onLeftClick(action: SlotHandler): SlotBuilder {
|
||||
onLeftClick = action
|
||||
@@ -46,8 +60,14 @@ class EcoSlotBuilder(private val provider: SlotProvider) : SlotBuilder {
|
||||
return this
|
||||
}
|
||||
|
||||
override fun setCaptive(): SlotBuilder {
|
||||
override fun notCaptiveFor(predicate: Predicate<Player>): SlotBuilder {
|
||||
notCaptiveFor = { predicate.test(it) }
|
||||
return this
|
||||
}
|
||||
|
||||
override fun setCaptive(fromEmpty: Boolean): SlotBuilder {
|
||||
captive = true
|
||||
captiveFromEmpty = fromEmpty
|
||||
return this
|
||||
}
|
||||
|
||||
@@ -58,9 +78,21 @@ class EcoSlotBuilder(private val provider: SlotProvider) : SlotBuilder {
|
||||
|
||||
override fun build(): Slot {
|
||||
return if (captive) {
|
||||
EcoCaptiveSlot(provider)
|
||||
EcoCaptiveSlot(
|
||||
provider,
|
||||
captiveFromEmpty,
|
||||
notCaptiveFor
|
||||
)
|
||||
} else {
|
||||
EcoSlot(provider, onLeftClick, onRightClick, onShiftLeftClick, onShiftRightClick, onMiddleClick, updater)
|
||||
EcoSlot(
|
||||
provider,
|
||||
onLeftClick,
|
||||
onRightClick,
|
||||
onShiftLeftClick,
|
||||
onShiftRightClick,
|
||||
onMiddleClick,
|
||||
updater
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.willfp.eco.internal.spigot.proxy.v1_17_R1
|
||||
|
||||
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_17_R1.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()))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.willfp.eco.internal.spigot.proxy.v1_18_R1
|
||||
|
||||
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_18_R1.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()))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.willfp.eco.internal.spigot.proxy.v1_18_R2
|
||||
|
||||
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_18_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()))
|
||||
}
|
||||
}
|
||||
39
eco-core/core-nms/v1_19_R1/build.gradle.kts
Normal file
39
eco-core/core-nms/v1_19_R1/build.gradle.kts
Normal file
@@ -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-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_R1.common"
|
||||
)
|
||||
relocate(
|
||||
"net.kyori.adventure.text.minimessage",
|
||||
"com.willfp.eco.internal.spigot.proxy.v1_19_R1.minimessage"
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.willfp.eco.internal.spigot.proxy.v1_19_R1
|
||||
|
||||
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")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
package com.willfp.eco.internal.spigot.proxy.v1_19_R1
|
||||
|
||||
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_R1.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<Component>()
|
||||
for (arg in component.args()) {
|
||||
args.add(modifyBaseComponent(arg, player))
|
||||
}
|
||||
component = component.args(args)
|
||||
}
|
||||
|
||||
val children = mutableListOf<Component>()
|
||||
for (child in component.children()) {
|
||||
children.add(modifyBaseComponent(child, player))
|
||||
}
|
||||
component = component.children(children)
|
||||
|
||||
val hoverEvent: HoverEvent<Any> = component.style().hoverEvent() as HoverEvent<Any>? ?: 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)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
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 net.minecraft.nbt.CompoundTag
|
||||
import net.minecraft.nbt.Tag
|
||||
import net.minecraft.resources.ResourceLocation
|
||||
import net.minecraft.world.entity.PathfinderMob
|
||||
import org.bukkit.Bukkit
|
||||
import org.bukkit.NamespacedKey
|
||||
import org.bukkit.craftbukkit.v1_19_R1.CraftServer
|
||||
import org.bukkit.craftbukkit.v1_19_R1.entity.CraftEntity
|
||||
import org.bukkit.craftbukkit.v1_19_R1.entity.CraftMob
|
||||
import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack
|
||||
import org.bukkit.craftbukkit.v1_19_R1.persistence.CraftPersistentDataContainer
|
||||
import org.bukkit.craftbukkit.v1_19_R1.persistence.CraftPersistentDataTypeRegistry
|
||||
import org.bukkit.craftbukkit.v1_19_R1.util.CraftMagicNumbers
|
||||
import org.bukkit.craftbukkit.v1_19_R1.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_R1.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<String, Tag> = 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")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.willfp.eco.internal.spigot.proxy.v1_19_R1
|
||||
|
||||
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_R1.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())
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.willfp.eco.internal.spigot.proxy.v1_19_R1
|
||||
|
||||
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 <T : Mob> createEntityController(entity: T): EntityController<T> {
|
||||
return EcoEntityController(entity)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package com.willfp.eco.internal.spigot.proxy.v1_19_R1
|
||||
|
||||
import com.willfp.eco.core.data.ExtendedPersistentDataContainer
|
||||
import com.willfp.eco.internal.spigot.proxy.ExtendedPersistentDataContainerFactoryProxy
|
||||
import net.minecraft.nbt.Tag
|
||||
import org.bukkit.craftbukkit.v1_19_R1.persistence.CraftPersistentDataContainer
|
||||
import org.bukkit.craftbukkit.v1_19_R1.persistence.CraftPersistentDataTypeRegistry
|
||||
import org.bukkit.persistence.PersistentDataContainer
|
||||
import org.bukkit.persistence.PersistentDataType
|
||||
|
||||
class ExtendedPersistentDataContainerFactory: ExtendedPersistentDataContainerFactoryProxy {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
private val registry: CraftPersistentDataTypeRegistry =
|
||||
CraftPersistentDataContainer::class.java.getDeclaredField("registry")
|
||||
.apply { isAccessible = true }.get(null) as CraftPersistentDataTypeRegistry
|
||||
|
||||
override fun adapt(pdc: PersistentDataContainer): ExtendedPersistentDataContainer {
|
||||
return when (pdc) {
|
||||
is CraftPersistentDataContainer -> EcoPersistentDataContainer(pdc)
|
||||
else -> throw IllegalArgumentException("Custom PDC instance is not supported!")
|
||||
}
|
||||
}
|
||||
|
||||
override fun newPdc(): PersistentDataContainer {
|
||||
return CraftPersistentDataContainer(registry)
|
||||
}
|
||||
|
||||
inner class EcoPersistentDataContainer(
|
||||
val handle: CraftPersistentDataContainer
|
||||
) : ExtendedPersistentDataContainer {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
private val customDataTags: MutableMap<String, Tag> =
|
||||
CraftPersistentDataContainer::class.java.getDeclaredField("customDataTags")
|
||||
.apply { isAccessible = true }.get(handle) as MutableMap<String, Tag>
|
||||
|
||||
override fun <T : Any, Z : Any> set(key: String, dataType: PersistentDataType<T, Z>, value: Z) {
|
||||
customDataTags[key] = registry.wrap(dataType.primitiveType, dataType.toPrimitive(value, handle.adapterContext))
|
||||
}
|
||||
|
||||
override fun <T : Any, Z : Any> has(key: String, dataType: PersistentDataType<T, Z>): Boolean {
|
||||
val value = customDataTags[key] ?: return false
|
||||
return registry.isInstanceOf(dataType.primitiveType, value)
|
||||
}
|
||||
|
||||
override fun <T : Any, Z : Any> get(key: String, dataType: PersistentDataType<T, Z>): Z? {
|
||||
val value = customDataTags[key] ?: return null
|
||||
return dataType.fromPrimitive(registry.extract(dataType.primitiveType, value), handle.adapterContext)
|
||||
}
|
||||
|
||||
override fun <T : Any, Z : Any> getOrDefault(
|
||||
key: String,
|
||||
dataType: PersistentDataType<T, Z>,
|
||||
defaultValue: Z
|
||||
): Z {
|
||||
return get(key, dataType) ?: defaultValue
|
||||
}
|
||||
|
||||
override fun remove(key: String) {
|
||||
customDataTags.remove(key)
|
||||
}
|
||||
|
||||
override fun getAllKeys(): MutableSet<String> {
|
||||
return customDataTags.keys
|
||||
}
|
||||
|
||||
override fun getBase(): PersistentDataContainer {
|
||||
return handle
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.willfp.eco.internal.spigot.proxy.v1_19_R1
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.willfp.eco.internal.spigot.proxy.v1_19_R1
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.willfp.eco.internal.spigot.proxy.v1_19_R1
|
||||
|
||||
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_R1.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()))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.willfp.eco.internal.spigot.proxy.v1_19_R1
|
||||
|
||||
import com.mojang.authlib.GameProfile
|
||||
import com.mojang.authlib.properties.Property
|
||||
import com.willfp.eco.internal.spigot.proxy.SkullProxy
|
||||
import org.bukkit.inventory.meta.SkullMeta
|
||||
import java.lang.reflect.Field
|
||||
import java.lang.reflect.Method
|
||||
import java.util.UUID
|
||||
|
||||
class Skull : SkullProxy {
|
||||
private lateinit var setProfile: Method
|
||||
private lateinit var profile: Field
|
||||
|
||||
override fun setSkullTexture(
|
||||
meta: SkullMeta,
|
||||
base64: String
|
||||
) {
|
||||
if (!this::setProfile.isInitialized) {
|
||||
setProfile = meta.javaClass.getDeclaredMethod("setProfile", GameProfile::class.java)
|
||||
setProfile.isAccessible = true
|
||||
}
|
||||
if (base64.length < 20) {
|
||||
return
|
||||
}
|
||||
|
||||
val uuid = UUID(
|
||||
base64.substring(base64.length - 20).hashCode().toLong(),
|
||||
base64.substring(base64.length - 10).hashCode().toLong()
|
||||
)
|
||||
val profile = GameProfile(uuid, "eco")
|
||||
profile.properties.put("textures", Property("textures", base64))
|
||||
setProfile.invoke(meta, profile)
|
||||
}
|
||||
|
||||
override fun getSkullTexture(
|
||||
meta: SkullMeta
|
||||
): String? {
|
||||
if (!this::profile.isInitialized) {
|
||||
profile = meta.javaClass.getDeclaredField("profile")
|
||||
profile.isAccessible = true
|
||||
}
|
||||
val profile = profile[meta] as GameProfile? ?: return null
|
||||
val properties = profile.properties ?: return null
|
||||
val prop = properties["textures"] ?: return null
|
||||
return prop.toMutableList().firstOrNull()?.name
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.willfp.eco.internal.spigot.proxy.v1_19_R1
|
||||
|
||||
import com.willfp.eco.internal.spigot.proxy.TPSProxy
|
||||
import org.bukkit.Bukkit
|
||||
import org.bukkit.craftbukkit.v1_19_R1.CraftServer
|
||||
|
||||
class TPS : TPSProxy {
|
||||
override fun getTPS(): Double {
|
||||
return (Bukkit.getServer() as CraftServer).handle.server.recentTps[0]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.willfp.eco.internal.spigot.proxy.v1_19_R1
|
||||
|
||||
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_R1.inventory.CraftItemStack
|
||||
import org.bukkit.craftbukkit.v1_19_R1.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
|
||||
}
|
||||
}
|
||||
@@ -47,7 +47,13 @@ private fun Plugin.getConflict(): Conflict? {
|
||||
return Conflict(this, ConflictType.LIB_LOADER)
|
||||
}
|
||||
|
||||
val zip = ZipFile(File(this::class.java.protectionDomain.codeSource.location.toURI()))
|
||||
val file = File(this::class.java.protectionDomain.codeSource.location.toURI())
|
||||
|
||||
if (!file.exists() || file.name.contains("PolymartHelper")) {
|
||||
return null
|
||||
}
|
||||
|
||||
val zip = ZipFile(file)
|
||||
|
||||
for (entry in zip.entries()) {
|
||||
if (entry.name.startsWith("kotlin/") || entry.name.startsWith("kotlinx/")) {
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.willfp.eco.core.data.ExtendedPersistentDataContainer
|
||||
import com.willfp.eco.core.entities.ai.EntityController
|
||||
import com.willfp.eco.core.fast.FastItemStack
|
||||
import com.willfp.eco.core.integrations.placeholder.PlaceholderIntegration
|
||||
import com.willfp.eco.core.items.SNBTHandler
|
||||
import com.willfp.eco.internal.EcoCleaner
|
||||
import com.willfp.eco.internal.EcoPropsParser
|
||||
import com.willfp.eco.internal.Plugins
|
||||
@@ -31,6 +32,7 @@ import com.willfp.eco.internal.spigot.data.EcoKeyRegistry
|
||||
import com.willfp.eco.internal.spigot.data.EcoProfileHandler
|
||||
import com.willfp.eco.internal.spigot.data.storage.HandlerType
|
||||
import com.willfp.eco.internal.spigot.integrations.bstats.MetricHandler
|
||||
import com.willfp.eco.internal.spigot.items.EcoSNBTHandler
|
||||
import com.willfp.eco.internal.spigot.proxy.CommonsInitializerProxy
|
||||
import com.willfp.eco.internal.spigot.proxy.DummyEntityFactoryProxy
|
||||
import com.willfp.eco.internal.spigot.proxy.EntityControllerFactoryProxy
|
||||
@@ -70,6 +72,8 @@ class EcoHandler : EcoSpigotPlugin(), Handler {
|
||||
}, this
|
||||
)
|
||||
|
||||
private val snbtHandler = EcoSNBTHandler(this)
|
||||
|
||||
@Suppress("RedundantNullableReturnType")
|
||||
private val keyFactory: InternalNamespacedKeyFactory? =
|
||||
if (this.configYml.getBool("use-safer-namespacedkey-creation"))
|
||||
@@ -170,4 +174,7 @@ class EcoHandler : EcoSpigotPlugin(), Handler {
|
||||
|
||||
override fun newPdc(): PersistentDataContainer =
|
||||
getProxy(ExtendedPersistentDataContainerFactoryProxy::class.java).newPdc()
|
||||
|
||||
override fun getSNBTHandler(): SNBTHandler =
|
||||
snbtHandler
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.willfp.eco.internal.spigot.items
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin
|
||||
import com.willfp.eco.core.items.SNBTHandler
|
||||
import com.willfp.eco.internal.spigot.proxy.SNBTConverterProxy
|
||||
import org.bukkit.inventory.ItemStack
|
||||
|
||||
class EcoSNBTHandler(
|
||||
private val plugin: EcoPlugin
|
||||
) : SNBTHandler {
|
||||
override fun fromSNBT(snbt: String): ItemStack? =
|
||||
plugin.getProxy(SNBTConverterProxy::class.java).fromSNBT(snbt)
|
||||
|
||||
override fun toSNBT(itemStack: ItemStack): String =
|
||||
plugin.getProxy(SNBTConverterProxy::class.java).toSNBT(itemStack)
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.willfp.eco.internal.spigot.proxy
|
||||
|
||||
import org.bukkit.inventory.ItemStack
|
||||
|
||||
interface SNBTConverterProxy {
|
||||
fun toSNBT(itemStack: ItemStack): String
|
||||
fun fromSNBT(snbt: String): ItemStack?
|
||||
}
|
||||
@@ -1,3 +1,3 @@
|
||||
version = 6.36.1
|
||||
version = 6.37.0
|
||||
plugin-name = eco
|
||||
kotlin.code.style = official
|
||||
@@ -15,6 +15,7 @@ include(":eco-core:core-nms:nms-common")
|
||||
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-proxy")
|
||||
include(":eco-core:core-plugin")
|
||||
include(":eco-core:core-backend")
|
||||
Reference in New Issue
Block a user