Config refactor (#6)
* Refactor config into categories * Bump version to 1.16.2
This commit is contained in:
parent
82f4e24404
commit
cc6fd0edb8
13 changed files with 115 additions and 79 deletions
|
@ -9,7 +9,7 @@ yarn_mappings=1.20.1+build.10
|
|||
loader_version=0.16.7
|
||||
|
||||
# Mod Properties
|
||||
mod_version=1.16.1
|
||||
mod_version=1.16.2
|
||||
maven_group=cc.reconnected
|
||||
archives_base_name=rcc-server
|
||||
|
||||
|
|
|
@ -1,26 +1,56 @@
|
|||
package cc.reconnected.server;
|
||||
|
||||
import io.wispforest.owo.config.annotation.Config;
|
||||
import io.wispforest.owo.config.annotation.Nest;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Config(name = "rcc-server-config", wrapperName = "RccServerConfig")
|
||||
public class RccServerConfigModel {
|
||||
@Nest
|
||||
public HttpApi httpApi = new HttpApi();
|
||||
|
||||
@Nest
|
||||
public Afk afk = new Afk();
|
||||
|
||||
@Nest
|
||||
public DirectMessages directMessages = new DirectMessages();
|
||||
|
||||
@Nest
|
||||
public TeleportRequests teleportRequests = new TeleportRequests();
|
||||
|
||||
@Nest
|
||||
public CustomTabList customTabList = new CustomTabList();
|
||||
|
||||
@Nest
|
||||
public NearCommand nearCommand = new NearCommand();
|
||||
|
||||
@Nest
|
||||
public AutoRestart autoRestart = new AutoRestart();
|
||||
|
||||
public static class HttpApi {
|
||||
public boolean enableHttpApi = true;
|
||||
public int httpPort = 25581;
|
||||
}
|
||||
|
||||
public static class Afk {
|
||||
public int afkTimeTrigger = 300;
|
||||
|
||||
public String afkMessage = "<gray><displayname> is now AFK</gray>";
|
||||
public String afkReturnMessage = "<gray><displayname> is no longer AFK</gray>";
|
||||
public String afkTag = "<gray>[AFK]</gray> ";
|
||||
}
|
||||
|
||||
public static class DirectMessages {
|
||||
public String tellMessage = "<gold>[</gold><source> <gray>→</gray> <target><gold>]</gold> <message>";
|
||||
public String tellMessageSpy = "\uD83D\uDC41 <gray>[<source> → <target>] <message></gray>";
|
||||
}
|
||||
|
||||
public static class TeleportRequests {
|
||||
public int teleportRequestTimeout = 120;
|
||||
}
|
||||
|
||||
public static class CustomTabList {
|
||||
public boolean enableTabList = true;
|
||||
public int tabListTickDelay = 5;
|
||||
public double tabPhasePeriod = 300;
|
||||
|
@ -33,10 +63,14 @@ public class RccServerConfigModel {
|
|||
));
|
||||
|
||||
public String playerTabName = "%rcc-server:afk%%player:displayname_visual%";
|
||||
}
|
||||
|
||||
public static class NearCommand {
|
||||
public int nearCommandMaxRange = 48;
|
||||
public int nearCommandDefaultRange = 32;
|
||||
}
|
||||
|
||||
public static class AutoRestart {
|
||||
public boolean enableAutoRestart = true;
|
||||
public String restartBarLabel = "Server restarting in <remaining_time>";
|
||||
public String restartKickMessage = "The server is restarting!";
|
||||
|
@ -64,4 +98,5 @@ public class RccServerConfigModel {
|
|||
2,
|
||||
1
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,8 +14,9 @@ import static net.minecraft.server.command.CommandManager.literal;
|
|||
public class RccCommand {
|
||||
public static void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment environment) {
|
||||
var rootCommand = literal("rcc")
|
||||
.requires(Permissions.require("rcc.command.afk", 3))
|
||||
.requires(Permissions.require("rcc.command.rcc", 3))
|
||||
.then(literal("reload")
|
||||
.requires(Permissions.require("rcc.command.rcc.reload", 3))
|
||||
.executes(context -> {
|
||||
context.getSource().sendFeedback(() -> Text.of("Reloading RCC config..."), true);
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ public class RestartCommand {
|
|||
|
||||
private static int schedule(CommandContext<ServerCommandSource> context, int seconds, @Nullable String message) {
|
||||
if (message == null) {
|
||||
message = RccServer.CONFIG.restartBarLabel();
|
||||
message = RccServer.CONFIG.autoRestart.restartBarLabel();
|
||||
}
|
||||
AutoRestart.schedule(seconds, message);
|
||||
|
||||
|
|
|
@ -26,9 +26,9 @@ public class NearCommand {
|
|||
context.getSource().sendFeedback(() -> Text.of("This command can only be executed by players!"), false);
|
||||
return 1;
|
||||
}
|
||||
return execute(context, RccServer.CONFIG.nearCommandDefaultRange(), context.getSource().getPlayer());
|
||||
return execute(context, RccServer.CONFIG.nearCommand.nearCommandDefaultRange(), context.getSource().getPlayer());
|
||||
})
|
||||
.then(argument("radius", IntegerArgumentType.integer(0, RccServer.CONFIG.nearCommandMaxRange()))
|
||||
.then(argument("radius", IntegerArgumentType.integer(0, RccServer.CONFIG.nearCommand.nearCommandMaxRange()))
|
||||
.executes(context -> {
|
||||
if (!context.getSource().isExecutedByPlayer()) {
|
||||
context.getSource().sendFeedback(() -> Text.of("This command can only be executed by players!"), false);
|
||||
|
|
|
@ -71,17 +71,17 @@ public class TellCommand {
|
|||
|
||||
var parsedMessage = MarkdownParser.defaultParser.parseNode(message);
|
||||
var you = Component.text("You", NamedTextColor.GRAY, TextDecoration.ITALIC);
|
||||
var sourceText = MiniMessage.miniMessage().deserialize(RccServer.CONFIG.tellMessage(),
|
||||
var sourceText = MiniMessage.miniMessage().deserialize(RccServer.CONFIG.directMessages.tellMessage(),
|
||||
Placeholder.component("source", you),
|
||||
Placeholder.component("target", targetDisplayName),
|
||||
Placeholder.component("message", parsedMessage.toText()));
|
||||
|
||||
var targetText = MiniMessage.miniMessage().deserialize(RccServer.CONFIG.tellMessage(),
|
||||
var targetText = MiniMessage.miniMessage().deserialize(RccServer.CONFIG.directMessages.tellMessage(),
|
||||
Placeholder.component("source", source.getDisplayName()),
|
||||
Placeholder.component("target", you),
|
||||
Placeholder.component("message", parsedMessage.toText()));
|
||||
|
||||
var text = MiniMessage.miniMessage().deserialize(RccServer.CONFIG.tellMessage(),
|
||||
var text = MiniMessage.miniMessage().deserialize(RccServer.CONFIG.directMessages.tellMessage(),
|
||||
Placeholder.component("source", source.getDisplayName()),
|
||||
Placeholder.component("target", targetDisplayName),
|
||||
Placeholder.component("message", parsedMessage.toText()));
|
||||
|
@ -104,7 +104,7 @@ public class TellCommand {
|
|||
|
||||
var lp = RccServer.getInstance().luckPerms();
|
||||
var playerAdapter = lp.getPlayerAdapter(ServerPlayerEntity.class);
|
||||
var spyText = MiniMessage.miniMessage().deserialize(RccServer.CONFIG.tellMessageSpy(),
|
||||
var spyText = MiniMessage.miniMessage().deserialize(RccServer.CONFIG.directMessages.tellMessageSpy(),
|
||||
Placeholder.component("source", source.getDisplayName()),
|
||||
Placeholder.component("target", targetDisplayName),
|
||||
Placeholder.component("message", parsedMessage.toText()));
|
||||
|
|
|
@ -25,7 +25,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||
|
||||
public class AfkTracker {
|
||||
private static final int cycleDelay = 1;
|
||||
private static final int absentTimeTrigger = RccServer.CONFIG.afkTimeTrigger() * 20; // seconds * 20 ticks
|
||||
private static final int absentTimeTrigger = RccServer.CONFIG.afk.afkTimeTrigger() * 20; // seconds * 20 ticks
|
||||
|
||||
private final ConcurrentHashMap<UUID, PlayerActivityState> playerActivityStates = new ConcurrentHashMap<>();
|
||||
|
||||
|
@ -57,7 +57,7 @@ public class AfkTracker {
|
|||
var displayNameJson = Text.Serializer.toJson(player.getDisplayName());
|
||||
var displayName = JSONComponentSerializer.json().deserialize(displayNameJson);
|
||||
|
||||
var message = MiniMessage.miniMessage().deserialize(RccServer.CONFIG.afkMessage(),
|
||||
var message = MiniMessage.miniMessage().deserialize(RccServer.CONFIG.afk.afkMessage(),
|
||||
Placeholder.component("displayname", displayName),
|
||||
Placeholder.unparsed("username", player.getGameProfile().getName()),
|
||||
Placeholder.unparsed("uuid", player.getUuid().toString())
|
||||
|
@ -72,7 +72,7 @@ public class AfkTracker {
|
|||
var displayNameJson = Text.Serializer.toJson(player.getDisplayName());
|
||||
var displayName = JSONComponentSerializer.json().deserialize(displayNameJson);
|
||||
|
||||
var message = MiniMessage.miniMessage().deserialize(RccServer.CONFIG.afkReturnMessage(),
|
||||
var message = MiniMessage.miniMessage().deserialize(RccServer.CONFIG.afk.afkReturnMessage(),
|
||||
Placeholder.component("displayname", displayName),
|
||||
Placeholder.unparsed("username", player.getGameProfile().getName()),
|
||||
Placeholder.unparsed("uuid", player.getUuid().toString())
|
||||
|
@ -85,7 +85,7 @@ public class AfkTracker {
|
|||
}
|
||||
|
||||
private static void loadAfkTag() {
|
||||
afkTag = Components.toText(MiniMessage.miniMessage().deserialize(RccServer.CONFIG.afkTag()));
|
||||
afkTag = Components.toText(MiniMessage.miniMessage().deserialize(RccServer.CONFIG.afk.afkTag()));
|
||||
}
|
||||
|
||||
private AfkTracker() {
|
||||
|
|
|
@ -33,7 +33,7 @@ public class AutoRestart {
|
|||
var miniMessage = MiniMessage.miniMessage();
|
||||
|
||||
RccEvents.READY.register((server, luckPerms) -> {
|
||||
if (RccServer.CONFIG.enableAutoRestart()) {
|
||||
if (RccServer.CONFIG.autoRestart.enableAutoRestart()) {
|
||||
scheduleNextRestart();
|
||||
}
|
||||
});
|
||||
|
@ -42,7 +42,7 @@ public class AutoRestart {
|
|||
if (restartBar == null || !timeBar.getUuid().equals(restartBar.getUuid()))
|
||||
return;
|
||||
|
||||
var notificationTimes = RccServer.CONFIG.restartNotifications();
|
||||
var notificationTimes = RccServer.CONFIG.autoRestart.restartNotifications();
|
||||
|
||||
var remainingSeconds = restartBar.getRemainingSeconds();
|
||||
if (notificationTimes.contains(remainingSeconds)) {
|
||||
|
@ -57,7 +57,7 @@ public class AutoRestart {
|
|||
return;
|
||||
|
||||
final var text = Components.toText(
|
||||
miniMessage.deserialize(RccServer.CONFIG.restartKickMessage())
|
||||
miniMessage.deserialize(RccServer.CONFIG.autoRestart.restartKickMessage())
|
||||
);
|
||||
server.getPlayerManager().getPlayerList().forEach(player -> {
|
||||
player.networkHandler.disconnect(text);
|
||||
|
@ -74,7 +74,7 @@ public class AutoRestart {
|
|||
}
|
||||
|
||||
private static void setup() {
|
||||
var soundName = RccServer.CONFIG.restartSound();
|
||||
var soundName = RccServer.CONFIG.autoRestart.restartSound();
|
||||
try {
|
||||
notificationKey = Key.key(soundName);
|
||||
} catch (InvalidKeyException e) {
|
||||
|
@ -115,10 +115,10 @@ public class AutoRestart {
|
|||
private static void notifyRestart(MinecraftServer server, BossBarManager.TimeBar bar) {
|
||||
var rcc = RccServer.getInstance();
|
||||
var audience = rcc.adventure().players();
|
||||
var sound = Sound.sound(notificationKey, Sound.Source.MASTER, 10f, RccServer.CONFIG.restartSoundPitch());
|
||||
var sound = Sound.sound(notificationKey, Sound.Source.MASTER, 10f, RccServer.CONFIG.autoRestart.restartSoundPitch());
|
||||
audience.playSound(sound, Sound.Emitter.self());
|
||||
|
||||
var comp = bar.parseLabel(RccServer.CONFIG.restartChatMessage());
|
||||
var comp = bar.parseLabel(RccServer.CONFIG.autoRestart.restartChatMessage());
|
||||
rcc.broadcastMessage(server, comp);
|
||||
}
|
||||
|
||||
|
@ -133,7 +133,7 @@ public class AutoRestart {
|
|||
var barStartTime = delay - barTime;
|
||||
|
||||
currentSchedule = scheduler.schedule(() -> {
|
||||
schedule(barTime, RccServer.CONFIG.restartBarLabel());
|
||||
schedule(barTime, RccServer.CONFIG.autoRestart.restartBarLabel());
|
||||
}, barStartTime, TimeUnit.SECONDS);
|
||||
|
||||
RccServer.LOGGER.info("Restart scheduled for in {} seconds", delay);
|
||||
|
@ -142,7 +142,7 @@ public class AutoRestart {
|
|||
|
||||
@Nullable
|
||||
private static Long getNextDelay() {
|
||||
var restartTimeStrings = RccServer.CONFIG.restartAt();
|
||||
var restartTimeStrings = RccServer.CONFIG.autoRestart.restartAt();
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
LocalDateTime nextRunTime = null;
|
||||
long shortestDelay = Long.MAX_VALUE;
|
||||
|
|
|
@ -23,7 +23,7 @@ public class HttpApiServer {
|
|||
private static int currentPlayerCount = 0;
|
||||
|
||||
public static void register() {
|
||||
if (!RccServer.CONFIG.enableHttpApi())
|
||||
if (!RccServer.CONFIG.httpApi.enableHttpApi())
|
||||
return;
|
||||
|
||||
try {
|
||||
|
@ -62,7 +62,7 @@ public class HttpApiServer {
|
|||
}
|
||||
|
||||
private HttpApiServer() throws IOException {
|
||||
server = HttpServer.create(new InetSocketAddress(RccServer.CONFIG.httpPort()), 0);
|
||||
server = HttpServer.create(new InetSocketAddress(RccServer.CONFIG.httpApi.httpPort()), 0);
|
||||
server.createContext("/tps", new TPSHandler());
|
||||
server.createContext("/mspt", new MSPTHandler());
|
||||
server.createContext("/player", new PlayerCountHandler());
|
||||
|
|
|
@ -10,23 +10,23 @@ import net.kyori.adventure.text.minimessage.MiniMessage;
|
|||
|
||||
public class TabList {
|
||||
public static void register() {
|
||||
if (!RccServer.CONFIG.enableTabList())
|
||||
if (!RccServer.CONFIG.customTabList.enableTabList())
|
||||
return;
|
||||
|
||||
var minimessage = MiniMessage.miniMessage();
|
||||
|
||||
ServerTickEvents.END_SERVER_TICK.register(server -> {
|
||||
var delay = Math.max(RccServer.CONFIG.tabListTickDelay(), 1);
|
||||
var delay = Math.max(RccServer.CONFIG.customTabList.tabListTickDelay(), 1);
|
||||
if(server.getTicks() % delay == 0) {
|
||||
var period = Math.max(RccServer.CONFIG.tabPhasePeriod(), 1);
|
||||
var period = Math.max(RccServer.CONFIG.customTabList.tabPhasePeriod(), 1);
|
||||
|
||||
var phase = (Math.sin((server.getTicks() * Math.PI * 2) / period) + 1) / 2d;
|
||||
|
||||
server.getPlayerManager().getPlayerList().forEach(player -> {
|
||||
var playerContext = PlaceholderContext.of(player);
|
||||
Component headerComponent = Component.empty();
|
||||
for (int i = 0; i < RccServer.CONFIG.tabHeader().size(); i++) {
|
||||
var line = RccServer.CONFIG.tabHeader().get(i);
|
||||
for (int i = 0; i < RccServer.CONFIG.customTabList.tabHeader().size(); i++) {
|
||||
var line = RccServer.CONFIG.customTabList.tabHeader().get(i);
|
||||
line = line.replace("{phase}", String.valueOf(phase));
|
||||
if (i > 0) {
|
||||
headerComponent = headerComponent.appendNewline();
|
||||
|
@ -36,8 +36,8 @@ public class TabList {
|
|||
}
|
||||
|
||||
Component footerComponent = Component.empty();
|
||||
for (int i = 0; i < RccServer.CONFIG.tabFooter().size(); i++) {
|
||||
var line = RccServer.CONFIG.tabFooter().get(i);
|
||||
for (int i = 0; i < RccServer.CONFIG.customTabList.tabFooter().size(); i++) {
|
||||
var line = RccServer.CONFIG.customTabList.tabFooter().get(i);
|
||||
line = line.replace("{phase}", String.valueOf(phase));
|
||||
if (i > 0) {
|
||||
footerComponent = footerComponent.appendNewline();
|
||||
|
|
|
@ -37,7 +37,7 @@ public class TeleportTracker {
|
|||
this.player = player;
|
||||
this.target = target;
|
||||
// Seconds in config per 20 ticks
|
||||
this.remainingTicks = RccServer.CONFIG.teleportRequestTimeout() * 20;
|
||||
this.remainingTicks = RccServer.CONFIG.teleportRequests.teleportRequestTimeout() * 20;
|
||||
}
|
||||
|
||||
public void expire() {
|
||||
|
|
|
@ -29,7 +29,7 @@ public abstract class ServerPlayNetworkManagerMixin {
|
|||
|
||||
@Inject(method = "tick", at = @At("TAIL"))
|
||||
private void rccServer$updatePlayerList(CallbackInfo ci) {
|
||||
if(RccServer.CONFIG.enableTabList()) {
|
||||
if(RccServer.CONFIG.customTabList.enableTabList()) {
|
||||
var packet = new PlayerListS2CPacket(EnumSet.of(PlayerListS2CPacket.Action.UPDATE_DISPLAY_NAME, PlayerListS2CPacket.Action.UPDATE_LISTED), List.of(this.player));
|
||||
this.server.getPlayerManager().sendToAll(packet);
|
||||
}
|
||||
|
|
|
@ -20,10 +20,10 @@ public class ServerPlayerEntityMixin {
|
|||
|
||||
@Inject(method = "getPlayerListName", at = @At("HEAD"), cancellable = true)
|
||||
private void rccServer$customizePlayerListName(CallbackInfoReturnable<Text> callback) {
|
||||
if (RccServer.CONFIG.enableTabList()) {
|
||||
if (RccServer.CONFIG.customTabList.enableTabList()) {
|
||||
var player = (ServerPlayerEntity) (Object) this;
|
||||
var playerContext = PlaceholderContext.of(player);
|
||||
var text = Placeholders.parseText(parser.parseNode(RccServer.CONFIG.playerTabName()), playerContext);
|
||||
var text = Placeholders.parseText(parser.parseNode(RccServer.CONFIG.customTabList.playerTabName()), playerContext);
|
||||
callback.setReturnValue(text);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue