Skip to content

Commit 0f31e84

Browse files
committed
CommandContext<...>.playerName() now if source is server, then return #server as nickname.
Signed-off-by: Pavel Erokhin (MairwunNx) <MairwunNx@gmail.com>
1 parent 7b462cc commit 0f31e84

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ fun CommandContext<CommandSource>.isPlayerSender(): Boolean =
1414
this.source.entity is ServerPlayerEntity
1515

1616
/**
17-
* @return player nickname from CommandContext.
17+
* @return if command source is player then nickname
18+
* from CommandContext. If command source is server
19+
* then return `#server`.
1820
* @since 1.14.4-1.0.1.0
1921
*/
20-
fun CommandContext<CommandSource>.playerName(): String = this.source.asPlayer().name.string
22+
fun CommandContext<CommandSource>.playerName(): String =
23+
if (this.isPlayerSender()) this.source.asPlayer().name.string else "#server"

0 commit comments

Comments
 (0)