-
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.
Merge pull request #154 from Y2Kwastaken/cleanup
Cleanup Old Modules
- Loading branch information
Showing
79 changed files
with
1,808 additions
and
1,195 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
...rc/main/kotlin/com/github/spigotbasics/core/command/parsed/arguments/BukkitRegistryArg.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,32 @@ | ||
package com.github.spigotbasics.core.command.parsed.arguments | ||
|
||
import org.bukkit.Bukkit | ||
import org.bukkit.Keyed | ||
import org.bukkit.NamespacedKey | ||
import org.bukkit.Registry | ||
import org.bukkit.command.CommandSender | ||
import java.util.stream.Collectors | ||
|
||
class BukkitRegistryArg<T : Keyed>(name: String, registryClass: Class<T>) : CommandArgument<T>(name) { | ||
private val registry: Registry<T> = Bukkit.getRegistry(registryClass) ?: error("$registryClass is not a bukkit registry type") | ||
|
||
override fun parse( | ||
sender: CommandSender, | ||
value: String, | ||
): T? { | ||
return if (value.isBlank()) null else registry.get(NamespacedKey.fromString(value) ?: return null) | ||
} | ||
|
||
override fun tabComplete( | ||
sender: CommandSender, | ||
typing: String, | ||
): List<String> { | ||
return registry.stream().map { entry -> | ||
val namespacedKeyed = entry.key | ||
if (namespacedKeyed.namespace == NamespacedKey.MINECRAFT) { | ||
return@map namespacedKeyed.key | ||
} | ||
return@map namespacedKeyed.toString() | ||
}.collect(Collectors.toList()) | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
.../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,21 @@ | ||
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
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
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 |
34 changes: 27 additions & 7 deletions
34
.../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,37 @@ | ||
package com.github.spigotbasics.modules.basicsbroadcast | ||
|
||
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() | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...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,26 @@ | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
| Command | Permission | | ||
|--------------------------|------------------| | ||
| `/chatcolor set <color>` | basics.chatcolor | | ||
| `/chatcolor reset` | basics.chatcolor | | ||
|
||
## Color Permissions | ||
|
||
Color permissions are given based upon certain permissions. Below will explain how you can grant permission | ||
to specific colors alongside ranges of colors. | ||
|
||
### Giving Ranges | ||
|
||
There are a few ranges provided in basic by default. | ||
|
||
- `basics.chatcolor.named`, gives access to all named colors, e.g. red, blue, dark_green. | ||
- `basics.chatcolor.hex`, gives access to all hex colors, e.g. #FF00FF, #00FF00, #EFABCE. | ||
- `basics.chatcolor.gradient.named`, gives access to any gradient that is named, e.g. red:blue, gold:light_purple, yellow:green. | ||
- `basics.chatcolor.gradient.hex`, gives access to any hex that is named, e.g. #FFF000:#000FFF, #EEFF00:#00FFEE. | ||
|
||
### Giving Specific Colors | ||
|
||
If you don't want to give players ranges, but rather specific colors you can do the following. An example will be given for each type | ||
|
||
- **Named**: `basics.chatcolor.red` | ||
- **Hex**: `basics.chatcolor.#987FFE` | ||
- **Named Gradient**: `basics.chatcolor.blue:red` | ||
- **Hex Gradient**: `basics.chatcolor.#FFF000:#000FFF` |
Oops, something went wrong.