Skip to content
Merged
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
25 changes: 15 additions & 10 deletions rebar/src/main/kotlin/io/github/pylonmc/rebar/Rebar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import kotlinx.coroutines.launch
import org.bukkit.Bukkit
import org.bukkit.Material
import org.bukkit.NamespacedKey
import org.bukkit.configuration.file.YamlConfiguration
import org.bukkit.entity.BlockDisplay
import org.bukkit.entity.FallingBlock
import org.bukkit.entity.Interaction
Expand Down Expand Up @@ -95,10 +96,21 @@ object Rebar : JavaPlugin(), RebarAddon {
logger.severe("!!!!!!!!!!!!!!!!!!!! WARNING !!!!!!!!!!!!!!!!!!!!")
logger.severe("You are running Rebar on Minecraft version $actualVersion")
logger.severe("This build of Rebar expects Minecraft version $expectedVersion")
logger.severe("Rebar may run fine, but you may encounter bugs ranging from mild to catastrophic")
logger.severe("Please update your Rebar version accordingly")
logger.severe("Please see https://github.com/pylonmc/rebar/releases for available Rebar versions")
try {
if (RebarConfig.BYPASS_VERSION_CHECK) {
logger.severe("Bypass version set to true in config; proceeding anyway")
} else {
logger.severe("Rebar will refuse to start")
logger.severe("You can attempt to start anyway by setting bypass-version-check to true in the config")
}
} catch (e: Exception){
throw RuntimeException("Error while getting value of bypass-version-check", e)
}
logger.severe("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
if (!RebarConfig.BYPASS_VERSION_CHECK) {
throw RuntimeException("The server is running $actualVersion but Rebar expected $expectedVersion")
}
}

InvUI.getInstance().setPlugin(this)
Expand Down Expand Up @@ -274,10 +286,6 @@ object Rebar : JavaPlugin(), RebarAddon {
)

addDefaultPermission("rebar.command.guide")
addDefaultPermission("rebar.command.waila")
addDefaultPermission("rebar.command.research.list.self")
addDefaultPermission("rebar.command.research.discover")
addDefaultPermission("rebar.command.research.points.query.self")
lifecycleManager.registerEventHandler(LifecycleEvents.COMMANDS) {
it.registrar().register(ROOT_COMMAND)
it.registrar().register(ROOT_COMMAND_RE_ALIAS)
Expand Down Expand Up @@ -404,10 +412,7 @@ object Rebar : JavaPlugin(), RebarAddon {

override val material = Material.BEDROCK

override val languages: Set<Locale> = setOf(
Locale.ENGLISH,
Locale.of("enws")
)
override val defaultLanguage: Locale = RebarConfig.DEFAULT_LANGUAGE
}

private fun addDefaultPermission(permission: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ import org.bukkit.event.Listener
import org.bukkit.event.server.PluginDisableEvent
import org.bukkit.plugin.java.JavaPlugin
import org.jetbrains.annotations.ApiStatus
import java.io.File
import java.util.Locale
import java.util.jar.JarFile

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

/**
* The set of [Locale]s this addon has translations for.
* The material to represent this addon in menus.
*/
val languages: Set<Locale>
val material: Material

/**
* The material to represent this addon in menus.
* The language to fall back to if a language entry is not found for the user's language.
*
* It is recommended to make this configurable in your addon's config.yml
*/
val material: Material
val defaultLanguage: Locale

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

RebarRegistry.ADDONS.register(this)
if (!suppressAddonNameWarning) {
for (locale in languages) {
for (locale in translator.languages) {
if (!translator.canTranslate("${key.namespace}.addon", locale)) {
Rebar.logger.warning("${key.namespace} is missing the 'addon' translation key for ${locale.displayName}")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ interface FluidBufferRebarBlock : FluidRebarBlock {
* @param output whether this buffer can be taken from by fluid output points
*/
fun createFluidBuffer(fluid: RebarFluid, capacity: Double, input: Boolean, output: Boolean) {
check(fluid !in fluidBuffers) { "Fluid $fluid already has a buffer" }
fluidBuffers[fluid] = FluidBufferData(0.0, capacity, input, output)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ interface FluidTankRebarBlock : FluidRebarBlock {
get() = fluidData.capacity - fluidData.amount

/**
* Sets the type of fluid in the fluid tank
* Sets the type of fluid in the fluid tank.
*/
fun setFluidType(fluid: RebarFluid?) {
fluidData.fluid = fluid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import io.github.pylonmc.rebar.event.RebarBlockLoadEvent
import io.github.pylonmc.rebar.event.RebarBlockPlaceEvent
import io.github.pylonmc.rebar.event.RebarBlockUnloadEvent
import net.kyori.adventure.text.Component
import org.bukkit.entity.Player
import org.bukkit.event.Event
import org.bukkit.event.EventHandler
import org.bukkit.event.EventPriority
Expand All @@ -31,16 +32,44 @@ import java.util.IdentityHashMap
*/
interface GuiRebarBlock : NoVanillaInventoryRebarBlock {

/**
* The title of the GUI
*/
val guiTitle: Component
get() = (this as RebarBlock).nameTranslationKey

/**
* Returns the block's GUI. Called when a block is created.
*/
fun createGui(): Gui

/**
* The title of the GUI
* Refreshes the stores GUI by calling [createGui] again.
*
* If players have the GUI already open, it will be closed and then re-opened with the
* new GUI manually.
*
* Strongly consider [updating individual items](https://docs.xenondevs.xyz/invui/item/)
* before you use this method, to prevent having to constantly close and re-open windows.
*/
val guiTitle: Component
get() = (this as RebarBlock).nameTranslationKey
fun refreshGui() {
val oldGui = guiBlocks[this]
val players = oldGui?.windows?.map { it.viewer } ?: emptyList()
oldGui?.windows?.forEach { it.close() }
guiBlocks[this] = createGui()
for (player in players) {
open(player)
Comment thread
Seggan marked this conversation as resolved.
}
}

fun open(player: Player) {
Window.builder()
.setUpperGui(guiBlocks[this]!!)
.setTitle(guiTitle)
.setViewer(player)
.build()
.open()
}

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

Window.builder()
.setUpperGui(guiBlocks[guiBlock]!!)
.setTitle(guiBlock.guiTitle)
.setViewer(event.player)
.build()
.open()
guiBlock.open(event.player)
}

@EventHandler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import io.github.pylonmc.rebar.content.guide.RebarGuide
import io.github.pylonmc.rebar.entity.display.transform.Rotation
import io.github.pylonmc.rebar.gametest.GameTestConfig
import io.github.pylonmc.rebar.i18n.RebarArgument
import io.github.pylonmc.rebar.i18n.RebarTranslator.Companion.translator
import io.github.pylonmc.rebar.i18n.customMiniMessage
import io.github.pylonmc.rebar.item.ItemTypeWrapper
import io.github.pylonmc.rebar.item.RebarItem
Expand Down Expand Up @@ -647,6 +648,7 @@ private val fillMultiblock = buildCommand("fillmultiblock") {
}

private val versions = buildCommand("versions") {
permission("rebar.command.versions")
executes { sender ->
RebarMetrics.onCommandRun("/rb versions")
val serverImplementation = Bukkit.getName()
Expand Down Expand Up @@ -678,6 +680,17 @@ private val versions = buildCommand("versions") {
}
}

private val reloadlang = buildCommand("reloadlang") {
permission("rebar.command.reloadlang")
executes { sender ->
RebarMetrics.onCommandRun("/rb reloadlang")
for (addon in RebarRegistry.ADDONS) {
addon.translator.reload()
}
sender.sendFeedback("reloadlang.success")
}
}

@JvmSynthetic
internal val ROOT_COMMAND = buildCommand("rebar") {
permission("rebar.command.guide")
Expand All @@ -699,6 +712,7 @@ internal val ROOT_COMMAND = buildCommand("rebar") {
then(confetti)
then(fillMultiblock)
then(versions)
then(reloadlang)
}

@JvmSynthetic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ object RebarConfig {

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

@JvmField
val BYPASS_VERSION_CHECK = config.getOrThrow("bypass-version-check", ConfigAdapter.BOOLEAN)

@JvmField
val DEFAULT_LANGUAGE = config.getOrThrow("default-language", ConfigAdapter.LOCALE)

@JvmField
val DEFAULT_TICK_INTERVAL = config.getOrThrow("default-tick-interval", ConfigAdapter.INTEGER)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import org.joml.Vector3d
import org.joml.Vector3f
import org.joml.Vector3i
import java.lang.reflect.Type
import java.util.Locale

interface ConfigAdapter<T> {

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

@JvmField val VECTOR_2I = ConfigAdapter {
val list = (it as List<*>).filterIsInstance<Int>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ open class RebarFluid(

init {
if (key !in nameWarningsSuppressed) {
for (locale in addon.languages) {
for (locale in addon.translator.languages) {
val translationKey = "${key.namespace}.fluid.${key.key}"
if (!addon.translator.canTranslate(translationKey, locale)) {
Rebar.logger.warning("${key.namespace} is missing a translation key for fluid ${key.key} (locale: ${locale.displayName} | expected translation key: $translationKey)")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class ItemButton private constructor(
builder.set(DataComponentTypes.ITEM_MODEL, Material.STRUCTURE_VOID.key)
}

if (!player.canCraft(itemSchema, respectBypass = false)) {
if (!player.canCraft(itemSchema)) {
builder.set(DataComponentTypes.ITEM_MODEL, Material.BARRIER.key)
.set(DataComponentTypes.ENCHANTMENT_GLINT_OVERRIDE, false)

Expand Down Expand Up @@ -99,7 +99,7 @@ class ItemButton private constructor(
}

if (player.guideHints) {
if (!player.canCraft(itemSchema, respectBypass = false)) {
if (!player.canCraft(itemSchema)) {
builder.lore(Component.translatable("rebar.guide.button.item.hints.unresearched"))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ import org.bukkit.NamespacedKey
*
* ### Custom Tags
* - `<arrow>`|`<arrow:\[color\]>` - Inserts a right arrow (→) with the specified color (default: 0x666666)
* - `<guidearrow> - Shorthand for `<arrow:0x3a293>`
* - `<guidearrow> - Shorthand for `<arrow:0x653d6d>`
* - `<diamond>`|`<diamond:\[color\]>` - Inserts a diamond (◆) with the specified color (default: 0x666666)
* - `<star>`|`<star:\[color\]>` - Inserts a star (★) with the specified color (default: [NamedTextColor.BLUE])
* - `<insn></insn>` - Applies a yellow styling (0xf9d104), used for instructions
* - `<guidehint></guidehint>` - Applies a light purple styling (0xeac5f4), used for guide hints
* - `<guideinsn></guideinsn>` - Applies a purple styling (0xc907f4), used for guide instructions
* - `<attr></attr>` - Applies a cyan styling (0xa9d9e8), used for attributes
* - `<unit:\[prefix\]:[unit]></unit>` - Formats a **constant** number as a unit, with an optional metric prefix
Expand All @@ -55,10 +56,11 @@ val customMiniMessage = MiniMessage.builder()
it.tag("diamond", ::diamond)
it.tag("star", ::star)
it.tag("insn") { _, _ -> Tag.styling(TextColor.color(0xf9d104)) }
it.tag("guidehint") { _, _ -> Tag.styling(TextColor.color(0xeac5f4), TextDecoration.ITALIC) }
it.tag("guideinsn") { _, _ -> Tag.styling(TextColor.color(0xc907f4)) }
it.tag("story") { _, _ ->
Tag.styling { builder ->
builder.color(TextColor.color(0xcc9bf2)).decorate(TextDecoration.ITALIC)
builder.color(TextColor.color(0xde76e0)).decorate(TextDecoration.ITALIC)
}
}
it.tag("attr") { _, _ -> Tag.styling(TextColor.color(0xa9d9e8)) }
Expand All @@ -79,7 +81,7 @@ private fun arrow(args: ArgumentQueue, @Suppress("unused") ctx: Context): Tag {
}

private fun guidearrow(args: ArgumentQueue, @Suppress("unused") ctx: Context): Tag {
val color = TextColor.color(0x3a293)
val color = TextColor.color(0x653d6d)
return Tag.selfClosingInserting(Component.text("\u2192").color(color))
}

Expand Down
Loading
Loading