Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import io.github.pylonmc.pylon.core.block.context.BlockBreakContext
import io.github.pylonmc.pylon.core.block.context.BlockCreateContext
import io.github.pylonmc.pylon.core.event.PylonBlockUnloadEvent
import io.github.pylonmc.pylon.core.item.PylonItem
import io.github.pylonmc.pylon.core.item.research.Research.Companion.canUse
import io.github.pylonmc.pylon.core.util.position.position
import io.papermc.paper.event.block.*
import io.papermc.paper.event.entity.EntityCompostItemEvent
Expand Down Expand Up @@ -49,13 +50,17 @@ internal object BlockListener : Listener {
val item = event.itemInHand
val player = event.player

val pylonItem = PylonItem.fromStack(item)
val pylonItem = PylonItem.fromStack(item) ?: return
if (!event.player.canUse(pylonItem, true)) {
event.isCancelled = true
return
}
val relative = event.blockPlaced.position - event.blockAgainst.position
val blockFace = BlockFace.entries.find { it.modX == relative.x && it.modY == relative.y && it.modZ == relative.z }
?: BlockFace.SELF
val pylonBlock = pylonItem?.place(BlockCreateContext.PlayerPlace(player, item, event.blockPlaced, blockFace))
val pylonBlock = pylonItem.place(BlockCreateContext.PlayerPlace(player, item, event.blockPlaced, blockFace))

if (pylonItem != null && pylonBlock == null) {
if (pylonBlock == null) {
event.isCancelled = true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import io.github.pylonmc.pylon.core.block.waila.Waila.Companion.wailaEnabled
import io.github.pylonmc.pylon.core.debug.DebugWaxedWeatheredCutCopperStairs
import io.github.pylonmc.pylon.core.guide.PylonGuide
import io.github.pylonmc.pylon.core.i18n.PylonArgument
import io.github.pylonmc.pylon.core.item.PylonItem
import io.github.pylonmc.pylon.core.item.research.Research
import io.github.pylonmc.pylon.core.item.research.Research.Companion.researchPoints
import io.github.pylonmc.pylon.core.item.research.Research.Companion.researches
Expand All @@ -28,6 +29,7 @@ import org.bukkit.Material
import org.bukkit.NamespacedKey
import org.bukkit.command.CommandSender
import org.bukkit.entity.Player
import org.bukkit.inventory.EquipmentSlot
import org.bukkit.permissions.Permission
import org.bukkit.permissions.PermissionDefault
import org.jetbrains.annotations.ApiStatus
Expand Down Expand Up @@ -83,6 +85,18 @@ internal class PylonCommand : BaseCommand() {
player.give(DebugWaxedWeatheredCutCopperStairs.STACK)
}

@Subcommand("key")
@Description("Shows you the key of the item in your main hand")
@CommandPermission("pylon.command.key")
fun key(player: Player) {
val item = PylonItem.fromStack(player.inventory.getItem(EquipmentSlot.HAND))
if (item == null) {
player.sendRichMessage("<red>You are not holding a Pylon item")
Comment thread
LordIdra marked this conversation as resolved.
return
}
player.sendRichMessage(item.key.toString())
}

@Subcommand("setblock")
@CommandCompletion("@blocks")
@Description("Set a block to be a pylon block")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.pylonmc.pylon.core.config

import io.github.pylonmc.pylon.core.PylonCore
import org.bukkit.NamespacedKey

object PylonConfig {

Expand Down Expand Up @@ -32,4 +33,16 @@ object PylonConfig {

@JvmStatic
val translationWrapLimit: Int by config

@JvmStatic
val disabledItems: Set<NamespacedKey> =
config.getOrThrow<List<String>>("disabled-items")
.mapNotNull {
val key = NamespacedKey.fromString(it)
if (key == null) {
PylonCore.logger.warning { "Invalid disabled-items key '$it'" }
}
key
}
.toSet()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package io.github.pylonmc.pylon.core.event

import io.github.pylonmc.pylon.core.block.PylonBlock
import io.github.pylonmc.pylon.core.recipe.PylonRecipe
import io.github.pylonmc.pylon.core.recipe.RecipeType
import org.bukkit.entity.Player
import org.bukkit.event.Cancellable
import org.bukkit.event.Event
import org.bukkit.event.HandlerList

/**
* Called when a crafting recipe is started
*/
class PrePylonCraftEvent<T: PylonRecipe> @JvmOverloads constructor(
val type: RecipeType<T>,
val recipe: T,
val block: PylonBlock? = null,
val player: Player? = null
) : Event(), Cancellable {

private var isCancelled = false

override fun isCancelled(): Boolean = isCancelled

override fun setCancelled(cancel: Boolean) {
isCancelled = cancel
}

override fun getHandlers(): HandlerList
= handlerList

companion object {
@JvmStatic
val handlerList: HandlerList = HandlerList()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package io.github.pylonmc.pylon.core.event

import io.github.pylonmc.pylon.core.block.PylonBlock
import io.github.pylonmc.pylon.core.recipe.PylonRecipe
import io.github.pylonmc.pylon.core.recipe.RecipeType
import org.bukkit.event.Event
import org.bukkit.event.HandlerList

/**
* Called when a crafting recipe is started
*/
class PylonCraftEvent<T: PylonRecipe> @JvmOverloads constructor(
val type: RecipeType<T>,
val recipe: T,
val block: PylonBlock? = null,
) : Event() {

override fun getHandlers(): HandlerList
= handlerList

companion object {
@JvmStatic
val handlerList: HandlerList = HandlerList()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ import io.github.pylonmc.pylon.core.i18n.PylonArgument
import io.github.pylonmc.pylon.core.item.PylonItem
import io.github.pylonmc.pylon.core.item.builder.ItemStackBuilder
import io.github.pylonmc.pylon.core.item.research.Research.Companion.canUse
import io.github.pylonmc.pylon.core.item.research.Research.Companion.canCraft
import io.github.pylonmc.pylon.core.item.research.Research.Companion.research
import io.github.pylonmc.pylon.core.item.research.Research.Companion.researchPoints
import io.github.pylonmc.pylon.core.item.research.Research.Companion.researches
import io.github.pylonmc.pylon.core.registry.PylonRegistry
import io.papermc.paper.datacomponent.DataComponentTypes
import io.papermc.paper.datacomponent.item.ItemLore
import net.kyori.adventure.text.Component
import net.kyori.adventure.text.TranslatableComponent
import org.bukkit.Bukkit
import org.bukkit.Material
import org.bukkit.NamespacedKey
import org.bukkit.entity.Player
Expand Down Expand Up @@ -57,7 +56,11 @@ class ItemButton(val stack: ItemStack) : AbstractItem() {
builder.name(stackName.arguments(placeholders))
}

if (!player.canUse(item)) {
if (item.isDisabled) {
builder.set(DataComponentTypes.ITEM_MODEL, Material.STRUCTURE_VOID.key)
}

if (!player.canCraft(item)) {
builder.set(DataComponentTypes.ITEM_MODEL, Material.BARRIER.key)
.set(DataComponentTypes.ENCHANTMENT_GLINT_OVERRIDE, false)
.lore(Component.translatable("pylon.pyloncore.guide.button.item.not-researched"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class AddonTranslator(private val addon: PylonAddon) : Translator {
val argument = component.renderer() as? PylonArgument ?: continue
val replacer = TextReplacementConfig.builder()
.match("%${argument.name}%")
.replacement(GlobalTranslator.render(argument.value, locale))
.replacement(GlobalTranslator.render(argument.value.asComponent(), locale))
.build()
translated = translated.replaceText(replacer)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ class PlayerTranslationHandler(val player: Player) {
GlobalTranslator.render(attacher.render(it, Unit), player.locale())
}
item.stack.editData(DataComponentTypes.LORE) { lore ->
val newLore: MutableList<Component> = (lore.lines() + item.addon.displayName).flatMapTo(mutableListOf()) { line ->
val toTranslate = (lore.lines() + item.addon.displayName).toMutableList()
if (item.isDisabled) {
toTranslate.add(Component.translatable("pylon.pyloncore.message.disabled.lore"))
}

val newLore: MutableList<Component> = toTranslate.flatMapTo(mutableListOf()) { line ->
val translated = GlobalTranslator.render(attacher.render(line, Unit), player.locale())
val encoded = LineWrapEncoder.encode(translated)
val wrapped = encoded.copy(lines = encoded.lines.flatMap(wrapper::wrap))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import net.kyori.adventure.text.ComponentLike
import net.kyori.adventure.text.TranslationArgument
import net.kyori.adventure.text.VirtualComponentRenderer

class PylonArgument private constructor(val name: String, val value: Component) : VirtualComponentRenderer<Unit> {
class PylonArgument private constructor(val name: String, val value: ComponentLike) : VirtualComponentRenderer<Unit> {

override fun apply(context: Unit): ComponentLike {
return value
Expand All @@ -17,8 +17,8 @@ class PylonArgument private constructor(val name: String, val value: Component)
return TranslationArgument.component(
Component.virtual(
Unit::class.java,
PylonArgument(name, value.asComponent())
)
PylonArgument(name, value)
).append(value) // Append the value for comparison purposes, it'll get thrown out anyway
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import io.github.pylonmc.pylon.core.PylonCore
import io.github.pylonmc.pylon.core.block.PylonBlock
import io.github.pylonmc.pylon.core.block.context.BlockCreateContext
import io.github.pylonmc.pylon.core.config.Config
import io.github.pylonmc.pylon.core.config.PylonConfig
import io.github.pylonmc.pylon.core.config.Settings
import io.github.pylonmc.pylon.core.datatypes.PylonSerializers
import io.github.pylonmc.pylon.core.i18n.AddonTranslator
Expand All @@ -24,6 +25,7 @@ open class PylonItem(val stack: ItemStack) : Keyed {
val researchBypassPermission = schema.researchBypassPermission
val addon = schema.addon
val pylonBlock = schema.pylonBlockKey
val isDisabled: Boolean = PylonConfig.disabledItems.contains(key)

fun getSettings() = Settings.get(key)

Expand Down
Loading
Loading