Skip to content

Commit

Permalink
refactor: swap to Brigadier commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy0000 committed Jun 8, 2024
1 parent 4492012 commit f368f62
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 103 deletions.
67 changes: 67 additions & 0 deletions src/main/kotlin/com/mineinabyss/blocky/BlockyBrigadierCommands.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.mineinabyss.blocky

import com.github.shynixn.mccoroutine.bukkit.launch
import com.mineinabyss.blocky.assets_generation.ResourcepackGeneration
import com.mineinabyss.blocky.menus.BlockyMainMenu
import com.mineinabyss.blocky.systems.allBlockyPrefabs
import com.mineinabyss.geary.papermc.tracking.items.gearyItems
import com.mineinabyss.geary.prefabs.PrefabKey
import com.mineinabyss.geary.prefabs.prefabs
import com.mineinabyss.guiy.inventory.guiy
import com.mineinabyss.idofront.commands.brigadier.commands
import com.mineinabyss.idofront.messaging.error
import com.mineinabyss.idofront.messaging.success
import com.mineinabyss.idofront.util.to
import com.mojang.brigadier.arguments.IntegerArgumentType
import io.papermc.paper.command.brigadier.argument.ArgumentTypes

object BlockyBrigadierCommands {

fun registerCommands() {
blocky.plugin.commands {
"blocky" {
"reload" {
executes {
blocky.plugin.createBlockyContext()
blocky.plugin.launch {
val blockyPrefabs = blocky.prefabQuery.entities()
val inheritedPrefabs = blockyPrefabs.asSequence().flatMap { it.prefabs }
.filter { it !in blockyPrefabs }.toSet().sortedBy { it.prefabs.size }

// Reload all prefabs that arent blockyPrefabs
inheritedPrefabs.forEach { prefabs.loader.reload(it) }

// Reload all blockyPrefabs that aren't in inheritedPrefabs
blockyPrefabs.filter { it !in inheritedPrefabs }.sortedBy { it.prefabs.size }
.forEach { prefabs.loader.reload(it) }
}
ResourcepackGeneration().generateDefaultAssets()
sender.success("Blocky has been reloaded!")
}
}
"give" {
val item by ArgumentTypes.key().suggests {
suggest(allBlockyPrefabs.distinctBy { it.prefabKey.full }.map { it.prefabKey.full })
}
val amount by IntegerArgumentType.integer(1)
val player by ArgumentTypes.player()
executes {
val (player, item, amount) = player().first()!! to item()!! to amount()!!
if (player.inventory.firstEmpty() == -1) {
player.error("No empty slots in inventory")
return@executes
}

val itemstack = gearyItems.createItem(PrefabKey.of(item.asString()))?.asQuantity(amount) ?: return@executes player.error("$item exists but is not a block.")
player.inventory.addItem(itemstack)
}
}
"menu" {
playerExecutes {
guiy { BlockyMainMenu(player) }
}
}
}
}
}
}
102 changes: 0 additions & 102 deletions src/main/kotlin/com/mineinabyss/blocky/BlockyCommandExecutor.kt

This file was deleted.

2 changes: 1 addition & 1 deletion src/main/kotlin/com/mineinabyss/blocky/BlockyPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class BlockyPlugin : JavaPlugin() {
listeners(WorldEditListener())
}

BlockyCommandExecutor()
BlockyBrigadierCommands.registerCommands()

geary.run {
createFurnitureSpawner()
Expand Down

0 comments on commit f368f62

Please sign in to comment.