Skip to content

Commit

Permalink
Merge pull request #154 from Y2Kwastaken/cleanup
Browse files Browse the repository at this point in the history
Cleanup Old Modules
  • Loading branch information
mfnalex authored Jun 2, 2024
2 parents 34a6fd8 + adde132 commit 2534f55
Show file tree
Hide file tree
Showing 79 changed files with 1,808 additions and 1,195 deletions.
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())
}
}
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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class CoreMessages(context: ConfigInstantiationContext) : SavedConfig(context) {

fun worldNotFound(name: String) = getMessage("world-not-found").tagUnparsed("argument", name)

fun worldNotLoaded(name: String) = getMessage("world-not-loaded").tagUnparsed("argument", name)

fun unsupportedServerSoftware(feature: String) = getMessage("unsupported-server-software").tagParsed("argument", feature)

fun selectorIncludesEntities(
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/resources/messages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ missing-value-for-argument: "<error><red>Missing value for <bright_red><#argumen
invalid-argument: "<error><red>Invalid argument: </red><bright_red><#argument></bright_red>"
player-not-found: "<error><red>Player not found: </red><bright_red><#argument></bright_red>"
world-not-found: "<error><red>World not found: </red><bright_red><#argument></bright_red>"
world-not-loaded: "<error><red>World not loaded: </red><bright_red><#argument></bright_red>"
unsupported-server-software: "<error><red>Your server software does not support <bright_red><hover:show_text:'<gray>Missing class/method:</gray> <#argument>'>this feature</hover></bright_red>!</red>"
not-enough-arguments-given-for-argument: "<error><red>Not enough arguments given for argument <bright_red><#argument></bright_red>!</red>"

Expand All @@ -40,4 +41,4 @@ command-module-disabled: "<error><red>The module that registered this command is

failed-to-load-data-on-join: "<red>[Basics] Failed to load player data in time - please try to join again!</red>"
error-executing-command: "<error><red>An error occured while executing this command!</red>"
error-executing-command-op: "<error><hover:show_text:'<#stacktrace>'><red>An error occured while executing this command!</red> <gray>(Hover for stacktrace - only visible to OPs)</gray></hover>"
error-executing-command-op: "<error><hover:show_text:'<#stacktrace>'><red>An error occured while executing this command!</red> <gray>(Hover for stacktrace - only visible to OPs)</gray></hover>"
8 changes: 8 additions & 0 deletions modules/basics-broadcast/README.md
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
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()
}
}
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()
}
}

This file was deleted.

27 changes: 27 additions & 0 deletions modules/basics-chat-format/README.md
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`
Loading

0 comments on commit 2534f55

Please sign in to comment.