diff --git a/README.md b/README.md index 3e5cc4e..ab58a18 100644 --- a/README.md +++ b/README.md @@ -63,10 +63,11 @@ The perm-pack to grant all permissions: `tweaks.commands.player` ### Server commands -| Command | Description | Permission | -|----------------------|----------------------|--------------------------| -| /broadcast [message] | broadcast a message | tweaks.command.broadcast | -| /lobby | connect to the lobby | | +| Command | Description | Permission | +|----------------------|-------------------------------|--------------------------| +| /broadcast [message] | broadcast a message | tweaks.command.broadcast | +| /lobby | connect to the lobby | | +| /motd [message] | change the motd of the server | tweaks.command.motd | The perm-pack to grant all permissions: `tweaks.commands.server` diff --git a/build.gradle.kts b/build.gradle.kts index dc8c22a..b7937ff 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -10,7 +10,7 @@ plugins { } group = "net.thenextlvl" -version = "2.0.7" +version = "2.0.8" repositories { mavenCentral() @@ -112,7 +112,8 @@ paper { } register("tweaks.commands.server") { this.children = listOf( - "tweaks.command.broadcast" + "tweaks.command.broadcast", + "tweaks.command.motd" ) } register("tweaks.commands.workstation") { diff --git a/src/main/java/net/thenextlvl/tweaks/TweaksPlugin.java b/src/main/java/net/thenextlvl/tweaks/TweaksPlugin.java index 0366160..691f52b 100644 --- a/src/main/java/net/thenextlvl/tweaks/TweaksPlugin.java +++ b/src/main/java/net/thenextlvl/tweaks/TweaksPlugin.java @@ -1,6 +1,7 @@ package net.thenextlvl.tweaks; import core.annotation.FieldsAreNotNullByDefault; +import core.file.FileIO; import core.file.format.GsonFile; import core.i18n.file.ComponentBundle; import core.io.IO; @@ -17,6 +18,7 @@ import net.thenextlvl.tweaks.command.player.*; import net.thenextlvl.tweaks.command.server.BroadcastCommand; import net.thenextlvl.tweaks.command.server.LobbyCommand; +import net.thenextlvl.tweaks.command.server.MotdCommand; import net.thenextlvl.tweaks.command.workstation.*; import net.thenextlvl.tweaks.config.*; import net.thenextlvl.tweaks.listener.ChatListener; @@ -40,7 +42,7 @@ public class TweaksPlugin extends JavaPlugin { private final Metrics metrics = new Metrics(this, 19651); - private final TweaksConfig config = new GsonFile<>( + private final FileIO configFile = new GsonFile<>( IO.of(getDataFolder(), "config.json"), new TweaksConfig( new GeneralConfig(5, (byte) -1, false, false, false, true), @@ -55,9 +57,9 @@ public class TweaksPlugin extends JavaPlugin { 20 ), new VanillaTweaks(0, 0, 0, false), - new ServerConfig(true, "lobby") + new ServerConfig(true, "lobby", null) ) - ).validate().save().getRoot(); + ).validate().save(); private final File translations = new File(getDataFolder(), "translations"); private final ComponentBundle bundle = new ComponentBundle(translations, audience -> audience instanceof Player player ? player.locale() : Locale.US) @@ -73,6 +75,8 @@ public void onLoad() { .resolver(Placeholder.component("prefix", bundle.component(Locale.US, "prefix"))) .build()) .build()); + var motd = config().serverConfig().motd(); + if (motd != null) Bukkit.motd(MiniMessage.miniMessage().deserialize(motd)); } @Override @@ -121,6 +125,7 @@ private void registerCommands() { registerCommand(new BroadcastCommand(this)); if (isLobbyCommandEnabled()) registerCommand(new LobbyCommand(this, new PluginMessenger(this))); + registerCommand(new MotdCommand(this)); // Item registerCommand(new HeadCommand(this)); @@ -158,6 +163,10 @@ private void registerCommand(CommandExecutor executor) { } } + public TweaksConfig config() { + return configFile().getRoot(); + } + public static TweaksPlugin get() { return JavaPlugin.getPlugin(TweaksPlugin.class); } diff --git a/src/main/java/net/thenextlvl/tweaks/command/server/MotdCommand.java b/src/main/java/net/thenextlvl/tweaks/command/server/MotdCommand.java new file mode 100644 index 0000000..577e46d --- /dev/null +++ b/src/main/java/net/thenextlvl/tweaks/command/server/MotdCommand.java @@ -0,0 +1,33 @@ +package net.thenextlvl.tweaks.command.server; + +import lombok.RequiredArgsConstructor; +import net.kyori.adventure.text.minimessage.MiniMessage; +import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; +import net.thenextlvl.tweaks.TweaksPlugin; +import net.thenextlvl.tweaks.command.api.CommandInfo; +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; + +@CommandInfo( + name = "motd", + permission = "tweaks.command.motd", + description = "change the motd of the server", + usage = "/motd [message]" +) +@RequiredArgsConstructor +public class MotdCommand implements CommandExecutor { + private final TweaksPlugin plugin; + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + var message = String.join(" ", args); + var motd = MiniMessage.miniMessage().deserialize(message); + plugin.bundle().sendMessage(sender, "motd.changed", Placeholder.component("motd", motd)); + plugin.config().serverConfig().motd(message); + plugin.configFile().save(); + Bukkit.motd(motd); + return true; + } +} diff --git a/src/main/java/net/thenextlvl/tweaks/config/ServerConfig.java b/src/main/java/net/thenextlvl/tweaks/config/ServerConfig.java index d0fe9b1..8d6fc82 100644 --- a/src/main/java/net/thenextlvl/tweaks/config/ServerConfig.java +++ b/src/main/java/net/thenextlvl/tweaks/config/ServerConfig.java @@ -1,9 +1,21 @@ package net.thenextlvl.tweaks.config; import com.google.gson.annotations.SerializedName; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.Setter; +import lombok.experimental.Accessors; +import org.jetbrains.annotations.Nullable; -public record ServerConfig( - @SerializedName("enable-lobby-command") boolean enableLobbyCommand, - @SerializedName("lobby-server-name") String lobbyServerName -) { +@Setter +@Getter +@AllArgsConstructor +@Accessors(fluent = true) +public class ServerConfig { + @SerializedName("enable-lobby-command") + private final boolean enableLobbyCommand; + @SerializedName("lobby-server-name") + private final String lobbyServerName; + @SerializedName("motd") + private @Nullable String motd; } diff --git a/src/main/resources/tweaks.properties b/src/main/resources/tweaks.properties index f24deef..43fbb6a 100644 --- a/src/main/resources/tweaks.properties +++ b/src/main/resources/tweaks.properties @@ -69,5 +69,6 @@ god.inactive.others= is no longer invulnerable broadcast.header= broadcast.format=Server | broadcast.footer= +motd.changed= Changed motd to chat.format= '> » '>'> chat.format.delete=[x] \ No newline at end of file diff --git a/src/main/resources/tweaks_german.properties b/src/main/resources/tweaks_german.properties index 1944cab..a8bd83c 100644 --- a/src/main/resources/tweaks_german.properties +++ b/src/main/resources/tweaks_german.properties @@ -63,4 +63,5 @@ god.active.self= Du bist jetzt unverwundbar god.active.others= ist jetzt unverwundbar god.inactive.self= Du bist nicht länger unverwundbar god.inactive.others= ist nicht länger unverwundbar -chat.format.delete=[x] \ No newline at end of file +chat.format.delete=[x] +motd.changed= Die motd ist jetzt \ No newline at end of file