-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Miles Holder
committed
May 8, 2024
1 parent
1305033
commit b482c02
Showing
6 changed files
with
70 additions
and
80 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
.../src/main/kotlin/com/github/spigotbasics/core/command/parsed/arguments/GreedyStringArg.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.github.spigotbasics.core.command.parsed.arguments | ||
|
||
import org.bukkit.command.CommandSender | ||
|
||
class GreedyStringArg(name: String) : CommandArgument<String>(name) { | ||
override val greedy: Boolean = true | ||
|
||
override fun parse(sender: CommandSender, value: String): String { | ||
return value | ||
} | ||
|
||
override fun tabComplete(sender: CommandSender, typing: String): List<String> { | ||
return emptyList() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
| Command | Permission | | ||
|-----------------------------------|-------------------------| | ||
| `/broadcast <message>` | basics.broadcast | | ||
| `/broadcast [--parsed] <message>` | basics.broadcast.parsed | | ||
|
||
> [!NOTE] | ||
> the `--parsed` argument while optional also required the `basics.broadcast.parsed` | ||
> permission when being used |
31 changes: 24 additions & 7 deletions
31
.../src/main/kotlin/com/github/spigotbasics/modules/basicsbroadcast/BasicsBroadcastModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,34 @@ | ||
package com.github.spigotbasics.modules.basicsbroadcast | ||
|
||
import com.github.spigotbasics.core.command.parsed.arguments.AnyStringArg | ||
import com.github.spigotbasics.core.command.parsed.arguments.GreedyStringArg | ||
import com.github.spigotbasics.core.command.parsed.arguments.LiteralArg | ||
import com.github.spigotbasics.core.module.AbstractBasicsModule | ||
import com.github.spigotbasics.core.module.loader.ModuleInstantiationContext | ||
|
||
class BasicsBroadcastModule(context: ModuleInstantiationContext) : AbstractBasicsModule(context) { | ||
val commandPerm = permissionManager.createSimplePermission("basics.broadcast", "Allows the user to broadcast messages") | ||
val parsedPerm = permissionManager.createSimplePermission("basics.broadcast.parsed", "Allows the user to broadcast parsed messages") | ||
private val commandPerm = permissionManager.createSimplePermission("basics.broadcast", "Allows the user to broadcast messages") | ||
private val parsedPerm = permissionManager.createSimplePermission("basics.broadcast.parsed", "Allows the user to broadcast parsed messages") | ||
|
||
override fun onEnable() { | ||
commandFactory.rawCommandBuilder("broadcast", commandPerm) | ||
.description("Broadcasts a message to all players") | ||
.usage("[--parsed] <message>") | ||
.executor(BroadcastExecutor(this)) | ||
.register() | ||
commandFactory.parsedCommandBuilder("broadcast", commandPerm) | ||
.mapContext { | ||
usage = "[--parsed] <message>" | ||
description("Broadcast a message to your server") | ||
|
||
path { | ||
arguments { | ||
named("message", GreedyStringArg("message")) | ||
} | ||
} | ||
|
||
path { | ||
arguments { | ||
permissions(parsedPerm) | ||
named("parsed", LiteralArg("--parsed")) | ||
named("message", GreedyStringArg("message")) | ||
} | ||
} | ||
}.executor(BroadcastCommand(this)).register() | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...dcast/src/main/kotlin/com/github/spigotbasics/modules/basicsbroadcast/BroadcastCommand.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.github.spigotbasics.modules.basicsbroadcast | ||
|
||
import com.github.spigotbasics.core.command.parsed.CommandContextExecutor | ||
import com.github.spigotbasics.core.command.parsed.context.MapContext | ||
import org.bukkit.command.CommandSender | ||
import org.bukkit.entity.Player | ||
|
||
class BroadcastCommand(private val module: BasicsBroadcastModule) : CommandContextExecutor<MapContext> { | ||
|
||
override fun execute(sender: CommandSender, context: MapContext) { | ||
val parsed = context["parsed"] != null | ||
val rawMessage = context["message"] as String | ||
|
||
val message = if (parsed) { | ||
module.messageFactory.createMessage(rawMessage).concerns(sender as? Player) | ||
} else { | ||
module.messageFactory.createPlainMessage(rawMessage) | ||
} | ||
|
||
message.sendToAllPlayers() | ||
message.sendToConsole() | ||
} | ||
} |
47 changes: 0 additions & 47 deletions
47
...cast/src/main/kotlin/com/github/spigotbasics/modules/basicsbroadcast/BroadcastExecutor.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters