Skip to content

Commit

Permalink
Add convenient shorthands for /party chat and /party invite
Browse files Browse the repository at this point in the history
  • Loading branch information
FluxCapacitor2 committed Jan 1, 2024
1 parent 8af7fa4 commit 0f15339
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ object Commands : Bootstrap() {
MindecraftesCommand("mindecraftes", "/mindecraftes"),
PardonCommand("pardon", "/pardon <player|ban ID>", "unban", "unmute"),
PartyCommand("party", "/party <invite|kick|promote|warp|chat|list> ...", "p"),
PartyChatShorthandCommand("pchat", "/pc <message>", "pc", "partychat"),
PingCommand("ping", "/ping", "latency"),
PlaysoundCommand("playsound", "/playsound <sound> <source> <target> [position] [volume] [pitch]", "ps"),
PunishCommand("ban", "/<ban|mute> <player> <duration> <reason>", "mute"),
Expand Down
41 changes: 33 additions & 8 deletions src/main/kotlin/com/bluedragonmc/server/command/PartyCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ import com.bluedragonmc.server.utils.miniMessage
import com.bluedragonmc.server.utils.plus
import com.bluedragonmc.server.utils.surroundWithSeparators
import net.kyori.adventure.text.Component
import net.minestom.server.entity.Player

class PartyCommand(name: String, usageString: String, vararg aliases: String) :
BlueDragonCommand(name, aliases, block = {
requirePlayers() // All subcommands require a player
usage(usageString)

/*
invite <player>
kick <player>
leave
promote <player>
warp
chat <message>
Expand Down Expand Up @@ -43,14 +46,7 @@ class PartyCommand(name: String, usageString: String, vararg aliases: String) :
subcommand("chat") {
val messageArgument by StringArrayArgument
suspendSyntax(messageArgument) {
val msg = if (Permissions.hasPermission(player.uuid, "chat.minimessage") != true) {
// Escape the chat message to prevent players using MiniMessage tags in party chat messages
miniMessage.escapeTags(get(messageArgument).joinToString(" "))
} else {
// The player is allowed to use MiniMessage
get(messageArgument).joinToString(" ")
}
Messaging.outgoing.partyChat(msg, player)
handlePartyChat(get(messageArgument).joinToString(" "), player)
}
}

Expand Down Expand Up @@ -94,4 +90,33 @@ class PartyCommand(name: String, usageString: String, vararg aliases: String) :
}
}

// If the player adds a player as the first argument instead of typing `invite <player>`
val playerArgument by PlayerArgument
suspendSyntax(playerArgument) {
Messaging.outgoing.inviteToParty(player.uuid, getFirstPlayer(playerArgument).uuid)
}

})

suspend fun handlePartyChat(message: String, player: Player) {
val msg = if (Permissions.hasPermission(player.uuid, "chat.minimessage") != true) {
// Escape the chat message to prevent players using MiniMessage tags in party chat messages
miniMessage.escapeTags(message)
} else {
// The player is allowed to use MiniMessage
message
}
Messaging.outgoing.partyChat(msg, player)
}

class PartyChatShorthandCommand(name: String, usageString: String, vararg aliases: String) :
BlueDragonCommand(name, aliases, block = {

requirePlayers()
usage(usageString)

val messageArgument by StringArrayArgument
suspendSyntax(messageArgument) {
handlePartyChat(get(messageArgument).joinToString(" "), player)
}
})

0 comments on commit 0f15339

Please sign in to comment.