Skip to content

Commit b3041a4

Browse files
committed
Assembly table changes
1 parent a8de8df commit b3041a4

File tree

5 files changed

+63
-9
lines changed

5 files changed

+63
-9
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ open class ConfigSection(val internalSection: ConfigurationSection) {
2828
* Gets all the values in the section that are themselves sections.
2929
* @throws NullPointerException if any top level keys do not correspond to a section
3030
*/
31-
fun getSections(): Set<ConfigSection> {
32-
val configSections: MutableSet<ConfigSection> = mutableSetOf()
31+
fun getSections(): List<ConfigSection> {
32+
val configSections: MutableList<ConfigSection> = mutableListOf()
3333
for (key in internalSection.getKeys(false)) {
3434
configSections.add(getSection(key)!!)
3535
}

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ import net.kyori.adventure.sound.Sound
77
import org.bukkit.Bukkit
88
import org.bukkit.NamespacedKey
99
import org.bukkit.Registry
10+
import org.joml.Vector2d
11+
import org.joml.Vector2f
12+
import org.joml.Vector2i
13+
import org.joml.Vector3d
14+
import org.joml.Vector3f
15+
import org.joml.Vector3i
1016
import java.lang.reflect.Type
1117

1218
interface ConfigAdapter<T> {
@@ -44,6 +50,37 @@ interface ConfigAdapter<T> {
4450
@JvmField val ITEM_STACK = ItemStackConfigAdapter
4551
@JvmField val BLOCK_DATA = ConfigAdapter { Bukkit.createBlockData(STRING.convert(it)) }
4652

53+
@JvmField val VECTOR_2I = ConfigAdapter {
54+
val list = (it as List<*>).filterIsInstance<Int>()
55+
check(list.size == 2) { "List must be of size 2" }
56+
Vector2i(list[0], list[1])
57+
}
58+
@JvmField val VECTOR_2F = ConfigAdapter {
59+
val list = (it as List<*>).filterIsInstance<Float>()
60+
check(list.size == 2) { "List must be of size 2" }
61+
Vector2f(list[0], list[1])
62+
}
63+
@JvmField val VECTOR_2D = ConfigAdapter {
64+
val list = (it as List<*>).filterIsInstance<Double>()
65+
check(list.size == 2) { "List must be of size 2" }
66+
Vector2d(list[0], list[1])
67+
}
68+
@JvmField val VECTOR_3I = ConfigAdapter {
69+
val list = (it as List<*>).filterIsInstance<Int>()
70+
check(list.size == 3) { "List must be of size 3" }
71+
Vector3i(list[0], list[1], list[2])
72+
}
73+
@JvmField val VECTOR_3F = ConfigAdapter {
74+
val list = (it as List<*>).filterIsInstance<Float>()
75+
check(list.size == 3) { "List must be of size 3" }
76+
Vector3f(list[0], list[1], list[2])
77+
}
78+
@JvmField val VECTOR_3D = ConfigAdapter {
79+
val list = (it as List<*>).filterIsInstance<Double>()
80+
check(list.size == 3) { "List must be of size 3" }
81+
Vector3d(list[0], list[1], list[2])
82+
}
83+
4784
/**
4885
* A [ConfigAdapter] for in game [Sound]s,
4986
* comprised of a key, source, volume and pitch.

rebar/src/main/kotlin/io/github/pylonmc/rebar/i18n/RebarArgument.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ class RebarArgument private constructor(val name: String, val value: ComponentLi
2121
)
2222
}
2323

24+
override fun fallbackString(): String {
25+
return "rebar:${name}"
26+
}
27+
2428
companion object {
2529
@JvmStatic
2630
fun of(name: String, value: ComponentLike): RebarArgument {

rebar/src/main/kotlin/io/github/pylonmc/rebar/i18n/RebarTranslator.kt

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,20 @@ class RebarTranslator private constructor(private val addon: RebarAddon) : Trans
8686
override fun translate(component: TranslatableComponent, locale: Locale): Component? {
8787
var translation = getRawTranslation(component.key(), locale, warn = true) ?: return null
8888
for (arg in component.arguments()) {
89-
val componentArg = arg.asComponent()
89+
var componentArg = arg.asComponent()
90+
if (componentArg is TextComponent && componentArg.content().startsWith("rebar:")) {
91+
// was a rebar argument that got serialized to vanilla
92+
val argName = componentArg.content().removePrefix("rebar:")
93+
val argValue = componentArg.children().firstOrNull() ?: Component.empty()
94+
componentArg = RebarArgument.of(argName, argValue).asComponent()
95+
}
96+
9097
if (componentArg !is VirtualComponent) continue
91-
val argument = componentArg.renderer()
92-
if (argument !is RebarArgument) continue
98+
val renderer = componentArg.renderer()
99+
if (renderer !is RebarArgument) continue
93100
val replacer = TextReplacementConfig.builder()
94-
.match("%${argument.name}%")
95-
.replacement(GlobalTranslator.render(argument.value.asComponent(), locale))
101+
.match("%${renderer.name}%")
102+
.replacement(GlobalTranslator.render(renderer.value.asComponent(), locale))
96103
.build()
97104
translation = translation.replaceText(replacer)
98105
}
@@ -217,12 +224,18 @@ class RebarTranslator private constructor(private val addon: RebarAddon) : Trans
217224
}
218225
}
219226

220-
val translated = GlobalTranslator.render(it.withArguments(arguments), locale)
227+
val concatenatedArguments: MutableList<TranslationArgumentLike> = arguments.toMutableList()
228+
if (it is TranslatableComponent) {
229+
concatenatedArguments.addAll(it.arguments())
230+
}
231+
232+
val translated = GlobalTranslator.render(it.withArguments(concatenatedArguments), locale)
221233
if (translated is TranslatableComponent && translated.fallback() != null) {
222234
Component.text(translated.fallback()!!)
223235
} else {
224236
translated
225237
}
238+
226239
}
227240
editData(DataComponentTypes.LORE) { lore ->
228241
val newLore = lore.lines().flatMap { line ->

rebar/src/main/kotlin/io/github/pylonmc/rebar/util/gui/GuiItems.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ private class RebarPageItem(private val forward: Boolean) : AbstractPagedGuiBoun
167167
.name(
168168
name.arguments(
169169
RebarArgument.of("current", gui.page + 1),
170-
RebarArgument.of("total", gui.page),
170+
RebarArgument.of("total", gui.pageCount),
171171
)
172172
)
173173
}

0 commit comments

Comments
 (0)