Skip to content

Commit 5b7e84b

Browse files
committed
complete overhaul
1 parent 05a7378 commit 5b7e84b

35 files changed

+959
-890
lines changed

.idea/.gitignore

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 14 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -52,66 +52,20 @@ If you see `commander` in the source code, you will know that is referencing a p
5252

5353
There are 2 examples in the `examples` folder:
5454
- [HelloWorldCommand](examples/HelloWorldCommand.kt): This demonstrates how to use CommandTree with a very basic command
55-
- [GroupCommand](examples/GroupCommand.kt): This provides a more advanced usage scenario.
56-
```kotlin
57-
// CommandLeafs
58-
CommandEmptyLeaf()
59-
CommandBoolLeaf()
60-
CommandIntLeaf()
61-
CommandDoubleLeaf()
62-
CommandStringLeaf()
63-
CommandPlayerLeaf()
64-
CommandLocationLeaf()
65-
CommandVarargLeaf()
66-
CommandPairLeaf()
67-
CommandTripleLeaf()
68-
69-
// CommandBranch
70-
// /command examples [first/second/third]
71-
// this command is to group a lot of command nodes together under 1 key word ("example" in this case)
72-
CommandBranch("example", arrayOf( ..., ... ) )
73-
74-
// Usage
75-
// note that each leaf also has a emptyEffect argument (which is not shown here)
76-
// Only the Empty leaf is shown doing that, that's because that's the only other argument that this leaf has
77-
val exampleCommand = CommandBranch("example", arrayOf(
78-
CommandEmptyLeaf("emptyArg", { player -> /* empty command logic */ }),
79-
CommandBoolLeaf("boolArg", { player, boolValue -> /* bool command logic */ }),
80-
CommandLocationLeaf("locationArg", { player, location -> /* location command logic */ }),
81-
82-
CommandIntLeaf("intArg1", 1/null, 10/null, { player, intValue -> /* int command logic */ }),
83-
CommandIntLeaf("intArg2", intArrayOf(1,3,5,7), { player, intValue -> /* int command logic */ }),
84-
CommandIntLeaf("intArg3", 0, { Teams.count } , { player, intValue -> /* int command logic */ }),
85-
// you can also provide real time inputs, it will be checked what the value is whenever you enter the command
86-
87-
CommandDoubleLeaf("doubleArg1", 0.0/null, 1.0/null, { player, doubleValue -> /* double command logic */ }),
88-
CommandDoubleLeaf("doubleArg2", 0.0, { Distance.max } , { player, doubleValue -> /* double command logic */ }),
89-
// doubles don't have any possibility for a list
90-
91-
CommandStringLeaf("stringArg1", null, { player, stringValue -> /* string command logic */ }), // anything
92-
CommandStringLeaf("stringArg2", arrayOf("option1", "option2"), { player, stringValue -> /* string command logic */ }), // only these options
93-
CommandStringLeaf("stringArg2", { Teams.teamNames }, { player, stringValue -> /* string command logic */ }), // real time
94-
95-
CommandPlayerLeaf("playerArg1", arrayOf(), { player, targetPlayer -> /* player command logic */ }), // fixed
96-
CommandPlayerLeaf("playerArg2", { Plugin.onlinePlayers }, { player, targetPlayer -> /* player command logic */ }), // dynamic
97-
98-
// the following 3 leafs need other leafs to operate, the title of the innerLeafs will never be shown, so they can be basicly any name
99-
// the vararg is a list of infinite arguments of the type you provided, the effect will return a list
100-
// the boolean is if you allow for it to return empty or not (true if it can, false if not)
101-
CommandVarargLeaf("varargArg",
102-
CommandIntLeaf("innerIntArg", 1, 100, { _, _ -> }), false, { player, varargValues -> /* vararg command logic */ }),
103-
// the pair is 2 argument types, grouped under 1 name (here "pairArg")
104-
CommandPairLeaf("pairArg",
105-
CommandIntLeaf("innerIntArg", 1, 100, { _, _ -> }),
106-
CommandBoolLeaf("innerBoolArg", { _, _ -> })),
107-
// the triple is 3 argument types, grouped under 1 name (here "tripleArg")
108-
CommandTripleLeaf("tripleArg",
109-
CommandIntLeaf("innerIntArg", 1, 100, { _, _ -> }),
110-
CommandBoolLeaf("innerBoolArg", { _, _ -> }),
111-
CommandStringLeaf("innerStringArg", arrayOf("option1", "option2"), { _, _ -> }))
112-
))
113-
```
55+
- [GroupCommand](examples/GroupCommand.kt): This provides a more advanced usage scenario.
56+
57+
and this is the list of partials that can be used
58+
- BranchPartial
59+
- EmptyPartial
60+
- BooleanPartial
61+
- StringPartial
62+
- PlayerPartial
63+
- IntPartial
64+
- DoublePartial
65+
- LocationPartial
66+
- VarargPartial
67+
- PairPartial
68+
- TriplePartial
11469

11570
## License
116-
11771
IDK how licenses work. If I ever find the time to assign a license, it will be a license that basically says "do whatever you want with it, Just reference me somewhere in the comments for example"

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ plugins {
66
}
77

88
group = "com.github.WantToBeeMe"
9-
version = "1.0.0"
9+
version = "2.0.0"
1010

1111
repositories {
1212
mavenCentral()

examples/GroupCommand.kt

Lines changed: 20 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,28 @@
11
package me.wanttobee.commandtree.examples
22

3-
import me.wanttobee.commandtree.ICommandNamespace
4-
import me.wanttobee.commandtree.ICommandObject
5-
import me.wanttobee.commandtree.nodes.*
3+
import me.wanttobee.commandtree.Description
4+
import me.wanttobee.commandtree.ITreeCommand
5+
import me.wanttobee.commandtree.partials.*
66
import org.bukkit.ChatColor
77

8-
// to make sure it all works you simply have to do `CommandTreeSystem.createCommand(GroupCommand)`
9-
// (and make sure the CommandTreeSystem has been initialized )
10-
object GroupCommand : ICommandNamespace {
11-
override val commandName: String = "group"
12-
override val commandSummary: String = "to show you some more complex commands you can make"
13-
override val systemCommands: Array<ICommandObject> = arrayOf(PairTree)
14-
override val hasOnlyOneGroupMember: Boolean = false
15-
override val isZeroParameterCommand: Boolean = false
8+
object GroupCommand : ITreeCommand {
9+
override val description = Description("to show you some more complex commands you can make",)
10+
.addSubDescription(name="pair", description="This is my cool pair tree", usage= "/mygroup pair <bool> <int>")
11+
.addSubDescription(name="message", description="This is my cool message tree", usage= "/mygroup message <message>")
12+
.addSubDescription(name= "more", description="moreee!!", usage= "/mygroup more")
1613

17-
// each object start with its own name before you can enter the parameters that the command was based on
18-
// this is a string command, it would look something like this `/group message [first_option, option_2, other_option]`
19-
// where you start with `message` and ofter that you get the 3 options where you can choose between in your complete
20-
object SayTree : ICommandObject {
21-
override val helpText: String = "This is my cool pair tree"
22-
override val baseTree: ICommandNode = CommandStringLeaf("message", arrayOf("first_option", "option_2", "other_option"),
23-
{commander, message -> commander.sendMessage("${ChatColor.RED}$message")}
24-
)
25-
}
14+
override val command = BranchPartial("mygroup").setStaticPartials(
15+
PairPartial<Boolean,Int>("pair").setPartials(
16+
BooleanPartial("bool"),
17+
IntPartial("int").setStaticRange(1..10)
18+
).setEffect {commander, value -> commander.sendMessage("${ChatColor.LIGHT_PURPLE}$value")},
19+
20+
StringPartial("message").setStaticOptions(arrayOf("first_option", "option_2", "other_option"))
21+
.setEffect {commander, message -> commander.sendMessage("${ChatColor.LIGHT_PURPLE}$message")},
2622

27-
// you can also make it so you have multiple options after the group-name
28-
// this one would look something like `/group pair [true/false] [1..10]`
29-
// where after pair you get the first option of the pair, which is a boolean,
30-
// and then you get the second option of the pair, which is a number between 1 and 10
31-
// you can stack pairs however you want. (make sure that if you do set a vararg in the pair, that it is the last argument of the pair stack, otherwise the pair will never finish)
32-
// There are some default multiple arguments already, for example the CommandLocationLeaf,
33-
// if you want 3 arguments, you could stack 2 pairs (so one slot of the first pair will be a new pair, totaling in 3)
34-
// byt you could also use the Triple instead
35-
object PairTree : ICommandObject {
36-
override val helpText: String = "This is my cool pair tree"
37-
override val baseTree: ICommandNode = CommandPairLeaf("pair",
38-
CommandBoolLeaf("bool", {_,_ -> } ),
39-
CommandIntLeaf("int",1,10, {_,_ -> } ),
40-
{commander, pair -> commander.sendMessage("${ChatColor.RED}${pair.first}${ChatColor.LIGHT_PURPLE}${pair.second}")}
23+
BranchPartial("more").setStaticPartials(
24+
EmptyPartial("even_more")
25+
.setEffect {commander -> commander.sendMessage("${ChatColor.GOLD}even more")}
4126
)
42-
}
27+
)
4328
}

examples/HelloWorldCommand.kt

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
package me.wanttobee.commandtree.examples
22

3-
import me.wanttobee.commandtree.ICommandNamespace
4-
import me.wanttobee.commandtree.ICommandObject
5-
import me.wanttobee.commandtree.nodes.CommandEmptyLeaf
6-
import me.wanttobee.commandtree.nodes.ICommandNode
3+
import me.wanttobee.commandtree.Description
4+
import me.wanttobee.commandtree.ITreeCommand
5+
import me.wanttobee.commandtree.partials.EmptyPartial
76
import org.bukkit.ChatColor
87

98
// this example is one of the most simple classes
@@ -20,17 +19,10 @@ import org.bukkit.ChatColor
2019

2120
// to make sure it all works you simply have to do `CommandTreeSystem.createCommand(HelloWorldCommand)`
2221
// (and make sure the CommandTreeSystem has been initialized )
23-
object HelloWorldCommand : ICommandNamespace {
24-
override val commandName: String = "helloWorld"
25-
override val commandSummary: String = "to say hello world"
26-
override val systemCommands: Array<ICommandObject> = arrayOf(HelloWorld)
27-
override val hasOnlyOneGroupMember: Boolean = true
28-
override val isZeroParameterCommand: Boolean = true
22+
object HelloWorldCommand : ITreeCommand {
23+
override val description = Description("to say hello world")
2924

30-
object HelloWorld : ICommandObject{
31-
override val helpText: String = "says hello world"
32-
override val baseTree: ICommandNode = CommandEmptyLeaf("say") { commander ->
33-
commander.sendMessage("${ChatColor.YELLOW} Hello World")
34-
}
25+
override val command = EmptyPartial("helloWorld").setEffect { commander ->
26+
commander.sendMessage("${ChatColor.YELLOW} Hello World")
3527
}
3628
}

src/main/java/me/wanttobee/commandtree/CommandTreeSystem.kt

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package me.wanttobee.commandtree
22

3+
import me.wanttobee.commandtree.partials.*
34
import org.bukkit.ChatColor
45
import org.bukkit.entity.Player
56
import org.bukkit.plugin.java.JavaPlugin
@@ -9,21 +10,33 @@ object CommandTreeSystem {
910
var title : String? = null
1011
private set
1112

13+
val allPartials = arrayOf(
14+
BranchPartial::class,
15+
EmptyPartial::class,
16+
BooleanPartial::class,
17+
StringPartial::class,
18+
PlayerPartial::class,
19+
IntPartial::class,
20+
DoublePartial::class,
21+
LocationPartial::class,
22+
VarargPartial::class,
23+
PairPartial::class,
24+
TriplePartial::class
25+
)
26+
1227
fun initialize(plugin: JavaPlugin, title: String?){
1328
minecraftPlugin = plugin
14-
CommandTreeSystem.title = title
29+
this.title = title
1530
}
1631

17-
fun createCommand(command : String, commandObject : IPlayerCommands){
32+
fun createCommand(commandObject : ITreeCommand){
33+
createCommand(commandObject.command.argName, commandObject)
34+
}
35+
fun createCommand(command : String, commandObject : IPlayerCommandExecutor){
1836
minecraftPlugin.getCommand(command)?.setExecutor(commandObject)
1937
minecraftPlugin.getCommand(command)?.tabCompleter = commandObject
2038
}
2139

22-
fun createCommand(commandObject : ICommandNamespace){
23-
minecraftPlugin.getCommand(commandObject.commandName)?.setExecutor(commandObject)
24-
minecraftPlugin.getCommand(commandObject.commandName)?.tabCompleter = commandObject
25-
}
26-
2740
fun sendErrorToCommander(commander: Player, errorMessage: String, extraInfo : String = ""){
2841
val titleBit = title ?: ""
2942
commander.sendMessage("$titleBit ${ChatColor.RED}$errorMessage ${ChatColor.GRAY}$extraInfo")
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package me.wanttobee.commandtree
2+
3+
class Description(val summary: String, val usage: String? = null) {
4+
val subDescriptions = mutableListOf<Triple<String,String,String?>>()
5+
6+
fun addSubDescription(
7+
name: String,
8+
description: String,
9+
usage: String? = null
10+
) : Description {
11+
subDescriptions.add(Triple(name,description,usage))
12+
return this
13+
}
14+
}

src/main/java/me/wanttobee/commandtree/ICommandNamespace.kt

Lines changed: 0 additions & 110 deletions
This file was deleted.

src/main/java/me/wanttobee/commandtree/ICommandObject.kt

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)