diff --git a/README.md b/README.md index ae3dc28d9..88ab2185b 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Visit our website: https://pylonmc.github.io/ ## Warning > [!CAUTION] -> REBAR IS CURRENTLY EXPERIMENTAL. ONLY RUN IT ON A TEST SERVER THAT YOU ARE WILLING TO DELETE. THE NEXT PYLON VERSION WILL PROBABLY NOT BE COMPATIBLE WITH THE PREVIOUS ONE. IF YOU INSTALL REBAR SOMEWHERE YOU SHOULDN'T AND END UP LOSING DATA, WE WILL POINT AND LAUGH AT YOU +> REBAR IS CURRENTLY EXPERIMENTAL. ONLY RUN IT ON A TEST SERVER THAT YOU ARE WILLING TO DELETE. THE NEXT REBAR VERSION WILL PROBABLY NOT BE COMPATIBLE WITH THE PREVIOUS ONE. IF YOU INSTALL REBAR SOMEWHERE YOU SHOULDN'T AND END UP LOSING DATA, WE WILL POINT AND LAUGH AT YOU ## Rebar in pictures using-smeltery diff --git a/nms/src/main/kotlin/io/github/pylonmc/rebar/i18n/packet/PlayerPacketHandler.kt b/nms/src/main/kotlin/io/github/pylonmc/rebar/i18n/packet/PlayerPacketHandler.kt index b873168f6..3e45f7647 100644 --- a/nms/src/main/kotlin/io/github/pylonmc/rebar/i18n/packet/PlayerPacketHandler.kt +++ b/nms/src/main/kotlin/io/github/pylonmc/rebar/i18n/packet/PlayerPacketHandler.kt @@ -12,6 +12,7 @@ import io.netty.channel.ChannelPromise import io.papermc.paper.datacomponent.DataComponentTypes import net.minecraft.network.HashedPatchMap import net.minecraft.network.HashedStack +import net.minecraft.network.protocol.Packet import net.minecraft.network.protocol.game.* import net.minecraft.server.level.ServerPlayer import net.minecraft.util.HashOps @@ -51,83 +52,90 @@ class PlayerPacketHandler(private val player: ServerPlayer, private val handler: private inner class PacketHandler : ChannelDuplexHandler() { override fun write(ctx: ChannelHandlerContext, packet: Any, promise: ChannelPromise) { - var packet = packet - when (packet) { - is ClientboundContainerSetContentPacket -> { - packet.items.forEach(::translate) - translate(packet.carriedItem) - } + @Suppress("UNCHECKED_CAST") + super.write(ctx, handleOutgoingPacket(packet as Packet), promise) + } - is ClientboundContainerSetSlotPacket -> translate(packet.item) - is ClientboundSetCursorItemPacket -> translate(packet.contents) - is ClientboundRecipeBookAddPacket -> { - // This requires a full copy for some reason - packet = ClientboundRecipeBookAddPacket( - packet.entries.map { - ClientboundRecipeBookAddPacket.Entry( - RecipeDisplayEntry( - it.contents.id, - handleRecipeDisplay(it.contents.display), - it.contents.group, - it.contents.category, - it.contents.craftingRequirements - ), - it.flags - ) - }, - packet.replace - ) - } - is ClientboundMerchantOffersPacket -> { - for (offer in packet.offers) { - translate(offer.baseCostA.itemStack) - offer.costB.ifPresent { - translate(it.itemStack) - } - translate(offer.result) - } - } + override fun channelRead(ctx: ChannelHandlerContext, packet: Any) { + @Suppress("UNCHECKED_CAST") + super.channelRead(ctx, handleIncomingPacket(packet as Packet)) + } + } + + private fun handleOutgoingPacket(packet: Packet): Packet = + when (packet) { + is ClientboundBundlePacket -> ClientboundBundlePacket(packet.subPackets().map(::handleOutgoingPacket)) + + is ClientboundContainerSetContentPacket -> packet.apply { + items.forEach(::translate) + translate(packet.carriedItem) + } - is ClientboundPlaceGhostRecipePacket -> { - packet = ClientboundPlaceGhostRecipePacket( - packet.containerId, - handleRecipeDisplay(packet.recipeDisplay) + is ClientboundContainerSetSlotPacket -> packet.apply { translate(item) } + is ClientboundSetCursorItemPacket -> packet.apply { translate(contents) } + is ClientboundRecipeBookAddPacket -> ClientboundRecipeBookAddPacket( + packet.entries.map { + ClientboundRecipeBookAddPacket.Entry( + RecipeDisplayEntry( + it.contents.id, + handleRecipeDisplay(it.contents.display), + it.contents.group, + it.contents.category, + it.contents.craftingRequirements + ), + it.flags ) + }, + packet.replace + ) + + is ClientboundMerchantOffersPacket -> packet.apply { + for (offer in offers) { + translate(offer.baseCostA.itemStack) + offer.costB.ifPresent { + translate(it.itemStack) + } + translate(offer.result) } } - super.write(ctx, packet, promise) + + is ClientboundPlaceGhostRecipePacket -> ClientboundPlaceGhostRecipePacket( + packet.containerId, + handleRecipeDisplay(packet.recipeDisplay) + ) + + else -> packet } - override fun channelRead(ctx: ChannelHandlerContext, packet: Any) { - var packet = packet - packet = when (packet) { - is ServerboundContainerClickPacket -> ServerboundContainerClickPacket( - packet.containerId, - packet.stateId, - packet.slotNum, - packet.buttonNum, - packet.clickType, - packet.changedSlots, - if (packet.changedSlots.size == 1) { - HashedStack.create( - player.containerMenu.getSlot(packet.changedSlots.keys.single()).item, - hashGenerator - ) + private fun handleIncomingPacket(packet: Packet): Packet = + when (packet) { + is ServerboundContainerClickPacket -> ServerboundContainerClickPacket( + packet.containerId, + packet.stateId, + packet.slotNum, + packet.buttonNum, + packet.clickType, + packet.changedSlots, + if (packet.changedSlots.size == 1) { + val slot = packet.changedSlots.keys.single() + val menu = player.containerMenu + if (menu.isValidSlotIndex(slot)) { + HashedStack.create(menu.getSlot(slot).item, hashGenerator) } else { - HashedStack.create(player.containerMenu.carried, hashGenerator) + HashedStack.EMPTY } - ) + } else { + HashedStack.create(player.containerMenu.carried, hashGenerator) + } + ) - is ServerboundSetCreativeModeSlotPacket -> ServerboundSetCreativeModeSlotPacket( - packet.slotNum, - reset(packet.itemStack) - ) + is ServerboundSetCreativeModeSlotPacket -> ServerboundSetCreativeModeSlotPacket( + packet.slotNum, + reset(packet.itemStack) + ) - else -> packet - } - super.channelRead(ctx, packet) + else -> packet } - } private fun handleRecipeDisplay(display: RecipeDisplay): RecipeDisplay { return when (display) { @@ -242,6 +250,6 @@ class PlayerPacketHandler(private val player: ServerPlayer, private val handler: } companion object { - private const val HANDLER_NAME = "pylon_packet_handler" + private const val HANDLER_NAME = "rebar_packet_handler" } } \ No newline at end of file diff --git a/nms/src/main/kotlin/io/github/pylonmc/rebar/nms/NmsAccessorImpl.kt b/nms/src/main/kotlin/io/github/pylonmc/rebar/nms/NmsAccessorImpl.kt index a34736f47..537932b3d 100644 --- a/nms/src/main/kotlin/io/github/pylonmc/rebar/nms/NmsAccessorImpl.kt +++ b/nms/src/main/kotlin/io/github/pylonmc/rebar/nms/NmsAccessorImpl.kt @@ -35,7 +35,7 @@ import org.bukkit.entity.Player import org.bukkit.inventory.EquipmentSlot import org.bukkit.inventory.ItemStack import org.bukkit.persistence.PersistentDataContainer -import java.util.* +import java.util.UUID import java.util.concurrent.ConcurrentHashMap @Suppress("unused") diff --git a/nms/src/main/kotlin/io/github/pylonmc/rebar/nms/recipe/RebarServerPlaceRecipe.kt b/nms/src/main/kotlin/io/github/pylonmc/rebar/nms/recipe/RebarServerPlaceRecipe.kt index 832600095..a91763124 100644 --- a/nms/src/main/kotlin/io/github/pylonmc/rebar/nms/recipe/RebarServerPlaceRecipe.kt +++ b/nms/src/main/kotlin/io/github/pylonmc/rebar/nms/recipe/RebarServerPlaceRecipe.kt @@ -209,8 +209,8 @@ class RebarServerPlaceRecipe private constructor( ServerPlaceRecipe.CraftingMenuAccess::class.java, Inventory::class.java, Boolean::class.javaPrimitiveType, - Integer::class.javaPrimitiveType, - Integer::class.javaPrimitiveType, + Int::class.javaPrimitiveType, + Int::class.javaPrimitiveType, List::class.java, List::class.java ) diff --git a/nms/src/main/kotlin/io/github/pylonmc/rebar/nms/recipe/util/StackedItemContentsWrapper.kt b/nms/src/main/kotlin/io/github/pylonmc/rebar/nms/recipe/util/StackedItemContentsWrapper.kt index 87a5548ae..54fcf04a8 100644 --- a/nms/src/main/kotlin/io/github/pylonmc/rebar/nms/recipe/util/StackedItemContentsWrapper.kt +++ b/nms/src/main/kotlin/io/github/pylonmc/rebar/nms/recipe/util/StackedItemContentsWrapper.kt @@ -23,6 +23,7 @@ object StackedItemContentsWrapper { } } +@Suppress("UNCHECKED_CAST") fun StackedItemContents.getRaw(): StackedContents = rawGetter.invokeExact(this) as StackedContents /** diff --git a/rebar/build.gradle.kts b/rebar/build.gradle.kts index 6ef6196af..bee9d1739 100644 --- a/rebar/build.gradle.kts +++ b/rebar/build.gradle.kts @@ -40,10 +40,8 @@ dependencies { paperLibraryApi("com.github.shynixn.mccoroutine:mccoroutine-bukkit-api:2.22.0") paperLibraryApi("com.github.shynixn.mccoroutine:mccoroutine-bukkit-core:2.22.0") - paperLibraryApi("xyz.xenondevs.invui:invui-core:1.49") - // see https://github.com/NichtStudioCode/InvUI/blob/main/inventoryaccess/inventory-access/src/main/java/xyz/xenondevs/inventoryaccess/version/InventoryAccessRevision.java - paperLibrary("xyz.xenondevs.invui:inventory-access-r26:1.49:remapped-mojang") - paperLibraryApi("xyz.xenondevs.invui:invui-kotlin:1.49") + paperLibraryApi("xyz.xenondevs.invui:invui:2.0.0-beta.1") + paperLibraryApi("xyz.xenondevs.invui:invui-kotlin:2.0.0-beta.1") implementation("com.github.Tofaa2.EntityLib:spigot:a5184b3bdc") implementation("com.github.retrooper:packetevents-spigot:2.11.1") implementation("info.debatty:java-string-similarity:2.0.0") diff --git a/rebar/src/main/java/io/github/pylonmc/rebar/RebarLoader.java b/rebar/src/main/java/io/github/pylonmc/rebar/RebarLoader.java index 3162683eb..ef52f9d2b 100644 --- a/rebar/src/main/java/io/github/pylonmc/rebar/RebarLoader.java +++ b/rebar/src/main/java/io/github/pylonmc/rebar/RebarLoader.java @@ -18,7 +18,7 @@ import java.util.stream.Stream; /** - * Loads the necessary libraries for Rebar Core to run - internal. + * Loads the necessary libraries for Rebar to run - internal. */ @ApiStatus.Internal @SuppressWarnings({"UnstableApiUsage", "unused"}) diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/Rebar.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/Rebar.kt index 2a48f1bc8..e01028c94 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/Rebar.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/Rebar.kt @@ -61,7 +61,8 @@ import org.bukkit.permissions.Permission import org.bukkit.permissions.PermissionDefault import org.bukkit.plugin.java.JavaPlugin import xyz.xenondevs.invui.InvUI -import java.util.* +import xyz.xenondevs.invui.i18n.Languages +import java.util.Locale import kotlin.io.path.* /** @@ -90,6 +91,7 @@ object Rebar : JavaPlugin(), RebarAddon { } InvUI.getInstance().setPlugin(this) + Languages.getInstance().enableServerSideTranslations(false) // we do our own val packetEvents = PacketEvents.getAPI() packetEvents.init() diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/RebarBootstrapper.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/RebarBootstrapper.kt index 250a67cf8..058ca5ce8 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/RebarBootstrapper.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/RebarBootstrapper.kt @@ -7,7 +7,7 @@ import org.bukkit.plugin.java.JavaPlugin import org.jetbrains.annotations.ApiStatus /** - * Bootstraps Rebar Core - internal. + * Bootstraps Rebar - internal. */ @ApiStatus.Internal @Suppress("UnstableApiUsage", "unused") diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/block/BlockListener.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/block/BlockListener.kt index 98eb4c093..6aede4fc9 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/block/BlockListener.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/block/BlockListener.kt @@ -45,7 +45,8 @@ import org.bukkit.event.player.PlayerToggleSneakEvent import org.bukkit.event.world.StructureGrowEvent import org.bukkit.inventory.BlockInventoryHolder import org.bukkit.inventory.EquipmentSlot -import java.util.* +import java.util.UUID +import java.util.WeakHashMap /** diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/block/BlockStorage.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/block/BlockStorage.kt index 485a187dc..797b53e60 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/block/BlockStorage.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/block/BlockStorage.kt @@ -5,14 +5,15 @@ import com.github.shynixn.mccoroutine.bukkit.launch import com.github.shynixn.mccoroutine.bukkit.minecraftDispatcher import io.github.pylonmc.rebar.Rebar import io.github.pylonmc.rebar.addon.RebarAddon +import io.github.pylonmc.rebar.block.BlockStorage.breakBlock import io.github.pylonmc.rebar.block.base.RebarBreakHandler import io.github.pylonmc.rebar.block.context.BlockBreakContext import io.github.pylonmc.rebar.block.context.BlockCreateContext -import io.github.pylonmc.rebar.resourcepack.block.BlockTextureEngine import io.github.pylonmc.rebar.config.RebarConfig import io.github.pylonmc.rebar.datatypes.RebarSerializers import io.github.pylonmc.rebar.event.* import io.github.pylonmc.rebar.registry.RebarRegistry +import io.github.pylonmc.rebar.resourcepack.block.BlockTextureEngine import io.github.pylonmc.rebar.util.isFromAddon import io.github.pylonmc.rebar.util.position.BlockPosition import io.github.pylonmc.rebar.util.position.ChunkPosition diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/block/PhantomBlock.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/block/PhantomBlock.kt index 7b0fbf701..a95b998ab 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/block/PhantomBlock.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/block/PhantomBlock.kt @@ -9,8 +9,8 @@ import io.github.pylonmc.rebar.i18n.RebarArgument import io.github.pylonmc.rebar.item.RebarItem import io.github.pylonmc.rebar.item.builder.ItemStackBuilder import io.github.pylonmc.rebar.util.rebarKey -import io.papermc.paper.datacomponent.DataComponentTypes import io.github.pylonmc.rebar.waila.WailaDisplay +import io.papermc.paper.datacomponent.DataComponentTypes import net.kyori.adventure.bossbar.BossBar import org.bukkit.Color import org.bukkit.Material diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/block/RebarBlock.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/block/RebarBlock.kt index ff50ec6ae..952a18efe 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/block/RebarBlock.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/block/RebarBlock.kt @@ -3,6 +3,8 @@ package io.github.pylonmc.rebar.block import com.github.retrooper.packetevents.protocol.world.Location import com.github.retrooper.packetevents.util.Vector3f import io.github.pylonmc.rebar.Rebar +import io.github.pylonmc.rebar.block.RebarBlock.Companion.rebarBlockTextureEntityKey +import io.github.pylonmc.rebar.block.RebarBlock.Companion.register import io.github.pylonmc.rebar.block.base.RebarDirectionalBlock import io.github.pylonmc.rebar.block.base.RebarEntityHolderBlock import io.github.pylonmc.rebar.block.base.RebarGuiBlock diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/block/base/RebarCargoBlock.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/block/base/RebarCargoBlock.kt index e759316b7..941125910 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/block/base/RebarCargoBlock.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/block/base/RebarCargoBlock.kt @@ -6,22 +6,16 @@ import com.github.shynixn.mccoroutine.bukkit.ticks import io.github.pylonmc.rebar.Rebar import io.github.pylonmc.rebar.block.BlockStorage import io.github.pylonmc.rebar.block.RebarBlock +import io.github.pylonmc.rebar.block.base.RebarCargoBlock.Companion.cargoItemsTransferredPerSecond import io.github.pylonmc.rebar.config.RebarConfig import io.github.pylonmc.rebar.content.cargo.CargoDuct import io.github.pylonmc.rebar.datatypes.RebarSerializers import io.github.pylonmc.rebar.entity.display.ItemDisplayBuilder import io.github.pylonmc.rebar.entity.display.transform.LineBuilder -import io.github.pylonmc.rebar.event.RebarBlockBreakEvent -import io.github.pylonmc.rebar.event.RebarBlockDeserializeEvent -import io.github.pylonmc.rebar.event.RebarBlockLoadEvent -import io.github.pylonmc.rebar.event.RebarBlockPlaceEvent -import io.github.pylonmc.rebar.event.RebarBlockSerializeEvent -import io.github.pylonmc.rebar.event.RebarBlockUnloadEvent -import io.github.pylonmc.rebar.event.RebarCargoConnectEvent -import io.github.pylonmc.rebar.event.RebarCargoDisconnectEvent +import io.github.pylonmc.rebar.event.* +import io.github.pylonmc.rebar.logistics.CargoRoutes import io.github.pylonmc.rebar.logistics.LogisticGroup import io.github.pylonmc.rebar.logistics.LogisticGroupType -import io.github.pylonmc.rebar.logistics.CargoRoutes import io.github.pylonmc.rebar.util.IMMEDIATE_FACES import io.github.pylonmc.rebar.util.rebarKey import kotlinx.coroutines.Job diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/block/base/RebarDirectionalBlock.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/block/base/RebarDirectionalBlock.kt index f5cc83b1f..0c5dc3d24 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/block/base/RebarDirectionalBlock.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/block/base/RebarDirectionalBlock.kt @@ -12,7 +12,6 @@ import org.bukkit.event.EventHandler import org.bukkit.event.Listener import org.jetbrains.annotations.ApiStatus import java.util.IdentityHashMap -import kotlin.collections.set /** * Represents a block that has a specific facing direction. diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/block/base/RebarGuiBlock.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/block/base/RebarGuiBlock.kt index fce28f273..f9318f92e 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/block/base/RebarGuiBlock.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/block/base/RebarGuiBlock.kt @@ -12,11 +12,10 @@ import org.bukkit.event.Listener import org.bukkit.event.player.PlayerInteractEvent import org.bukkit.inventory.EquipmentSlot import org.jetbrains.annotations.MustBeInvokedByOverriders -import xyz.xenondevs.inventoryaccess.component.AdventureComponentWrapper import xyz.xenondevs.invui.gui.Gui import xyz.xenondevs.invui.inventory.VirtualInventory import xyz.xenondevs.invui.window.Window -import java.util.* +import java.util.IdentityHashMap /** * A simple interface that opens a GUI when the block is right clicked @@ -55,9 +54,9 @@ interface RebarGuiBlock : RebarBreakHandler, RebarInteractBlock, RebarNoVanillaC event.setUseInteractedBlock(Event.Result.DENY) event.setUseItemInHand(Event.Result.DENY) - Window.single() - .setGui(guiBlocks[this]!!) - .setTitle(AdventureComponentWrapper(guiTitle)) + Window.builder() + .setUpperGui(guiBlocks[this]!!) + .setTitle(guiTitle) .setViewer(event.player) .build() .open() diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/block/base/RebarLogisticBlock.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/block/base/RebarLogisticBlock.kt index 1cef892dd..ca814c666 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/block/base/RebarLogisticBlock.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/block/base/RebarLogisticBlock.kt @@ -3,15 +3,15 @@ package io.github.pylonmc.rebar.block.base import io.github.pylonmc.rebar.event.RebarBlockBreakEvent import io.github.pylonmc.rebar.event.RebarBlockUnloadEvent import io.github.pylonmc.rebar.logistics.LogisticGroup -import io.github.pylonmc.rebar.logistics.slot.LogisticSlot import io.github.pylonmc.rebar.logistics.LogisticGroupType +import io.github.pylonmc.rebar.logistics.slot.LogisticSlot import io.github.pylonmc.rebar.logistics.slot.VirtualInventoryLogisticSlot import org.bukkit.block.Block import org.bukkit.event.EventHandler import org.bukkit.event.Listener import org.jetbrains.annotations.ApiStatus import xyz.xenondevs.invui.inventory.VirtualInventory -import java.util.* +import java.util.IdentityHashMap /** * A block which can have items removed or added via a logistics system. diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/block/base/RebarRecipeProcessor.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/block/base/RebarRecipeProcessor.kt index c0f12924c..e0b64ac16 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/block/base/RebarRecipeProcessor.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/block/base/RebarRecipeProcessor.kt @@ -40,6 +40,7 @@ interface RebarRecipeProcessor { @Suppress("UNCHECKED_CAST") val currentRecipe: T? + @Suppress("UNCHECKED_CAST") @ApiStatus.NonExtendable // cast should always be safe due to type restriction when starting recipe get() = recipeProcessorData.currentRecipe as T? diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/block/base/RebarSimpleMultiblock.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/block/base/RebarSimpleMultiblock.kt index 00a1edde2..b1a041103 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/block/base/RebarSimpleMultiblock.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/block/base/RebarSimpleMultiblock.kt @@ -41,7 +41,8 @@ import org.bukkit.util.Vector import org.jetbrains.annotations.ApiStatus import org.jetbrains.annotations.MustBeInvokedByOverriders import org.joml.Vector3i -import java.util.* +import java.util.IdentityHashMap +import java.util.UUID import kotlin.math.abs import kotlin.math.min import kotlin.time.Duration.Companion.seconds diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/block/base/RebarTickingBlock.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/block/base/RebarTickingBlock.kt index a3512f1e1..0ac046524 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/block/base/RebarTickingBlock.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/block/base/RebarTickingBlock.kt @@ -9,12 +9,7 @@ import io.github.pylonmc.rebar.block.BlockListener.logEventHandleErr import io.github.pylonmc.rebar.block.RebarBlock import io.github.pylonmc.rebar.config.RebarConfig import io.github.pylonmc.rebar.datatypes.RebarSerializers -import io.github.pylonmc.rebar.event.RebarBlockBreakEvent -import io.github.pylonmc.rebar.event.RebarBlockDeserializeEvent -import io.github.pylonmc.rebar.event.RebarBlockLoadEvent -import io.github.pylonmc.rebar.event.RebarBlockPlaceEvent -import io.github.pylonmc.rebar.event.RebarBlockSerializeEvent -import io.github.pylonmc.rebar.event.RebarBlockUnloadEvent +import io.github.pylonmc.rebar.event.* import io.github.pylonmc.rebar.util.rebarKey import kotlinx.coroutines.Job import kotlinx.coroutines.delay diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/command/RebarCommand.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/command/RebarCommand.kt index 87e348ac8..7fd3c45e6 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/command/RebarCommand.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/command/RebarCommand.kt @@ -307,7 +307,7 @@ private val researchPointsSet = buildCommand("set") { for (player in getArgument>("players")) { player.researchPoints = points sender.sendFeedback( - "research.points.modify", + "research.points.set", RebarArgument.of("player", player.name), RebarArgument.of("points", points) ) diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/config/adapter/ConfigAdapter.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/config/adapter/ConfigAdapter.kt index c98494ead..7c57f66ac 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/config/adapter/ConfigAdapter.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/config/adapter/ConfigAdapter.kt @@ -18,6 +18,7 @@ interface ConfigAdapter { */ fun convert(value: Any): T + @Suppress("unused") companion object { // @formatter:off @JvmField val BYTE = ConfigAdapter { if (it is String) it.toByte() else (it as Number).toByte() } @@ -85,7 +86,7 @@ interface ConfigAdapter { */ @JvmField val RANDOMIZED_SOUND = RandomizedSoundConfigAdapter - @JvmField val PYLON_FLUID = KEYED.fromRegistry(RebarRegistry.FLUIDS) + @JvmField val REBAR_FLUID = KEYED.fromRegistry(RebarRegistry.FLUIDS) @JvmField val FLUID_TEMPERATURE = ENUM.from() @JvmField val FLUID_OR_ITEM = FluidOrItemConfigAdapter @JvmField val RECIPE_INPUT = RecipeInputConfigAdapter diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/config/adapter/FluidOrItemConfigAdapter.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/config/adapter/FluidOrItemConfigAdapter.kt index f37aab5fa..d4e099485 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/config/adapter/FluidOrItemConfigAdapter.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/config/adapter/FluidOrItemConfigAdapter.kt @@ -13,7 +13,7 @@ object FluidOrItemConfigAdapter : ConfigAdapter { FluidOrItem.of(item) } else when (value) { is Pair<*, *> -> { - val fluid = ConfigAdapter.PYLON_FLUID.convert(value.first!!) + val fluid = ConfigAdapter.REBAR_FLUID.convert(value.first!!) val amount = ConfigAdapter.DOUBLE.convert(value.second!!) FluidOrItem.of(fluid, amount) } diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/config/adapter/ItemTagConfigAdapter.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/config/adapter/ItemTagConfigAdapter.kt index 04585eca1..d0501d60b 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/config/adapter/ItemTagConfigAdapter.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/config/adapter/ItemTagConfigAdapter.kt @@ -44,9 +44,9 @@ object ItemTagConfigAdapter : ConfigAdapter> { } // Check our own tags - val pylonTag = RebarRegistry.ITEM_TAGS[tagKey] - if (pylonTag != null) { - return pylonTag + val rebarTag = RebarRegistry.ITEM_TAGS[tagKey] + if (rebarTag != null) { + return rebarTag } throw IllegalArgumentException("Item tag not found: $value") diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/config/adapter/RecipeInputConfigAdapter.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/config/adapter/RecipeInputConfigAdapter.kt index fcebf1abe..283969833 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/config/adapter/RecipeInputConfigAdapter.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/config/adapter/RecipeInputConfigAdapter.kt @@ -56,7 +56,7 @@ object RecipeInputFluidAdapter : ConfigAdapter { ) is Pair<*, *> -> { - val fluid = ConfigAdapter.PYLON_FLUID.convert(value.first!!) + val fluid = ConfigAdapter.REBAR_FLUID.convert(value.first!!) val amount = ConfigAdapter.DOUBLE.convert(value.second!!) RecipeInput.of(fluid, amount) } diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/content/debug/DebugWaxedWeatheredCutCopperStairs.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/content/debug/DebugWaxedWeatheredCutCopperStairs.kt index b8a78fa4e..a8521c7c6 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/content/debug/DebugWaxedWeatheredCutCopperStairs.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/content/debug/DebugWaxedWeatheredCutCopperStairs.kt @@ -38,17 +38,17 @@ internal class DebugWaxedWeatheredCutCopperStairs(stack: ItemStack) if (event.action == Action.PHYSICAL) return val block = event.clickedBlock ?: return - val pylonBlock = BlockStorage.get(block) + val rebarBlock = BlockStorage.get(block) val player = event.player - if (pylonBlock == null) { + if (rebarBlock == null) { player.sendDebugActionBar("not_a_block") return } if (event.action.isLeftClick) { - onUsedToLeftClickBlock(player, block, pylonBlock) + onUsedToLeftClickBlock(player, block, rebarBlock) } else if (event.action.isRightClick) { - onUsedToRightClickBlock(player, block, pylonBlock) + onUsedToRightClickBlock(player, block, rebarBlock) } } @@ -106,18 +106,18 @@ internal class DebugWaxedWeatheredCutCopperStairs(stack: ItemStack) override fun onUsedToDamageEntity(event: EntityDamageByEntityEvent) { event.isCancelled = true val player = event.damager as? Player ?: return - val pylonEntity = EntityStorage.get(event.entity) - if (pylonEntity == null) { + val rebarEntity = EntityStorage.get(event.entity) + if (rebarEntity == null) { player.sendDebugActionBar("not_an_entity") return } if (player.currentInput.isSneak) { - pylonEntity.entity.remove() + rebarEntity.entity.remove() player.sendDebug( "deleted_data", - RebarArgument.of("type", pylonEntity.schema.key.toString()), - RebarArgument.of("location", pylonEntity.entity.uniqueId.toString()) + RebarArgument.of("type", rebarEntity.schema.key.toString()), + RebarArgument.of("location", rebarEntity.entity.uniqueId.toString()) ) return } @@ -125,22 +125,22 @@ internal class DebugWaxedWeatheredCutCopperStairs(stack: ItemStack) override fun onUsedToRightClickEntity(event: PlayerInteractEntityEvent) { event.isCancelled = true - val pylonEntity = EntityStorage.get(event.rightClicked) + val rebarEntity = EntityStorage.get(event.rightClicked) val player = event.player - if (pylonEntity == null) { + if (rebarEntity == null) { player.sendDebugActionBar("not_an_entity") return } player.sendDebug( "key.entity", - RebarArgument.of("key", pylonEntity.schema.key.toString()) + RebarArgument.of("key", rebarEntity.schema.key.toString()) ) // TODO implement this once entities can tick // event.player.sendMessage( // MiniMessage.miniMessage().deserialize( -// when (pylonEntity) { +// when (rebarEntity) { // is RebarTickingBlock -> if (false) { // "Ticking: Yes" // } else { @@ -151,8 +151,8 @@ internal class DebugWaxedWeatheredCutCopperStairs(stack: ItemStack) // } // ) // ) - pylonEntity.writeDebugInfo(pylonEntity.entity.persistentDataContainer) - val serialized = NmsAccessor.instance.serializePdc(pylonEntity.entity.persistentDataContainer) + rebarEntity.writeDebugInfo(rebarEntity.entity.persistentDataContainer) + val serialized = NmsAccessor.instance.serializePdc(rebarEntity.entity.persistentDataContainer) player.sendDebug( "data", RebarArgument.of("data", serialized) diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/content/fluid/FluidPipe.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/content/fluid/FluidPipe.kt index 20b49978c..d0e2ace1d 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/content/fluid/FluidPipe.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/content/fluid/FluidPipe.kt @@ -99,12 +99,12 @@ open class FluidPipe(stack: ItemStack) : RebarItem(stack), RebarInteractor { } private fun tryStartConnection(player: Player, block: Block): Boolean { - val pylonBlock = BlockStorage.get(block) + val rebarBlock = BlockStorage.get(block) - if (pylonBlock is FluidIntersectionMarker) { - if (pylonBlock.pipe == this) { + if (rebarBlock is FluidIntersectionMarker) { + if (rebarBlock.pipe == this) { // This pipe matches the pipe we right clicked; start a connection - FluidPipePlacementService.startConnection(player, FluidPipePlacementPoint.PointDisplay(pylonBlock.fluidIntersectionDisplay), this) + FluidPipePlacementService.startConnection(player, FluidPipePlacementPoint.PointDisplay(rebarBlock.fluidIntersectionDisplay), this) } else { // This pipe does not match the pipe we right clicked player.sendActionBar(Component.translatable("rebar.message.pipe.not_of_same_type")) @@ -112,10 +112,10 @@ open class FluidPipe(stack: ItemStack) : RebarItem(stack), RebarInteractor { return true } - if (pylonBlock is FluidSectionMarker) { - if (pylonBlock.pipeDisplay!!.pipe == this) { + if (rebarBlock is FluidSectionMarker) { + if (rebarBlock.pipeDisplay!!.pipe == this) { // This pipe matches the pipe we right clicked; start a connection - FluidPipePlacementService.startConnection(player, FluidPipePlacementPoint.Section(pylonBlock), this) + FluidPipePlacementService.startConnection(player, FluidPipePlacementPoint.Section(rebarBlock), this) } else { // This pipe does not match the pipe we right clicked player.sendActionBar(Component.translatable("rebar.message.pipe.not_of_same_type")) diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/content/guide/RebarGuide.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/content/guide/RebarGuide.kt index 7bbb2cfb6..2b32551d2 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/content/guide/RebarGuide.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/content/guide/RebarGuide.kt @@ -34,7 +34,7 @@ import org.bukkit.event.Listener import org.bukkit.event.player.PlayerInteractEvent import org.bukkit.event.player.PlayerJoinEvent import org.bukkit.inventory.ItemStack -import java.util.* +import java.util.UUID /** * The one and only Rebar guide. diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/datatypes/ProgressItemPersistentDataType.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/datatypes/ProgressItemPersistentDataType.kt index 1ec253ec7..9f2aac397 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/datatypes/ProgressItemPersistentDataType.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/datatypes/ProgressItemPersistentDataType.kt @@ -31,7 +31,7 @@ object ProgressItemPersistentDataType : PersistentDataType = mutableMapOf() diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/entity/EntityStorage.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/entity/EntityStorage.kt index 948cd708d..f45b50a3a 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/entity/EntityStorage.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/entity/EntityStorage.kt @@ -15,13 +15,12 @@ import io.github.pylonmc.rebar.registry.RebarRegistry import io.github.pylonmc.rebar.util.isFromAddon import kotlinx.coroutines.Job import kotlinx.coroutines.delay -import org.bukkit.Bukkit import org.bukkit.NamespacedKey import org.bukkit.entity.Entity import org.bukkit.event.EventHandler import org.bukkit.event.Listener import org.bukkit.event.world.EntitiesLoadEvent -import java.util.* +import java.util.UUID import java.util.concurrent.ConcurrentHashMap import java.util.concurrent.locks.ReentrantReadWriteLock import java.util.function.Consumer diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/entity/RebarEntity.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/entity/RebarEntity.kt index 551580af7..95c9ba22a 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/entity/RebarEntity.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/entity/RebarEntity.kt @@ -5,6 +5,7 @@ import io.github.pylonmc.rebar.config.Config import io.github.pylonmc.rebar.config.Settings import io.github.pylonmc.rebar.content.debug.DebugWaxedWeatheredCutCopperStairs import io.github.pylonmc.rebar.datatypes.RebarSerializers +import io.github.pylonmc.rebar.entity.RebarEntity.Companion.register import io.github.pylonmc.rebar.event.RebarEntitySerializeEvent import io.github.pylonmc.rebar.registry.RebarRegistry import io.github.pylonmc.rebar.util.rebarKey diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/entity/RebarEntitySchema.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/entity/RebarEntitySchema.kt index 98db0ea80..be03bd1c6 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/entity/RebarEntitySchema.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/entity/RebarEntitySchema.kt @@ -9,7 +9,7 @@ import java.lang.invoke.MethodHandle * Stores information about a Rebar entity type, including its key, vanilla entity class, * and Pylion entity class. * - * You should not need to use this if you are not working on Rebar Core. + * You should not need to use this if you are not working on Rebar. */ class RebarEntitySchema( private val key: NamespacedKey, diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/entity/base/RebarTickingEntity.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/entity/base/RebarTickingEntity.kt index a2a3fb2fe..eaa746863 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/entity/base/RebarTickingEntity.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/entity/base/RebarTickingEntity.kt @@ -17,7 +17,7 @@ import kotlinx.coroutines.delay import org.bukkit.event.EventHandler import org.bukkit.event.Listener import org.jetbrains.annotations.ApiStatus -import java.util.* +import java.util.IdentityHashMap /** * Represents an entity that 'ticks' (does something at a fixed time interval). diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/entity/display/transform/Rotation.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/entity/display/transform/Rotation.kt index 1b860396f..073784e37 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/entity/display/transform/Rotation.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/entity/display/transform/Rotation.kt @@ -1,10 +1,6 @@ package io.github.pylonmc.rebar.entity.display.transform -import org.joml.Matrix4f -import org.joml.Quaterniond -import org.joml.Quaternionf -import org.joml.Vector3d -import org.joml.Vector3f +import org.joml.* open class Rotation private constructor( protected val vector: Vector3f?, diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/entity/display/transform/RotationBackwards.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/entity/display/transform/RotationBackwards.kt index 667571a30..bc33d17e2 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/entity/display/transform/RotationBackwards.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/entity/display/transform/RotationBackwards.kt @@ -1,10 +1,6 @@ package io.github.pylonmc.rebar.entity.display.transform -import org.joml.Matrix4f -import org.joml.Quaterniond -import org.joml.Quaternionf -import org.joml.Vector3d -import org.joml.Vector3f +import org.joml.* open class RotationBackwards private constructor( protected val vector: Vector3f?, diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/fluid/placement/FluidPipePlacementPoint.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/fluid/placement/FluidPipePlacementPoint.kt index 8d2dbfe69..b7f7e251f 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/fluid/placement/FluidPipePlacementPoint.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/fluid/placement/FluidPipePlacementPoint.kt @@ -1,11 +1,7 @@ package io.github.pylonmc.rebar.fluid.placement import io.github.pylonmc.rebar.block.BlockStorage -import io.github.pylonmc.rebar.content.fluid.FluidEndpointDisplay -import io.github.pylonmc.rebar.content.fluid.FluidIntersectionDisplay -import io.github.pylonmc.rebar.content.fluid.FluidIntersectionMarker -import io.github.pylonmc.rebar.content.fluid.FluidPointDisplay -import io.github.pylonmc.rebar.content.fluid.FluidSectionMarker +import io.github.pylonmc.rebar.content.fluid.* import io.github.pylonmc.rebar.util.position.BlockPosition import org.bukkit.block.BlockFace import org.joml.Vector3f diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/button/BackButton.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/button/BackButton.kt index 77f5e828d..3de976a7a 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/button/BackButton.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/button/BackButton.kt @@ -9,12 +9,13 @@ import net.kyori.adventure.text.Component import org.bukkit.Material import org.bukkit.entity.Player import org.bukkit.event.inventory.ClickType -import org.bukkit.event.inventory.InventoryClickEvent -import xyz.xenondevs.invui.item.impl.AbstractItem +import xyz.xenondevs.invui.Click +import xyz.xenondevs.invui.item.AbstractItem /** * Represents the back button in the guide. */ +@Suppress("UnstableApiUsage") class BackButton : AbstractItem() { override fun getItemProvider(player: Player): ItemStackBuilder { @@ -27,7 +28,7 @@ class BackButton : AbstractItem() { return stack } - override fun handleClick(clickType: ClickType, player: Player, event: InventoryClickEvent) { + override fun handleClick(clickType: ClickType, player: Player, click: Click) { val history = RebarGuide.history.getOrPut(player.uniqueId) { mutableListOf() } if (clickType.isShiftClick) { diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/button/FluidButton.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/button/FluidButton.kt index bb3d19ee6..0d83b0dca 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/button/FluidButton.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/button/FluidButton.kt @@ -16,8 +16,8 @@ import net.kyori.adventure.text.Component import org.bukkit.Material import org.bukkit.entity.Player import org.bukkit.event.inventory.ClickType -import org.bukkit.event.inventory.InventoryClickEvent -import xyz.xenondevs.invui.item.impl.AbstractItem +import xyz.xenondevs.invui.Click +import xyz.xenondevs.invui.item.AbstractItem import kotlin.time.Duration.Companion.seconds /** @@ -97,7 +97,7 @@ open class FluidButton( .name(Component.translatable("rebar.guide.button.fluid.error")) } - override fun handleClick(clickType: ClickType, player: Player, event: InventoryClickEvent) { + override fun handleClick(clickType: ClickType, player: Player, click: Click) { try { if (clickType.isLeftClick) { val page = FluidRecipesPage(currentFluid.key) diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/button/ItemButton.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/button/ItemButton.kt index c7256cb11..a5ea3aff9 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/button/ItemButton.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/button/ItemButton.kt @@ -21,13 +21,14 @@ import org.bukkit.Material import org.bukkit.Registry import org.bukkit.entity.Player import org.bukkit.event.inventory.ClickType -import org.bukkit.event.inventory.InventoryClickEvent import org.bukkit.inventory.ItemStack import org.bukkit.inventory.RecipeChoice +import xyz.xenondevs.invui.Click +import xyz.xenondevs.invui.gui.SlotElement +import xyz.xenondevs.invui.gui.get +import xyz.xenondevs.invui.item.AbstractBoundItem import xyz.xenondevs.invui.item.Item import xyz.xenondevs.invui.item.ItemProvider -import xyz.xenondevs.invui.item.impl.AbstractItem -import xyz.xenondevs.invui.item.impl.SimpleItem import kotlin.time.Duration.Companion.seconds /** @@ -43,7 +44,7 @@ class ItemButton @JvmOverloads constructor( * A function to apply to the button item after creating it. */ val preDisplayDecorator: (ItemStack, Player) -> ItemStack = { stack, _ -> stack } -) : AbstractItem() { +) : AbstractBoundItem() { /** * @param stacks The items to display. If multiple are provided, the button will automatically @@ -132,7 +133,7 @@ class ItemButton @JvmOverloads constructor( } } - override fun handleClick(clickType: ClickType, player: Player, event: InventoryClickEvent) { + override fun handleClick(clickType: ClickType, player: Player, click: Click) { try { when (clickType) { ClickType.LEFT -> { @@ -151,7 +152,12 @@ class ItemButton @JvmOverloads constructor( } research.addTo(player, false) player.researchPoints -= research.cost - notifyWindows() + for (slot in 0 until gui.size) { + val item = gui[slot] as? SlotElement.Item ?: continue + if (item.item is ItemButton) { + item.item.notifyWindows() + } + } } } @@ -171,14 +177,14 @@ class ItemButton @JvmOverloads constructor( ClickType.MIDDLE -> { if (!player.hasPermission("rebar.guide.cheat")) return - val stack = getCheatItemStack(currentStack, event) + val stack = getCheatItemStack(currentStack, click) stack.amount = stack.maxStackSize player.setItemOnCursor(stack) } ClickType.DROP -> { if (!player.hasPermission("rebar.guide.cheat")) return - val stack = getCheatItemStack(currentStack, event) + val stack = getCheatItemStack(currentStack, click) stack.amount = 1 if (player.itemOnCursor.isEmpty) { player.setItemOnCursor(stack) @@ -189,14 +195,14 @@ class ItemButton @JvmOverloads constructor( ClickType.CONTROL_DROP -> { if (!player.hasPermission("rebar.guide.cheat")) return - val stack = getCheatItemStack(currentStack, event) + val stack = getCheatItemStack(currentStack, click) stack.amount = stack.maxStackSize player.dropItem(stack) } ClickType.SWAP_OFFHAND -> { if (!player.hasPermission("rebar.guide.cheat")) return - val stack = getCheatItemStack(currentStack, event) + val stack = getCheatItemStack(currentStack, click) stack.amount = 1 player.give(stack) } @@ -209,20 +215,20 @@ class ItemButton @JvmOverloads constructor( } companion object { - private fun getCheatItemStack(currentStack: ItemStack, event: InventoryClickEvent): ItemStack { + private fun getCheatItemStack(currentStack: ItemStack, click: Click): ItemStack { val clonedUnkown = currentStack.clone() val rebarItem = RebarItem.fromStack(clonedUnkown) if (rebarItem == null) { // Item is not Rebar val type = Registry.MATERIAL.get(clonedUnkown.type.key)!! - val amount = if (event.isShiftClick) { type.maxStackSize } else { 1 } + val amount = if (click.clickType.isShiftClick) { type.maxStackSize } else { 1 } val clonedNotRebar = ItemStack(type, amount) return clonedNotRebar } else { // Rebar item handling val clonedRebar = rebarItem.schema.getItemStack() - clonedRebar.amount = if (event.isShiftClick) { clonedRebar.maxStackSize } else { 1 } + clonedRebar.amount = if (click.clickType.isShiftClick) { clonedRebar.maxStackSize } else { 1 } return clonedRebar } } @@ -230,7 +236,7 @@ class ItemButton @JvmOverloads constructor( @JvmStatic fun from(stack: ItemStack?): Item { if (stack == null) { - return SimpleItem(ItemStack(Material.AIR)) + return EMPTY } return ItemButton(stack) @@ -239,7 +245,7 @@ class ItemButton @JvmOverloads constructor( @JvmStatic fun from(stack: ItemStack?, preDisplayDecorator: (ItemStack, Player) -> ItemStack): Item { if (stack == null) { - return SimpleItem(ItemStack(Material.AIR)) + return EMPTY } return ItemButton(listOf(stack), preDisplayDecorator) @@ -248,7 +254,7 @@ class ItemButton @JvmOverloads constructor( @JvmStatic fun from(input: RecipeInput.Item?): Item { if (input == null) { - return SimpleItem(ItemStack(Material.AIR)) + return EMPTY } return ItemButton(*input.representativeItems.toTypedArray()) @@ -258,7 +264,7 @@ class ItemButton @JvmOverloads constructor( fun from(choice: RecipeChoice?): Item = when (choice) { is RecipeChoice.MaterialChoice -> ItemButton(choice.choices.map(::ItemStack)) is RecipeChoice.ExactChoice -> ItemButton(choice.choices) - else -> SimpleItem(ItemStackBuilder.of(Material.AIR)) + else -> EMPTY } } } \ No newline at end of file diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/button/PageButton.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/button/PageButton.kt index 175378c71..2db7beadd 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/button/PageButton.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/button/PageButton.kt @@ -7,9 +7,10 @@ import net.kyori.adventure.text.Component import org.bukkit.Material import org.bukkit.entity.Player import org.bukkit.event.inventory.ClickType -import org.bukkit.event.inventory.InventoryClickEvent import org.bukkit.inventory.ItemStack -import xyz.xenondevs.invui.item.impl.AbstractItem +import xyz.xenondevs.invui.Click +import xyz.xenondevs.invui.item.AbstractItem +import xyz.xenondevs.invui.item.ItemProvider /** * A button that opens another page in the guide. @@ -25,12 +26,12 @@ open class PageButton(val stack: ItemStack, val page: GuidePage) : AbstractItem( constructor(material: Material, page: GuidePage) : this(ItemStack(material), page) - override fun getItemProvider(viewer: Player?) = ItemStackBuilder.gui(stack, "${rebarKey("guide_page")}:${page.key}") + override fun getItemProvider(viewer: Player): ItemProvider = ItemStackBuilder.gui(stack, "${rebarKey("guide_page")}:${page.key}") .name(Component.translatable("${page.key.namespace}.guide.page.${page.key.key}")) .clearLore() .lore(Component.translatable("${page.key.namespace}.guide.button.${page.key.key}", "")) - override fun handleClick(clickType: ClickType, player: Player, event: InventoryClickEvent) { + override fun handleClick(clickType: ClickType, player: Player, click: Click) { page.open(player) } } diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/button/ResearchButton.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/button/ResearchButton.kt index 9f98bbbdf..201997a3e 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/button/ResearchButton.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/button/ResearchButton.kt @@ -12,15 +12,17 @@ import net.kyori.adventure.text.Component import org.bukkit.Material import org.bukkit.entity.Player import org.bukkit.event.inventory.ClickType -import org.bukkit.event.inventory.InventoryClickEvent import org.bukkit.inventory.ItemStack +import xyz.xenondevs.invui.Click +import xyz.xenondevs.invui.gui.SlotElement +import xyz.xenondevs.invui.gui.get +import xyz.xenondevs.invui.item.AbstractBoundItem import xyz.xenondevs.invui.item.ItemProvider -import xyz.xenondevs.invui.item.impl.AbstractItem /** * A button that shows a research. */ -open class ResearchButton(val research: Research) : AbstractItem() { +open class ResearchButton(val research: Research) : AbstractBoundItem() { override fun getItemProvider(player: Player): ItemProvider = try { val playerHasResearch = Research.getResearches(player).contains(research) @@ -51,7 +53,7 @@ open class ResearchButton(val research: Research) : AbstractItem() { item.lore(Component.translatable("rebar.guide.button.research.unlocks-title")) val shouldCutOff = research.unlocks.size > MAX_UNLOCK_LIST_LINES - var itemListCount = if (shouldCutOff) { + val itemListCount = if (shouldCutOff) { MAX_UNLOCK_LIST_LINES - 1 } else { research.unlocks.size @@ -90,7 +92,7 @@ open class ResearchButton(val research: Research) : AbstractItem() { .name(Component.translatable("rebar.guide.button.fluid.error")) } - override fun handleClick(clickType: ClickType, player: Player, event: InventoryClickEvent) { + override fun handleClick(clickType: ClickType, player: Player, click: Click) { try { if (clickType.isLeftClick) { if (research.isResearchedBy(player) || research.cost == null || research.cost > player.researchPoints) { @@ -98,7 +100,12 @@ open class ResearchButton(val research: Research) : AbstractItem() { } research.addTo(player) player.researchPoints -= research.cost - windows.forEach { it.close(); it.open() } // TODO refresh windows when we've updated to 2.0.0 + for (slot in 0 until gui.size) { + val item = gui[slot] as? SlotElement.Item ?: continue + if (item.item is ResearchButton) { + item.item.notifyWindows() + } + } } else if (clickType.isRightClick) { ResearchItemsPage(research).open(player) } else if (clickType == ClickType.MIDDLE) { diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/button/ResearchesButton.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/button/ResearchesButton.kt index b9f89cae2..3d5114bf5 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/button/ResearchesButton.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/button/ResearchesButton.kt @@ -5,8 +5,8 @@ import io.github.pylonmc.rebar.guide.pages.research.AddonResearchesPage import io.github.pylonmc.rebar.item.builder.ItemStackBuilder import org.bukkit.entity.Player import org.bukkit.event.inventory.ClickType -import org.bukkit.event.inventory.InventoryClickEvent -import xyz.xenondevs.invui.item.impl.AbstractItem +import xyz.xenondevs.invui.Click +import xyz.xenondevs.invui.item.AbstractItem /** * A button that opens the research page for a specific addon. @@ -14,10 +14,10 @@ import xyz.xenondevs.invui.item.impl.AbstractItem class ResearchesButton(val addon: RebarAddon) : AbstractItem() { val page = AddonResearchesPage(addon) - override fun getItemProvider() = ItemStackBuilder.of(addon.material) + override fun getItemProvider(viewer: Player) = ItemStackBuilder.of(addon.material) .name(addon.displayName) - override fun handleClick(clickType: ClickType, player: Player, event: InventoryClickEvent) { + override fun handleClick(clickType: ClickType, player: Player, click: Click) { page.open(player) } } \ No newline at end of file diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/button/setting/CyclePlayerSettingButton.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/button/setting/CyclePlayerSettingButton.kt index 042722432..e3c0bb4ce 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/button/setting/CyclePlayerSettingButton.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/button/setting/CyclePlayerSettingButton.kt @@ -8,10 +8,10 @@ import net.kyori.adventure.text.TranslatableComponent import org.bukkit.NamespacedKey import org.bukkit.entity.Player import org.bukkit.event.inventory.ClickType -import org.bukkit.event.inventory.InventoryClickEvent import org.bukkit.inventory.ItemStack +import xyz.xenondevs.invui.Click +import xyz.xenondevs.invui.item.AbstractItem import xyz.xenondevs.invui.item.ItemProvider -import xyz.xenondevs.invui.item.impl.AbstractItem /** * A button which cycles through a fixed set of values for a player setting. (Think enums for example.) @@ -47,7 +47,7 @@ data class CyclePlayerSettingButton ( val decorator: (Player, S) -> ItemStack, val placeholderProvider: (Player, S) -> MutableList = { _, _ -> mutableListOf() } ) : AbstractItem() { - override fun getItemProvider(player: Player): ItemProvider? { + override fun getItemProvider(player: Player): ItemProvider { val setting = getter(player) val identifier = identifier(setting) val placeholders = placeholderProvider(player, setting) @@ -56,7 +56,7 @@ data class CyclePlayerSettingButton ( .lore(Component.translatable("${key.namespace}.guide.button.${key.key}.${identifier}.lore").arguments(placeholders)) } - override fun handleClick(clickType: ClickType, player: Player, event: InventoryClickEvent) { + override fun handleClick(clickType: ClickType, player: Player, click: Click) { val currentIndex = sortedValues.indexOfFirst { identifier(it) == identifier(getter(player)) } val nextIndex = (currentIndex + (if (clickType.isLeftClick) 1 else -1)) % sortedValues.size setter(player, sortedValues[nextIndex]) diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/button/setting/NumericPlayerSettingButton.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/button/setting/NumericPlayerSettingButton.kt index b50c9807c..a9e74e6be 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/button/setting/NumericPlayerSettingButton.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/button/setting/NumericPlayerSettingButton.kt @@ -7,10 +7,10 @@ import net.kyori.adventure.text.ComponentLike import org.bukkit.NamespacedKey import org.bukkit.entity.Player import org.bukkit.event.inventory.ClickType -import org.bukkit.event.inventory.InventoryClickEvent import org.bukkit.inventory.ItemStack +import xyz.xenondevs.invui.Click +import xyz.xenondevs.invui.item.AbstractItem import xyz.xenondevs.invui.item.ItemProvider -import xyz.xenondevs.invui.item.impl.AbstractItem /** * A button for changing a numeric setting for a player. (e.g. volume, brightness, etc.) @@ -55,7 +55,7 @@ data class NumericPlayerSettingButton( RebarArgument.of("value", Component.text(setting.toString())) ) } ) : AbstractItem() { - override fun getItemProvider(player: Player): ItemProvider? { + override fun getItemProvider(player: Player): ItemProvider { val setting = getter(player) val placeholders = placeholderProvider(player, setting) return ItemStackBuilder.of(decorator(player, setting)) @@ -63,7 +63,7 @@ data class NumericPlayerSettingButton( .lore(Component.translatable("${key.namespace}.guide.button.${key.key}.lore").arguments(placeholders)) } - override fun handleClick(clickType: ClickType, player: Player, event: InventoryClickEvent) { + override fun handleClick(clickType: ClickType, player: Player, click: Click) { var value = getter(player).toDouble() val step = if (clickType.isShiftClick) shiftStep.toDouble() else step.toDouble() value += if (clickType.isLeftClick) step else -step diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/button/setting/TogglePlayerSettingButton.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/button/setting/TogglePlayerSettingButton.kt index 77007cc39..41b1ee81f 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/button/setting/TogglePlayerSettingButton.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/button/setting/TogglePlayerSettingButton.kt @@ -8,10 +8,10 @@ import org.bukkit.Material import org.bukkit.NamespacedKey import org.bukkit.entity.Player import org.bukkit.event.inventory.ClickType -import org.bukkit.event.inventory.InventoryClickEvent import org.bukkit.inventory.ItemStack +import xyz.xenondevs.invui.Click +import xyz.xenondevs.invui.item.AbstractItem import xyz.xenondevs.invui.item.ItemProvider -import xyz.xenondevs.invui.item.impl.AbstractItem /** * A button which toggles a boolean setting for a player. @@ -38,7 +38,7 @@ data class TogglePlayerSettingButton( val decorator: (Player, Boolean) -> ItemStack = { _, toggled -> if (toggled) ItemStack(Material.LIME_CONCRETE) else ItemStack(Material.RED_CONCRETE) }, val placeholderProvider: (Player, Boolean) -> MutableList = { _, _ -> mutableListOf() } ) : AbstractItem() { - override fun getItemProvider(player: Player) : ItemProvider? { + override fun getItemProvider(player: Player) : ItemProvider { val toggled = isEnabled(player) val identifier = if (toggled) "enabled" else "disabled" val placeholders = placeholderProvider(player, toggled) @@ -48,7 +48,7 @@ data class TogglePlayerSettingButton( .addCustomModelDataString("${key}_${identifier}") } - override fun handleClick(clickType: ClickType, player: Player, event: InventoryClickEvent) { + override fun handleClick(clickType: ClickType, player: Player, click: Click) { toggle(player) notifyWindows() } diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/pages/RootPage.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/pages/RootPage.kt index 69dc9df60..8ed2dace2 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/pages/RootPage.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/pages/RootPage.kt @@ -6,23 +6,23 @@ import io.github.pylonmc.rebar.guide.pages.base.SimpleStaticGuidePage import io.github.pylonmc.rebar.util.gui.GuiItems import io.github.pylonmc.rebar.util.rebarKey import org.bukkit.entity.Player -import xyz.xenondevs.inventoryaccess.component.AdventureComponentWrapper import xyz.xenondevs.invui.gui.Gui +import xyz.xenondevs.invui.gui.Markers import xyz.xenondevs.invui.gui.PagedGui -import xyz.xenondevs.invui.gui.structure.Markers +import xyz.xenondevs.invui.item.Item import xyz.xenondevs.invui.window.Window /** * The first page that appears when you open the guide. */ -class RootPage() : SimpleStaticGuidePage( +class RootPage : SimpleStaticGuidePage( rebarKey("root"), mutableListOf(RebarGuide.infoButton, RebarGuide.researchesButton, RebarGuide.fluidsButton) ) { override fun getGui(player: Player): Gui { val buttons = buttonSupplier.get() - val gui = PagedGui.items() + val gui = PagedGui.itemsBuilder() .setStructure( "# e # # # # # s #", "x x x x x x x x x", @@ -37,24 +37,25 @@ class RootPage() : SimpleStaticGuidePage( .addIngredient('x', Markers.CONTENT_LIST_SLOT_HORIZONTAL) .addPageChangeHandler { _, newPage -> saveCurrentPage(player, newPage) } + val content = mutableListOf() for (button in buttons) { if (button is PageButton) { if (button.page.shouldDisplay(player)) { - gui.addContent(button) + content.add(button) } } else { - gui.addContent(button) + content.add(button) } } - return gui.build().apply { loadCurrentPage(player, this) } + return gui.setContent(content).build().apply { loadCurrentPage(player, this) } } override fun open(player: Player) { try { - Window.single() - .setGui(getGui(player)) - .setTitle(AdventureComponentWrapper(title)) + Window.builder() + .setUpperGui(getGui(player)) + .setTitle(title) .open(player) RebarGuide.history.put(player.uniqueId, mutableListOf(this)) } catch (t: Throwable) { diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/pages/base/GuidePage.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/pages/base/GuidePage.kt index 0eaf5a607..d75f8b780 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/pages/base/GuidePage.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/pages/base/GuidePage.kt @@ -4,7 +4,6 @@ import io.github.pylonmc.rebar.content.guide.RebarGuide import net.kyori.adventure.text.Component import org.bukkit.Keyed import org.bukkit.entity.Player -import xyz.xenondevs.inventoryaccess.component.AdventureComponentWrapper import xyz.xenondevs.invui.gui.Gui import xyz.xenondevs.invui.window.Window @@ -37,9 +36,9 @@ interface GuidePage : Keyed { */ fun open(player: Player) { try { - Window.single() - .setGui(getGui(player)) - .setTitle(AdventureComponentWrapper(title)) + Window.builder() + .setUpperGui(getGui(player)) + .setTitle(title) .open(player) RebarGuide.history.getOrPut(player.uniqueId) { mutableListOf() }.add(this) } catch (t: Throwable) { diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/pages/base/PagedGuidePage.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/pages/base/PagedGuidePage.kt index 207d9daa3..acefac5dd 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/pages/base/PagedGuidePage.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/pages/base/PagedGuidePage.kt @@ -5,7 +5,8 @@ import org.bukkit.event.EventHandler import org.bukkit.event.Listener import org.bukkit.event.player.PlayerQuitEvent import xyz.xenondevs.invui.gui.PagedGui -import java.util.* +import java.util.UUID +import java.util.WeakHashMap /** * Represents a GuidePage with multiple pages diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/pages/base/SearchPage.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/pages/base/SearchPage.kt index f113cfcfd..c68230e45 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/pages/base/SearchPage.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/pages/base/SearchPage.kt @@ -13,10 +13,9 @@ import net.kyori.adventure.translation.GlobalTranslator import org.bukkit.Material import org.bukkit.NamespacedKey import org.bukkit.entity.Player -import xyz.xenondevs.inventoryaccess.component.AdventureComponentWrapper import xyz.xenondevs.invui.gui.Gui +import xyz.xenondevs.invui.gui.Markers import xyz.xenondevs.invui.gui.PagedGui -import xyz.xenondevs.invui.gui.structure.Markers import xyz.xenondevs.invui.item.Item import xyz.xenondevs.invui.window.AnvilWindow import java.util.UUID @@ -34,7 +33,7 @@ abstract class SearchPage(key: NamespacedKey) : SimpleStaticGuidePage(key) { override fun open(player: Player) { var firstRename = true val search = searches.getOrDefault(player.uniqueId, "") - val lowerGui = PagedGui.items() + val lowerGui = PagedGui.itemsBuilder() .setStructure( "x x x x x x x x x", "x x x x x x x x x", @@ -49,7 +48,7 @@ abstract class SearchPage(key: NamespacedKey) : SimpleStaticGuidePage(key) { .setContent(getItems(player, search)) .addPageChangeHandler { _, newPage -> saveCurrentPage(player, newPage) } .build() - val upperGui = Gui.normal() + val upperGui = Gui.builder() .setStructure("# S #") .addIngredient('S', searchSpecifiersStack) .addIngredient('#', GuiItems.background(search)) @@ -57,11 +56,11 @@ abstract class SearchPage(key: NamespacedKey) : SimpleStaticGuidePage(key) { loadCurrentPage(player, lowerGui) try { - AnvilWindow.split() + AnvilWindow.builder() .setViewer(player) .setUpperGui(upperGui) .setLowerGui(lowerGui) - .setTitle(AdventureComponentWrapper(title)) + .setTitle(title) .addRenameHandler { search -> if (firstRename) { // The first rename happens immediately when the anvil is opened, we need to ignore it diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/pages/base/SimpleDynamicGuidePage.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/pages/base/SimpleDynamicGuidePage.kt index f1c9eb437..f3bdddca3 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/pages/base/SimpleDynamicGuidePage.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/pages/base/SimpleDynamicGuidePage.kt @@ -6,8 +6,8 @@ import io.github.pylonmc.rebar.util.gui.GuiItems import org.bukkit.NamespacedKey import org.bukkit.entity.Player import xyz.xenondevs.invui.gui.Gui +import xyz.xenondevs.invui.gui.Markers import xyz.xenondevs.invui.gui.PagedGui -import xyz.xenondevs.invui.gui.structure.Markers import xyz.xenondevs.invui.item.Item import java.util.function.Supplier @@ -38,7 +38,7 @@ open class SimpleDynamicGuidePage( * Returns a page containing the header (the top row of the page) and a section * for the items to go. */ - open fun getHeader(player: Player, buttons: List) = PagedGui.items() + open fun getHeader(player: Player, buttons: List) = PagedGui.itemsBuilder() .setStructure( "< b # # # # # s >", "x x x x x x x x x", @@ -59,15 +59,17 @@ open class SimpleDynamicGuidePage( val buttons = buttonSupplier.get() val gui = getHeader(player, buttons) - for (button in buttons) { - if (button is PageButton) { - if (button.page.shouldDisplay(player)) { - gui.addContent(button) + gui.setContent(buildList { + for (button in buttons) { + if (button is PageButton) { + if (button.page.shouldDisplay(player)) { + add(button) + } + } else { + add(button) } - } else { - gui.addContent(button) } - } + }) return gui.build().apply { loadCurrentPage(player, this) } } diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/pages/base/TabbedGuidePage.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/pages/base/TabbedGuidePage.kt index 96f6d470b..8721dbb7c 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/pages/base/TabbedGuidePage.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/pages/base/TabbedGuidePage.kt @@ -5,7 +5,8 @@ import org.bukkit.event.EventHandler import org.bukkit.event.Listener import org.bukkit.event.player.PlayerQuitEvent import xyz.xenondevs.invui.gui.TabGui -import java.util.* +import java.util.UUID +import java.util.WeakHashMap /** * Represents a GuidePage with multiple tabs diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/pages/fluid/FluidRecipesPage.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/pages/fluid/FluidRecipesPage.kt index 96d76d86c..ec54b2a07 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/pages/fluid/FluidRecipesPage.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/pages/fluid/FluidRecipesPage.kt @@ -9,8 +9,8 @@ import io.github.pylonmc.rebar.util.rebarKey import org.bukkit.NamespacedKey import org.bukkit.entity.Player import xyz.xenondevs.invui.gui.Gui +import xyz.xenondevs.invui.gui.Markers import xyz.xenondevs.invui.gui.PagedGui -import xyz.xenondevs.invui.gui.structure.Markers /** * Displays all the recipes for the given fluid. @@ -32,7 +32,7 @@ open class FluidRecipesPage(fluidKey: NamespacedKey) : PagedGuidePage { override fun getKey() = KEY - open fun getHeader(player: Player, pages: List) = PagedGui.guis() + open fun getHeader(player: Player, pages: List) = PagedGui.guisBuilder() .setStructure( "< b # # g # # s >", "x x x x x x x x x", @@ -52,9 +52,7 @@ open class FluidRecipesPage(fluidKey: NamespacedKey) : PagedGuidePage { override fun getGui(player: Player): Gui { val gui = getHeader(player, pages) - for (page in pages) { - gui.addContent(page) - } + gui.setContent(pages) return gui.build().apply { loadCurrentPage(player, this) } } diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/pages/fluid/FluidUsagesPage.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/pages/fluid/FluidUsagesPage.kt index 4c7bf6e13..95b016d36 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/pages/fluid/FluidUsagesPage.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/pages/fluid/FluidUsagesPage.kt @@ -8,8 +8,8 @@ import io.github.pylonmc.rebar.util.gui.GuiItems import io.github.pylonmc.rebar.util.rebarKey import org.bukkit.entity.Player import xyz.xenondevs.invui.gui.Gui +import xyz.xenondevs.invui.gui.Markers import xyz.xenondevs.invui.gui.PagedGui -import xyz.xenondevs.invui.gui.structure.Markers /** * Displays all the recipes that use the given [fluid]. @@ -30,7 +30,7 @@ open class FluidUsagesPage(val fluid: RebarFluid) : PagedGuidePage { override fun getKey() = KEY - open fun getHeader(player: Player, pages: List) = PagedGui.guis() + open fun getHeader(player: Player, pages: List) = PagedGui.guisBuilder() .setStructure( "< b # # # # # s >", "x x x x x x x x x", @@ -49,9 +49,7 @@ open class FluidUsagesPage(val fluid: RebarFluid) : PagedGuidePage { override fun getGui(player: Player): Gui { val gui = getHeader(player, pages) - for (page in pages) { - gui.addContent(page) - } + gui.setContent(pages) return gui.build().apply { loadCurrentPage(player, this) } } diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/pages/item/ItemIngredientsPage.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/pages/item/ItemIngredientsPage.kt index f86c66d3e..705809e78 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/pages/item/ItemIngredientsPage.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/pages/item/ItemIngredientsPage.kt @@ -17,9 +17,9 @@ import net.kyori.adventure.text.Component import org.bukkit.Material import org.bukkit.entity.Player import xyz.xenondevs.invui.gui.Gui +import xyz.xenondevs.invui.gui.Markers import xyz.xenondevs.invui.gui.PagedGui import xyz.xenondevs.invui.gui.TabGui -import xyz.xenondevs.invui.gui.structure.Markers import xyz.xenondevs.invui.item.Item /** @@ -35,7 +35,7 @@ open class ItemIngredientsPage(val input: FluidOrItem) : TabbedGuidePage { override fun getKey() = KEY private class ItemListDisplayTab(private val items: List) : SimpleStaticGuidePage(rebarKey("unused")) { - override fun getGui(player: Player) = PagedGui.items() + override fun getGui(player: Player) = PagedGui.itemsBuilder() .setStructure( "< # # # # # # # >", "x x x x x x x x x", @@ -72,7 +72,7 @@ open class ItemIngredientsPage(val input: FluidOrItem) : TabbedGuidePage { } }.map(::fluidOrItemButton)) - override fun getGui(player: Player): Gui = TabGui.normal() + override fun getGui(player: Player): Gui = TabGui.builder() .setStructure( "# b # i # y # # #", "x x x x x x x x x", @@ -94,8 +94,7 @@ open class ItemIngredientsPage(val input: FluidOrItem) : TabbedGuidePage { ) .addIngredient('x', Markers.CONTENT_LIST_SLOT_HORIZONTAL) .addTabChangeHandler { _, newTab -> saveCurrentTab(player, newTab) } - .addTab(ingredientsTab.getGui(player)) - .addTab(byproductsTab.getGui(player)) + .setTabs(listOf(ingredientsTab.getGui(player), byproductsTab.getGui(player))) .build() .apply { loadCurrentTab(player, this) } diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/pages/item/ItemRecipesPage.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/pages/item/ItemRecipesPage.kt index 0e32efa54..fe3da154b 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/pages/item/ItemRecipesPage.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/pages/item/ItemRecipesPage.kt @@ -9,8 +9,8 @@ import io.github.pylonmc.rebar.util.rebarKey import org.bukkit.entity.Player import org.bukkit.inventory.ItemStack import xyz.xenondevs.invui.gui.Gui +import xyz.xenondevs.invui.gui.Markers import xyz.xenondevs.invui.gui.PagedGui -import xyz.xenondevs.invui.gui.structure.Markers /** * Displays all the recipes for the given [stack]. @@ -31,7 +31,7 @@ open class ItemRecipesPage(val stack: ItemStack) : PagedGuidePage { override fun getKey() = KEY - open fun getHeader(player: Player, pages: List) = PagedGui.guis() + open fun getHeader(player: Player, pages: List) = PagedGui.guisBuilder() .setStructure( "< b # # g # # s >", "x x x x x x x x x", @@ -51,9 +51,7 @@ open class ItemRecipesPage(val stack: ItemStack) : PagedGuidePage { override fun getGui(player: Player): Gui { val gui = getHeader(player, pages) - for (page in pages) { - gui.addContent(page) - } + gui.setContent(pages) return gui.build().apply { loadCurrentPage(player, this) } } diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/pages/item/ItemUsagesPage.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/pages/item/ItemUsagesPage.kt index 3b3bf3967..8273a70d2 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/pages/item/ItemUsagesPage.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/pages/item/ItemUsagesPage.kt @@ -8,8 +8,8 @@ import io.github.pylonmc.rebar.util.rebarKey import org.bukkit.entity.Player import org.bukkit.inventory.ItemStack import xyz.xenondevs.invui.gui.Gui +import xyz.xenondevs.invui.gui.Markers import xyz.xenondevs.invui.gui.PagedGui -import xyz.xenondevs.invui.gui.structure.Markers /** * Displays all the recipes that use the given [stack]. @@ -30,7 +30,7 @@ open class ItemUsagesPage(val stack: ItemStack) : PagedGuidePage { override fun getKey() = KEY - open fun getHeader(player: Player, pages: List) = PagedGui.guis() + open fun getHeader(player: Player, pages: List) = PagedGui.guisBuilder() .setStructure( "< b # # # # # s >", "x x x x x x x x x", @@ -49,9 +49,7 @@ open class ItemUsagesPage(val stack: ItemStack) : PagedGuidePage { override fun getGui(player: Player): Gui { val gui = getHeader(player, pages) - for (page in pages) { - gui.addContent(page) - } + gui.setContent(pages) return gui.build().apply { loadCurrentPage(player, this) } } diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/pages/settings/PlayerSettingsPage.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/pages/settings/PlayerSettingsPage.kt index df55ad28c..e42218ab5 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/pages/settings/PlayerSettingsPage.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/pages/settings/PlayerSettingsPage.kt @@ -8,8 +8,8 @@ import io.github.pylonmc.rebar.util.gui.GuiItems import org.bukkit.NamespacedKey import org.bukkit.entity.Player import xyz.xenondevs.invui.gui.Gui +import xyz.xenondevs.invui.gui.Markers import xyz.xenondevs.invui.gui.PagedGui -import xyz.xenondevs.invui.gui.structure.Markers import xyz.xenondevs.invui.item.Item /** @@ -18,7 +18,7 @@ import xyz.xenondevs.invui.item.Item open class PlayerSettingsPage(key: NamespacedKey) : SimpleStaticGuidePage(key, mutableListOf()) { override fun getGui(player: Player): Gui { val buttons = buttonSupplier.get() - val gui = PagedGui.items() + val gui = PagedGui.itemsBuilder() .setStructure( "# b # # # # # s #", "# # # # # # # # #", diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/i18n/RebarTranslator.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/i18n/RebarTranslator.kt index 1b56eae05..88d68d7d4 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/i18n/RebarTranslator.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/i18n/RebarTranslator.kt @@ -22,11 +22,7 @@ import io.papermc.paper.datacomponent.DataComponentTypes import io.papermc.paper.datacomponent.item.ItemLore import io.papermc.paper.datacomponent.item.ResolvableProfile import net.kyori.adventure.key.Key -import net.kyori.adventure.text.Component -import net.kyori.adventure.text.TextReplacementConfig -import net.kyori.adventure.text.TranslatableComponent -import net.kyori.adventure.text.TranslationArgumentLike -import net.kyori.adventure.text.VirtualComponent +import net.kyori.adventure.text.* import net.kyori.adventure.text.format.NamedTextColor import net.kyori.adventure.text.format.Style import net.kyori.adventure.text.format.TextDecoration diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/item/RebarItemListener.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/item/RebarItemListener.kt index 1bcc7a539..a25af579a 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/item/RebarItemListener.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/item/RebarItemListener.kt @@ -386,8 +386,8 @@ internal object RebarItemListener : Listener { private fun handle(event: PlayerPickItemEvent) { val reachDistance = event.player.getAttribute(Attribute.BLOCK_INTERACTION_RANGE)?.value ?: 4.5 val block = event.player.getTargetBlockExact(ceil(reachDistance).toInt()) ?: return - val pylonBlock = BlockStorage.get(block) ?: return - val blockItem = pylonBlock.getPickItem() ?: return + val rebarBlock = BlockStorage.get(block) ?: return + val blockItem = rebarBlock.getPickItem() ?: return val blockRebarItem = RebarItem.fromStack(blockItem) ?: return val sourceSlot = event.sourceSlot diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/item/base/RebarArmor.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/item/base/RebarArmor.kt index 4cc07ab20..c81f3c5ef 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/item/base/RebarArmor.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/item/base/RebarArmor.kt @@ -1,7 +1,7 @@ package io.github.pylonmc.rebar.item.base -import net.kyori.adventure.key.Key import io.github.pylonmc.rebar.item.RebarItem +import net.kyori.adventure.key.Key /** * Represents a [RebarItem] that is wearable piece of armor. diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/item/base/RebarInventoryEffectItem.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/item/base/RebarInventoryEffectItem.kt index 4a4f44538..43ceef16c 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/item/base/RebarInventoryEffectItem.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/item/base/RebarInventoryEffectItem.kt @@ -9,7 +9,7 @@ import org.bukkit.entity.Player import org.bukkit.persistence.PersistentDataType import org.bukkit.scheduler.BukkitTask import org.jetbrains.annotations.MustBeInvokedByOverriders -import java.util.* +import java.util.UUID interface RebarInventoryEffectItem : RebarInventoryTicker { @MustBeInvokedByOverriders diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/item/builder/ItemStackBuilder.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/item/builder/ItemStackBuilder.kt index 00a3d66be..216c3df27 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/item/builder/ItemStackBuilder.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/item/builder/ItemStackBuilder.kt @@ -31,8 +31,8 @@ import org.bukkit.inventory.ItemStack import org.bukkit.inventory.meta.ItemMeta import org.bukkit.persistence.PersistentDataContainer import org.jetbrains.annotations.ApiStatus -import xyz.xenondevs.invui.item.Item import xyz.xenondevs.invui.item.ItemProvider +import java.util.Locale import java.util.function.Consumer /** @@ -41,7 +41,7 @@ import java.util.function.Consumer * * Implements InvUI's [ItemProvider], so can be used instead of an [ItemStack] in GUIs. */ -@Suppress("UnstableApiUsage") +@Suppress("UnstableApiUsage", "unused") open class ItemStackBuilder internal constructor(val stack: ItemStack) : ItemProvider { fun amount(amount: Int) = apply { stack.amount = amount @@ -326,7 +326,13 @@ open class ItemStackBuilder internal constructor(val stack: ItemStack) : ItemPro * Ignore this method; InvUI item provider implementation. */ @ApiStatus.Internal - override fun get(lang: String?) = build() + override fun get() = build() + + /** + * Ignore this method; InvUI item provider implementation. + */ + @ApiStatus.Internal + override fun get(locale: Locale) = build() companion object { @@ -367,11 +373,6 @@ open class ItemStackBuilder internal constructor(val stack: ItemStack) : ItemPro return of(ItemStack(material)) } - @JvmStatic - fun of(item: Item): ItemStackBuilder { - return of(ItemStack(item.itemProvider.get())) - } - /** * Creates a new [ItemStack] for a GUI item, sets its pdc key and adds * a custom model data string for resource packs. @@ -480,7 +481,7 @@ open class ItemStackBuilder internal constructor(val stack: ItemStack) : ItemPro * ``` */ @JvmStatic - fun pylonHelmet(stack: ItemStack, key: NamespacedKey, hasDurability: Boolean) = pylonArmor(stack, key, EquipmentSlotGroup.HEAD, hasDurability) + fun rebarHelmet(stack: ItemStack, key: NamespacedKey, hasDurability: Boolean) = rebarArmor(stack, key, EquipmentSlotGroup.HEAD, hasDurability) /** * Creates a new [ItemStack] for a [RebarItem] that can be worn in the [helmet][EquipmentSlotGroup.HEAD] slot. @@ -497,7 +498,7 @@ open class ItemStackBuilder internal constructor(val stack: ItemStack) : ItemPro * ``` */ @JvmStatic - fun pylonHelmet(material: Material, key: NamespacedKey, hasDurability: Boolean) = pylonHelmet(ItemStack(material), key, hasDurability) + fun rebarHelmet(material: Material, key: NamespacedKey, hasDurability: Boolean) = rebarHelmet(ItemStack(material), key, hasDurability) /** * Creates a new [ItemStack] for a [RebarItem] that can be worn in the [chestplate][EquipmentSlotGroup.CHEST] slot. @@ -514,7 +515,7 @@ open class ItemStackBuilder internal constructor(val stack: ItemStack) : ItemPro * ``` */ @JvmStatic - fun pylonChestplate(stack: ItemStack, key: NamespacedKey, hasDurability: Boolean) = pylonArmor(stack, key, EquipmentSlotGroup.CHEST, hasDurability) + fun rebarChestplate(stack: ItemStack, key: NamespacedKey, hasDurability: Boolean) = rebarArmor(stack, key, EquipmentSlotGroup.CHEST, hasDurability) /** * Creates a new [ItemStack] for a [RebarItem] that can be worn in the [chestplate][EquipmentSlotGroup.CHEST] slot. @@ -531,7 +532,7 @@ open class ItemStackBuilder internal constructor(val stack: ItemStack) : ItemPro * ``` */ @JvmStatic - fun pylonChestplate(material: Material, key: NamespacedKey, hasDurability: Boolean) = pylonChestplate(ItemStack(material), key, hasDurability) + fun rebarChestplate(material: Material, key: NamespacedKey, hasDurability: Boolean) = rebarChestplate(ItemStack(material), key, hasDurability) /** * Creates a new [ItemStack] for a [RebarItem] that can be worn in the [leggings][EquipmentSlotGroup.LEGS] slot. @@ -548,7 +549,7 @@ open class ItemStackBuilder internal constructor(val stack: ItemStack) : ItemPro * ``` */ @JvmStatic - fun pylonLeggings(stack: ItemStack, key: NamespacedKey, hasDurability: Boolean) = pylonArmor(stack, key, EquipmentSlotGroup.LEGS, hasDurability) + fun rebarLeggings(stack: ItemStack, key: NamespacedKey, hasDurability: Boolean) = rebarArmor(stack, key, EquipmentSlotGroup.LEGS, hasDurability) /** * Creates a new [ItemStack] for a [RebarItem] that can be worn in the [leggings][EquipmentSlotGroup.LEGS] slot. @@ -565,7 +566,7 @@ open class ItemStackBuilder internal constructor(val stack: ItemStack) : ItemPro * ``` */ @JvmStatic - fun pylonLeggings(material: Material, key: NamespacedKey, hasDurability: Boolean) = pylonLeggings(ItemStack(material), key, hasDurability) + fun rebarLeggings(material: Material, key: NamespacedKey, hasDurability: Boolean) = rebarLeggings(ItemStack(material), key, hasDurability) /** * Creates a new [ItemStack] for a [RebarItem] that can be worn in the [boots][EquipmentSlotGroup.FEET] slot. @@ -582,7 +583,7 @@ open class ItemStackBuilder internal constructor(val stack: ItemStack) : ItemPro * ``` */ @JvmStatic - fun pylonBoots(stack: ItemStack, key: NamespacedKey, hasDurability: Boolean) = pylonArmor(stack, key, EquipmentSlotGroup.FEET, hasDurability) + fun rebarBoots(stack: ItemStack, key: NamespacedKey, hasDurability: Boolean) = rebarArmor(stack, key, EquipmentSlotGroup.FEET, hasDurability) /** * Creates a new [ItemStack] for a [RebarItem] that can be worn in the [boots][EquipmentSlotGroup.FEET] slot. @@ -599,7 +600,7 @@ open class ItemStackBuilder internal constructor(val stack: ItemStack) : ItemPro * ``` */ @JvmStatic - fun pylonBoots(material: Material, key: NamespacedKey, hasDurability: Boolean) = pylonBoots(ItemStack(material), key, hasDurability) + fun rebarBoots(material: Material, key: NamespacedKey, hasDurability: Boolean) = rebarBoots(ItemStack(material), key, hasDurability) /** * Creates a new [ItemStack] for a [RebarItem] that can be worn in the specified [slot]. @@ -616,7 +617,7 @@ open class ItemStackBuilder internal constructor(val stack: ItemStack) : ItemPro * ``` */ @JvmStatic - fun pylonArmor(stack: ItemStack, key: NamespacedKey, slot: EquipmentSlotGroup, hasDurability: Boolean) = rebar(stack, key) { builder, settings -> + fun rebarArmor(stack: ItemStack, key: NamespacedKey, slot: EquipmentSlotGroup, hasDurability: Boolean) = rebar(stack, key) { builder, settings -> builder.armor( slot, settings.getOrThrow("armor", ConfigAdapter.DOUBLE), @@ -645,8 +646,8 @@ open class ItemStackBuilder internal constructor(val stack: ItemStack) : ItemPro * ``` */ @JvmStatic - fun pylonArmor(material: Material, key: NamespacedKey, slot: EquipmentSlotGroup, hasDurability: Boolean) - = pylonArmor(ItemStack(material), key, slot, hasDurability) + fun rebarArmor(material: Material, key: NamespacedKey, slot: EquipmentSlotGroup, hasDurability: Boolean) + = rebarArmor(ItemStack(material), key, slot, hasDurability) /** * Creates a new [ItemStack] for a [RebarItem] that can be used as a tool for the [mineable] blocks. (See [pickaxeMineable] @@ -663,7 +664,7 @@ open class ItemStackBuilder internal constructor(val stack: ItemStack) : ItemPro * ``` */ @JvmStatic - fun pylonTool(stack: ItemStack, key: NamespacedKey, mineable: RegistryKeySet, hasDurability: Boolean) = rebar(stack, key) { builder, settings -> + fun rebarTool(stack: ItemStack, key: NamespacedKey, mineable: RegistryKeySet, hasDurability: Boolean) = rebar(stack, key) { builder, settings -> builder.tool( mineable, settings.getOrThrow("mining-speed", ConfigAdapter.FLOAT), @@ -692,8 +693,8 @@ open class ItemStackBuilder internal constructor(val stack: ItemStack) : ItemPro * ``` */ @JvmStatic - fun pylonTool(material: Material, key: NamespacedKey, mineable: RegistryKeySet, hasDurability: Boolean) - = pylonTool(ItemStack(material), key, mineable, hasDurability) + fun rebarTool(material: Material, key: NamespacedKey, mineable: RegistryKeySet, hasDurability: Boolean) + = rebarTool(ItemStack(material), key, mineable, hasDurability) /** * Creates a new [ItemStack] for a [RebarItem] that can be used as a weapon. @@ -719,7 +720,7 @@ open class ItemStackBuilder internal constructor(val stack: ItemStack) : ItemPro * ``` */ @JvmStatic - fun pylonWeapon(stack: ItemStack, key: NamespacedKey, hasDurability: Boolean, hasKnockback: Boolean, disablesShield: Boolean) = rebar(stack, key) { builder, settings -> + fun rebarWeapon(stack: ItemStack, key: NamespacedKey, hasDurability: Boolean, hasKnockback: Boolean, disablesShield: Boolean) = rebar(stack, key) { builder, settings -> builder.weapon( settings.getOrThrow("attack-damage", ConfigAdapter.DOUBLE), settings.getOrThrow("attack-speed", ConfigAdapter.DOUBLE), @@ -764,8 +765,8 @@ open class ItemStackBuilder internal constructor(val stack: ItemStack) : ItemPro * ``` */ @JvmStatic - fun pylonWeapon(material: Material, key: NamespacedKey, hasDurability: Boolean, hasKnockback: Boolean, disablesShield: Boolean) - = pylonWeapon(ItemStack(material), key, hasDurability, hasKnockback, disablesShield) + fun rebarWeapon(material: Material, key: NamespacedKey, hasDurability: Boolean, hasKnockback: Boolean, disablesShield: Boolean) + = rebarWeapon(ItemStack(material), key, hasDurability, hasKnockback, disablesShield) /** * Creates a new [ItemStack] for a [RebarItem] that can be used as a weapon and tool for the [mineable] blocks. (See [pickaxeMineable] and related for basic tools) @@ -796,9 +797,9 @@ open class ItemStackBuilder internal constructor(val stack: ItemStack) : ItemPro * ``` */ @JvmStatic - fun pylonToolWeapon(stack: ItemStack, key: NamespacedKey, mineable: RegistryKeySet, hasDurability: Boolean, hasKnockback: Boolean, disablesShield: Boolean): ItemStackBuilder { + fun rebarToolWeapon(stack: ItemStack, key: NamespacedKey, mineable: RegistryKeySet, hasDurability: Boolean, hasKnockback: Boolean, disablesShield: Boolean): ItemStackBuilder { val settings = Settings.get(key) - return pylonWeapon(stack, key, hasDurability, hasKnockback, disablesShield).tool( + return rebarWeapon(stack, key, hasDurability, hasKnockback, disablesShield).tool( mineable, settings.getOrThrow("mining-speed", ConfigAdapter.FLOAT), settings.getOrThrow("mining-durability-damage", ConfigAdapter.INT) @@ -834,8 +835,8 @@ open class ItemStackBuilder internal constructor(val stack: ItemStack) : ItemPro * ``` */ @JvmStatic - fun pylonToolWeapon(material: Material, key: NamespacedKey, mineable: RegistryKeySet, hasDurability: Boolean, hasKnockback: Boolean, disablesShield: Boolean) - = pylonToolWeapon(ItemStack(material), key, mineable, hasDurability, hasKnockback, disablesShield) + fun rebarToolWeapon(material: Material, key: NamespacedKey, mineable: RegistryKeySet, hasDurability: Boolean, hasKnockback: Boolean, disablesShield: Boolean) + = rebarToolWeapon(ItemStack(material), key, mineable, hasDurability, hasKnockback, disablesShield) fun ItemAttributeModifiers.Builder.copy(modifiers: List?) : ItemAttributeModifiers.Builder { modifiers?.forEach { entry -> diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/logistics/CargoRoutes.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/logistics/CargoRoutes.kt index be8922ef1..55c323193 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/logistics/CargoRoutes.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/logistics/CargoRoutes.kt @@ -7,6 +7,7 @@ import io.github.pylonmc.rebar.event.RebarBlockBreakEvent import io.github.pylonmc.rebar.event.RebarBlockLoadEvent import io.github.pylonmc.rebar.event.RebarBlockPlaceEvent import io.github.pylonmc.rebar.event.RebarBlockUnloadEvent +import io.github.pylonmc.rebar.logistics.CargoRoutes.blockRoutesCache import io.github.pylonmc.rebar.util.IMMEDIATE_FACES import io.github.pylonmc.rebar.util.position.BlockPosition import io.github.pylonmc.rebar.util.position.position diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/logistics/LogisticGroup.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/logistics/LogisticGroup.kt index e9c755e3b..47d7db5ae 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/logistics/LogisticGroup.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/logistics/LogisticGroup.kt @@ -1,26 +1,7 @@ package io.github.pylonmc.rebar.logistics -import io.github.pylonmc.rebar.logistics.slot.BrewingStandFuelLogisticSlot -import io.github.pylonmc.rebar.logistics.slot.BrewingStandPotionLogisticSlot -import io.github.pylonmc.rebar.logistics.slot.ChiseledBookshelfFuelLogisticSlot -import io.github.pylonmc.rebar.logistics.slot.FurnaceFuelLogisticSlot -import io.github.pylonmc.rebar.logistics.slot.JukeboxLogisticSlot -import io.github.pylonmc.rebar.logistics.slot.LogisticSlot -import io.github.pylonmc.rebar.logistics.slot.VanillaInventoryLogisticSlot -import org.bukkit.block.Barrel -import org.bukkit.block.Block -import org.bukkit.block.BrewingStand -import org.bukkit.block.Chest -import org.bukkit.block.ChiseledBookshelf -import org.bukkit.block.Crafter -import org.bukkit.block.Dispenser -import org.bukkit.block.DoubleChest -import org.bukkit.block.Dropper -import org.bukkit.block.Furnace -import org.bukkit.block.Hopper -import org.bukkit.block.Jukebox -import org.bukkit.block.Shelf -import org.bukkit.block.ShulkerBox +import io.github.pylonmc.rebar.logistics.slot.* +import org.bukkit.block.* import org.bukkit.inventory.ItemStack /** diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/logistics/slot/ItemDisplayLogisticSlot.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/logistics/slot/ItemDisplayLogisticSlot.kt index ea72c6416..cd110cd3f 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/logistics/slot/ItemDisplayLogisticSlot.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/logistics/slot/ItemDisplayLogisticSlot.kt @@ -1,7 +1,6 @@ package io.github.pylonmc.rebar.logistics.slot import org.bukkit.entity.ItemDisplay -import org.bukkit.inventory.Inventory import org.bukkit.inventory.ItemStack open class ItemDisplayLogisticSlot(val display: ItemDisplay) : LogisticSlot { diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/particles/ConfettiParticle.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/particles/ConfettiParticle.kt index 6320895e4..4f07fdef2 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/particles/ConfettiParticle.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/particles/ConfettiParticle.kt @@ -12,7 +12,7 @@ import org.bukkit.util.Vector import org.joml.AxisAngle4f import org.joml.Quaternionf import org.joml.Vector3f -import java.util.* +import java.util.Random import java.util.function.Consumer class ConfettiParticle { diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/recipe/RecipeListener.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/recipe/RecipeListener.kt index 6757568a9..b021b1d11 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/recipe/RecipeListener.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/recipe/RecipeListener.kt @@ -167,11 +167,11 @@ internal object RebarRecipeListener : Listener { private fun onCook(e: BlockCookEvent) { if (RebarItem.fromStack(e.source) == null) return - var pylonRecipe: CookingRecipeWrapper? = null + var rebarRecipe: CookingRecipeWrapper? = null for (recipe in RecipeType.vanillaCookingRecipes()) { if (recipe.key !in VanillaRecipeType.nonRebarRecipes && recipe.recipe.inputChoice.test(e.source)) { e.result = recipe.recipe.result.clone() - pylonRecipe = recipe + rebarRecipe = recipe break } } @@ -187,16 +187,16 @@ internal object RebarRecipeListener : Listener { val furnace = (e.block.state as Furnace) val input = furnace.inventory.smelting if (input != null && input.isRebarAndIsNot()) { - var pylonRecipe: CookingRecipeWrapper? = null + var rebarRecipe: CookingRecipeWrapper? = null for (recipe in RecipeType.vanillaCookingRecipes()) { if (recipe.key !in VanillaRecipeType.nonRebarRecipes && recipe.recipe.inputChoice.test(input)) { - pylonRecipe = recipe + rebarRecipe = recipe break } } - val isFurnaceOutputValidToPutRecipeResultIn = pylonRecipe != null - && (furnace.inventory.result == null || pylonRecipe.isOutput(furnace.inventory.result!!)) - if (pylonRecipe == null || !isFurnaceOutputValidToPutRecipeResultIn) { + val isFurnaceOutputValidToPutRecipeResultIn = rebarRecipe != null + && (furnace.inventory.result == null || rebarRecipe.isOutput(furnace.inventory.result!!)) + if (rebarRecipe == null || !isFurnaceOutputValidToPutRecipeResultIn) { e.isCancelled = true } } diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/recipe/vanilla/Cooking.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/recipe/vanilla/Cooking.kt index c9a702c44..63d4a9500 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/recipe/vanilla/Cooking.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/recipe/vanilla/Cooking.kt @@ -24,7 +24,7 @@ sealed class CookingRecipeWrapper(final override val recipe: CookingRecipe<*>) : protected abstract val displayBlock: Material - override fun display(): Gui = Gui.normal() + override fun display(): Gui = Gui.builder() .setStructure( "# # # # # # # # #", "# # # # # # # # #", diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/recipe/vanilla/Crafting.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/recipe/vanilla/Crafting.kt index a76070088..3c8210f05 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/recipe/vanilla/Crafting.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/recipe/vanilla/Crafting.kt @@ -28,7 +28,7 @@ class ShapedRecipeWrapper(override val recipe: ShapedRecipe) : CraftingRecipeWra } override fun display(): Gui { - val gui = Gui.normal() + val gui = Gui.builder() .setStructure( "# # # # # # # # #", "# # # 0 1 2 # # #", @@ -64,7 +64,7 @@ sealed class AShapelessRecipeWrapper(recipe: CraftingRecipe) : CraftingRecipeWra override val inputs: List by lazy { choiceList.filterNotNull().map(RecipeChoice::asRecipeInput) } - override fun display() = Gui.normal() + override fun display() = Gui.builder() .setStructure( "# # # # # # # # #", "# # # 0 1 2 # # #", diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/recipe/vanilla/Smithing.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/recipe/vanilla/Smithing.kt index 1806302ef..163a595fd 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/recipe/vanilla/Smithing.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/recipe/vanilla/Smithing.kt @@ -23,7 +23,7 @@ sealed class SmithingRecipeWrapper(recipe: SmithingRecipe) : VanillaRecipeWrappe override val inputs: List = listOf(recipe.base.asRecipeInput(), recipe.addition.asRecipeInput()) override val results: List = listOf(FluidOrItem.of(recipe.result)) - override fun display() = Gui.normal() + override fun display() = Gui.builder() .setStructure( "# # # # # # # # #", "# # # # # # # # #", diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/util/RebarUtils.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/util/RebarUtils.kt index 2b2dc05d1..f489f922b 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/util/RebarUtils.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/util/RebarUtils.kt @@ -569,7 +569,7 @@ fun damageItem(itemStack: ItemStack, amount: Int, entity: LivingEntity, slot: Eq * A shorthand for a commonly used [VirtualInventory] handler which prevents players * from removing items from it. * - * Usage: Call [VirtualInventory.setPreUpdateHandler] and supply this function to it + * Usage: Call [VirtualInventory.addPreUpdateHandler] and supply this function to it */ @JvmField val DISALLOW_PLAYERS_FROM_ADDING_ITEMS_HANDLER = Consumer { event: ItemPreUpdateEvent -> diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/util/gui/GuiItems.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/util/gui/GuiItems.kt index 0aef26a1e..b94b534e1 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/util/gui/GuiItems.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/util/gui/GuiItems.kt @@ -10,20 +10,18 @@ import io.papermc.paper.datacomponent.DataComponentTypes import io.papermc.paper.datacomponent.item.TooltipDisplay import net.kyori.adventure.text.Component import org.bukkit.Material +import org.bukkit.entity.Player +import org.bukkit.event.inventory.ClickType +import xyz.xenondevs.invui.Click import xyz.xenondevs.invui.gui.PagedGui import xyz.xenondevs.invui.gui.ScrollGui import xyz.xenondevs.invui.gui.TabGui -import xyz.xenondevs.invui.item.Item -import xyz.xenondevs.invui.item.ItemProvider -import xyz.xenondevs.invui.item.impl.AutoCycleItem -import xyz.xenondevs.invui.item.impl.SimpleItem -import xyz.xenondevs.invui.item.impl.controlitem.PageItem -import xyz.xenondevs.invui.item.impl.controlitem.ScrollItem -import xyz.xenondevs.invui.item.impl.controlitem.TabItem +import xyz.xenondevs.invui.item.* /** * A utility class containing items commonly used in GUIs. */ +@Suppress("unused") object GuiItems { val rebarGuiItemKeyKey = rebarKey("gui_item_key") @@ -32,7 +30,7 @@ object GuiItems { */ @JvmStatic @JvmOverloads - fun background(name: String = ""): Item = SimpleItem( + fun background(name: String = ""): Item = Item.simple( ItemStackBuilder.gui(Material.GRAY_STAINED_GLASS_PANE, rebarKey("background")) .name(name) .set(DataComponentTypes.TOOLTIP_DISPLAY, TooltipDisplay.tooltipDisplay().hideTooltip(true)) @@ -43,7 +41,7 @@ object GuiItems { */ @JvmStatic @JvmOverloads - fun backgroundBlack(name: String = ""): Item = SimpleItem( + fun backgroundBlack(name: String = ""): Item = Item.simple( ItemStackBuilder.gui(Material.BLACK_STAINED_GLASS_PANE, rebarKey("background_black")) .name(name) .set(DataComponentTypes.TOOLTIP_DISPLAY, TooltipDisplay.tooltipDisplay().hideTooltip(true)) @@ -53,7 +51,7 @@ object GuiItems { * A lime glass pane named 'Input' */ @JvmStatic - fun input(): Item = SimpleItem( + fun input(): Item = Item.simple( ItemStackBuilder.gui(Material.LIME_STAINED_GLASS_PANE, rebarKey("input")) .name(Component.translatable("rebar.gui.input")) ) @@ -62,7 +60,7 @@ object GuiItems { * An orange glass pane named 'Output' */ @JvmStatic - fun output(): Item = SimpleItem( + fun output(): Item = Item.simple( ItemStackBuilder.gui(Material.ORANGE_STAINED_GLASS_PANE, rebarKey("output")) .name(Component.translatable("rebar.gui.output")) ) @@ -82,17 +80,20 @@ object GuiItems { val states: MutableList = mutableListOf() var i = 0 while (i < timeTicks) { - states.add(ItemStackBuilder.of(template.build().clone()) - .set(DataComponentTypes.MAX_DAMAGE, timeTicks) - .set(DataComponentTypes.DAMAGE, i) - .set( - DataComponentTypes.TOOLTIP_DISPLAY, TooltipDisplay.tooltipDisplay() - .addHiddenComponents(DataComponentTypes.DAMAGE, DataComponentTypes.MAX_DAMAGE) - ) + states.add( + ItemStackBuilder.of(template.build().clone()) + .set(DataComponentTypes.MAX_DAMAGE, timeTicks) + .set(DataComponentTypes.DAMAGE, i) + .set( + DataComponentTypes.TOOLTIP_DISPLAY, TooltipDisplay.tooltipDisplay() + .addHiddenComponents(DataComponentTypes.DAMAGE, DataComponentTypes.MAX_DAMAGE) + ) ) i++ } - return AutoCycleItem(1, *(states.toTypedArray())) + return Item.builder() + .setCyclingItemProvider(1, states) + .build() } /** @@ -138,44 +139,59 @@ object GuiItems { fun tab(item: ItemStackBuilder, tab: Int): Item = RebarTabItem(item, tab) } -private class RebarScrollItem(private val direction: Int, private val key: String?) : ScrollItem(direction) { +private class RebarScrollItem(private val direction: Int, private val key: String) : AbstractScrollGuiBoundItem() { private val name = Component.translatable("rebar.gui.scroll.$key") - override fun getItemProvider(gui: ScrollGui<*>): ItemProvider { - val material = - if (gui.canScroll(direction)) Material.GREEN_STAINED_GLASS_PANE else Material.RED_STAINED_GLASS_PANE + override fun getItemProvider(viewer: Player): ItemProvider { + val material = if (gui.canScroll) Material.GREEN_STAINED_GLASS_PANE else Material.RED_STAINED_GLASS_PANE return ItemStackBuilder.gui(material, rebarKey("scroll_$key")).name(name) } + + override fun handleClick(clickType: ClickType, player: Player, click: Click) { + gui.line += direction + } + + private val ScrollGui<*>.canScroll: Boolean + get() = if (direction > 0) line < maxLine else line > 0 } -private class RebarPageItem(private val forward: Boolean) : PageItem(forward) { - private val background = background().itemProvider +private class RebarPageItem(private val forward: Boolean) : AbstractPagedGuiBoundItem() { + private val background = background() private val name = Component.translatable("rebar.gui.page.${if (forward) "next" else "previous"}") - override fun getItemProvider(gui: PagedGui<*>): ItemProvider { - if (gui.pageAmount < 2) return background + override fun getItemProvider(viewer: Player): ItemProvider { + if (gui.pageCount < 2) return background.getItemProvider(viewer) val material = if (gui.canPage) Material.GREEN_STAINED_GLASS_PANE else Material.RED_STAINED_GLASS_PANE return ItemStackBuilder.gui(material, rebarKey("page_${if (forward) "next" else "previous"}")) .name( name.arguments( - RebarArgument.of("current", gui.currentPage + 1), - RebarArgument.of("total", gui.pageAmount), + RebarArgument.of("current", gui.page + 1), + RebarArgument.of("total", gui.page), ) ) } + override fun handleClick(clickType: ClickType, player: Player, click: Click) { + if (forward) gui.page++ else gui.page-- + } + private val PagedGui<*>.canPage: Boolean - get() = if (forward) hasNextPage() else hasPreviousPage() + get() = if (forward) page < pageCount - 1 else page > 0 } -private class RebarTabItem(private val item: ItemStackBuilder, private val tab: Int) : TabItem(tab) { - override fun getItemProvider(gui: TabGui): ItemProvider { - return if (gui.currentTab == tab) { +private class RebarTabItem(private val item: ItemStackBuilder, private val tab: Int) : AbstractTabGuiBoundItem() { + + override fun getItemProvider(viewer: Player): ItemProvider { + return if (gui.tab == tab) { item.clone().set(DataComponentTypes.ENCHANTMENT_GLINT_OVERRIDE, true) } else { item } } + + override fun handleClick(clickType: ClickType, player: Player, click: Click) { + gui.tab = tab + } } diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/util/gui/ProgressItem.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/util/gui/ProgressItem.kt index 847e55a64..5cec9ae53 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/util/gui/ProgressItem.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/util/gui/ProgressItem.kt @@ -9,11 +9,11 @@ import net.kyori.adventure.text.Component import org.bukkit.Material import org.bukkit.entity.Player import org.bukkit.event.inventory.ClickType -import org.bukkit.event.inventory.InventoryClickEvent import org.bukkit.inventory.ItemStack +import xyz.xenondevs.invui.Click +import xyz.xenondevs.invui.item.AbstractItem import xyz.xenondevs.invui.item.Item import xyz.xenondevs.invui.item.ItemProvider -import xyz.xenondevs.invui.item.impl.AbstractItem import java.time.Duration import kotlin.math.min @@ -31,26 +31,39 @@ import kotlin.math.min * @param countDown If true, the progress bar will be inverted, meaning that 0.0 is full and 1.0 is empty. */ open class ProgressItem @JvmOverloads constructor( - builder: ItemStackBuilder, + item: Item, @JvmSynthetic internal val countDown: Boolean = true ) : AbstractItem() { + @JvmOverloads constructor(builder: ItemStackBuilder, inverse: Boolean = true) : this(Item.simple(builder), inverse) + @JvmOverloads constructor(material: Material, inverse: Boolean = true) : this(ItemStackBuilder.of(material), inverse) @JvmOverloads constructor(stack: ItemStack, inverse: Boolean = true) : this(ItemStackBuilder.of(stack), inverse) - @JvmOverloads constructor(item: Item, inverse: Boolean = true) : this(ItemStackBuilder.of(item), inverse) - /** * The item to be displayed */ - var itemStackBuilder: ItemStackBuilder = builder - set(value) { + var item: Item = item + @JvmName("setItemInternal") + private set(value) { field = value notifyWindows() } + fun setItem(item: Item) { + this.item = item + } + + fun setItem(stack: ItemStack) { + item = Item.simple(stack) + } + + fun setItem(builder: ItemStackBuilder) { + item = Item.simple(builder) + } + /** * The total time of whatever process this item is representing */ @@ -64,7 +77,7 @@ open class ProgressItem @JvmOverloads constructor( } /** - * How far through the [totalTime] we are + * How far through the [totalTime] we are, between 0.0 and 1.0 */ var progress: Double = 0.0 set(value) { @@ -72,6 +85,9 @@ open class ProgressItem @JvmOverloads constructor( notifyWindows() } + var lastDisplayedItem: ItemStack = ItemStack.empty() + private set + /** * Sets how far through the [totalTime] we are */ @@ -103,13 +119,13 @@ open class ProgressItem @JvmOverloads constructor( } @Suppress("UnstableApiUsage") - override fun getItemProvider(): ItemProvider { + override fun getItemProvider(viewer: Player): ItemProvider { var progressValue = progress if (!countDown) { progressValue = 1 - progressValue } - val builder = itemStackBuilder + val builder = ItemStackBuilder.of(item.getItemProvider(viewer).get()) .clone() .set(DataComponentTypes.MAX_DAMAGE, MAX_DURABILITY) @@ -140,15 +156,17 @@ open class ProgressItem @JvmOverloads constructor( builder.lore( Component.translatable( "rebar.gui.time_left", - RebarArgument.of("time", UnitFormat.formatDuration(remaining, true, false)) + RebarArgument.of("time", UnitFormat.formatDuration(remaining, abbreviate = true, useMillis = false)) ) ) } + lastDisplayedItem = builder.build() + return builder } - override fun handleClick(clickType: ClickType, player: Player, event: InventoryClickEvent) {} + override fun handleClick(clickType: ClickType, player: Player, click: Click) {} companion object { private const val MAX_DURABILITY = 1000 diff --git a/rebar/src/main/kotlin/io/github/pylonmc/rebar/waila/Waila.kt b/rebar/src/main/kotlin/io/github/pylonmc/rebar/waila/Waila.kt index 4890ac1e1..6d509b61a 100644 --- a/rebar/src/main/kotlin/io/github/pylonmc/rebar/waila/Waila.kt +++ b/rebar/src/main/kotlin/io/github/pylonmc/rebar/waila/Waila.kt @@ -15,6 +15,7 @@ import io.github.pylonmc.rebar.i18n.RebarArgument import io.github.pylonmc.rebar.util.position.BlockPosition import io.github.pylonmc.rebar.util.position.position import io.github.pylonmc.rebar.util.rebarKey +import io.github.pylonmc.rebar.waila.Waila.Companion.addWailaOverride import io.papermc.paper.raytracing.RayTraceTarget import kotlinx.coroutines.Job import kotlinx.coroutines.delay diff --git a/test/src/main/java/io/github/pylonmc/rebar/test/base/GameTest.java b/test/src/main/java/io/github/pylonmc/rebar/test/base/GameTest.java index be9b7da97..e3e551f15 100644 --- a/test/src/main/java/io/github/pylonmc/rebar/test/base/GameTest.java +++ b/test/src/main/java/io/github/pylonmc/rebar/test/base/GameTest.java @@ -2,9 +2,9 @@ import io.github.pylonmc.rebar.gametest.GameTestConfig; import io.github.pylonmc.rebar.gametest.GameTestFailException; -import io.github.pylonmc.rebar.util.position.BlockPosition; import io.github.pylonmc.rebar.test.RebarTest; import io.github.pylonmc.rebar.test.util.TestUtil; +import io.github.pylonmc.rebar.util.position.BlockPosition; import org.bukkit.NamespacedKey; import org.jetbrains.annotations.NotNull; diff --git a/test/src/main/java/io/github/pylonmc/rebar/test/test/block/BlockStorageChunkReloadTest.java b/test/src/main/java/io/github/pylonmc/rebar/test/test/block/BlockStorageChunkReloadTest.java index 637770b91..c05ede218 100644 --- a/test/src/main/java/io/github/pylonmc/rebar/test/test/block/BlockStorageChunkReloadTest.java +++ b/test/src/main/java/io/github/pylonmc/rebar/test/test/block/BlockStorageChunkReloadTest.java @@ -3,10 +3,10 @@ import io.github.pylonmc.rebar.block.BlockStorage; import io.github.pylonmc.rebar.block.RebarBlock; import io.github.pylonmc.rebar.block.RebarBlockSchema; -import io.github.pylonmc.rebar.util.position.ChunkPosition; import io.github.pylonmc.rebar.test.base.AsyncTest; import io.github.pylonmc.rebar.test.block.BlockWithField; import io.github.pylonmc.rebar.test.util.TestUtil; +import io.github.pylonmc.rebar.util.position.ChunkPosition; import org.bukkit.Chunk; import org.bukkit.block.Block; diff --git a/test/src/main/java/io/github/pylonmc/rebar/test/test/entity/EntityStorageChunkReloadTest.java b/test/src/main/java/io/github/pylonmc/rebar/test/test/entity/EntityStorageChunkReloadTest.java index 02b6ce3db..9c8ca6c18 100644 --- a/test/src/main/java/io/github/pylonmc/rebar/test/test/entity/EntityStorageChunkReloadTest.java +++ b/test/src/main/java/io/github/pylonmc/rebar/test/test/entity/EntityStorageChunkReloadTest.java @@ -20,9 +20,9 @@ protected void test() { Chunk chunk = TestUtil.getRandomChunk(false).join(); Location location = chunk.getBlock(5, 100, 5).getLocation(); UUID uuid = TestUtil.runSync(() -> { - SimpleEntity pylonEntity = new SimpleEntity(location); - EntityStorage.add(pylonEntity); - return pylonEntity.getUuid(); + SimpleEntity rebarEntity = new SimpleEntity(location); + EntityStorage.add(rebarEntity); + return rebarEntity.getUuid(); }).join(); assertThat(EntityStorage.isRebarEntity(uuid)) diff --git a/test/src/main/java/io/github/pylonmc/rebar/test/test/entity/EntityStorageSimpleTest.java b/test/src/main/java/io/github/pylonmc/rebar/test/test/entity/EntityStorageSimpleTest.java index b5750f341..ae7e33bad 100644 --- a/test/src/main/java/io/github/pylonmc/rebar/test/test/entity/EntityStorageSimpleTest.java +++ b/test/src/main/java/io/github/pylonmc/rebar/test/test/entity/EntityStorageSimpleTest.java @@ -18,9 +18,9 @@ public EntityStorageSimpleTest() { super(new GameTestConfig.Builder(new NamespacedKey(RebarTest.instance(), "entity_storage_add_test")) .size(1) .setUp((test) -> { - SimpleEntity pylonEntity = new SimpleEntity(test.location()); - UUID uuid = pylonEntity.getEntity().getUniqueId(); - EntityStorage.add(pylonEntity); + SimpleEntity rebarEntity = new SimpleEntity(test.location()); + UUID uuid = rebarEntity.getEntity().getUniqueId(); + EntityStorage.add(rebarEntity); assertThat(EntityStorage.isRebarEntity(uuid)) .isTrue(); @@ -31,10 +31,10 @@ public EntityStorageSimpleTest() { .isNotNull() .extracting(SimpleEntity::getSomeQuantity) .isEqualTo(69); - assertThat(pylonEntity.getEntity().hasAI()) + assertThat(rebarEntity.getEntity().hasAI()) .isFalse(); - pylonEntity.getEntity().remove(); + rebarEntity.getEntity().remove(); assertThat(EntityStorage.isRebarEntity(uuid)) .isFalse(); diff --git a/test/src/main/java/io/github/pylonmc/rebar/test/test/entity/EntityStorageUnregisteredEntityTest.java b/test/src/main/java/io/github/pylonmc/rebar/test/test/entity/EntityStorageUnregisteredEntityTest.java index f7f51f090..a57acf951 100644 --- a/test/src/main/java/io/github/pylonmc/rebar/test/test/entity/EntityStorageUnregisteredEntityTest.java +++ b/test/src/main/java/io/github/pylonmc/rebar/test/test/entity/EntityStorageUnregisteredEntityTest.java @@ -43,9 +43,9 @@ protected void test() { Chunk chunk = TestUtil.getRandomChunk(false).join(); Location location = chunk.getBlock(5, 100, 5).getLocation(); UUID uuid = TestUtil.runSync(() -> { - UnregisteredEntity pylonEntity = new UnregisteredEntity(location); - EntityStorage.add(pylonEntity); - return pylonEntity.getUuid(); + UnregisteredEntity rebarEntity = new UnregisteredEntity(location); + EntityStorage.add(rebarEntity); + return rebarEntity.getUuid(); }).join(); assertThat(EntityStorage.isRebarEntity(uuid)) diff --git a/test/src/main/java/io/github/pylonmc/rebar/test/test/item/RebarItemStackInterfaceTest.java b/test/src/main/java/io/github/pylonmc/rebar/test/test/item/RebarItemStackInterfaceTest.java index 5639001cf..4394f8d47 100644 --- a/test/src/main/java/io/github/pylonmc/rebar/test/test/item/RebarItemStackInterfaceTest.java +++ b/test/src/main/java/io/github/pylonmc/rebar/test/test/item/RebarItemStackInterfaceTest.java @@ -13,7 +13,7 @@ public class RebarItemStackInterfaceTest extends GameTest { public RebarItemStackInterfaceTest() { - super(new GameTestConfig.Builder(RebarTest.key("pylon_item_stack_interface_test")) + super(new GameTestConfig.Builder(RebarTest.key("rebar_item_stack_interface_test")) .size(0) .timeoutTicks(100) .setUp((test) -> { diff --git a/test/src/main/java/io/github/pylonmc/rebar/test/test/recipe/FurnaceTest.java b/test/src/main/java/io/github/pylonmc/rebar/test/test/recipe/FurnaceTest.java index 856dcb00e..aa2b5adb4 100644 --- a/test/src/main/java/io/github/pylonmc/rebar/test/test/recipe/FurnaceTest.java +++ b/test/src/main/java/io/github/pylonmc/rebar/test/test/recipe/FurnaceTest.java @@ -1,7 +1,7 @@ package io.github.pylonmc.rebar.test.test.recipe; -import io.github.pylonmc.rebar.recipe.RecipeType; import io.github.pylonmc.rebar.gametest.GameTestConfig; +import io.github.pylonmc.rebar.recipe.RecipeType; import io.github.pylonmc.rebar.test.RebarTest; import io.github.pylonmc.rebar.test.base.GameTest; import io.github.pylonmc.rebar.test.item.Items; diff --git a/test/src/main/java/io/github/pylonmc/rebar/test/test/serializer/SerializerTestBlockPosition.java b/test/src/main/java/io/github/pylonmc/rebar/test/test/serializer/SerializerTestBlockPosition.java index d4780182e..d39d2907a 100644 --- a/test/src/main/java/io/github/pylonmc/rebar/test/test/serializer/SerializerTestBlockPosition.java +++ b/test/src/main/java/io/github/pylonmc/rebar/test/test/serializer/SerializerTestBlockPosition.java @@ -1,8 +1,8 @@ package io.github.pylonmc.rebar.test.test.serializer; import io.github.pylonmc.rebar.datatypes.RebarSerializers; -import io.github.pylonmc.rebar.util.position.BlockPosition; import io.github.pylonmc.rebar.test.RebarTest; +import io.github.pylonmc.rebar.util.position.BlockPosition; public class SerializerTestBlockPosition extends SerializerTest { diff --git a/test/src/main/java/io/github/pylonmc/rebar/test/test/serializer/SerializerTestChunkPosition.java b/test/src/main/java/io/github/pylonmc/rebar/test/test/serializer/SerializerTestChunkPosition.java index 3cba872aa..11538ce48 100644 --- a/test/src/main/java/io/github/pylonmc/rebar/test/test/serializer/SerializerTestChunkPosition.java +++ b/test/src/main/java/io/github/pylonmc/rebar/test/test/serializer/SerializerTestChunkPosition.java @@ -1,8 +1,8 @@ package io.github.pylonmc.rebar.test.test.serializer; import io.github.pylonmc.rebar.datatypes.RebarSerializers; -import io.github.pylonmc.rebar.util.position.ChunkPosition; import io.github.pylonmc.rebar.test.RebarTest; +import io.github.pylonmc.rebar.util.position.ChunkPosition; public class SerializerTestChunkPosition extends SerializerTest { diff --git a/test/src/main/java/io/github/pylonmc/rebar/test/test/serializer/SerializerTestSetOfInts.java b/test/src/main/java/io/github/pylonmc/rebar/test/test/serializer/SerializerTestSetOfInts.java index 89ca5b801..88327f582 100644 --- a/test/src/main/java/io/github/pylonmc/rebar/test/test/serializer/SerializerTestSetOfInts.java +++ b/test/src/main/java/io/github/pylonmc/rebar/test/test/serializer/SerializerTestSetOfInts.java @@ -1,6 +1,7 @@ package io.github.pylonmc.rebar.test.test.serializer; import io.github.pylonmc.rebar.datatypes.RebarSerializers; + import java.util.Set; diff --git a/test/src/main/java/io/github/pylonmc/rebar/test/test/serializer/SerializerTestSetOfSetOfStrings.java b/test/src/main/java/io/github/pylonmc/rebar/test/test/serializer/SerializerTestSetOfSetOfStrings.java index 94c04a196..d83bd3351 100644 --- a/test/src/main/java/io/github/pylonmc/rebar/test/test/serializer/SerializerTestSetOfSetOfStrings.java +++ b/test/src/main/java/io/github/pylonmc/rebar/test/test/serializer/SerializerTestSetOfSetOfStrings.java @@ -1,6 +1,7 @@ package io.github.pylonmc.rebar.test.test.serializer; import io.github.pylonmc.rebar.datatypes.RebarSerializers; + import java.util.Set; public class SerializerTestSetOfSetOfStrings extends SerializerTest { diff --git a/test/src/main/java/io/github/pylonmc/rebar/test/util/TestUtil.java b/test/src/main/java/io/github/pylonmc/rebar/test/util/TestUtil.java index b1a1672a2..784b24e0c 100644 --- a/test/src/main/java/io/github/pylonmc/rebar/test/util/TestUtil.java +++ b/test/src/main/java/io/github/pylonmc/rebar/test/util/TestUtil.java @@ -1,7 +1,7 @@ package io.github.pylonmc.rebar.test.util; -import io.github.pylonmc.rebar.util.position.ChunkPosition; import io.github.pylonmc.rebar.test.RebarTest; +import io.github.pylonmc.rebar.util.position.ChunkPosition; import org.bukkit.Bukkit; import org.bukkit.Chunk; import org.jetbrains.annotations.CheckReturnValue;