Skip to content

Commit b677509

Browse files
committed
Added helper class to register minecraft commands through the new command api.
1 parent 662bcdc commit b677509

File tree

6 files changed

+107
-5
lines changed

6 files changed

+107
-5
lines changed

ScriptableMC-Engine-Core/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ dependencies {
3030
implementation("org.jetbrains.kotlin:kotlin-reflect")
3131
implementation("commons-io:commons-io:2.6")
3232
implementation("de.tr7zw:item-nbt-api:2.2.0")
33-
implementation("dev.jorel:commandapi-core:3.4")
33+
compileOnly("dev.jorel:commandapi-core:3.4")
3434

3535
testImplementation("junit", "junit", "4.12")
3636
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
package com.smc.utils
2+
3+
import dev.jorel.commandapi.CommandAPICommand
4+
import dev.jorel.commandapi.CommandPermission
5+
import dev.jorel.commandapi.arguments.Argument
6+
import dev.jorel.commandapi.executors.*
7+
8+
@Suppress("unused")
9+
class MinecraftCommand(commandName: String) {
10+
private val apiCommand: CommandAPICommand = CommandAPICommand(commandName)
11+
private val arguments: LinkedHashMap<String, Argument> = linkedMapOf()
12+
13+
fun executes(executor: CommandExecutor): MinecraftCommand {
14+
apiCommand.executes(executor)
15+
return this
16+
}
17+
18+
fun executesWithResult(executor: ResultingCommandExecutor): MinecraftCommand {
19+
apiCommand.executes(executor)
20+
return this
21+
}
22+
23+
fun executesCommandBlock(executor: CommandBlockCommandExecutor): MinecraftCommand {
24+
apiCommand.executesCommandBlock(executor)
25+
return this
26+
}
27+
28+
fun executesCommandBlockWithResult(executor: CommandBlockResultingCommandExecutor): MinecraftCommand {
29+
apiCommand.executesCommandBlock(executor)
30+
return this
31+
}
32+
33+
fun executesConsole(executor: ConsoleCommandExecutor): MinecraftCommand {
34+
apiCommand.executesConsole(executor)
35+
return this
36+
}
37+
38+
fun executesConsoleWithResult(executor: ConsoleResultingCommandExecutor): MinecraftCommand {
39+
apiCommand.executesConsole(executor)
40+
return this
41+
}
42+
43+
fun executesEntity(executor: EntityCommandExecutor): MinecraftCommand {
44+
apiCommand.executesEntity(executor)
45+
return this
46+
}
47+
48+
fun executesEntityWithResult(executor: EntityResultingCommandExecutor): MinecraftCommand {
49+
apiCommand.executesEntity(executor)
50+
return this
51+
}
52+
53+
fun executesPlayer(executor: PlayerCommandExecutor): MinecraftCommand {
54+
apiCommand.executesPlayer(executor)
55+
return this
56+
}
57+
58+
fun executesPlayerWithResult(executor: PlayerResultingCommandExecutor): MinecraftCommand {
59+
apiCommand.executesPlayer(executor)
60+
return this
61+
}
62+
63+
fun executesProxy(executor: ProxyCommandExecutor): MinecraftCommand {
64+
apiCommand.executesProxy(executor)
65+
return this
66+
}
67+
68+
fun executesProxyWithResult(executor: ProxyResultingCommandExecutor): MinecraftCommand {
69+
apiCommand.executesProxy(executor)
70+
return this
71+
}
72+
73+
fun withArgument(name: String, arg: Argument): MinecraftCommand {
74+
arguments[name] = arg
75+
return this
76+
}
77+
78+
fun withPermission(permission: CommandPermission): MinecraftCommand {
79+
apiCommand.withPermission(permission)
80+
return this
81+
}
82+
83+
fun withAliases(vararg aliases: String): MinecraftCommand {
84+
apiCommand.withAliases(*aliases)
85+
return this
86+
}
87+
88+
fun register() {
89+
apiCommand
90+
.withArguments(arguments)
91+
.register()
92+
}
93+
}

ScriptableMC-Engine-JS/Bundled/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ dependencies {
3636
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
3737
implementation("org.jetbrains.kotlin:kotlin-reflect")
3838
implementation("commons-io:commons-io:2.6")
39+
compileOnly("dev.jorel:commandapi-core:3.4")
3940

4041
testImplementation("junit", "junit", "4.12")
4142
}

ScriptableMC-Engine-JS/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ dependencies {
3434
implementation("org.jetbrains.kotlin:kotlin-reflect")
3535
implementation("commons-io:commons-io:2.6")
3636
implementation("de.tr7zw:item-nbt-api:2.2.0")
37-
implementation("dev.jorel:commandapi-core:3.4")
37+
compileOnly("dev.jorel:commandapi-core:3.4")
3838

3939
testImplementation("junit", "junit", "4.12")
4040
}

ScriptableMC-Engine-JS/src/main/resources/plugin.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@ version: '1.3.0'
44
api-version: '1.13'
55
author: AStorks
66
main: com.pixlfox.scriptablemc.SMCJavaScriptEngineMain
7-
depend: []
8-
softdepend: [PlaceholderAPI]
7+
softdepend: [PlaceholderAPI, CommandAPI]

ScriptableMC-Tools-TS/src/main/kotlin/com/pixlfox/scriptablemc/TypescriptLibraryExporter.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ import com.beust.klaxon.JsonObject
55
import com.beust.klaxon.Parser
66
import com.thoughtworks.paranamer.BytecodeReadingParanamer
77
import com.thoughtworks.paranamer.Paranamer
8+
import org.bukkit.Server
89
import org.bukkit.plugin.PluginDescriptionFile
910
import java.io.File
1011
import java.lang.reflect.*
12+
import kotlin.reflect.jvm.jvmErasure
1113

1214

1315
@Suppress("MemberVisibilityCanBePrivate", "UnstableApiUsage", "unused")
@@ -159,6 +161,7 @@ class TypescriptLibraryExporter(args: Array<String> = arrayOf()) {
159161
com.smc.utils.ItemBuilder::class.java,
160162
com.smc.utils.MysqlWrapper::class.java,
161163
com.smc.utils.Http::class.java,
164+
com.smc.utils.MinecraftCommand::class.java,
162165

163166
com.smc.version.Version::class.java,
164167
com.smc.version.MinecraftVersions::class.java,
@@ -616,7 +619,6 @@ class TypescriptLibraryExporter(args: Array<String> = arrayOf()) {
616619
var source = "declare var Java: any;\n"
617620
source += generateTypescriptImports(_class)
618621
source += generateTypescriptInterface(_class)
619-
620622
source += if(_class.isEnum) generateTypescriptEnum(_class as Class<Enum<*>>) else generateTypescriptClass(_class)
621623

622624
return source
@@ -932,6 +934,13 @@ class TypescriptLibraryExporter(args: Array<String> = arrayOf()) {
932934
companion object {
933935
@JvmStatic
934936
fun main(args: Array<String>) {
937+
val test = Server::class
938+
val testMembers = test.members
939+
940+
for (testMember in testMembers) {
941+
println(testMember.returnType.jvmErasure.simpleName)
942+
}
943+
935944
if(args.contains("--lib-smc")) {
936945
TypescriptLibraryExporter(args)
937946
.basePath("./lib-smc")

0 commit comments

Comments
 (0)