Skip to content

Commit b6eb41c

Browse files
authored
Merge pull request #846 from pylonmc/idra/misc-tweaks
Misc tweaks
2 parents 0c1ab8c + e50f57c commit b6eb41c

20 files changed

Lines changed: 164 additions & 79 deletions

File tree

rebar/src/main/kotlin/io/github/pylonmc/rebar/Rebar.kt

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import kotlinx.coroutines.launch
5454
import org.bukkit.Bukkit
5555
import org.bukkit.Material
5656
import org.bukkit.NamespacedKey
57+
import org.bukkit.configuration.file.YamlConfiguration
5758
import org.bukkit.entity.BlockDisplay
5859
import org.bukkit.entity.FallingBlock
5960
import org.bukkit.entity.Interaction
@@ -95,10 +96,21 @@ object Rebar : JavaPlugin(), RebarAddon {
9596
logger.severe("!!!!!!!!!!!!!!!!!!!! WARNING !!!!!!!!!!!!!!!!!!!!")
9697
logger.severe("You are running Rebar on Minecraft version $actualVersion")
9798
logger.severe("This build of Rebar expects Minecraft version $expectedVersion")
98-
logger.severe("Rebar may run fine, but you may encounter bugs ranging from mild to catastrophic")
99-
logger.severe("Please update your Rebar version accordingly")
10099
logger.severe("Please see https://github.com/pylonmc/rebar/releases for available Rebar versions")
100+
try {
101+
if (RebarConfig.BYPASS_VERSION_CHECK) {
102+
logger.severe("Bypass version set to true in config; proceeding anyway")
103+
} else {
104+
logger.severe("Rebar will refuse to start")
105+
logger.severe("You can attempt to start anyway by setting bypass-version-check to true in the config")
106+
}
107+
} catch (e: Exception){
108+
throw RuntimeException("Error while getting value of bypass-version-check", e)
109+
}
101110
logger.severe("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
111+
if (!RebarConfig.BYPASS_VERSION_CHECK) {
112+
throw RuntimeException("The server is running $actualVersion but Rebar expected $expectedVersion")
113+
}
102114
}
103115

104116
InvUI.getInstance().setPlugin(this)
@@ -274,10 +286,6 @@ object Rebar : JavaPlugin(), RebarAddon {
274286
)
275287

276288
addDefaultPermission("rebar.command.guide")
277-
addDefaultPermission("rebar.command.waila")
278-
addDefaultPermission("rebar.command.research.list.self")
279-
addDefaultPermission("rebar.command.research.discover")
280-
addDefaultPermission("rebar.command.research.points.query.self")
281289
lifecycleManager.registerEventHandler(LifecycleEvents.COMMANDS) {
282290
it.registrar().register(ROOT_COMMAND)
283291
it.registrar().register(ROOT_COMMAND_RE_ALIAS)
@@ -404,10 +412,7 @@ object Rebar : JavaPlugin(), RebarAddon {
404412

405413
override val material = Material.BEDROCK
406414

407-
override val languages: Set<Locale> = setOf(
408-
Locale.ENGLISH,
409-
Locale.of("enws")
410-
)
415+
override val defaultLanguage: Locale = RebarConfig.DEFAULT_LANGUAGE
411416
}
412417

413418
private fun addDefaultPermission(permission: String) {

rebar/src/main/kotlin/io/github/pylonmc/rebar/addon/RebarAddon.kt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ import org.bukkit.event.Listener
1818
import org.bukkit.event.server.PluginDisableEvent
1919
import org.bukkit.plugin.java.JavaPlugin
2020
import org.jetbrains.annotations.ApiStatus
21+
import java.io.File
2122
import java.util.Locale
23+
import java.util.jar.JarFile
2224

2325
/**
2426
* Welcome to the place where it all begins: the Rebar addon!
@@ -31,14 +33,16 @@ interface RebarAddon : Keyed {
3133
val javaPlugin: JavaPlugin
3234

3335
/**
34-
* The set of [Locale]s this addon has translations for.
36+
* The material to represent this addon in menus.
3537
*/
36-
val languages: Set<Locale>
38+
val material: Material
3739

3840
/**
39-
* The material to represent this addon in menus.
41+
* The language to fall back to if a language entry is not found for the user's language.
42+
*
43+
* It is recommended to make this configurable in your addon's config.yml
4044
*/
41-
val material: Material
45+
val defaultLanguage: Locale
4246

4347
/**
4448
* The name used to represent this addon in the guide and other places.
@@ -77,7 +81,7 @@ interface RebarAddon : Keyed {
7781

7882
RebarRegistry.ADDONS.register(this)
7983
if (!suppressAddonNameWarning) {
80-
for (locale in languages) {
84+
for (locale in translator.languages) {
8185
if (!translator.canTranslate("${key.namespace}.addon", locale)) {
8286
Rebar.logger.warning("${key.namespace} is missing the 'addon' translation key for ${locale.displayName}")
8387
}

rebar/src/main/kotlin/io/github/pylonmc/rebar/block/interfaces/FluidBufferRebarBlock.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ interface FluidBufferRebarBlock : FluidRebarBlock {
4545
* @param output whether this buffer can be taken from by fluid output points
4646
*/
4747
fun createFluidBuffer(fluid: RebarFluid, capacity: Double, input: Boolean, output: Boolean) {
48+
check(fluid !in fluidBuffers) { "Fluid $fluid already has a buffer" }
4849
fluidBuffers[fluid] = FluidBufferData(0.0, capacity, input, output)
4950
}
5051

rebar/src/main/kotlin/io/github/pylonmc/rebar/block/interfaces/FluidTankRebarBlock.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ interface FluidTankRebarBlock : FluidRebarBlock {
6262
get() = fluidData.capacity - fluidData.amount
6363

6464
/**
65-
* Sets the type of fluid in the fluid tank
65+
* Sets the type of fluid in the fluid tank.
6666
*/
6767
fun setFluidType(fluid: RebarFluid?) {
6868
fluidData.fluid = fluid

rebar/src/main/kotlin/io/github/pylonmc/rebar/block/interfaces/GuiRebarBlock.kt

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import io.github.pylonmc.rebar.event.RebarBlockLoadEvent
77
import io.github.pylonmc.rebar.event.RebarBlockPlaceEvent
88
import io.github.pylonmc.rebar.event.RebarBlockUnloadEvent
99
import net.kyori.adventure.text.Component
10+
import org.bukkit.entity.Player
1011
import org.bukkit.event.Event
1112
import org.bukkit.event.EventHandler
1213
import org.bukkit.event.EventPriority
@@ -31,16 +32,44 @@ import java.util.IdentityHashMap
3132
*/
3233
interface GuiRebarBlock : NoVanillaInventoryRebarBlock {
3334

35+
/**
36+
* The title of the GUI
37+
*/
38+
val guiTitle: Component
39+
get() = (this as RebarBlock).nameTranslationKey
40+
3441
/**
3542
* Returns the block's GUI. Called when a block is created.
3643
*/
3744
fun createGui(): Gui
3845

3946
/**
40-
* The title of the GUI
47+
* Refreshes the stores GUI by calling [createGui] again.
48+
*
49+
* If players have the GUI already open, it will be closed and then re-opened with the
50+
* new GUI manually.
51+
*
52+
* Strongly consider [updating individual items](https://docs.xenondevs.xyz/invui/item/)
53+
* before you use this method, to prevent having to constantly close and re-open windows.
4154
*/
42-
val guiTitle: Component
43-
get() = (this as RebarBlock).nameTranslationKey
55+
fun refreshGui() {
56+
val oldGui = guiBlocks[this]
57+
val players = oldGui?.windows?.map { it.viewer } ?: emptyList()
58+
oldGui?.windows?.forEach { it.close() }
59+
guiBlocks[this] = createGui()
60+
for (player in players) {
61+
open(player)
62+
}
63+
}
64+
65+
fun open(player: Player) {
66+
Window.builder()
67+
.setUpperGui(guiBlocks[this]!!)
68+
.setTitle(guiTitle)
69+
.setViewer(player)
70+
.build()
71+
.open()
72+
}
4473

4574
companion object : Listener {
4675
private val guiBlocks = IdentityHashMap<GuiRebarBlock, Gui>()
@@ -74,12 +103,7 @@ interface GuiRebarBlock : NoVanillaInventoryRebarBlock {
74103
event.setUseInteractedBlock(Event.Result.DENY)
75104
event.setUseItemInHand(Event.Result.DENY)
76105

77-
Window.builder()
78-
.setUpperGui(guiBlocks[guiBlock]!!)
79-
.setTitle(guiBlock.guiTitle)
80-
.setViewer(event.player)
81-
.build()
82-
.open()
106+
guiBlock.open(event.player)
83107
}
84108

85109
@EventHandler

rebar/src/main/kotlin/io/github/pylonmc/rebar/command/RebarCommand.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import io.github.pylonmc.rebar.content.guide.RebarGuide
1818
import io.github.pylonmc.rebar.entity.display.transform.Rotation
1919
import io.github.pylonmc.rebar.gametest.GameTestConfig
2020
import io.github.pylonmc.rebar.i18n.RebarArgument
21+
import io.github.pylonmc.rebar.i18n.RebarTranslator.Companion.translator
2122
import io.github.pylonmc.rebar.i18n.customMiniMessage
2223
import io.github.pylonmc.rebar.item.ItemTypeWrapper
2324
import io.github.pylonmc.rebar.item.RebarItem
@@ -647,6 +648,7 @@ private val fillMultiblock = buildCommand("fillmultiblock") {
647648
}
648649

649650
private val versions = buildCommand("versions") {
651+
permission("rebar.command.versions")
650652
executes { sender ->
651653
RebarMetrics.onCommandRun("/rb versions")
652654
val serverImplementation = Bukkit.getName()
@@ -678,6 +680,17 @@ private val versions = buildCommand("versions") {
678680
}
679681
}
680682

683+
private val reloadlang = buildCommand("reloadlang") {
684+
permission("rebar.command.reloadlang")
685+
executes { sender ->
686+
RebarMetrics.onCommandRun("/rb reloadlang")
687+
for (addon in RebarRegistry.ADDONS) {
688+
addon.translator.reload()
689+
}
690+
sender.sendFeedback("reloadlang.success")
691+
}
692+
}
693+
681694
@JvmSynthetic
682695
internal val ROOT_COMMAND = buildCommand("rebar") {
683696
permission("rebar.command.guide")
@@ -699,6 +712,7 @@ internal val ROOT_COMMAND = buildCommand("rebar") {
699712
then(confetti)
700713
then(fillMultiblock)
701714
then(versions)
715+
then(reloadlang)
702716
}
703717

704718
@JvmSynthetic

rebar/src/main/kotlin/io/github/pylonmc/rebar/config/RebarConfig.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ object RebarConfig {
1212

1313
private val config = ConfigSection.copyResource(Rebar, "config.yml")
1414

15+
@JvmField
16+
val BYPASS_VERSION_CHECK = config.getOrThrow("bypass-version-check", ConfigAdapter.BOOLEAN)
17+
18+
@JvmField
19+
val DEFAULT_LANGUAGE = config.getOrThrow("default-language", ConfigAdapter.LOCALE)
20+
1521
@JvmField
1622
val DEFAULT_TICK_INTERVAL = config.getOrThrow("default-tick-interval", ConfigAdapter.INTEGER)
1723

rebar/src/main/kotlin/io/github/pylonmc/rebar/config/adapter/ConfigAdapter.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import org.joml.Vector3d
1515
import org.joml.Vector3f
1616
import org.joml.Vector3i
1717
import java.lang.reflect.Type
18+
import java.util.Locale
1819

1920
interface ConfigAdapter<T> {
2021

@@ -53,6 +54,7 @@ interface ConfigAdapter<T> {
5354
@JvmField val ITEM_TYPE_WRAPPER = KEYED.fromGetter { ItemTypeWrapper(it) }
5455
@JvmField val ITEM_STACK = ItemStackConfigAdapter
5556
@JvmField val BLOCK_DATA = ConfigAdapter { Bukkit.createBlockData(STRING.convert(it)) }
57+
@JvmField val LOCALE = ConfigAdapter { Locale.of(STRING.convert(it)) }
5658

5759
@JvmField val VECTOR_2I = ConfigAdapter {
5860
val list = (it as List<*>).filterIsInstance<Int>()

rebar/src/main/kotlin/io/github/pylonmc/rebar/fluid/RebarFluid.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ open class RebarFluid(
6262

6363
init {
6464
if (key !in nameWarningsSuppressed) {
65-
for (locale in addon.languages) {
65+
for (locale in addon.translator.languages) {
6666
val translationKey = "${key.namespace}.fluid.${key.key}"
6767
if (!addon.translator.canTranslate(translationKey, locale)) {
6868
Rebar.logger.warning("${key.namespace} is missing a translation key for fluid ${key.key} (locale: ${locale.displayName} | expected translation key: $translationKey)")

rebar/src/main/kotlin/io/github/pylonmc/rebar/guide/button/ItemButton.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class ItemButton private constructor(
6767
builder.set(DataComponentTypes.ITEM_MODEL, Material.STRUCTURE_VOID.key)
6868
}
6969

70-
if (!player.canCraft(itemSchema, respectBypass = false)) {
70+
if (!player.canCraft(itemSchema)) {
7171
builder.set(DataComponentTypes.ITEM_MODEL, Material.BARRIER.key)
7272
.set(DataComponentTypes.ENCHANTMENT_GLINT_OVERRIDE, false)
7373

@@ -99,7 +99,7 @@ class ItemButton private constructor(
9999
}
100100

101101
if (player.guideHints) {
102-
if (!player.canCraft(itemSchema, respectBypass = false)) {
102+
if (!player.canCraft(itemSchema)) {
103103
builder.lore(Component.translatable("rebar.guide.button.item.hints.unresearched"))
104104
}
105105
}

0 commit comments

Comments
 (0)