b7f9306

Branches > main > b7f9306 > files / src / main / kotlin / net / bowmap / server

items and uhhh a lot

Grahp, 2026-06-29

Commit: b7f930603665e07a02bad7a4a4c301ecd4fc1e1b
Parent: 7c46d88

9 changed files:

src/main/kotlin/net/bowmap/Main.kt modified (view file)

@@ -7,6 +7,7 @@ import net.bowmap.server.setup import net.bowmap.stormbow.Listeners import net.bowmap.handlers.*+import net.bowmap.stormbow.setupStormbow  class Main : JavaPlugin() {   override fun onEnable() {@@ -20,6 +21,7 @@       Death.register()       Welcome.register()       Fishing.register()+      Durability.register()     } catch (t: Exception) {       logger.severe("Startup Failed!")       server.shutdown()@@ -35,3 +37,4 @@ // Disable the nether just in case, lol // Remove all uses of ItemStack! +// Storage

src/main/kotlin/net/bowmap/handlers/Death.kt modified (view file)

@@ -30,10 +30,12 @@ object Death {   fun register() {     handler<PlayerDied> {+      // TODO tp to 0, 0       effects(Cancel(), Broadcast(message = deathMessage(player, cause)))     }      handler<PlayerKilledEntity> {+      // TODO loot tables       effects(Give(player, BUG))     }   }

src/main/kotlin/net/bowmap/handlers/Durability.kt added (view file)

@@ -0,0 +1,14 @@+package net.bowmap.handlers++import net.bowmap.stormbow.handler+import net.bowmap.stormbow.fact.*+import net.bowmap.stormbow.effect.*++object Durability {+  fun register() {+    // Bowmap items do not have durability!+    handler<ItemLostDurability> {+      effects(Cancel())+    }+  }+}

src/main/kotlin/net/bowmap/server/item/Item.kt modified (view file)

@@ -1,6 +1,8 @@ package net.bowmap.server.item  import net.kyori.adventure.text.Component+import net.kyori.adventure.text.format.NamedTextColor+import net.kyori.adventure.text.format.TextDecoration import org.bukkit.inventory.ItemStack import org.bukkit.Material import kotlinx.collections.immutable.*@@ -14,40 +16,34 @@   } } +enum class Rarity {+  COMMON, UNCOMMON, RARE+}++fun rarityLoreComponent(rarity: Rarity): Component = when (rarity) {+  Rarity.COMMON -> Component.text("COMMON", NamedTextColor.WHITE).decoration(TextDecoration.ITALIC, false).decoration(TextDecoration.BOLD, true)+  Rarity.UNCOMMON -> Component.text("UNCOMMON", NamedTextColor.GREEN).decoration(TextDecoration.ITALIC, false).decoration(TextDecoration.BOLD, true)+  Rarity.RARE -> Component.text("RARE", NamedTextColor.BLUE).decoration(TextDecoration.ITALIC, false).decoration(TextDecoration.BOLD, true)+}+ data class Item(   val material: Material,   val amount: Int = 1,   val texture: Texture = Texture(material = material),+  // Can have a custom name for its rarity   val name: Component,-  val lore: PersistentList<Component> = persistentListOf()+  val rarity: Rarity = Rarity.COMMON,+  // Lore is a function of multiple things about an item+  val description: String? = null, ) -fun toItemStack(item: Item): ItemStack {-  // TODO custommodeldata-  val itemStack = ItemStack(item.material, item.amount)-  val meta = itemStack.getItemMeta()--  // itemName is not editable via an anvil, which is the desired behavior-  // TODO make sure its not italics!-  meta.itemName(item.name)-  if (item.lore.isNotEmpty()) {-    // TODO Make sure it's not purple and italics...-    meta.lore(item.lore)+fun computeLore(item: Item): PersistentList<Component> {+  var loreList = persistentListOf<Component>()+  // TODO need spacing, so make a list of these lists and put spaces between them then merge+  if (item.description != null) {+    // TODO split the lore by text size+    loreList = loreList.adding(Component.text(item.description, NamedTextColor.GRAY).decoration(TextDecoration.ITALIC, false))   }--  itemStack.setItemMeta(meta)-  return itemStack-}--fun toItem(itemStack: ItemStack): Item {-  // TODO custommodeldata-  // See the above itemName comment-  val meta = itemStack.getItemMeta()-  val lore = meta.lore()?.toPersistentList() ?: persistentListOf()-  return Item(-    material = itemStack.type,-    amount = itemStack.amount,-    name = meta.itemName(),-    lore = lore-  )+  loreList = loreList.adding(rarityLoreComponent(item.rarity))+  return loreList }

src/main/kotlin/net/bowmap/server/item/ItemStacks.kt added (view file)

@@ -0,0 +1,32 @@++/// Itemstack interop functions+package net.bowmap.server.item++import org.bukkit.inventory.ItemStack++fun toItemStack(item: Item): ItemStack {+  // TODO custommodeldata+  val itemStack = ItemStack(item.material, item.amount)+  val meta = itemStack.getItemMeta()++  // itemName is not editable via an anvil, which is the desired behavior+  // TODO make sure its not italics!+  meta.itemName(item.name)+  meta.lore(computeLore(item))++  itemStack.setItemMeta(meta)+  return itemStack+}++/// Turns a vanilla ItemStack into a Bowmap item.+/// This function is the inverse of toItemStack, so that toItem(toItemStack(x)) == x+fun toItem(itemStack: ItemStack): Item {+  // TODO custommodeldata+  // See the above itemName comment+  val meta = itemStack.getItemMeta()+  return Item(+    material = itemStack.type,+    amount = itemStack.amount,+    name = meta.itemName(),+  )+}

src/main/kotlin/net/bowmap/server/item/Items.kt modified (view file)

@@ -9,8 +9,5 @@ val BUG = Item(   material = Material.STONE_BUTTON,   name = Component.text("Bug"),-  lore = persistentListOf(-    Component.text("You encountered something that hasn't been implemented yet,", NamedTextColor.GRAY).decoration(TextDecoration.ITALIC, false),-    Component.text("so you get this instead.", NamedTextColor.GRAY).decoration(TextDecoration.ITALIC, false)-  )+  description = "You encountered a very long lore line!" )

src/main/kotlin/net/bowmap/stormbow/Listeners.kt modified (view file)

@@ -1,9 +1,3 @@-// Listens to events and turns them into facts-// So what about synchronous events that need to be handled right then and there?-// They do need to exist.--// A fact is just something that happened, so it has no notion of sync/async, only in the handling of a fact does- package net.bowmap.stormbow  import io.papermc.paper.event.player.AsyncChatEvent@@ -35,18 +29,17 @@    @EventHandler   fun onItemDamage(e: PlayerItemDamageEvent) {-    // Logic leaking into this layer but oh well-    // Basically this should be controlled by a fact + effect but I can't be bothered-    e.setCancelled(true)+    val effects = handle(ItemLostDurability(player = e.player, itemStack = e.item))+    if (contains<Cancel>(effects)) {+      e.setCancelled(true)+    }   }    @EventHandler   fun onBlockBreak(e: BlockBreakEvent) {-    // Logic leaking into this layer but oh well-    // Basically this should be controlled by a fact + effect but I can't be bothered     val f = PlayerBrokeBlock(player = e.player, block = e.block)     val effects = handle(f)-    if (effects.any {it is Cancel}) {+    if (contains<Cancel>(effects)) {       e.setCancelled(true)     }     execute(effects)@@ -59,7 +52,7 @@      if (victim is Player) {       val effects = handle(PlayerDied(player = victim, cause = e.damageSource))-      if (effects.any {it is Cancel}) {+      if (contains<Cancel>(effects)) {         e.setCancelled(true)       }       execute(effects)@@ -105,7 +98,7 @@       }        State.CAUGHT_FISH -> {-        val effects = handle(PlayerCaughtFish(player = e.player, hook = e.hook))+        execute(handle(PlayerCaughtFish(player = e.player, hook = e.hook)))          e.caught?.remove()         e.expToDrop = 0

src/main/kotlin/net/bowmap/stormbow/Setup.kt modified (view file)

@@ -1,6 +1,8 @@  package net.bowmap.stormbow +import org.bukkit.plugin.java.JavaPlugin+ fun setupStormbow(plugin: JavaPlugin) {-  plugin.server.pluginManager.registerEvents(Listeners(), this);+  plugin.server.pluginManager.registerEvents(Listeners(), plugin); }

src/main/kotlin/net/bowmap/stormbow/fact/Facts.kt modified (view file)

@@ -3,6 +3,7 @@ import org.bukkit.entity.* import org.bukkit.damage.DamageSource import org.bukkit.block.Block+import org.bukkit.inventory.ItemStack import net.kyori.adventure.audience.Audience import net.kyori.adventure.text.Component @@ -16,3 +17,5 @@ data class PlayerQuit(val player: Player) : Fact data class PlayerStartedFishing(val player: Player, val hook: FishHook) : Fact data class PlayerCaughtFish(val player: Player, val hook: FishHook) : Fact+// Bowmap items do not have durability, so they can't be used here+data class ItemLostDurability(val player: Player, val itemStack: ItemStack) : Fact