goauth

Fabric plugin for enhanced whitelists
git clone git://git.bain.cz/goauth.git
Log | Files | Refs | README | LICENSE

commit 2baa7f700612159ce436f3c7dd3c71d17cebcc6d
parent 70b1c258022c90715d2ab21f1afad32def0f9f74
Author: bain <bain@bain.cz>
Date:   Mon, 26 Sep 2022 16:55:54 +0200

parametrize text

Diffstat:
Msrc/main/java/cz/bain/plugins/goauth/DummyServerPlayNetworkHandler.java | 2+-
Msrc/main/java/cz/bain/plugins/goauth/Goauth.java | 11+++++++----
Msrc/main/java/cz/bain/plugins/goauth/GoauthConfig.java | 16+++++++++++++++-
Msrc/main/java/cz/bain/plugins/goauth/events/listeners/OnPlayerConnectListener.java | 2+-
4 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/src/main/java/cz/bain/plugins/goauth/DummyServerPlayNetworkHandler.java b/src/main/java/cz/bain/plugins/goauth/DummyServerPlayNetworkHandler.java @@ -36,7 +36,7 @@ public class DummyServerPlayNetworkHandler extends ServerPlayNetworkHandler { } if (this.ticks > 160 && this.ticks % 40 == 0) - this.sendPacket(new GameMessageS2CPacket(Text.of("Please authenticate in chat"), true)); + this.sendPacket(new GameMessageS2CPacket(Text.of(this.plugin.reminderText), true)); server.getProfiler().push("keepAlive"); long l = Util.getMeasuringTimeMs(); diff --git a/src/main/java/cz/bain/plugins/goauth/Goauth.java b/src/main/java/cz/bain/plugins/goauth/Goauth.java @@ -26,13 +26,11 @@ public class Goauth implements ModInitializer { public boolean running = true; public AuthStore authStore; public String authLinkText; + public String welcomeText; + public String reminderText; @Override public void onInitialize() { - OnPlayerConnectCallback.EVENT.register(new OnPlayerConnectListener(this)); - OnServerTickCallback.EVENT.register(new OnServerTickListener(this)); - ServerLifecycleEvents.SERVER_STOPPED.register(server -> running = false); - GoauthConfig config; try { config = new GoauthConfig(new File("goauth.properties")); @@ -53,6 +51,8 @@ public class Goauth implements ModInitializer { return; } + this.welcomeText = config.get("welcome-text", "Welcome! Please authenticate: "); + this.reminderText = config.get("reminder-text", "Please authenticate in chat"); this.authLinkText = config.getRequired("auth-link-text"); this.authLink = config.get("auth-link", ""); @@ -62,6 +62,9 @@ public class Goauth implements ModInitializer { ); this.authStore.load(); + OnPlayerConnectCallback.EVENT.register(new OnPlayerConnectListener(this)); + OnServerTickCallback.EVENT.register(new OnServerTickListener(this)); + ServerLifecycleEvents.SERVER_STOPPED.register(server -> running = false); new Thread(new AuthUpdateRunner(key, this, port)).start(); this.logger.info("Initialized!"); } diff --git a/src/main/java/cz/bain/plugins/goauth/GoauthConfig.java b/src/main/java/cz/bain/plugins/goauth/GoauthConfig.java @@ -14,7 +14,21 @@ public class GoauthConfig { if (!file.exists()) { try (FileWriter writer = new FileWriter(file)) { - writer.write("port=8001\nkey=<32-byte-key>\nauth-link-text=Authenticate\n\n# optional\n# auth-link=https://bain.cz/\n"); + writer.write(""" + port=8001 + key=<32-byte-key> + auth-link-text=Authenticate + + # optional + # auth-link=https://bain.cz/ + + # Shown as: "<welcome-text> <auth-link-text>", with <auth-link-text> being a link to + # <auth-link>?username=$username + # welcome-text=Welcome! Please authenticate: + + # shown after the chat message disappears + # reminder-text=Please authenticate in chat + """); } throw new IOException("goauth.properties didn't exist, please review its contents and restart the server"); } diff --git a/src/main/java/cz/bain/plugins/goauth/events/listeners/OnPlayerConnectListener.java b/src/main/java/cz/bain/plugins/goauth/events/listeners/OnPlayerConnectListener.java @@ -91,7 +91,7 @@ public class OnPlayerConnectListener implements OnPlayerConnectCallback { serverPlayNetworkHandler.sendPacket(new PlayerSpawnPositionS2CPacket(new BlockPos(0, 0, 0), 0.0f)); - MutableText welcomeMsg = Text.literal("Welcome! Please authenticate: ").formatted(Formatting.BOLD, Formatting.YELLOW); + MutableText welcomeMsg = Text.literal(this.plugin.welcomeText + " ").formatted(Formatting.BOLD, Formatting.YELLOW); MutableText text = Text.literal(this.plugin.authLinkText); Style urlStyle = Style.EMPTY .withBold(false)