Skip to content

Commit b10a487

Browse files
authored
Merge pull request #553 from pylonmc/guide-polishing
Guide polishing :flag_pl:
2 parents 590055a + a01481f commit b10a487

11 files changed

Lines changed: 178 additions & 66 deletions

File tree

pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/content/guide/PylonGuide.kt

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ class PylonGuide(stack: ItemStack) : PylonItem(stack), PylonInteractor {
7171
@JvmStatic
7272
val hiddenItems: MutableSet<NamespacedKey> = mutableSetOf()
7373

74+
/**
75+
* Admin items do not show up in searches unless a player has the `pylon.guide.cheat` permission
76+
*/
77+
@JvmStatic
78+
val adminOnlyItems: MutableSet<NamespacedKey> = mutableSetOf()
79+
7480
/**
7581
* Hidden fluids do not show up in searches
7682
*/
@@ -86,7 +92,11 @@ class PylonGuide(stack: ItemStack) : PylonItem(stack), PylonInteractor {
8692
@JvmStatic
8793
val fluidsPage = object : SimpleDynamicGuidePage(
8894
pylonKey("fluids"),
89-
{ PylonRegistry.FLUIDS.map { FluidButton(it) }.toMutableList() }
95+
{
96+
PylonRegistry.FLUIDS.filter { it.key !in hiddenFluids }
97+
.map { FluidButton(it) }
98+
.toMutableList()
99+
}
90100
) {}
91101

92102
@JvmStatic
@@ -156,6 +166,14 @@ class PylonGuide(stack: ItemStack) : PylonItem(stack), PylonInteractor {
156166
hiddenItems.add(key)
157167
}
158168

169+
/**
170+
* Hide an item from showing up in searches unless a player has the `pylon.guide.cheat` permission
171+
*/
172+
@JvmStatic
173+
fun hideItemUnlessAdmin(key: NamespacedKey) {
174+
adminOnlyItems.add(key)
175+
}
176+
159177
/**
160178
* Hide a fluid from showing up in searches
161179
*/

pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/button/BackButton.kt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package io.github.pylonmc.pylon.core.guide.button
22

33
import io.github.pylonmc.pylon.core.content.guide.PylonGuide
44
import io.github.pylonmc.pylon.core.item.builder.ItemStackBuilder
5+
import io.github.pylonmc.pylon.core.item.research.Research.Companion.guideHints
56
import io.github.pylonmc.pylon.core.util.pylonKey
7+
import io.papermc.paper.datacomponent.DataComponentTypes
68
import net.kyori.adventure.text.Component
79
import org.bukkit.Material
810
import org.bukkit.entity.Player
@@ -15,9 +17,15 @@ import xyz.xenondevs.invui.item.impl.AbstractItem
1517
*/
1618
class BackButton : AbstractItem() {
1719

18-
override fun getItemProvider() = ItemStackBuilder.gui(Material.ENCHANTED_BOOK, pylonKey("guide_back"))
19-
.name(Component.translatable("pylon.pyloncore.guide.button.back.name"))
20-
.lore(Component.translatable("pylon.pyloncore.guide.button.back.lore"))
20+
override fun getItemProvider(player: Player): ItemStackBuilder {
21+
val stack = ItemStackBuilder.gui(Material.ENCHANTED_BOOK, pylonKey("guide_back"))
22+
.set(DataComponentTypes.ENCHANTMENT_GLINT_OVERRIDE, false)
23+
.name(Component.translatable("pylon.pyloncore.guide.button.back.name"))
24+
if (player.guideHints) {
25+
stack.lore(Component.translatable("pylon.pyloncore.guide.button.back.hints"))
26+
}
27+
return stack
28+
}
2129

2230
override fun handleClick(clickType: ClickType, player: Player, event: InventoryClickEvent) {
2331
val history = PylonGuide.history.getOrPut(player.uniqueId) { mutableListOf() }

pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/button/FluidButton.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import io.github.pylonmc.pylon.core.guide.pages.fluid.FluidRecipesPage
77
import io.github.pylonmc.pylon.core.guide.pages.fluid.FluidUsagesPage
88
import io.github.pylonmc.pylon.core.i18n.PylonArgument
99
import io.github.pylonmc.pylon.core.item.builder.ItemStackBuilder
10+
import io.github.pylonmc.pylon.core.item.research.Research.Companion.guideHints
1011
import io.github.pylonmc.pylon.core.recipe.RecipeInput
1112
import io.github.pylonmc.pylon.core.util.gui.unit.UnitFormat
1213
import io.papermc.paper.datacomponent.DataComponentTypes
@@ -73,8 +74,8 @@ open class FluidButton(
7374
}
7475
}
7576

76-
override fun getItemProvider() = try {
77-
if (amount == null) {
77+
override fun getItemProvider(player: Player) = try {
78+
val stack = if (amount == null) {
7879
preDisplayDecorator.invoke(ItemStackBuilder.of(currentFluid.item))
7980
} else {
8081
preDisplayDecorator.invoke(ItemStackBuilder.of(currentFluid.item))
@@ -86,6 +87,10 @@ open class FluidButton(
8687
)
8788
)
8889
}
90+
if (player.guideHints) {
91+
stack.lore(Component.translatable("pylon.pyloncore.guide.button.fluid.hints"))
92+
}
93+
stack
8994
} catch (e: Exception) {
9095
e.printStackTrace()
9196
ItemStackBuilder.of(Material.BARRIER)

pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/button/ItemButton.kt

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import io.github.pylonmc.pylon.core.item.PylonItem
1111
import io.github.pylonmc.pylon.core.item.builder.ItemStackBuilder
1212
import io.github.pylonmc.pylon.core.item.research.Research.Companion.canCraft
1313
import io.github.pylonmc.pylon.core.item.research.Research.Companion.canUse
14+
import io.github.pylonmc.pylon.core.item.research.Research.Companion.guideHints
1415
import io.github.pylonmc.pylon.core.item.research.Research.Companion.researchPoints
1516
import io.github.pylonmc.pylon.core.recipe.RecipeInput
1617
import io.papermc.paper.datacomponent.DataComponentTypes
@@ -103,8 +104,17 @@ class ItemButton @JvmOverloads constructor(
103104
} else {
104105
builder.lore(Component.translatable("pylon.pyloncore.guide.button.item.not-researched"))
105106
}
107+
}
106108

107-
builder.lore(Component.translatable("pylon.pyloncore.guide.button.item.research-instructions"))
109+
if (player.guideHints) {
110+
if (!player.canCraft(item)) {
111+
builder.lore(Component.translatable("pylon.pyloncore.guide.button.item.hints.unresearched"))
112+
} else {
113+
builder.lore(Component.translatable("pylon.pyloncore.guide.button.item.hints.researched"))
114+
}
115+
if (player.hasPermission("pylon.guide.cheat")) {
116+
builder.lore(Component.translatable("pylon.pyloncore.guide.button.item.hints.admin"))
117+
}
108118
}
109119

110120
return builder
@@ -163,7 +173,11 @@ class ItemButton @JvmOverloads constructor(
163173
if (!player.hasPermission("pylon.guide.cheat")) return
164174
val stack = getCheatItemStack(currentStack, event)
165175
stack.amount = 1
166-
player.dropItem(stack)
176+
if (player.itemOnCursor.isEmpty) {
177+
player.setItemOnCursor(stack)
178+
} else if (player.itemOnCursor.isSimilar(stack)) {
179+
player.itemOnCursor.add()
180+
}
167181
}
168182

169183
ClickType.CONTROL_DROP -> {

pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/button/ResearchButton.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import io.github.pylonmc.pylon.core.guide.pages.research.ResearchItemsPage
44
import io.github.pylonmc.pylon.core.i18n.PylonArgument
55
import io.github.pylonmc.pylon.core.item.builder.ItemStackBuilder
66
import io.github.pylonmc.pylon.core.item.research.Research
7+
import io.github.pylonmc.pylon.core.item.research.Research.Companion.guideHints
78
import io.github.pylonmc.pylon.core.item.research.Research.Companion.researchPoints
89
import io.github.pylonmc.pylon.core.util.getAddon
910
import io.github.pylonmc.pylon.core.util.pylonKey
@@ -34,7 +35,6 @@ open class ResearchButton(val research: Research) : AbstractItem() {
3435
}
3536
} else {
3637
addResearchCostLore(item, player, research)
37-
item.lore(Component.translatable("pylon.pyloncore.guide.button.research.instructions"))
3838
}
3939

4040
item.lore(Component.translatable("pylon.pyloncore.guide.button.research.unlocks-title"))
@@ -66,6 +66,12 @@ open class ResearchButton(val research: Research) : AbstractItem() {
6666
))
6767
}
6868

69+
if (player.guideHints) {
70+
item.lore(Component.translatable("pylon.pyloncore.guide.button.research.hints."
71+
+ (if (playerHasResearch) "researched" else "unresearched")
72+
))
73+
}
74+
6975
item.lore(getAddon(research.key).displayName)
7076

7177
item

pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/SearchItemsAndFluidsPage.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import io.github.pylonmc.pylon.core.util.plainText
99
import io.github.pylonmc.pylon.core.util.pylonKey
1010
import net.kyori.adventure.text.Component
1111
import net.kyori.adventure.translation.GlobalTranslator
12-
import org.bukkit.Material
1312
import org.bukkit.entity.Player
1413
import xyz.xenondevs.invui.item.Item
1514

@@ -19,7 +18,7 @@ import xyz.xenondevs.invui.item.Item
1918
class SearchItemsAndFluidsPage : SearchPage(pylonKey("search")) {
2019

2120
fun getItemButtons(player: Player): MutableList<Pair<Item, String>> = PylonRegistry.ITEMS.filter {
22-
it.key !in PylonGuide.hiddenItems
21+
it.key !in PylonGuide.hiddenItems || (it.key in PylonGuide.adminOnlyItems && player.hasPermission("pylon.guide.cheat"))
2322
}.map { item ->
2423
val name = GlobalTranslator.render(Component.translatable("pylon.${item.key.namespace}.item.${item.key.key}.name"), player.locale())
2524
ItemButton(item.getItemStack()) to name.plainText.lowercase(player.locale())

pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/base/SimpleStaticGuidePage.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import io.github.pylonmc.pylon.core.guide.button.FluidButton
55
import io.github.pylonmc.pylon.core.guide.button.ItemButton
66
import io.github.pylonmc.pylon.core.guide.button.PageButton
77
import io.github.pylonmc.pylon.core.guide.button.ResearchButton
8+
import io.github.pylonmc.pylon.core.item.builder.ItemStackBuilder
89
import io.github.pylonmc.pylon.core.item.research.Research
910
import org.bukkit.Material
1011
import org.bukkit.NamespacedKey
@@ -31,6 +32,8 @@ open class SimpleStaticGuidePage @JvmOverloads constructor(
3132

3233
open fun addButton(button: Item) = buttons.add(button)
3334
open fun addPage(material: Material, page: GuidePage) = addButton(PageButton(material, page))
35+
open fun addPage(stack: ItemStack, page: GuidePage) = addButton(PageButton(stack.clone(), page))
36+
open fun addPage(builder: ItemStackBuilder, page: GuidePage) = addButton(PageButton(builder.build().clone(), page))
3437
open fun addItem(item: ItemStack) = addButton(ItemButton(item))
3538
open fun addFluid(fluid: PylonFluid) = addButton(FluidButton(fluid))
3639
open fun addResearch(research: Research) = addButton(ResearchButton(research))

pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/guide/pages/settings/MainSettingsPage.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package io.github.pylonmc.pylon.core.guide.pages.settings
33
import io.github.pylonmc.pylon.core.config.PylonConfig
44
import io.github.pylonmc.pylon.core.guide.button.PageButton
55
import io.github.pylonmc.pylon.core.guide.button.setting.TogglePlayerSettingButton
6+
import io.github.pylonmc.pylon.core.item.research.Research.Companion.guideHints
67
import io.github.pylonmc.pylon.core.item.research.Research.Companion.researchConfetti
78
import io.github.pylonmc.pylon.core.item.research.Research.Companion.researchSounds
89
import io.github.pylonmc.pylon.core.util.pylonKey
@@ -30,6 +31,13 @@ object MainSettingsPage : PlayerSettingsPage(pylonKey("settings")) {
3031
isEnabled = { player -> player.researchSounds }
3132
)
3233

34+
@JvmStatic
35+
val guideHintsButton = TogglePlayerSettingButton(
36+
pylonKey("toggle-guide-hints"),
37+
toggle = { player -> player.guideHints = !player.guideHints },
38+
isEnabled = { player -> player.guideHints }
39+
)
40+
3341
init {
3442
if (PylonConfig.WailaConfig.enabled) {
3543
addSetting(wailaSettingsButton)
@@ -41,5 +49,7 @@ object MainSettingsPage : PlayerSettingsPage(pylonKey("settings")) {
4149
addSetting(researchConfettiButton)
4250
addSetting(researchSoundsButton)
4351
}
52+
53+
addSetting(guideHintsButton)
4454
}
4555
}

pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/item/builder/PylonMiniMessage.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ val customMiniMessage = MiniMessage.builder()
3535
.tags(TagResolver.standard())
3636
.editTags {
3737
it.tag("arrow", ::arrow)
38+
it.tag("guidearrow", ::guidearrow)
3839
it.tag("diamond", ::diamond)
3940
it.tag("star", ::star)
4041
it.tag(setOf("instruction", "insn")) { _, _ -> Tag.styling(TextColor.color(0xf9d104)) }
@@ -52,6 +53,11 @@ private fun arrow(args: ArgumentQueue, @Suppress("unused") ctx: Context): Tag {
5253
return Tag.selfClosingInserting(Component.text("\u2192").color(color))
5354
}
5455

56+
private fun guidearrow(args: ArgumentQueue, @Suppress("unused") ctx: Context): Tag {
57+
val color = args.peek()?.value()?.let(::parseColor) ?: TextColor.color(0x3a293)
58+
return Tag.selfClosingInserting(Component.text("\u2192").color(color))
59+
}
60+
5561
private fun diamond(args: ArgumentQueue, @Suppress("unused") ctx: Context): Tag {
5662
val color = args.peek()?.value()?.let(::parseColor) ?: TextColor.color(0x666666)
5763
return Tag.selfClosingInserting(Component.text("\u25C6").color(color))

pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/item/research/Research.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,18 +143,23 @@ data class Research(
143143
companion object : Listener {
144144
private val researchesKey = pylonKey("researches")
145145
private val researchPointsKey = pylonKey("research_points")
146-
private val researchEffectsKey = pylonKey("research_effects")
146+
private val researchConfettiKey = pylonKey("research_confetti")
147+
private val researchSoundsKey = pylonKey("research_sounds")
148+
private val guideHintsKey = pylonKey("guide_hints")
147149
private val researchesType =
148150
PylonSerializers.SET.setTypeFrom(PylonSerializers.KEYED.keyedTypeFrom(PylonRegistry.RESEARCHES::getOrThrow))
149151

150152
@JvmStatic
151153
var Player.researchPoints: Long by persistentData(researchPointsKey, PylonSerializers.LONG, 0)
152154

153155
@JvmStatic
154-
var Player.researchConfetti: Boolean by persistentData(researchEffectsKey, PylonSerializers.BOOLEAN, true)
156+
var Player.researchConfetti: Boolean by persistentData(researchConfettiKey, PylonSerializers.BOOLEAN, true)
155157

156158
@JvmStatic
157-
var Player.researchSounds: Boolean by persistentData(researchEffectsKey, PylonSerializers.BOOLEAN, true)
159+
var Player.researchSounds: Boolean by persistentData(researchSoundsKey, PylonSerializers.BOOLEAN, true)
160+
161+
@JvmStatic
162+
var Player.guideHints: Boolean by persistentData(guideHintsKey, PylonSerializers.BOOLEAN, true)
158163

159164
@JvmStatic
160165
fun getResearches(player: OfflinePlayer): Set<Research> {

0 commit comments

Comments
 (0)