Skip to content

Commit

Permalink
added /motd command
Browse files Browse the repository at this point in the history
  • Loading branch information
NonSwag committed Mar 17, 2024
1 parent cbd65b7 commit 40ec646
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 14 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down
5 changes: 3 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ plugins {
}

group = "net.thenextlvl"
version = "2.0.7"
version = "2.0.8"

repositories {
mavenCentral()
Expand Down Expand Up @@ -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") {
Expand Down
15 changes: 12 additions & 3 deletions src/main/java/net/thenextlvl/tweaks/TweaksPlugin.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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<TweaksConfig> configFile = new GsonFile<>(
IO.of(getDataFolder(), "config.json"),
new TweaksConfig(
new GeneralConfig(5, (byte) -1, false, false, false, true),
Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -158,6 +163,10 @@ private void registerCommand(CommandExecutor executor) {
}
}

public TweaksConfig config() {
return configFile().getRoot();
}

public static TweaksPlugin get() {
return JavaPlugin.getPlugin(TweaksPlugin.class);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
20 changes: 16 additions & 4 deletions src/main/java/net/thenextlvl/tweaks/config/ServerConfig.java
Original file line number Diff line number Diff line change
@@ -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;
}
1 change: 1 addition & 0 deletions src/main/resources/tweaks.properties
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,6 @@ god.inactive.others=<prefix> <green><player> <white>is no longer invulnerable
broadcast.header=<reset>
broadcast.format=<red>Server <gray>| <message>
broadcast.footer=<reset>
motd.changed=<prefix> <white>Changed motd to <green><motd>
chat.format=<delete><player_prefix><click:suggest_command:'/msg <player> '><player><reset> <dark_gray>» <reset><click:copy_to_clipboard:'<message_content>'><hover:show_text:'<lang:chat.copy.click>'><message>
chat.format.delete=<hover:show_text:'Click to delete this message'><dark_gray>[<dark_red><bold>x</bold><dark_gray>] <reset>
3 changes: 2 additions & 1 deletion src/main/resources/tweaks_german.properties
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,5 @@ god.active.self=<prefix> <white>Du bist jetzt unverwundbar
god.active.others=<prefix> <green><player> <white>ist jetzt unverwundbar
god.inactive.self=<prefix> <white>Du bist nicht länger unverwundbar
god.inactive.others=<prefix> <green><player> <white>ist nicht länger unverwundbar
chat.format.delete=<hover:show_text:'Klicke um diese Nachricht zu löschen'><dark_gray>[<dark_red><bold>x</bold><dark_gray>] <reset>
chat.format.delete=<hover:show_text:'Klicke um diese Nachricht zu löschen'><dark_gray>[<dark_red><bold>x</bold><dark_gray>] <reset>
motd.changed=<prefix> <white>Die motd ist jetzt <green><motd>

0 comments on commit 40ec646

Please sign in to comment.