Skip to content

Commit 6c40bca

Browse files
committed
CommandEvent.isPlayerSender added to CommandEventExtensions.kt.
`CommandEvent.player` (changed return type to nullable ServerPlayerEntity) now return null if source is server. Signed-off-by: Pavel Erokhin (MairwunNx) <MairwunNx@gmail.com>
1 parent 0f31e84 commit 6c40bca

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/main/kotlin/com/mairwunnx/projectessentials/core/extensions/CommandEventExtensions.kt

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ import net.minecraftforge.event.CommandEvent
1515
*/
1616
val CommandEvent.commandName: String
1717
get() = this.executedCommand
18-
.replace("/", "")
19-
.split(" ")[0]
18+
.replace("/", "").split(" ")[0]
2019

2120
/**
2221
* Return fully executed command as string.
@@ -29,12 +28,20 @@ val CommandEvent.executedCommand: String
2928
get() = this.parseResults.reader.string
3029

3130
/**
32-
* Return **`ServerPlayerEntity`** class instance from
33-
* **`CommandEvent`** class instance.
31+
* Return true if source is player.
32+
* @since 1.14.4-1.2.1
33+
*/
34+
val CommandEvent.isPlayerSender: Boolean
35+
get() = this.source.entity is ServerPlayerEntity
36+
37+
/**
38+
* Return **`ServerPlayerEntity?`** class instance from
39+
* **`CommandEvent`** class instance. If source is server
40+
* then return null.
3441
* @since 1.14.4-1.0.0.0
3542
*/
36-
val CommandEvent.player: ServerPlayerEntity
37-
get() = this.parseResults.context.source.asPlayer()
43+
val CommandEvent.player: ServerPlayerEntity?
44+
get() = if (this.isPlayerSender) this.source.asPlayer() else null
3845

3946
/**
4047
* Return command **`source`** from **`CommandEvent`**

0 commit comments

Comments
 (0)