From 91371ba9900a46f5889014cf5af5de11af53a93d Mon Sep 17 00:00:00 2001 From: IuCC <80768059+IuCC123@users.noreply.github.com> Date: Fri, 7 Jul 2023 22:51:38 +0200 Subject: [PATCH] /rainbow command (#347) --- README.md | 1 + src/main/java/pw/kaboom/extras/Main.java | 3 +- .../commands/CommandBroadcastRainbow.java | 32 +++++++++++++++++++ src/main/resources/plugin.yml | 6 +++- 4 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 src/main/java/pw/kaboom/extras/commands/CommandBroadcastRainbow.java diff --git a/README.md b/README.md index a3e662f..bea6993 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ Extras is a Bukkit plugin that that adds extra functionality to the Kaboom serve | Command | Aliases | Permission | Description | |-----------------------|---------------------|-----------------------------|---------------------------------------------------------| +| /broadcastrainbow | /bcr | extras.broadcastrainbow | Broadcasts a rainbow message | | /broadcastminimessage | /broadcastmm, /bcmm | extras.broadcastminimessage | Broadcasts a deserialized MiniMessage component | | /broadcastraw | /bcraw, /tellraw | extras.broadcastraw | Broadcasts raw text to the server | | /broadcastvanilla | /bcv | extras.broadcastvanilla | Broadcasts text in vanilla style | diff --git a/src/main/java/pw/kaboom/extras/Main.java b/src/main/java/pw/kaboom/extras/Main.java index f855b7f..e97f0a0 100644 --- a/src/main/java/pw/kaboom/extras/Main.java +++ b/src/main/java/pw/kaboom/extras/Main.java @@ -50,6 +50,7 @@ public final class Main extends JavaPlugin { prefixConfig = YamlConfiguration.loadConfiguration(prefixConfigFile); /* Commands */ + this.getCommand("broadcastrainbow").setExecutor(new CommandBroadcastRainbow()); this.getCommand("broadcastminimessage").setExecutor(new CommandBroadcastMM()); this.getCommand("broadcastvanilla").setExecutor(new CommandBroadcastVanilla()); this.getCommand("clearchat").setExecutor(new CommandClearChat()); @@ -69,7 +70,7 @@ public final class Main extends JavaPlugin { this.getCommand("spidey").setExecutor(new CommandSpidey()); this.getCommand("tellraw").setExecutor(new CommandTellraw()); this.getCommand("username").setExecutor(new CommandUsername()); - + /* Block-related modules */ BlockPhysics.init(this); diff --git a/src/main/java/pw/kaboom/extras/commands/CommandBroadcastRainbow.java b/src/main/java/pw/kaboom/extras/commands/CommandBroadcastRainbow.java new file mode 100644 index 0000000..afda201 --- /dev/null +++ b/src/main/java/pw/kaboom/extras/commands/CommandBroadcastRainbow.java @@ -0,0 +1,32 @@ +package pw.kaboom.extras.commands; + +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.minimessage.MiniMessage; +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import javax.annotation.Nonnull; + +public final class CommandBroadcastRainbow implements CommandExecutor { + private static final MiniMessage MINI_MESSAGE = MiniMessage.miniMessage(); + + public boolean onCommand(final @Nonnull CommandSender sender, + final @Nonnull Command command, + final @Nonnull String label, + final String[] args) { + if (args.length == 0) { + sender.sendMessage(Component + .text("Usage: /" + label + " ", + NamedTextColor.RED)); + return true; + } + final String strippedTags = MINI_MESSAGE.stripTags(String.join(" ", args)); + final Component component = MINI_MESSAGE.deserialize("" + strippedTags); + Bukkit.getServer().broadcast(component); + return true; + } +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 4032abf..066f47e 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -9,6 +9,10 @@ commands: aliases: [ broadcastmm, bcmm ] description: Broadcasts a deserialized MiniMessage component permission: extras.broadcastminimessage + broadcastrainbow: + aliases: [ bcr ] + description: Broadcasts a rainbow message + permission: extras.broadcastrainbow broadcastraw: aliases: [ bcraw, tellraw ] description: Broadcasts raw text to the server @@ -72,4 +76,4 @@ commands: permission: extras.spidey username: description: Changes your username on the server - permission: extras.username \ No newline at end of file + permission: extras.username