1
1
package com.undefined.api.command
2
2
3
- import com.undefined.api.command.info.AllCommand
3
+ import com.undefined.api.command.info.FullCommand
4
4
import com.undefined.api.command.sub.UndefinedSubCommand
5
+ import com.undefined.api.extension.sendMessage
5
6
import com.undefined.api.nms.extensions.getPrivateField
7
+ import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer
6
8
import org.bukkit.Bukkit
7
9
import org.bukkit.command.CommandMap
8
10
import org.bukkit.command.CommandSender
@@ -12,7 +14,7 @@ import org.bukkit.entity.Player
12
14
import org.bukkit.util.StringUtil
13
15
14
16
15
- class UndefinedCommand (name : String , permission : String? = null , description : String = " " , aliases : List <String > = emptyList()): BaseUndefinedCommand() {
17
+ class UndefinedCommand (name : String , permission : String? = null , description : String = " " , aliases : List <String > = emptyList()) : BaseUndefinedCommand() {
16
18
17
19
init {
18
20
UndefinedCoreCommand (name, permission, description, aliases, {
@@ -29,19 +31,18 @@ class UndefinedCommand(name: String, permission: String? = null, description: St
29
31
}
30
32
}
31
33
32
- genExecute .forEach { execution -> if (! execution.invoke(sender)) return @UndefinedCoreCommand false }
33
- mainExecute .forEach { execution -> if (! execution.invoke(AllCommand (sender, arg ))) return @UndefinedCoreCommand false }
34
+ generalExecute .forEach { execution -> if (! execution.invoke(sender)) return @UndefinedCoreCommand false }
35
+ fullExecute .forEach { execution -> if (! execution.invoke(FullCommand (sender, args ))) return @UndefinedCoreCommand false }
34
36
35
- if (arg .isNullOrEmpty()) return @UndefinedCoreCommand false
37
+ if (args .isNullOrEmpty()) return @UndefinedCoreCommand false
36
38
37
- var lastSub : BaseUndefinedCommand = this @UndefinedCommand
38
- arg .forEach { arg ->
39
- val sub = getAndRun(lastSub , arg, this .arg , sender is Player , sender, this .arg .indexOf(arg)) ? : return @UndefinedCoreCommand false
40
- lastSub = sub
39
+ var lastSubCommand : BaseUndefinedCommand = this @UndefinedCommand
40
+ args .forEach { arg ->
41
+ val currentSubCommand = getAndRun(lastSubCommand , arg, this .args , sender is Player , sender, this .args .indexOf(arg)) ? : return @UndefinedCoreCommand false
42
+ lastSubCommand = currentSubCommand
41
43
}
42
44
43
45
return @UndefinedCoreCommand true
44
-
45
46
}, {
46
47
if (this .second.isNullOrEmpty()) return @UndefinedCoreCommand mutableListOf ()
47
48
val index = this .second!! .size - 1
@@ -69,31 +70,40 @@ class UndefinedCommand(name: String, permission: String? = null, description: St
69
70
private fun getAndRun (
70
71
sub : BaseUndefinedCommand ,
71
72
name : String ,
72
- arg : Array <out String >? ,
73
+ args : Array <out String >? ,
73
74
isPlayer : Boolean ,
74
- commandSender : CommandSender ,
75
+ sender : CommandSender ,
75
76
indexOf : Int
76
77
) : UndefinedSubCommand ? {
77
78
val command = sub.getSubCommand(name)
78
79
command?.let {
79
80
if (isPlayer) {
80
81
it.playerExecute.forEach { func ->
81
- (commandSender as ? Player )?.let { player ->
82
+ (sender as ? Player )?.let { player ->
82
83
if (! func.invoke(player)) return null
83
84
}
84
85
}
85
86
} else {
86
87
it.consoleExecute.forEach { func ->
87
- (commandSender as ? ConsoleCommandSender )?.let { console ->
88
+ (sender as ? ConsoleCommandSender )?.let { console ->
88
89
if (! func.invoke(console)) return null
89
90
}
90
91
}
91
92
}
92
- it.genExecute.forEach { if (! it.invoke(commandSender)) return null }
93
- it.mainExecute.forEach { if (! it.invoke(AllCommand (commandSender, arg))) return null }
94
-
95
- if (! it.runSpecialExecute(arg!! , commandSender, indexOf)) return null
93
+ it.generalExecute.forEach { if (! it.invoke(sender)) return null }
94
+ it.fullExecute.forEach { if (! it.invoke(FullCommand (sender, args))) return null }
96
95
96
+ if (! it.runSpecialExecute(args!! , sender, indexOf)) return null
97
+ } ? : run {
98
+ if (isPlayer) {
99
+ (sender as ? Player )?.let { player ->
100
+ incorrectMessages.forEach { player.sendMessage(it.invoke(FullCommand (sender, args))) }
101
+ }
102
+ } else {
103
+ (sender as ? ConsoleCommandSender )?.let { console ->
104
+ incorrectMessages.forEach { console.sendMessage(PlainTextComponentSerializer .plainText().serialize(it.invoke(FullCommand (sender, args)))) }
105
+ }
106
+ }
97
107
}
98
108
return command
99
109
}
@@ -103,9 +113,9 @@ class UndefinedCommand(name: String, permission: String? = null, description: St
103
113
104
114
}
105
115
106
- class UndefinedCoreCommand (name : String , permission : String? = null , description : String = " " , aliases : List <String > = emptyList(), private val execution : AllCommand .() -> Boolean , private val tabCompletion : Pair <CommandSender , Array <out String >? >.() -> MutableList <String >) : BukkitCommand(name) {
116
+ class UndefinedCoreCommand (name : String , permission : String? = null , description : String = " " , aliases : List <String > = emptyList(), private val execution : FullCommand .() -> Boolean , private val tabCompletion : Pair <CommandSender , Array <out String >? >.() -> MutableList <String >) : BukkitCommand(name) {
107
117
108
- override fun execute (sender : CommandSender , alias : String , args : Array <out String >? ): Boolean = execution.invoke(AllCommand (sender, args))
118
+ override fun execute (sender : CommandSender , alias : String , args : Array <out String >? ): Boolean = execution.invoke(FullCommand (sender, args))
109
119
override fun tabComplete (sender : CommandSender , alias : String , args : Array <out String >? ): MutableList <String > = tabCompletion.invoke(Pair (sender, args))
110
120
111
121
init {
0 commit comments