Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import io.github.pylonmc.rebar.guide.button.FluidButton
import io.github.pylonmc.rebar.guide.button.PageButton
import io.github.pylonmc.rebar.guide.button.AddonPageButton
import io.github.pylonmc.rebar.guide.pages.RootPage
import io.github.pylonmc.rebar.guide.pages.SearchItemsAndFluidsPage
import io.github.pylonmc.rebar.guide.pages.LatinSearchItemsAndFluidsPage
import io.github.pylonmc.rebar.guide.pages.base.GuidePage
import io.github.pylonmc.rebar.guide.pages.base.SearchPage
import io.github.pylonmc.rebar.guide.pages.base.SimpleDynamicGuidePage
import io.github.pylonmc.rebar.guide.pages.base.SimpleInfoPage
import io.github.pylonmc.rebar.guide.pages.help.HelpPage
Expand Down Expand Up @@ -39,6 +40,7 @@ import org.bukkit.event.player.PlayerInteractEvent
import org.bukkit.event.player.PlayerJoinEvent
import org.bukkit.inventory.ItemStack
import xyz.xenondevs.invui.item.Item
import java.util.Locale
import java.util.UUID

/**
Expand Down Expand Up @@ -143,10 +145,28 @@ class RebarGuide(stack: ItemStack) : RebarItem(stack), RebarInteractor {
val backButton = BackButton()

@JvmStatic
val searchItemsAndFluidsPage = SearchItemsAndFluidsPage()
val latinSearchItemsAndFluidsPage = LatinSearchItemsAndFluidsPage()

@JvmStatic
val searchItemsAndFluidsButton = PageButton(Material.OAK_SIGN, searchItemsAndFluidsPage)
val latinSearchItemsAndFluidsButton = PageButton(Material.OAK_SIGN, latinSearchItemsAndFluidsPage)

/**
* Maps locales to their corresponding search page buttons.
* This allows different locales to use adapted search pages with appropriate text indexers.
*/
@JvmStatic
val localSearchPages: MutableMap<Locale, PageButton> = mutableMapOf()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A doc on here wouldn't hurt, to explain why there are multiple search pages


@JvmStatic
fun getSearchButton(player: Player): PageButton =
getSearchButton(player.locale())

@JvmStatic
fun getSearchButton(locale: Locale): PageButton {
localSearchPages[locale]?.let { return it }
localSearchPages[locale] = latinSearchItemsAndFluidsButton
return latinSearchItemsAndFluidsButton
}

@JvmStatic
val mainSettingsPage = MainSettingsPage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import xyz.xenondevs.invui.item.Item
/**
* Allows you to search all items and fluids by hijacking the anvil GUI.
*/
class SearchItemsAndFluidsPage : SearchPage(rebarKey("search")) {
class LatinSearchItemsAndFluidsPage : SearchPage(rebarKey("search")) {

fun getItemButtons(player: Player): MutableList<Pair<Item, String>> = RebarRegistry.ITEMS.filter {
it.key !in RebarGuide.hiddenItems || (it.key in RebarGuide.adminOnlyItems && player.hasPermission("rebar.guide.cheat"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ open class MachineRecipesPage(recipeType: RecipeType<*>) : PagedGuidePage {
.addIngredient('#', GuiItems.background())
.addIngredient('<', GuiItems.pagePrevious())
.addIngredient('b', RebarGuide.backButton)
.addIngredient('s', RebarGuide.searchItemsAndFluidsButton)
.addIngredient('s', RebarGuide.getSearchButton(player))
.addIngredient('>', GuiItems.pageNext())
.addIngredient('x', Markers.CONTENT_LIST_SLOT_HORIZONTAL)
.addPageChangeHandler { _, newPage -> saveCurrentPage(player, newPage) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class RootPage : SimpleStaticGuidePage(
)
.addIngredient('#', GuiItems.background())
.addIngredient('e', RebarGuide.mainSettingsButton)
.addIngredient('s', RebarGuide.searchItemsAndFluidsButton)
.addIngredient('s', RebarGuide.getSearchButton(player))
.addIngredient('x', Markers.CONTENT_LIST_SLOT_HORIZONTAL)
.addPageChangeHandler { _, newPage -> saveCurrentPage(player, newPage) }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,9 @@ abstract class SearchPage(key: NamespacedKey) : SimpleStaticGuidePage(key) {
data class Lore(val filter: String) : SearchSpecifier {
override fun weight(player: Player, entry: Pair<Item, String>): Double? {
val stack = entry.first.getItemProvider(player).get()
return stack.lore()?.map {
return stack.lore()?.mapNotNull {
weight(filter, it.plainText.lowercase(player.locale()))
}?.filterNotNull()?.minOrNull()
}?.minOrNull()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package io.github.pylonmc.rebar.guide.pages.base

import io.github.pylonmc.rebar.content.guide.RebarGuide
import io.github.pylonmc.rebar.guide.button.GuideButton
import io.github.pylonmc.rebar.guide.button.PageButton
import io.github.pylonmc.rebar.util.gui.GuiItems
import org.bukkit.NamespacedKey
import org.bukkit.entity.Player
Expand Down Expand Up @@ -51,7 +50,7 @@ open class SimpleDynamicGuidePage(
.addIngredient('#', GuiItems.background())
.addIngredient('<', GuiItems.pagePrevious())
.addIngredient('b', RebarGuide.backButton)
.addIngredient('s', RebarGuide.searchItemsAndFluidsButton)
.addIngredient('s', RebarGuide.getSearchButton(player))
.addIngredient('>', GuiItems.pageNext())
.addIngredient('x', Markers.CONTENT_LIST_SLOT_HORIZONTAL)
.addPageChangeHandler { _, newPage -> saveCurrentPage(player, newPage) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ open class SimpleInfoPage : SimpleStaticGuidePage(rebarKey("info"), mutableListO
.addIngredient('+', GuiItems.backgroundBlack())
.addIngredient('<', GuiItems.pagePrevious())
.addIngredient('b', RebarGuide.backButton)
.addIngredient('s', RebarGuide.searchItemsAndFluidsButton)
.addIngredient('s', RebarGuide.getSearchButton(player))
.addIngredient('>', GuiItems.pageNext())
.addIngredient('x', Markers.CONTENT_LIST_SLOT_HORIZONTAL)
.addPageChangeHandler { _, newPage -> saveCurrentPage(player, newPage) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ open class FluidRecipesPage(fluidKey: NamespacedKey) : PagedGuidePage {
.addIngredient('<', GuiItems.pagePrevious())
.addIngredient('b', RebarGuide.backButton)
.addIngredient('g', RebarGuide.ingredientsButton(FluidOrItem.of(fluid, 1000.0)))
.addIngredient('s', RebarGuide.searchItemsAndFluidsButton)
.addIngredient('s', RebarGuide.getSearchButton(player))
.addIngredient('>', GuiItems.pageNext())
.addIngredient('x', Markers.CONTENT_LIST_SLOT_HORIZONTAL)
.addPageChangeHandler { _, newPage -> saveCurrentPage(player, newPage) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ open class FluidUsagesPage(val fluid: RebarFluid) : PagedGuidePage {
.addIngredient('#', GuiItems.background())
.addIngredient('<', GuiItems.pagePrevious())
.addIngredient('b', RebarGuide.backButton)
.addIngredient('s', RebarGuide.searchItemsAndFluidsButton)
.addIngredient('s', RebarGuide.getSearchButton(player))
.addIngredient('>', GuiItems.pageNext())
.addIngredient('x', Markers.CONTENT_LIST_SLOT_HORIZONTAL)
.addPageChangeHandler { _, newPage -> saveCurrentPage(player, newPage) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ open class ItemRecipesPage(val stack: ItemStack) : PagedGuidePage {
.addIngredient('b', RebarGuide.backButton)
.addIngredient('g', RebarGuide.ingredientsButton(FluidOrItem.of(stack)))
.addIngredient('i', RebarGuide.infoButton(FluidOrItem.of(stack)))
.addIngredient('s', RebarGuide.searchItemsAndFluidsButton)
.addIngredient('s', RebarGuide.getSearchButton(player))
.addIngredient('>', GuiItems.pageNext())
.addIngredient('x', Markers.CONTENT_LIST_SLOT_HORIZONTAL)
.addPageChangeHandler { _, newPage -> saveCurrentPage(player, newPage) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ open class ItemUsagesPage(val stack: ItemStack) : PagedGuidePage {
.addIngredient('#', GuiItems.background())
.addIngredient('<', GuiItems.pagePrevious())
.addIngredient('b', RebarGuide.backButton)
.addIngredient('s', RebarGuide.searchItemsAndFluidsButton)
.addIngredient('s', RebarGuide.getSearchButton(player))
.addIngredient('>', GuiItems.pageNext())
.addIngredient('x', Markers.CONTENT_LIST_SLOT_HORIZONTAL)
.addPageChangeHandler { _, newPage -> saveCurrentPage(player, newPage) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ open class PlayerSettingsPage(key: NamespacedKey) : SimpleStaticGuidePage(key, m
)
.addIngredient('#', GuiItems.background())
.addIngredient('b', BackButton())
.addIngredient('s', RebarGuide.searchItemsAndFluidsButton)
.addIngredient('s', RebarGuide.getSearchButton(player))
.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() })
Expand Down
Loading