Skip to content
This repository was archived by the owner on Nov 28, 2025. It is now read-only.

Commit 2ac460f

Browse files
authored
Merge pull request #116 from DockyardMC/feature/list-command
Rewrite some commands to match vanilla and add /list
2 parents db0c9f3 + e33e5aa commit 2ac460f

19 files changed

+121
-76
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ dependencies {
5252
// Minecraft
5353
api("io.github.jglrxavpok.hephaistos:common:2.2.0")
5454
api("io.github.jglrxavpok.hephaistos:gson:2.2.0")
55-
api("io.github.dockyardmc:scroll:2.7")
55+
api("io.github.dockyardmc:scroll:2.8")
5656
implementation("io.github.dockyardmc:wikivg-datagen:1.3")
5757

5858
// Pathfinding

src/main/kotlin/io/github/dockyardmc/DockyardServer.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import io.github.dockyardmc.events.Events
88
import io.github.dockyardmc.events.ServerFinishLoadEvent
99
import io.github.dockyardmc.events.WorldFinishLoadingEvent
1010
import io.github.dockyardmc.implementations.block.DefaultBlockHandlers
11-
import io.github.dockyardmc.implementations.commands.DockyardCommands
11+
import io.github.dockyardmc.implementations.commands.DefaultCommands
1212
import io.github.dockyardmc.npc.NpcCommand
1313
import io.github.dockyardmc.protocol.NetworkCompression
1414
import io.github.dockyardmc.protocol.packets.registry.ClientPacketRegistry
@@ -66,7 +66,7 @@ class DockyardServer(configBuilder: Config.() -> Unit) {
6666
RegistryManager.register(ItemTagRegistry)
6767
RegistryManager.register(BiomeTagRegistry)
6868

69-
if(ConfigManager.config.implementationConfig.defaultCommands) DockyardCommands()
69+
if(ConfigManager.config.implementationConfig.defaultCommands) DefaultCommands().register()
7070
if(ConfigManager.config.implementationConfig.npcCommand) NpcCommand()
7171
if(ConfigManager.config.implementationConfig.spark) SparkDockyardIntegration().initialize()
7272
if(ConfigManager.config.implementationConfig.applyBlockPlacementRules) DefaultBlockHandlers().register()

src/main/kotlin/io/github/dockyardmc/commands/ArgumentTypes.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,6 @@ class EnumArgument(
217217
}
218218
}
219219

220-
class ListArgument() {
221-
222-
}
223-
224220

225221
class CommandArgumentData(
226222
val argument: CommandArgument,

src/main/kotlin/io/github/dockyardmc/commands/CommandHandler.kt

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ import java.util.*
2121

2222
object CommandHandler {
2323

24-
val prefix get() = ConfigManager.config.implementationConfig.commandErrorPrefix
25-
2624
fun handleCommandInput(inputCommand: String, executor: CommandExecutor, testEnv: Boolean = false) {
2725
DockyardServer.scheduler.run {
2826
val tokens = inputCommand.removePrefix("/").split(" ").toMutableList()
@@ -47,19 +45,16 @@ object CommandHandler {
4745
} catch (ex: Exception) {
4846
if (testEnv) throw IllegalArgumentException(ex)
4947
if (ex is CommandException) {
50-
val message = "$prefix${ex.message}"
48+
val message = "<red>${ex.message}"
5149
executor.sendMessage(message)
5250
} else {
5351
log(ex)
54-
if (ConfigManager.config.implementationConfig.notifyUserOfExceptionDuringCommand) {
55-
executor.sendMessage("${prefix}A <orange>${ex::class.qualifiedName} <red>was thrown during execution of this command!")
56-
}
52+
executor.sendMessage("<dark_red>Error <dark_gray>| <red>A <orange><hover:show_text:'<dark_red>${ex.message}'>${ex::class.qualifiedName}</hover> <red>was thrown during execution of this command!")
5753
}
5854
}
5955
}
6056
}
6157

62-
6358
fun handleCommand(
6459
command: Command,
6560
executor: CommandExecutor,
@@ -117,7 +112,7 @@ object CommandHandler {
117112
Float::class -> value.toFloatOrNull() ?: throw CommandException("\"$value\" is not of type Float")
118113
Long::class -> value.toLongOrNull() ?: throw CommandException("\"$value\" is not of type Long")
119114
UUID::class -> UUID.fromString(value)
120-
Item::class -> ItemRegistry.get(value) ?: throw CommandException("\"$value\" is not of type Item")
115+
Item::class -> ItemRegistry.getOrNull(value) ?: ItemRegistry.getOrNull("minecraft:$value") ?: throw CommandException("\"$value\" is not of type Item")
121116
RegistryBlock::class -> {
122117
if (value.contains("[")) {
123118
//block state

src/main/kotlin/io/github/dockyardmc/config/Config.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ class Config {
4747

4848
class ImplementationConfig {
4949
var applyBlockPlacementRules: Boolean = true
50-
var notifyUserOfExceptionDuringCommand: Boolean = true
51-
var commandErrorPrefix: String = "<dark_red>Error <dark_gray>| <red>"
5250
var commandNoPermissionsMessage: String = "You do not have permissions to execute this command!"
5351
var defaultEntityViewDistanceBlocks: Int = 64
5452
var defaultCommands: Boolean = true
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package io.github.dockyardmc.implementations
2+
3+
interface DefaultImplementationModule {
4+
fun register()
5+
}
6+

src/main/kotlin/io/github/dockyardmc/implementations/block/DefaultBlockHandlers.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package io.github.dockyardmc.implementations.block
22

3+
import io.github.dockyardmc.implementations.DefaultImplementationModule
34
import io.github.dockyardmc.world.block.handlers.*
45

5-
class DefaultBlockHandlers {
6+
class DefaultBlockHandlers: DefaultImplementationModule {
67

78
private val facingBlocks: List<String> = listOf(
89
"minecraft:furnace",
@@ -19,7 +20,7 @@ class DefaultBlockHandlers {
1920
"minecraft:bookshelf",
2021
)
2122

22-
fun register() {
23+
override fun register() {
2324
BlockHandlerManager.register(BlockHandlerManager.Type.TAG, "minecraft:slabs", SlabBlockHandler())
2425
BlockHandlerManager.register(BlockHandlerManager.Type.BLOCK, "minecraft:barrel", BarrelBlockHandler())
2526
BlockHandlerManager.register(BlockHandlerManager.Type.TAG, "minecraft:buttons", ButtonBlockHandler())

src/main/kotlin/io/github/dockyardmc/implementations/commands/ClearCommand.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
package io.github.dockyardmc.implementations.commands
22

33
import io.github.dockyardmc.commands.Commands
4+
import io.github.dockyardmc.commands.PlayerArgument
5+
import io.github.dockyardmc.player.Player
46

57
class ClearCommand {
68

79
init {
810
Commands.add("/clear") {
911
withPermission("dockyard.commands.clear")
1012
withDescription("Clears your inventory")
11-
execute {
12-
val player = it.getPlayerOrThrow()
13+
addOptionalArgument("player", PlayerArgument())
14+
execute { ctx ->
15+
val player = getArgumentOrNull<Player>("player") ?: ctx.getPlayerOrThrow()
1316
player.inventory.clear()
1417
}
1518
}

src/main/kotlin/io/github/dockyardmc/implementations/commands/DebugCommand.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class DebugCommand {
1414

1515
addSubcommand("world") {
1616
addArgument("world", WorldArgument())
17-
execute {
17+
execute { ctx ->
1818
val world = getArgument<World>("world")
1919
val message = buildString {
2020
append("\n")
@@ -25,12 +25,12 @@ class DebugCommand {
2525
appendLine(" <gray>Scheduler running: ${(!world.scheduler.paused.value).toScrollText()}")
2626
appendLine(" <gray>Scheduler tick rate: <lime>${world.scheduler.tickRate.value.inWholeMilliseconds}ms")
2727
}
28-
it.sendMessage(message)
28+
ctx.sendMessage(message)
2929
}
3030
}
3131
addSubcommand("events") {
32-
execute {
33-
it.sendMessage(Events.debugTree())
32+
execute { ctx ->
33+
ctx.sendMessage(Events.debugTree())
3434
}
3535
}
3636
}

src/main/kotlin/io/github/dockyardmc/implementations/commands/DockyardCommands.kt renamed to src/main/kotlin/io/github/dockyardmc/implementations/commands/DefaultCommands.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
package io.github.dockyardmc.implementations.commands
22

33
import io.github.dockyardmc.config.ConfigManager
4+
import io.github.dockyardmc.implementations.DefaultImplementationModule
45

5-
class DockyardCommands {
6+
class DefaultCommands: DefaultImplementationModule {
67

7-
init {
8+
override fun register() {
89
GamemodeCommand()
910
VersionAndHelpCommand()
1011
WorldCommand()
1112
SoundCommand()
1213
GiveCommand()
1314
TeleportCommand()
1415
TimeCommand()
15-
TickRateCommand()
16+
SchedulerCommand()
1617
ClearCommand()
18+
ListCommand()
1719
if(ConfigManager.config.debug) {
1820
DebugCommand()
1921
}

0 commit comments

Comments
 (0)