Skip to content

Commit f500194

Browse files
authored
Merge pull request #141 from pylonmc/add-pylon-guide
Add pylon guide
2 parents 94005ce + 78c943f commit f500194

58 files changed

Lines changed: 1996 additions & 188 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

pylon-core/build.gradle.kts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ plugins {
1212
}
1313

1414
repositories {
15+
mavenCentral()
1516
maven("https://repo.xenondevs.xyz/releases") {
1617
name = "InvUI"
1718
}
@@ -28,6 +29,8 @@ dependencies {
2829

2930
runtimeOnly(project(":nms"))
3031

32+
implementation("info.debatty:java-string-similarity:2.0.0")
33+
3134
paperLibraryApi("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.10.1")
3235

3336
compileOnly("io.papermc.paper:paper-api:1.21.4-R0.1-SNAPSHOT")

pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/PylonCore.kt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,17 @@ import io.github.pylonmc.pylon.core.debug.DebugWaxedWeatheredCutCopperStairs
1313
import io.github.pylonmc.pylon.core.entity.EntityListener
1414
import io.github.pylonmc.pylon.core.entity.EntityStorage
1515
import io.github.pylonmc.pylon.core.entity.PylonEntity
16+
import io.github.pylonmc.pylon.core.guide.PylonGuide
1617
import io.github.pylonmc.pylon.core.i18n.AddonTranslator
1718
import io.github.pylonmc.pylon.core.item.PylonItem
1819
import io.github.pylonmc.pylon.core.item.PylonItemListener
1920
import io.github.pylonmc.pylon.core.item.research.Research
2021
import io.github.pylonmc.pylon.core.mobdrop.MobDropListener
22+
import io.github.pylonmc.pylon.core.recipe.PylonRecipeListener
23+
import io.github.pylonmc.pylon.core.recipe.RecipeType
2124
import io.github.pylonmc.pylon.core.registry.PylonRegistry
2225
import org.bukkit.Bukkit
26+
import org.bukkit.Material
2327
import org.bukkit.NamespacedKey
2428
import org.bukkit.entity.BlockDisplay
2529
import org.bukkit.plugin.java.JavaPlugin
@@ -50,6 +54,7 @@ object PylonCore : JavaPlugin(), PylonAddon {
5054
Bukkit.getPluginManager().registerEvents(PylonGuiBlock, this)
5155
Bukkit.getPluginManager().registerEvents(PylonEntityHolderBlock, this)
5256
Bukkit.getPluginManager().registerEvents(PylonSimpleMultiblock, this)
57+
Bukkit.getPluginManager().registerEvents(PylonRecipeListener, this)
5358

5459
Bukkit.getScheduler().runTaskTimer(
5560
this,
@@ -72,12 +77,21 @@ object PylonCore : JavaPlugin(), PylonAddon {
7277
registerWithPylon()
7378

7479
PylonItem.register(DebugWaxedWeatheredCutCopperStairs::class.java, DebugWaxedWeatheredCutCopperStairs.STACK)
80+
PylonGuide.hideItem(DebugWaxedWeatheredCutCopperStairs.KEY)
81+
7582
PylonItem.register(PhantomBlock.ErrorItem::class.java, PhantomBlock.ErrorItem.STACK)
83+
PylonGuide.hideItem(PhantomBlock.ErrorItem.KEY)
84+
85+
PylonItem.register(PylonGuide::class.java, PylonGuide.STACK)
86+
PylonGuide.hideItem(PylonGuide.KEY)
87+
7688
PylonEntity.register(
7789
PylonSimpleMultiblock.MultiblockGhostBlock.KEY,
7890
BlockDisplay::class.java,
7991
PylonSimpleMultiblock.MultiblockGhostBlock::class.java
8092
)
93+
94+
RecipeType.addVanillaRecipes()
8195
}
8296

8397
override fun onDisable() {
@@ -93,7 +107,7 @@ object PylonCore : JavaPlugin(), PylonAddon {
93107

94108
override val javaPlugin = this
95109

96-
override val displayName = "Core"
110+
override val material = Material.BEDROCK
97111

98112
override val languages: Set<Locale> = setOf(
99113
Locale.ENGLISH,

pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/addon/PylonAddon.kt

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,17 @@ import io.github.pylonmc.pylon.core.PylonCore
44
import io.github.pylonmc.pylon.core.config.Config
55
import io.github.pylonmc.pylon.core.config.ConfigSection
66
import io.github.pylonmc.pylon.core.i18n.AddonTranslator
7+
import io.github.pylonmc.pylon.core.item.builder.ItemStackBuilder
78
import io.github.pylonmc.pylon.core.registry.PylonRegistry
9+
import net.kyori.adventure.text.Component
10+
import net.kyori.adventure.text.TranslatableComponent
11+
import net.kyori.adventure.text.format.NamedTextColor
12+
import net.kyori.adventure.text.format.TextDecoration
813
import org.bukkit.Keyed
14+
import org.bukkit.Material
915
import org.bukkit.NamespacedKey
1016
import org.bukkit.configuration.file.YamlConfiguration
17+
import org.bukkit.inventory.ItemStack
1118
import org.bukkit.plugin.java.JavaPlugin
1219
import java.util.Locale
1320

@@ -17,10 +24,12 @@ interface PylonAddon : Keyed {
1724

1825
val languages: Set<Locale>
1926

20-
/**
21-
* The display name used, for example, at the bottom of items to show which addon an item is from
22-
*/
23-
val displayName: String
27+
val material: Material
28+
29+
val displayName: TranslatableComponent
30+
get() = Component.translatable("pylon.${key.namespace}.addon")
31+
.decoration(TextDecoration.ITALIC, true)
32+
.color(NamedTextColor.BLUE)
2433

2534
override fun getKey(): NamespacedKey
2635
= NamespacedKey(javaPlugin, javaPlugin.name.lowercase())
@@ -31,6 +40,15 @@ interface PylonAddon : Keyed {
3140
fun registerWithPylon() {
3241
PylonRegistry.ADDONS.register(this)
3342
AddonTranslator.register(this)
43+
44+
if (key !in addonNameWarningsSupressed) {
45+
val translator = AddonTranslator.translators[this]!!
46+
for (locale in languages) {
47+
if (!translator.canTranslate("pylon.${key.namespace}.addon", locale)) {
48+
PylonCore.logger.warning("${key.namespace} is missing the 'addon' translation key for ${locale.displayName}")
49+
}
50+
}
51+
}
3452
}
3553

3654
/**
@@ -65,4 +83,14 @@ interface PylonAddon : Keyed {
6583
}
6684
return config
6785
}
86+
87+
companion object {
88+
89+
private val addonNameWarningsSupressed: MutableSet<NamespacedKey> = mutableSetOf()
90+
91+
@JvmStatic
92+
fun supressAddonNameWarnings(key: NamespacedKey) {
93+
addonNameWarningsSupressed.add(key)
94+
}
95+
}
6896
}

pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/block/BlockListener.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ import org.bukkit.event.inventory.BrewingStandFuelEvent
2828
import org.bukkit.event.inventory.FurnaceBurnEvent
2929
import org.bukkit.event.inventory.FurnaceExtractEvent
3030
import org.bukkit.event.player.PlayerInteractEvent
31-
import org.bukkit.event.player.PlayerTakeLecternBookEvent
3231
import org.bukkit.event.player.PlayerToggleSneakEvent
32+
import org.bukkit.event.player.PlayerTakeLecternBookEvent
3333

3434

3535
/**

pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/block/PhantomBlock.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class PhantomBlock(
8282
companion object {
8383
val KEY = pylonKey("error_item")
8484
val BLOCK_KEY = pylonKey("block")
85-
val STACK = ItemStackBuilder.pylonItem(Material.BARRIER, key)
85+
val STACK = ItemStackBuilder.pylonItem(Material.BARRIER, KEY)
8686
.build()
8787
}
8888
}

pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/command/PylonCommand.kt

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import io.github.pylonmc.pylon.core.PylonCore
88
import io.github.pylonmc.pylon.core.block.BlockStorage
99
import io.github.pylonmc.pylon.core.block.waila.Waila.Companion.wailaEnabled
1010
import io.github.pylonmc.pylon.core.debug.DebugWaxedWeatheredCutCopperStairs
11+
import io.github.pylonmc.pylon.core.guide.PylonGuide
1112
import io.github.pylonmc.pylon.core.i18n.PylonArgument
1213
import io.github.pylonmc.pylon.core.item.research.Research
1314
import io.github.pylonmc.pylon.core.item.research.Research.Companion.researchPoints
@@ -36,6 +37,29 @@ import org.jetbrains.annotations.ApiStatus
3637
@ApiStatus.Internal
3738
internal class PylonCommand : BaseCommand() {
3839

40+
@Default
41+
@Description("Open the Pylon guide")
42+
@CommandPermission("pylon.command.guide")
43+
fun default(player: Player) {
44+
PylonGuide.open(player)
45+
}
46+
47+
@Subcommand("guide")
48+
@Description("Obtain the Pylon guide")
49+
@CommandPermission("pylon.command.guide")
50+
fun guide(player: Player) {
51+
player.inventory.addItem(PylonGuide.STACK)
52+
}
53+
54+
init {
55+
Bukkit.getPluginManager().addPermission(
56+
Permission(
57+
"pylon.command.guide",
58+
PermissionDefault.TRUE
59+
)
60+
)
61+
}
62+
3963
@Subcommand("give")
4064
@CommandCompletion("@players @items")
4165
@Description("Give a Pylon item to a player")
@@ -223,9 +247,24 @@ internal class PylonCommand : BaseCommand() {
223247
player.sendRichMessage("<red>Research not found: $research")
224248
return
225249
}
226-
player.removeResearch(res)
227-
val name = MiniMessage.miniMessage().serialize(res.name)
228-
player.sendRichMessage("<green>Removed research $name from ${player.name}")
250+
if (player.hasResearch(res)) {
251+
player.removeResearch(res)
252+
val name = MiniMessage.miniMessage().serialize(res.name)
253+
player.sendRichMessage("<green>Removed research $name from ${player.name}")
254+
} else {
255+
player.sendRichMessage("<red>${player.name} does not have $name")
256+
}
257+
}
258+
259+
@Subcommand("removeall")
260+
@CommandCompletion("@players")
261+
@Description("Remove all researches from a player")
262+
@CommandPermission("pylon.command.research.modify")
263+
fun removeAll(p: OnlinePlayer) {
264+
val player = p.player
265+
for (research in player.researches) {
266+
player.removeResearch(research)
267+
}
229268
}
230269

231270
@Subcommand("points")
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package io.github.pylonmc.pylon.core.event
2+
3+
import io.github.pylonmc.pylon.core.registry.PylonRegistry
4+
import org.bukkit.Keyed
5+
import org.bukkit.event.Event
6+
import org.bukkit.event.HandlerList
7+
8+
class PylonRegisterEvent(
9+
val registry: PylonRegistry<*>,
10+
val value: Keyed,
11+
) : Event() {
12+
override fun getHandlers(): HandlerList
13+
= handlerList
14+
15+
companion object {
16+
@JvmStatic
17+
val handlerList: HandlerList = HandlerList()
18+
}
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package io.github.pylonmc.pylon.core.event
2+
3+
import io.github.pylonmc.pylon.core.registry.PylonRegistry
4+
import org.bukkit.Keyed
5+
import org.bukkit.event.Event
6+
import org.bukkit.event.HandlerList
7+
8+
class PylonUnregisterEvent(
9+
val registry: PylonRegistry<*>,
10+
val value: Keyed,
11+
) : Event() {
12+
override fun getHandlers(): HandlerList
13+
= handlerList
14+
15+
companion object {
16+
@JvmStatic
17+
val handlerList: HandlerList = HandlerList()
18+
}
19+
}

pylon-core/src/main/kotlin/io/github/pylonmc/pylon/core/fluid/PylonFluid.kt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package io.github.pylonmc.pylon.core.fluid
22

3+
import io.github.pylonmc.pylon.core.PylonCore
4+
import io.github.pylonmc.pylon.core.i18n.AddonTranslator
5+
import io.github.pylonmc.pylon.core.item.builder.ItemStackBuilder
36
import io.github.pylonmc.pylon.core.registry.PylonRegistry
7+
import io.github.pylonmc.pylon.core.util.key.getAddon
48
import net.kyori.adventure.text.Component
59
import org.bukkit.Keyed
610
import org.bukkit.Material
@@ -22,6 +26,18 @@ open class PylonFluid(
2226

2327
override fun getKey(): NamespacedKey = key
2428

29+
init {
30+
val addon = PylonRegistry.ADDONS[NamespacedKey(key.namespace, key.namespace)]!!
31+
val translator = AddonTranslator.translators[addon]!!
32+
33+
for (locale in addon.languages) {
34+
val translationKey = "pylon.${key.namespace}.fluid.${key.key}"
35+
check(translator.canTranslate(translationKey, locale)) {
36+
PylonCore.logger.warning("${key.namespace} is missing a translation key for fluid ${key.key} (locale: ${locale.displayName} | expected translation key: $translationKey")
37+
}
38+
}
39+
}
40+
2541
fun addTag(tag: PylonFluidTag) = apply {
2642
check(!hasTag(tag.javaClass)) { "Fluid already has a tag of the same type" }
2743
tags.add(tag)
@@ -46,6 +62,19 @@ open class PylonFluid(
4662
PylonRegistry.FLUIDS.register(this)
4763
}
4864

65+
fun getItem(): ItemStackBuilder {
66+
val item = ItemStackBuilder.of(material)
67+
.name(Component.translatable("pylon.${key.namespace}.fluid.${key.key}"))
68+
69+
for (tag in tags) {
70+
item.lore(tag.displayText)
71+
}
72+
73+
item.lore(getAddon(key).displayName)
74+
75+
return item
76+
}
77+
4978
override fun equals(other: Any?): Boolean = other is PylonFluid && key == other.key
5079
override fun hashCode(): Int = key.hashCode()
5180
override fun toString(): String = key.toString()
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package io.github.pylonmc.pylon.core.fluid
22

3+
import net.kyori.adventure.text.Component
4+
35
interface PylonFluidTag {
4-
// TODO add text display methods once the guide is added
6+
val displayText: Component
57
}

0 commit comments

Comments
 (0)