diff --git a/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/PylonCore.kt b/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/PylonCore.kt index 10189ad91..2fed84a06 100644 --- a/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/PylonCore.kt +++ b/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/PylonCore.kt @@ -23,9 +23,6 @@ import io.github.pylonmc.pylon.core.entity.EntityListener import io.github.pylonmc.pylon.core.entity.EntityStorage import io.github.pylonmc.pylon.core.entity.PylonEntity import io.github.pylonmc.pylon.core.fluid.placement.FluidPipePlacementService -import io.github.pylonmc.pylon.core.guide.button.PageButton -import io.github.pylonmc.pylon.core.guide.button.setting.TogglePlayerSettingButton -import io.github.pylonmc.pylon.core.guide.pages.PlayerSettingsPage import io.github.pylonmc.pylon.core.i18n.PylonTranslator import io.github.pylonmc.pylon.core.item.PylonInventoryTicker import io.github.pylonmc.pylon.core.item.PylonItem @@ -39,10 +36,8 @@ import io.github.pylonmc.pylon.core.recipe.RecipeCompletion import io.github.pylonmc.pylon.core.recipe.RecipeType import io.github.pylonmc.pylon.core.registry.PylonRegistry import io.github.pylonmc.pylon.core.resourcepack.armor.ArmorTextureEngine -import io.github.pylonmc.pylon.core.resourcepack.armor.ArmorTextureEngine.hasCustomArmorTextures import io.github.pylonmc.pylon.core.resourcepack.block.BlockTextureEngine import io.github.pylonmc.pylon.core.util.mergeGlobalConfig -import io.github.pylonmc.pylon.core.util.pylonKey import io.github.pylonmc.pylon.core.waila.Waila import io.github.retrooper.packetevents.factory.spigot.SpigotPacketEventsBuilder import io.papermc.paper.ServerBuildInfo @@ -145,34 +140,18 @@ object PylonCore : JavaPlugin(), PylonAddon { pm.registerEvents(RecipeCompletion, this) if (PylonConfig.WailaConfig.enabled) { - PylonGuide.settingsPage.addSetting(PageButton(PlayerSettingsPage.wailaSettings)) pm.registerEvents(Waila, this) } - PylonGuide.settingsPage.addSetting(PageButton(PlayerSettingsPage.resourcePackSettings)) - if (PylonConfig.ArmorTextureConfig.ENABLED) { - if (!PylonConfig.ArmorTextureConfig.FORCED) { - PlayerSettingsPage.resourcePackSettings.addSetting(TogglePlayerSettingButton( - pylonKey("toggle-armor-textures"), - toggle = { player -> player.hasCustomArmorTextures = !player.hasCustomArmorTextures }, - isEnabled = { player -> player.hasCustomArmorTextures }, - )) - } packetEvents.eventManager.registerListener(ArmorTextureEngine, PacketListenerPriority.HIGHEST) } if (PylonConfig.BlockTextureConfig.ENABLED) { - PlayerSettingsPage.resourcePackSettings.addSetting(PageButton(PlayerSettingsPage.blockTextureSettings)) pm.registerEvents(BlockTextureEngine, this) BlockTextureEngine.updateOccludingCacheJob.start() } - if (PylonConfig.RESEARCHES_ENABLED) { - PylonGuide.settingsPage.addSetting(PlayerSettingsPage.researchConfetti) - PylonGuide.settingsPage.addSetting(PlayerSettingsPage.researchSounds) - } - Bukkit.getScheduler().runTaskTimer( this, MultiblockCache.MultiblockChecker, diff --git a/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/content/guide/PylonGuide.kt b/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/content/guide/PylonGuide.kt index ee03a37dc..0df45a780 100644 --- a/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/content/guide/PylonGuide.kt +++ b/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/content/guide/PylonGuide.kt @@ -1,17 +1,26 @@ package io.github.pylonmc.pylon.core.content.guide +import io.github.pylonmc.pylon.core.addon.PylonAddon import io.github.pylonmc.pylon.core.config.PylonConfig -import io.github.pylonmc.pylon.core.guide.pages.InfoPage -import io.github.pylonmc.pylon.core.guide.pages.PlayerSettingsPage +import io.github.pylonmc.pylon.core.guide.button.BackButton +import io.github.pylonmc.pylon.core.guide.button.FluidButton +import io.github.pylonmc.pylon.core.guide.button.PageButton +import io.github.pylonmc.pylon.core.guide.button.ResearchesButton import io.github.pylonmc.pylon.core.guide.pages.RootPage import io.github.pylonmc.pylon.core.guide.pages.SearchItemsAndFluidsPage import io.github.pylonmc.pylon.core.guide.pages.base.GuidePage -import io.github.pylonmc.pylon.core.guide.pages.fluid.FluidsPage +import io.github.pylonmc.pylon.core.guide.pages.base.SimpleDynamicGuidePage +import io.github.pylonmc.pylon.core.guide.pages.base.SimpleStaticGuidePage import io.github.pylonmc.pylon.core.guide.pages.item.ItemIngredientsPage +import io.github.pylonmc.pylon.core.guide.pages.research.AddonResearchesPage +import io.github.pylonmc.pylon.core.guide.pages.research.ResearchItemsPage import io.github.pylonmc.pylon.core.guide.pages.research.ResearchesPage +import io.github.pylonmc.pylon.core.guide.pages.settings.MainSettingsPage import io.github.pylonmc.pylon.core.item.PylonItem import io.github.pylonmc.pylon.core.item.base.PylonInteractor import io.github.pylonmc.pylon.core.item.builder.ItemStackBuilder +import io.github.pylonmc.pylon.core.item.research.Research +import io.github.pylonmc.pylon.core.registry.PylonRegistry import io.github.pylonmc.pylon.core.util.pylonKey import io.papermc.paper.datacomponent.DataComponentTypes import net.kyori.adventure.key.Key @@ -24,7 +33,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.UUID +import java.util.* /** * The one and only Pylon guide. @@ -75,22 +84,52 @@ class PylonGuide(stack: ItemStack) : PylonItem(stack), PylonInteractor { val hiddenResearches: MutableSet = mutableSetOf() @JvmStatic - val fluidsPage = FluidsPage() + val fluidsPage = object : SimpleDynamicGuidePage( + pylonKey("fluids"), + { PylonRegistry.FLUIDS.map { FluidButton(it) }.toMutableList() } + ) {} @JvmStatic - val infoPage = InfoPage() + val fluidsButton = PageButton(Material.WATER_BUCKET, fluidsPage) + + @JvmStatic + val infoPage = SimpleStaticGuidePage(pylonKey("info")) + + @JvmStatic + val infoButton = PageButton(Material.LANTERN, infoPage) @JvmStatic val researchesPage = ResearchesPage() + @JvmStatic + val researchesButton = PageButton(Material.BREWING_STAND, researchesPage) + + @JvmStatic + fun addonResearchesPage(addon: PylonAddon) = AddonResearchesPage(addon) + + @JvmStatic + fun addonResearchesButton(addon: PylonAddon) = ResearchesButton(addon) + + @JvmStatic + fun researchItemsPage(research: Research) = ResearchItemsPage(research) + @JvmStatic val rootPage = RootPage() + @JvmStatic + val backButton = BackButton() + @JvmStatic val searchItemsAndFluidsPage = SearchItemsAndFluidsPage() @JvmStatic - val settingsPage = PlayerSettingsPage() + val searchItemsAndFluidsButton = PageButton(Material.OAK_SIGN, searchItemsAndFluidsPage) + + @JvmStatic + val mainSettingsPage = MainSettingsPage + + @JvmStatic + val mainSettingsButton = PageButton(Material.COMPARATOR, mainSettingsPage) /** * Lowest priority to avoid another plugin saving the players data or doing something @@ -106,6 +145,9 @@ class PylonGuide(stack: ItemStack) : PylonItem(stack), PylonInteractor { @JvmStatic fun ingredientsPage(stack: ItemStack) = ItemIngredientsPage(stack) + @JvmStatic + fun ingredientsButton(stack: ItemStack) = PageButton(Material.SCULK_SENSOR, ingredientsPage(stack)) + /** * Hide an item from showing up in searches */ diff --git a/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/button/BackButton.kt b/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/button/BackButton.kt index 24f5104b1..1fbd9a303 100644 --- a/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/button/BackButton.kt +++ b/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/button/BackButton.kt @@ -13,7 +13,7 @@ import xyz.xenondevs.invui.item.impl.AbstractItem /** * Represents the back button in the guide. */ -open class BackButton() : AbstractItem() { +class BackButton : AbstractItem() { override fun getItemProvider() = ItemStackBuilder.gui(Material.ENCHANTED_BOOK, pylonKey("guide_back")) .name(Component.translatable("pylon.pyloncore.guide.button.back.name")) @@ -24,7 +24,7 @@ open class BackButton() : AbstractItem() { if (clickType.isShiftClick) { history.clear() - PylonGuide.rootPage.open(player); + PylonGuide.rootPage.open(player) } else if (history.size >= 2) { history.removeLast() // remove the current page history.removeLast().open(player) diff --git a/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/button/ItemButton.kt b/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/button/ItemButton.kt index 461055d5a..d16545cd8 100644 --- a/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/button/ItemButton.kt +++ b/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/button/ItemButton.kt @@ -16,7 +16,6 @@ import io.github.pylonmc.pylon.core.recipe.RecipeInput import io.papermc.paper.datacomponent.DataComponentTypes import kotlinx.coroutines.delay import net.kyori.adventure.text.Component -import org.bukkit.Bukkit import org.bukkit.Material import org.bukkit.Registry import org.bukkit.entity.Player diff --git a/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/button/PageButton.kt b/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/button/PageButton.kt index 80050345e..6aed8f889 100644 --- a/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/button/PageButton.kt +++ b/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/button/PageButton.kt @@ -1,20 +1,34 @@ package io.github.pylonmc.pylon.core.guide.button import io.github.pylonmc.pylon.core.guide.pages.base.GuidePage -import io.github.pylonmc.pylon.core.guide.pages.RootPage; +import io.github.pylonmc.pylon.core.item.builder.ItemStackBuilder +import io.github.pylonmc.pylon.core.util.pylonKey +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 /** * A button that opens another page in the guide. * + * The name and lore of [stack] are ignored, and overwritten by the supplied name and lore. + * + * The name will be inherited from the page name. The lore will be blank, unless you add it + * at `pylon..guide.button.: "your name here"` + * * @see GuidePage */ -open class PageButton(val page: GuidePage) : AbstractItem() { +open class PageButton(val stack: ItemStack, val page: GuidePage) : AbstractItem() { + + constructor(material: Material, page: GuidePage) : this(ItemStack(material), page) - override fun getItemProvider() = page.item + override fun getItemProvider(viewer: Player?) = ItemStackBuilder.gui(stack, "${pylonKey("guide_page")}:${page.key}") + .name(Component.translatable("pylon.${page.key.namespace}.guide.page.${page.key.key}")) + .clearLore() + .lore(Component.translatable("pylon.${page.key.namespace}.guide.button.${page.key.key}", "")) override fun handleClick(clickType: ClickType, player: Player, event: InventoryClickEvent) { page.open(player) diff --git a/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/button/ResearchButton.kt b/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/button/ResearchButton.kt index 4ecf5d049..a3d26697d 100644 --- a/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/button/ResearchButton.kt +++ b/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/button/ResearchButton.kt @@ -6,7 +6,6 @@ import io.github.pylonmc.pylon.core.item.builder.ItemStackBuilder import io.github.pylonmc.pylon.core.item.research.Research import io.github.pylonmc.pylon.core.item.research.Research.Companion.researchPoints import io.github.pylonmc.pylon.core.util.getAddon -import io.github.pylonmc.pylon.core.util.gui.GuiItems import io.github.pylonmc.pylon.core.util.pylonKey import net.kyori.adventure.text.Component import org.bukkit.Material diff --git a/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/button/ResearchesButton.kt b/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/button/ResearchesButton.kt new file mode 100644 index 000000000..ce1023b9f --- /dev/null +++ b/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/button/ResearchesButton.kt @@ -0,0 +1,23 @@ +package io.github.pylonmc.pylon.core.guide.button + +import io.github.pylonmc.pylon.core.addon.PylonAddon +import io.github.pylonmc.pylon.core.guide.pages.research.AddonResearchesPage +import io.github.pylonmc.pylon.core.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 + +/** + * A button that opens the research page for a specific addon. + */ +class ResearchesButton(val addon: PylonAddon) : AbstractItem() { + val page = AddonResearchesPage(addon) + + override fun getItemProvider() = ItemStackBuilder.of(addon.material) + .name(addon.displayName) + + override fun handleClick(clickType: ClickType, player: Player, event: InventoryClickEvent) { + page.open(player) + } +} \ No newline at end of file diff --git a/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/button/setting/NumericPlayerSettingButton.kt b/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/button/setting/NumericPlayerSettingButton.kt index 996323420..3a3b482d7 100644 --- a/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/button/setting/NumericPlayerSettingButton.kt +++ b/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/button/setting/NumericPlayerSettingButton.kt @@ -35,7 +35,7 @@ import xyz.xenondevs.invui.item.impl.AbstractItem * - This is useful for adding visual indicators of the current setting value, such as changing the material or custom model data. * - The name and lore of the button will be applied on top of this ItemStack. * - * [placeholderProvider] Provides additional placeholders for the translation. (See [TranslatableComponent.arguments] and [PylonArgument]) + * [placeholderProvider] Provides additional placeholders for the translation. (See [net.kyori.adventure.text.TranslatableComponent.arguments] and [PylonArgument]) * - By default there is a placeholder "value" which contains the current setting value. */ data class NumericPlayerSettingButton( diff --git a/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/button/setting/TogglePlayerSettingButton.kt b/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/button/setting/TogglePlayerSettingButton.kt index a70b7c3d9..b97f314d7 100644 --- a/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/button/setting/TogglePlayerSettingButton.kt +++ b/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/button/setting/TogglePlayerSettingButton.kt @@ -27,7 +27,7 @@ import xyz.xenondevs.invui.item.impl.AbstractItem * - The name and lore of the button will be applied on top of this ItemStack. * - By default the button is lime concrete when enabled and red concrete when disabled with custom model data of "{key}_enabled" and "{key}_disabled" respectively. * - * [placeholderProvider] Provides additional placeholders for the translation. (See [TranslatableComponent.arguments] and [PylonArgument]) + * [placeholderProvider] Provides additional placeholders for the translation. (See [net.kyori.adventure.text.TranslatableComponent.arguments] and [PylonArgument]) */ data class TogglePlayerSettingButton( val key: NamespacedKey, diff --git a/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/InfoPage.kt b/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/InfoPage.kt deleted file mode 100644 index b78597224..000000000 --- a/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/InfoPage.kt +++ /dev/null @@ -1,13 +0,0 @@ -package io.github.pylonmc.pylon.core.guide.pages - -import io.github.pylonmc.pylon.core.guide.pages.base.SimpleStaticGuidePage -import io.github.pylonmc.pylon.core.util.pylonKey -import org.bukkit.Material - -/** - * Displays buttons for info sections. - */ -class InfoPage : SimpleStaticGuidePage( - pylonKey("info"), - Material.LANTERN -) \ No newline at end of file diff --git a/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/PlayerSettingsPage.kt b/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/PlayerSettingsPage.kt index 5b4291520..e69de29bb 100644 --- a/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/PlayerSettingsPage.kt +++ b/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/PlayerSettingsPage.kt @@ -1,141 +0,0 @@ -package io.github.pylonmc.pylon.core.guide.pages - -import io.github.pylonmc.pylon.core.config.PylonConfig -import io.github.pylonmc.pylon.core.content.guide.PylonGuide -import io.github.pylonmc.pylon.core.guide.button.BackButton -import io.github.pylonmc.pylon.core.guide.button.PageButton -import io.github.pylonmc.pylon.core.guide.button.setting.CyclePlayerSettingButton -import io.github.pylonmc.pylon.core.guide.button.setting.TogglePlayerSettingButton -import io.github.pylonmc.pylon.core.guide.pages.base.SimpleStaticGuidePage -import io.github.pylonmc.pylon.core.i18n.PylonArgument -import io.github.pylonmc.pylon.core.item.builder.ItemStackBuilder -import io.github.pylonmc.pylon.core.item.research.Research.Companion.researchConfetti -import io.github.pylonmc.pylon.core.item.research.Research.Companion.researchSounds -import io.github.pylonmc.pylon.core.resourcepack.block.BlockTextureEngine.cullingPreset -import io.github.pylonmc.pylon.core.resourcepack.block.BlockTextureEngine.hasCustomBlockTextures -import io.github.pylonmc.pylon.core.util.gui.GuiItems -import io.github.pylonmc.pylon.core.util.pylonKey -import io.github.pylonmc.pylon.core.waila.Waila.Companion.wailaConfig -import org.bukkit.Material -import org.bukkit.NamespacedKey -import org.bukkit.entity.Player -import xyz.xenondevs.invui.gui.Gui -import xyz.xenondevs.invui.gui.PagedGui -import xyz.xenondevs.invui.gui.structure.Markers -import xyz.xenondevs.invui.item.Item - -/** - * Contains buttons to change player settings. - */ -class PlayerSettingsPage( - key: NamespacedKey = pylonKey("settings"), - material: Material = Material.COMPARATOR, - buttons: MutableList = mutableListOf(), -) : SimpleStaticGuidePage(key, material, buttons) { - override fun getGui(player: Player): Gui { - val buttons = buttonSupplier.get() - val gui = PagedGui.items() - .setStructure( - "# b # # # # # s #", - "# # # # # # # # #", - "# x x x x x x x #", - "# # # # # # # # #", - ) - .addIngredient('#', GuiItems.background()) - .addIngredient('b', BackButton()) - .addIngredient('s', PageButton(PylonGuide.searchItemsAndFluidsPage)) - .addIngredient('x', Markers.CONTENT_LIST_SLOT_HORIZONTAL) - .addPageChangeHandler { _, newPage -> saveCurrentPage(player, newPage) } - .setContent(buttons.filter { it !is PageButton || it.page !is PlayerSettingsPage || it.page.buttons.isNotEmpty() }) - return gui.build().apply { loadCurrentPage(player, this) } - } - - fun addSetting(item: Item) { - buttons.add(item) - buttons.sortBy { if (it is PageButton) 0 else 1 } - } - - companion object { - @JvmStatic - val wailaSettings = PlayerSettingsPage( - pylonKey("waila_settings"), - Material.SPYGLASS - ).apply { - addSetting(TogglePlayerSettingButton( - pylonKey("toggle-waila"), - toggle = { player -> player.wailaConfig.enabled = !player.wailaConfig.enabled }, - isEnabled = { player -> player.wailaConfig.enabled } - )) - addSetting(TogglePlayerSettingButton( - pylonKey("toggle-vanilla-waila"), - toggle = { player -> player.wailaConfig.vanillaWailaEnabled = !player.wailaConfig.vanillaWailaEnabled }, - isEnabled = { player -> player.wailaConfig.vanillaWailaEnabled } - )) - if (PylonConfig.WailaConfig.ENABLED_TYPES.size > 1) { - addSetting(CyclePlayerSettingButton( - pylonKey("cycle-waila-type"), - PylonConfig.WailaConfig.ENABLED_TYPES, - identifier = { type -> type.name.lowercase() }, - getter = { player -> player.wailaConfig.type }, - setter = { player, type -> player.wailaConfig.type = type }, - decorator = { player, type -> ItemStackBuilder.of(Material.PAPER) - .addCustomModelDataString("waila_type=${type.name.lowercase()}") - .build() - } - )) - } - } - - @JvmStatic - val resourcePackSettings = PlayerSettingsPage( - pylonKey("resource_pack_settings"), - Material.PAINTING - ) - - @JvmStatic - val blockTextureSettings = PlayerSettingsPage( - pylonKey("block_texture_settings"), - Material.BOOKSHELF - ).apply { - if (!PylonConfig.BlockTextureConfig.FORCED) { - addSetting(TogglePlayerSettingButton( - pylonKey("toggle-block-textures"), - toggle = { player -> player.hasCustomBlockTextures = !player.hasCustomBlockTextures }, - isEnabled = { player -> player.hasCustomBlockTextures } - )) - } - addSetting(CyclePlayerSettingButton( - pylonKey("cycle-culling-preset"), - PylonConfig.BlockTextureConfig.CULLING_PRESETS.values.sortedBy { it.index }, - identifier = { preset -> preset.id }, - getter = { player -> player.cullingPreset }, - setter = { player, preset -> player.cullingPreset = preset }, - decorator = { player, preset -> ItemStackBuilder.of(preset.material) - .addCustomModelDataString("culling_preset=${preset.id}") - .build() - }, - placeholderProvider = { player, preset -> mutableListOf( - PylonArgument.of("hiddenInterval", preset.hiddenInterval), - PylonArgument.of("visibleInterval", preset.visibleInterval), - PylonArgument.of("alwaysShowRadius", preset.alwaysShowRadius), - PylonArgument.of("cullRadius", preset.cullRadius), - PylonArgument.of("maxOccludingCount", preset.maxOccludingCount) - )} - )) - } - - @JvmStatic - val researchConfetti = TogglePlayerSettingButton( - pylonKey("toggle-research-confetti"), - toggle = { player -> player.researchConfetti = !player.researchConfetti }, - isEnabled = { player -> player.researchConfetti } - ) - - @JvmStatic - val researchSounds = TogglePlayerSettingButton( - pylonKey("toggle-research-sounds"), - toggle = { player -> player.researchSounds = !player.researchSounds }, - isEnabled = { player -> player.researchSounds } - ) - } -} \ No newline at end of file diff --git a/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/RootPage.kt b/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/RootPage.kt index 5e54c3626..d434c3e0a 100644 --- a/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/RootPage.kt +++ b/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/RootPage.kt @@ -5,7 +5,6 @@ import io.github.pylonmc.pylon.core.guide.button.PageButton import io.github.pylonmc.pylon.core.guide.pages.base.SimpleStaticGuidePage import io.github.pylonmc.pylon.core.util.gui.GuiItems import io.github.pylonmc.pylon.core.util.pylonKey -import org.bukkit.Material import org.bukkit.entity.Player import xyz.xenondevs.inventoryaccess.component.AdventureComponentWrapper import xyz.xenondevs.invui.gui.Gui @@ -18,12 +17,7 @@ import xyz.xenondevs.invui.window.Window */ class RootPage() : SimpleStaticGuidePage( pylonKey("root"), - Material.ENCHANTED_BOOK, - mutableListOf( - PageButton(PylonGuide.infoPage), - PageButton(PylonGuide.researchesPage), - PageButton(PylonGuide.fluidsPage), - ) + mutableListOf(PylonGuide.infoButton, PylonGuide.researchesButton, PylonGuide.fluidsButton) ) { override fun getGui(player: Player): Gui { @@ -38,8 +32,8 @@ class RootPage() : SimpleStaticGuidePage( "x x x x x x x x x", ) .addIngredient('#', GuiItems.background()) - .addIngredient('e', PageButton(PylonGuide.settingsPage)) - .addIngredient('s', PageButton(PylonGuide.searchItemsAndFluidsPage)) + .addIngredient('e', PylonGuide.mainSettingsButton) + .addIngredient('s', PylonGuide.searchItemsAndFluidsButton) .addIngredient('x', Markers.CONTENT_LIST_SLOT_HORIZONTAL) .addPageChangeHandler { _, newPage -> saveCurrentPage(player, newPage) } diff --git a/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/SearchItemsAndFluidsPage.kt b/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/SearchItemsAndFluidsPage.kt index 63023ad3a..097bfc747 100644 --- a/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/SearchItemsAndFluidsPage.kt +++ b/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/SearchItemsAndFluidsPage.kt @@ -16,10 +16,7 @@ import xyz.xenondevs.invui.item.Item /** * Allows you to search all items and fluids by hijacking the anvil GUI. */ -class SearchItemsAndFluidsPage : SearchPage( - pylonKey("search"), - Material.OAK_SIGN -) { +class SearchItemsAndFluidsPage : SearchPage(pylonKey("search")) { fun getItemButtons(player: Player): MutableList> = PylonRegistry.ITEMS.filter { it.key !in PylonGuide.hiddenItems diff --git a/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/base/GuidePage.kt b/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/base/GuidePage.kt index 5572d8612..03e564d03 100644 --- a/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/base/GuidePage.kt +++ b/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/base/GuidePage.kt @@ -6,7 +6,6 @@ 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.item.ItemProvider import xyz.xenondevs.invui.window.Window /** @@ -14,12 +13,6 @@ import xyz.xenondevs.invui.window.Window */ interface GuidePage : Keyed { - /** - * The item representing this page. This will be used in any [io.github.pylonmc.pylon.core.guide.button.PageButton]s - * that point to this page. - */ - val item: ItemProvider - /** * The title of this page, displayed at the top of the GUI when the page is open. */ diff --git a/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/base/SearchPage.kt b/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/base/SearchPage.kt index 0916a928e..5c47d1cec 100644 --- a/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/base/SearchPage.kt +++ b/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/base/SearchPage.kt @@ -2,7 +2,6 @@ package io.github.pylonmc.pylon.core.guide.pages.base import info.debatty.java.stringsimilarity.JaroWinkler import io.github.pylonmc.pylon.core.content.guide.PylonGuide -import io.github.pylonmc.pylon.core.guide.button.BackButton import io.github.pylonmc.pylon.core.guide.button.FluidButton import io.github.pylonmc.pylon.core.item.PylonItem import io.github.pylonmc.pylon.core.item.builder.ItemStackBuilder @@ -28,7 +27,7 @@ import java.util.UUID * @param key A key that uniquely identifies this page. Used to generate translation keys for * this page */ -abstract class SearchPage(key: NamespacedKey, material: Material) : SimpleStaticGuidePage(key, material) { +abstract class SearchPage(key: NamespacedKey) : SimpleStaticGuidePage(key) { abstract fun getItemNamePairs(player: Player, search: String): List> @@ -44,7 +43,7 @@ abstract class SearchPage(key: NamespacedKey, material: Material) : SimpleStatic ) .addIngredient('x', Markers.CONTENT_LIST_SLOT_HORIZONTAL) .addIngredient('#', GuiItems.background()) - .addIngredient('B', BackButton()) + .addIngredient('B', PylonGuide.backButton) .addIngredient('<', GuiItems.pagePrevious()) .addIngredient('>', GuiItems.pageNext()) .setContent(getItems(player, search)) diff --git a/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/base/SimpleDynamicGuidePage.kt b/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/base/SimpleDynamicGuidePage.kt index 7aad359d3..95b56a826 100644 --- a/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/base/SimpleDynamicGuidePage.kt +++ b/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/base/SimpleDynamicGuidePage.kt @@ -1,20 +1,14 @@ package io.github.pylonmc.pylon.core.guide.pages.base import io.github.pylonmc.pylon.core.content.guide.PylonGuide -import io.github.pylonmc.pylon.core.guide.button.BackButton import io.github.pylonmc.pylon.core.guide.button.PageButton -import io.github.pylonmc.pylon.core.item.builder.ItemStackBuilder import io.github.pylonmc.pylon.core.util.gui.GuiItems -import io.github.pylonmc.pylon.core.util.pylonKey -import net.kyori.adventure.text.Component -import org.bukkit.Material import org.bukkit.NamespacedKey import org.bukkit.entity.Player import xyz.xenondevs.invui.gui.Gui import xyz.xenondevs.invui.gui.PagedGui import xyz.xenondevs.invui.gui.structure.Markers import xyz.xenondevs.invui.item.Item -import xyz.xenondevs.invui.item.impl.controlitem.PageItem import java.util.function.Supplier /** @@ -22,19 +16,16 @@ import java.util.function.Supplier * For example, the research page just displays all the researches for a given * addon, with next/previous page buttons and a header. * + * The title of the page will be `pylon..guide.page.` + * * Next/previous buttons are only shown if there are multiple pages. */ open class SimpleDynamicGuidePage( /** - * A key that uniquely identifies this page. Used to get the translation keys for this page. + * A key that uniquely identifies this page. Used to get the translation key for the title of this page. */ private val key: NamespacedKey, - /** - * The material representing this page. Used for [PageButton]s that point to this page. - */ - val material: Material, - /** * Supplies the buttons to be displayed on this page. */ @@ -43,9 +34,6 @@ open class SimpleDynamicGuidePage( override fun getKey() = key - override val item = ItemStackBuilder.gui(material, "${pylonKey("guide_page")}:$key") - .name(Component.translatable("pylon.${key.namespace}.guide.page.${key.key}")) - /** * Returns a page containing the header (the top row of the page) and a section * for the items to go. @@ -61,8 +49,8 @@ open class SimpleDynamicGuidePage( ) .addIngredient('#', GuiItems.background()) .addIngredient('<', GuiItems.pagePrevious()) - .addIngredient('b', BackButton()) - .addIngredient('s', PageButton(PylonGuide.searchItemsAndFluidsPage)) + .addIngredient('b', PylonGuide.backButton) + .addIngredient('s', PylonGuide.searchItemsAndFluidsButton) .addIngredient('>', GuiItems.pageNext()) .addIngredient('x', Markers.CONTENT_LIST_SLOT_HORIZONTAL) .addPageChangeHandler { _, newPage -> saveCurrentPage(player, newPage) } diff --git a/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/base/SimpleStaticGuidePage.kt b/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/base/SimpleStaticGuidePage.kt index a5fac0867..d42397630 100644 --- a/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/base/SimpleStaticGuidePage.kt +++ b/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/base/SimpleStaticGuidePage.kt @@ -13,26 +13,25 @@ import xyz.xenondevs.invui.item.Item /** * A guide page which has a fixed set of buttons. Do not use this if the buttons - * on the page need to change at runtime. + * on the page will ever need to change. + * + * The title of the page will be `pylon..guide.page.` */ open class SimpleStaticGuidePage @JvmOverloads constructor( /** - * A key that uniquely identifies this page. Used to get the translation keys for this page. + * A key that uniquely identifies this page. Used to get the translation key for the title of this page. */ - private val key: NamespacedKey, - - material: Material, + key: NamespacedKey, /** * The list of buttons to be displayed on this page. */ val buttons: MutableList = mutableListOf() -) : SimpleDynamicGuidePage(key, material, { buttons }) { - - override fun getKey(): NamespacedKey = key +) : SimpleDynamicGuidePage(key, { buttons }) { - open fun addItem(item: ItemStack) = buttons.add(ItemButton(item)) - open fun addFluid(fluid: PylonFluid) = buttons.add(FluidButton(fluid)) - open fun addResearch(research: Research) = buttons.add(ResearchButton(research)) - open fun addPage(page: GuidePage) = buttons.add(PageButton(page)) + open fun addButton(button: Item) = buttons.add(button) + open fun addPage(material: Material, page: GuidePage) = addButton(PageButton(material, page)) + open fun addItem(item: ItemStack) = addButton(ItemButton(item)) + open fun addFluid(fluid: PylonFluid) = addButton(FluidButton(fluid)) + open fun addResearch(research: Research) = addButton(ResearchButton(research)) } \ No newline at end of file diff --git a/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/fluid/FluidRecipesPage.kt b/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/fluid/FluidRecipesPage.kt index d834cb6ac..3f8f5727c 100644 --- a/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/fluid/FluidRecipesPage.kt +++ b/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/fluid/FluidRecipesPage.kt @@ -1,9 +1,6 @@ package io.github.pylonmc.pylon.core.guide.pages.fluid import io.github.pylonmc.pylon.core.content.guide.PylonGuide -import io.github.pylonmc.pylon.core.guide.button.BackButton -import io.github.pylonmc.pylon.core.guide.button.PageButton -import io.github.pylonmc.pylon.core.item.builder.ItemStackBuilder import io.github.pylonmc.pylon.core.guide.pages.base.PagedGuidePage import io.github.pylonmc.pylon.core.registry.PylonRegistry import io.github.pylonmc.pylon.core.util.gui.GuiItems @@ -13,7 +10,6 @@ import org.bukkit.entity.Player import xyz.xenondevs.invui.gui.Gui import xyz.xenondevs.invui.gui.PagedGui import xyz.xenondevs.invui.gui.structure.Markers -import xyz.xenondevs.invui.item.ItemProvider /** * Displays all the recipes for the given fluid. @@ -33,9 +29,6 @@ open class FluidRecipesPage(fluidKey: NamespacedKey) : PagedGuidePage { } } - override val item: ItemProvider - get() = ItemStackBuilder.of(fluid.item) - override fun getKey() = KEY open fun getHeader(player: Player, pages: List) = PagedGui.guis() @@ -49,9 +42,9 @@ open class FluidRecipesPage(fluidKey: NamespacedKey) : PagedGuidePage { ) .addIngredient('#', GuiItems.background()) .addIngredient('<', GuiItems.pagePrevious()) - .addIngredient('b', BackButton()) - .addIngredient('g', PageButton(PylonGuide.ingredientsPage(fluid.item))) - .addIngredient('s', PageButton(PylonGuide.searchItemsAndFluidsPage)) + .addIngredient('b', PylonGuide.backButton) + .addIngredient('g', PylonGuide.ingredientsButton(fluid.item)) + .addIngredient('s', PylonGuide.searchItemsAndFluidsButton) .addIngredient('>', GuiItems.pageNext()) .addIngredient('x', Markers.CONTENT_LIST_SLOT_HORIZONTAL) .addPageChangeHandler { _, newPage -> saveCurrentPage(player, newPage) } diff --git a/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/fluid/FluidUsagesPage.kt b/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/fluid/FluidUsagesPage.kt index d88189269..2f17aad24 100644 --- a/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/fluid/FluidUsagesPage.kt +++ b/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/fluid/FluidUsagesPage.kt @@ -2,9 +2,6 @@ package io.github.pylonmc.pylon.core.guide.pages.fluid import io.github.pylonmc.pylon.core.content.guide.PylonGuide import io.github.pylonmc.pylon.core.fluid.PylonFluid -import io.github.pylonmc.pylon.core.guide.button.BackButton -import io.github.pylonmc.pylon.core.guide.button.PageButton -import io.github.pylonmc.pylon.core.item.builder.ItemStackBuilder import io.github.pylonmc.pylon.core.guide.pages.base.PagedGuidePage import io.github.pylonmc.pylon.core.registry.PylonRegistry import io.github.pylonmc.pylon.core.util.gui.GuiItems @@ -13,7 +10,6 @@ import org.bukkit.entity.Player import xyz.xenondevs.invui.gui.Gui import xyz.xenondevs.invui.gui.PagedGui import xyz.xenondevs.invui.gui.structure.Markers -import xyz.xenondevs.invui.item.ItemProvider /** * Displays all the recipes that use the given [fluid]. @@ -32,9 +28,6 @@ open class FluidUsagesPage(val fluid: PylonFluid) : PagedGuidePage { } } - override val item: ItemProvider - get() = ItemStackBuilder.of(fluid.item) - override fun getKey() = KEY open fun getHeader(player: Player, pages: List) = PagedGui.guis() @@ -48,8 +41,8 @@ open class FluidUsagesPage(val fluid: PylonFluid) : PagedGuidePage { ) .addIngredient('#', GuiItems.background()) .addIngredient('<', GuiItems.pagePrevious()) - .addIngredient('b', BackButton()) - .addIngredient('s', PageButton(PylonGuide.searchItemsAndFluidsPage)) + .addIngredient('b', PylonGuide.backButton) + .addIngredient('s', PylonGuide.searchItemsAndFluidsButton) .addIngredient('>', GuiItems.pageNext()) .addIngredient('x', Markers.CONTENT_LIST_SLOT_HORIZONTAL) .addPageChangeHandler { _, newPage -> saveCurrentPage(player, newPage) } diff --git a/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/fluid/FluidsPage.kt b/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/fluid/FluidsPage.kt deleted file mode 100644 index 7b905ce0f..000000000 --- a/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/fluid/FluidsPage.kt +++ /dev/null @@ -1,16 +0,0 @@ -package io.github.pylonmc.pylon.core.guide.pages.fluid - -import io.github.pylonmc.pylon.core.guide.button.FluidButton -import io.github.pylonmc.pylon.core.guide.pages.base.SimpleDynamicGuidePage -import io.github.pylonmc.pylon.core.registry.PylonRegistry -import io.github.pylonmc.pylon.core.util.pylonKey -import org.bukkit.Material - -/** - * Displays all the fluids. - */ -class FluidsPage : SimpleDynamicGuidePage( - pylonKey("fluids"), - Material.WATER_BUCKET, - { PylonRegistry.FLUIDS.map { FluidButton(it) }.toMutableList() } -) \ No newline at end of file diff --git a/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/item/ItemIngredientsPage.kt b/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/item/ItemIngredientsPage.kt index fffb94366..05c3b24b8 100644 --- a/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/item/ItemIngredientsPage.kt +++ b/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/item/ItemIngredientsPage.kt @@ -1,6 +1,6 @@ package io.github.pylonmc.pylon.core.guide.pages.item -import io.github.pylonmc.pylon.core.guide.button.BackButton +import io.github.pylonmc.pylon.core.content.guide.PylonGuide import io.github.pylonmc.pylon.core.guide.button.FluidButton import io.github.pylonmc.pylon.core.guide.button.ItemButton import io.github.pylonmc.pylon.core.guide.pages.base.SimpleStaticGuidePage @@ -29,10 +29,7 @@ import kotlin.math.max * * @author balugaq */ -open class ItemIngredientsPage(val stack: ItemStack) : SimpleStaticGuidePage( - pylonKey("item_ingredients"), - Material.SCULK_SENSOR -) { +open class ItemIngredientsPage(val stack: ItemStack) : SimpleStaticGuidePage(pylonKey("item_ingredients")) { override fun getKey() = KEY // page is 0 based @@ -78,7 +75,7 @@ open class ItemIngredientsPage(val stack: ItemStack) : SimpleStaticGuidePage( ) .addIngredient('#', GuiItems.background()) .addIngredient('<', GuiItems.pagePrevious()) - .addIngredient('b', BackButton()) + .addIngredient('b', PylonGuide.backButton) .addIngredient('>', GuiItems.pageNext()) .addIngredient('x', Markers.CONTENT_LIST_SLOT_HORIZONTAL) .addPageChangeHandler { _, newPage -> saveCurrentPage(player, newPage) } diff --git a/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/item/ItemRecipesPage.kt b/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/item/ItemRecipesPage.kt index 217fe8bd8..61188dbc6 100644 --- a/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/item/ItemRecipesPage.kt +++ b/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/item/ItemRecipesPage.kt @@ -1,10 +1,7 @@ package io.github.pylonmc.pylon.core.guide.pages.item import io.github.pylonmc.pylon.core.content.guide.PylonGuide -import io.github.pylonmc.pylon.core.guide.button.BackButton -import io.github.pylonmc.pylon.core.guide.button.PageButton import io.github.pylonmc.pylon.core.guide.pages.base.PagedGuidePage -import io.github.pylonmc.pylon.core.item.builder.ItemStackBuilder import io.github.pylonmc.pylon.core.registry.PylonRegistry import io.github.pylonmc.pylon.core.util.gui.GuiItems import io.github.pylonmc.pylon.core.util.pylonKey @@ -13,7 +10,6 @@ import org.bukkit.inventory.ItemStack import xyz.xenondevs.invui.gui.Gui import xyz.xenondevs.invui.gui.PagedGui import xyz.xenondevs.invui.gui.structure.Markers -import xyz.xenondevs.invui.item.ItemProvider /** * Displays all the recipes for the given [stack]. @@ -32,9 +28,6 @@ open class ItemRecipesPage(val stack: ItemStack) : PagedGuidePage { } } - override val item: ItemProvider - get() = ItemStackBuilder.of(stack) - override fun getKey() = KEY open fun getHeader(player: Player, pages: List) = PagedGui.guis() @@ -48,9 +41,9 @@ open class ItemRecipesPage(val stack: ItemStack) : PagedGuidePage { ) .addIngredient('#', GuiItems.background()) .addIngredient('<', GuiItems.pagePrevious()) - .addIngredient('b', BackButton()) - .addIngredient('g', PageButton(PylonGuide.ingredientsPage(stack))) - .addIngredient('s', PageButton(PylonGuide.searchItemsAndFluidsPage)) + .addIngredient('b', PylonGuide.backButton) + .addIngredient('g', PylonGuide.ingredientsButton(stack)) + .addIngredient('s', PylonGuide.searchItemsAndFluidsButton) .addIngredient('>', GuiItems.pageNext()) .addIngredient('x', Markers.CONTENT_LIST_SLOT_HORIZONTAL) .addPageChangeHandler { _, newPage -> saveCurrentPage(player, newPage) } diff --git a/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/item/ItemUsagesPage.kt b/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/item/ItemUsagesPage.kt index 6d411631e..1385219f5 100644 --- a/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/item/ItemUsagesPage.kt +++ b/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/item/ItemUsagesPage.kt @@ -1,11 +1,7 @@ package io.github.pylonmc.pylon.core.guide.pages.item import io.github.pylonmc.pylon.core.content.guide.PylonGuide -import io.github.pylonmc.pylon.core.guide.button.BackButton -import io.github.pylonmc.pylon.core.guide.button.PageButton -import io.github.pylonmc.pylon.core.guide.pages.base.GuidePage import io.github.pylonmc.pylon.core.guide.pages.base.PagedGuidePage -import io.github.pylonmc.pylon.core.item.builder.ItemStackBuilder import io.github.pylonmc.pylon.core.registry.PylonRegistry import io.github.pylonmc.pylon.core.util.gui.GuiItems import io.github.pylonmc.pylon.core.util.pylonKey @@ -14,7 +10,6 @@ import org.bukkit.inventory.ItemStack import xyz.xenondevs.invui.gui.Gui import xyz.xenondevs.invui.gui.PagedGui import xyz.xenondevs.invui.gui.structure.Markers -import xyz.xenondevs.invui.item.ItemProvider /** * Displays all the recipes that use the given [stack]. @@ -33,9 +28,6 @@ open class ItemUsagesPage(val stack: ItemStack) : PagedGuidePage { } } - override val item: ItemProvider - get() = ItemStackBuilder.of(stack) - override fun getKey() = KEY open fun getHeader(player: Player, pages: List) = PagedGui.guis() @@ -49,8 +41,8 @@ open class ItemUsagesPage(val stack: ItemStack) : PagedGuidePage { ) .addIngredient('#', GuiItems.background()) .addIngredient('<', GuiItems.pagePrevious()) - .addIngredient('b', BackButton()) - .addIngredient('s', PageButton(PylonGuide.searchItemsAndFluidsPage)) + .addIngredient('b', PylonGuide.backButton) + .addIngredient('s', PylonGuide.searchItemsAndFluidsButton) .addIngredient('>', GuiItems.pageNext()) .addIngredient('x', Markers.CONTENT_LIST_SLOT_HORIZONTAL) .addPageChangeHandler { _, newPage -> saveCurrentPage(player, newPage) } diff --git a/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/research/AddonResearchesPage.kt b/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/research/AddonResearchesPage.kt index cbbd5d5b4..821995530 100644 --- a/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/research/AddonResearchesPage.kt +++ b/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/research/AddonResearchesPage.kt @@ -4,17 +4,15 @@ import io.github.pylonmc.pylon.core.addon.PylonAddon import io.github.pylonmc.pylon.core.content.guide.PylonGuide import io.github.pylonmc.pylon.core.guide.button.ResearchButton import io.github.pylonmc.pylon.core.guide.pages.base.SimpleDynamicGuidePage -import io.github.pylonmc.pylon.core.item.builder.ItemStackBuilder import io.github.pylonmc.pylon.core.registry.PylonRegistry import io.github.pylonmc.pylon.core.util.pylonKey -import net.kyori.adventure.text.Component +import net.kyori.adventure.text.format.Style /** * Shows all the researches for the given [addon]. */ class AddonResearchesPage(val addon: PylonAddon) : SimpleDynamicGuidePage( pylonKey("researches_" + addon.key.key), - addon.material, { PylonRegistry.RESEARCHES.filter { it.key.namespace == addon.key.namespace && it.key !in PylonGuide.hiddenResearches @@ -23,10 +21,5 @@ class AddonResearchesPage(val addon: PylonAddon) : SimpleDynamicGuidePage( } } ) { - override val item: ItemStackBuilder - get() = ItemStackBuilder.gui(addon.material, addon.key) - .name(addon.displayName) - - override val title: Component - get() = Component.translatable("pylon.pyloncore.guide.page.researches") + override val title = addon.displayName.style(Style.empty()) } \ No newline at end of file diff --git a/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/research/ResearchItemsPage.kt b/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/research/ResearchItemsPage.kt index 14b96e4fd..eb724b8fb 100644 --- a/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/research/ResearchItemsPage.kt +++ b/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/research/ResearchItemsPage.kt @@ -14,7 +14,6 @@ import xyz.xenondevs.invui.item.Item */ class ResearchItemsPage(research: Research) : SimpleStaticGuidePage( KEY, - research.material, research.unlocks.map { ItemButton(PylonRegistry.ITEMS[it]!!.getItemStack()) }.toMutableList() diff --git a/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/research/ResearchesPage.kt b/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/research/ResearchesPage.kt index e503acd33..57ce2be90 100644 --- a/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/research/ResearchesPage.kt +++ b/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/research/ResearchesPage.kt @@ -1,25 +1,22 @@ package io.github.pylonmc.pylon.core.guide.pages.research import io.github.pylonmc.pylon.core.content.guide.PylonGuide -import io.github.pylonmc.pylon.core.guide.button.PageButton import io.github.pylonmc.pylon.core.guide.pages.base.SimpleDynamicGuidePage import io.github.pylonmc.pylon.core.registry.PylonRegistry import io.github.pylonmc.pylon.core.util.pylonKey -import org.bukkit.Material /** * Shows buttons to view each addon's researches. */ class ResearchesPage : SimpleDynamicGuidePage( pylonKey("researches"), - Material.BREWING_STAND, { PylonRegistry.ADDONS.getValues().filter { addon -> PylonRegistry.RESEARCHES.getKeys().any { it.namespace == addon.key.namespace && it !in PylonGuide.hiddenResearches } }.map { addon -> - PageButton(AddonResearchesPage(addon)) + PylonGuide.addonResearchesButton(addon) } } ) \ No newline at end of file diff --git a/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/settings/BlockTextureSettingsPage.kt b/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/settings/BlockTextureSettingsPage.kt new file mode 100644 index 000000000..be75fa44c --- /dev/null +++ b/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/settings/BlockTextureSettingsPage.kt @@ -0,0 +1,45 @@ +package io.github.pylonmc.pylon.core.guide.pages.settings + +import io.github.pylonmc.pylon.core.config.PylonConfig +import io.github.pylonmc.pylon.core.guide.button.setting.CyclePlayerSettingButton +import io.github.pylonmc.pylon.core.guide.button.setting.TogglePlayerSettingButton +import io.github.pylonmc.pylon.core.i18n.PylonArgument +import io.github.pylonmc.pylon.core.item.builder.ItemStackBuilder +import io.github.pylonmc.pylon.core.resourcepack.block.BlockTextureEngine.cullingPreset +import io.github.pylonmc.pylon.core.resourcepack.block.BlockTextureEngine.hasCustomBlockTextures +import io.github.pylonmc.pylon.core.util.pylonKey + +object BlockTextureSettingsPage : PlayerSettingsPage(pylonKey("block_texture_settings")) { + init { + if (!PylonConfig.BlockTextureConfig.FORCED) { + addSetting( + TogglePlayerSettingButton( + pylonKey("toggle-block-textures"), + toggle = { player -> player.hasCustomBlockTextures = !player.hasCustomBlockTextures }, + isEnabled = { player -> player.hasCustomBlockTextures } + )) + } + addSetting( + CyclePlayerSettingButton( + pylonKey("cycle-culling-preset"), + PylonConfig.BlockTextureConfig.CULLING_PRESETS.values.sortedBy { it.index }, + identifier = { preset -> preset.id }, + getter = { player -> player.cullingPreset }, + setter = { player, preset -> player.cullingPreset = preset }, + decorator = { player, preset -> + ItemStackBuilder.Companion.of(preset.material) + .addCustomModelDataString("culling_preset=${preset.id}") + .build() + }, + placeholderProvider = { player, preset -> + mutableListOf( + PylonArgument.Companion.of("hiddenInterval", preset.hiddenInterval), + PylonArgument.Companion.of("visibleInterval", preset.visibleInterval), + PylonArgument.Companion.of("alwaysShowRadius", preset.alwaysShowRadius), + PylonArgument.Companion.of("cullRadius", preset.cullRadius), + PylonArgument.Companion.of("maxOccludingCount", preset.maxOccludingCount) + ) + } + )) + } +} \ No newline at end of file diff --git a/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/settings/MainSettingsPage.kt b/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/settings/MainSettingsPage.kt new file mode 100644 index 000000000..f2dd5a562 --- /dev/null +++ b/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/settings/MainSettingsPage.kt @@ -0,0 +1,45 @@ +package io.github.pylonmc.pylon.core.guide.pages.settings + +import io.github.pylonmc.pylon.core.config.PylonConfig +import io.github.pylonmc.pylon.core.guide.button.PageButton +import io.github.pylonmc.pylon.core.guide.button.setting.TogglePlayerSettingButton +import io.github.pylonmc.pylon.core.item.research.Research.Companion.researchConfetti +import io.github.pylonmc.pylon.core.item.research.Research.Companion.researchSounds +import io.github.pylonmc.pylon.core.util.pylonKey +import org.bukkit.Material + +object MainSettingsPage : PlayerSettingsPage(pylonKey("settings")) { + + @JvmStatic + val wailaSettingsButton = PageButton(Material.SPYGLASS, WailaSettingsPage) + + @JvmStatic + val resourcePackSettingsButton = PageButton(Material.PAINTING, ResourcePackSettingsPage) + + @JvmStatic + val researchConfettiButton = TogglePlayerSettingButton( + pylonKey("toggle-research-confetti"), + toggle = { player -> player.researchConfetti = !player.researchConfetti }, + isEnabled = { player -> player.researchConfetti } + ) + + @JvmStatic + val researchSoundsButton = TogglePlayerSettingButton( + pylonKey("toggle-research-sounds"), + toggle = { player -> player.researchSounds = !player.researchSounds }, + isEnabled = { player -> player.researchSounds } + ) + + init { + if (PylonConfig.WailaConfig.enabled) { + addSetting(wailaSettingsButton) + } + + addSetting(resourcePackSettingsButton) + + if (PylonConfig.RESEARCHES_ENABLED) { + addSetting(researchConfettiButton) + addSetting(researchSoundsButton) + } + } +} \ No newline at end of file diff --git a/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/settings/PlayerSettingsPage.kt b/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/settings/PlayerSettingsPage.kt new file mode 100644 index 000000000..2e0770ff5 --- /dev/null +++ b/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/settings/PlayerSettingsPage.kt @@ -0,0 +1,41 @@ +package io.github.pylonmc.pylon.core.guide.pages.settings + +import io.github.pylonmc.pylon.core.content.guide.PylonGuide +import io.github.pylonmc.pylon.core.guide.button.BackButton +import io.github.pylonmc.pylon.core.guide.button.PageButton +import io.github.pylonmc.pylon.core.guide.pages.base.SimpleStaticGuidePage +import io.github.pylonmc.pylon.core.util.gui.GuiItems +import org.bukkit.NamespacedKey +import org.bukkit.entity.Player +import xyz.xenondevs.invui.gui.Gui +import xyz.xenondevs.invui.gui.PagedGui +import xyz.xenondevs.invui.gui.structure.Markers +import xyz.xenondevs.invui.item.Item + +/** + * Contains buttons to change player settings. + */ +open class PlayerSettingsPage(key: NamespacedKey) : SimpleStaticGuidePage(key, mutableListOf()) { + override fun getGui(player: Player): Gui { + val buttons = buttonSupplier.get() + val gui = PagedGui.items() + .setStructure( + "# b # # # # # s #", + "# # # # # # # # #", + "# x x x x x x x #", + "# # # # # # # # #", + ) + .addIngredient('#', GuiItems.background()) + .addIngredient('b', BackButton()) + .addIngredient('s', PylonGuide.searchItemsAndFluidsButton) + .addIngredient('x', Markers.CONTENT_LIST_SLOT_HORIZONTAL) + .addPageChangeHandler { _, newPage -> saveCurrentPage(player, newPage) } + .setContent(buttons.filter { it !is PageButton || it.page !is PlayerSettingsPage || it.page.buttons.isNotEmpty() }) + return gui.build().apply { loadCurrentPage(player, this) } + } + + fun addSetting(item: Item) { + buttons.add(item) + buttons.sortBy { if (it is PageButton) 0 else 1 } + } +} \ No newline at end of file diff --git a/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/settings/ResourcePackSettingsPage.kt b/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/settings/ResourcePackSettingsPage.kt new file mode 100644 index 000000000..6ebddf20d --- /dev/null +++ b/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/settings/ResourcePackSettingsPage.kt @@ -0,0 +1,30 @@ +package io.github.pylonmc.pylon.core.guide.pages.settings + +import io.github.pylonmc.pylon.core.config.PylonConfig +import io.github.pylonmc.pylon.core.guide.button.PageButton +import io.github.pylonmc.pylon.core.guide.button.setting.TogglePlayerSettingButton +import io.github.pylonmc.pylon.core.resourcepack.armor.ArmorTextureEngine.hasCustomArmorTextures +import io.github.pylonmc.pylon.core.util.pylonKey +import org.bukkit.Material + +object ResourcePackSettingsPage : PlayerSettingsPage(pylonKey("resource_pack_settings")) { + + @JvmStatic + val blockTextureSettingsButton = PageButton(Material.BOOKSHELF, BlockTextureSettingsPage) + + init { + if (PylonConfig.ArmorTextureConfig.ENABLED && !PylonConfig.ArmorTextureConfig.FORCED) { + addSetting( + TogglePlayerSettingButton( + pylonKey("toggle-armor-textures"), + toggle = { player -> player.hasCustomArmorTextures = !player.hasCustomArmorTextures }, + isEnabled = { player -> player.hasCustomArmorTextures }, + ) + ) + } + + if (PylonConfig.BlockTextureConfig.ENABLED) { + addSetting(blockTextureSettingsButton) + } + } +} \ No newline at end of file diff --git a/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/settings/WailaSettingsPage.kt b/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/settings/WailaSettingsPage.kt new file mode 100644 index 000000000..0250ab58d --- /dev/null +++ b/pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/settings/WailaSettingsPage.kt @@ -0,0 +1,43 @@ +package io.github.pylonmc.pylon.core.guide.pages.settings + +import io.github.pylonmc.pylon.core.config.PylonConfig +import io.github.pylonmc.pylon.core.guide.button.setting.CyclePlayerSettingButton +import io.github.pylonmc.pylon.core.guide.button.setting.TogglePlayerSettingButton +import io.github.pylonmc.pylon.core.item.builder.ItemStackBuilder +import io.github.pylonmc.pylon.core.util.pylonKey +import io.github.pylonmc.pylon.core.waila.Waila.Companion.wailaConfig +import org.bukkit.Material + +object WailaSettingsPage : PlayerSettingsPage(pylonKey("waila_settings")) { + init { + addSetting( + TogglePlayerSettingButton( + pylonKey("toggle-waila"), + toggle = { player -> player.wailaConfig.enabled = !player.wailaConfig.enabled }, + isEnabled = { player -> player.wailaConfig.enabled } + )) + addSetting( + TogglePlayerSettingButton( + pylonKey("toggle-vanilla-waila"), + toggle = { player -> + player.wailaConfig.vanillaWailaEnabled = !player.wailaConfig.vanillaWailaEnabled + }, + isEnabled = { player -> player.wailaConfig.vanillaWailaEnabled } + )) + if (PylonConfig.WailaConfig.ENABLED_TYPES.size > 1) { + addSetting( + CyclePlayerSettingButton( + pylonKey("cycle-waila-type"), + PylonConfig.WailaConfig.ENABLED_TYPES, + identifier = { type -> type.name.lowercase() }, + getter = { player -> player.wailaConfig.type }, + setter = { player, type -> player.wailaConfig.type = type }, + decorator = { player, type -> + ItemStackBuilder.Companion.of(Material.PAPER) + .addCustomModelDataString("waila_type=${type.name.lowercase()}") + .build() + } + )) + } + } +} \ No newline at end of file