From 6e24ca0dfceee4d147c9211938ce482ebde042e4 Mon Sep 17 00:00:00 2001 From: FeuSalamander Date: Sun, 1 Jan 2023 20:50:57 +0100 Subject: [PATCH] fixed leave message, fixed reload command --- .../feusalamander/vmessage/Configuration.java | 29 ++++++++++++------- .../me/feusalamander/vmessage/Listeners.java | 6 +++- .../feusalamander/vmessage/ReloadCommand.java | 8 +++-- 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/src/main/java/me/feusalamander/vmessage/Configuration.java b/src/main/java/me/feusalamander/vmessage/Configuration.java index 82920cd..1353776 100644 --- a/src/main/java/me/feusalamander/vmessage/Configuration.java +++ b/src/main/java/me/feusalamander/vmessage/Configuration.java @@ -1,7 +1,12 @@ package me.feusalamander.vmessage; import com.moandjiezana.toml.Toml; +import com.velocitypowered.api.command.CommandSource; +import com.velocitypowered.api.command.SimpleCommand; +import com.velocitypowered.api.proxy.Player; +import net.kyori.adventure.text.Component; +import java.io.File; import java.io.InputStream; import java.nio.file.Files; import java.nio.file.Path; @@ -16,7 +21,8 @@ public final class Configuration { private boolean joinEnabled; private boolean leaveEnabled; private boolean changeEnabled; - private final Toml config; + private Toml config; + private static File file; Configuration(Toml config) { messageFormat = config.getString("Message.format", ""); @@ -29,13 +35,13 @@ public final class Configuration { leaveEnabled = config.getBoolean("Leave.enabled", false); changeEnabled = config.getBoolean("Server-change.enabled", false); this.config = config; - } static Configuration load(Path dataDirectory) { Path f = createConfig(dataDirectory); if (f != null) { - Toml config = new Toml().read(f.toFile()); + file = f.toFile(); + Toml config = new Toml().read(file); return new Configuration(config); } return null; @@ -91,14 +97,15 @@ public final class Configuration { return this.changeEnabled; } void reload(){ - messageFormat = config.getString("Message.format", ""); - joinFormat = config.getString("Join.format", ""); - leaveFormat = config.getString("Leave.format", ""); - changeFormat = config.getString("Server-change.format", ""); + config = config.read(file); + this.messageFormat = config.getString("Message.format"); + this.joinFormat = config.getString("Join.format"); + this.leaveFormat = config.getString("Leave.format"); + this.changeFormat = config.getString("Server-change.format"); - messageEnabled = config.getBoolean("Message.enabled", false); - joinEnabled = config.getBoolean("Join.enabled", false); - leaveEnabled = config.getBoolean("Leave.enabled", false); - changeEnabled = config.getBoolean("Server-change.enabled", false); + this.messageEnabled = config.getBoolean("Message.enabled"); + this.joinEnabled = config.getBoolean("Join.enabled"); + this.leaveEnabled = config.getBoolean("Leave.enabled"); + this.changeEnabled = config.getBoolean("Server-change.enabled"); } } diff --git a/src/main/java/me/feusalamander/vmessage/Listeners.java b/src/main/java/me/feusalamander/vmessage/Listeners.java index f1af910..972441e 100644 --- a/src/main/java/me/feusalamander/vmessage/Listeners.java +++ b/src/main/java/me/feusalamander/vmessage/Listeners.java @@ -6,6 +6,7 @@ import com.velocitypowered.api.event.connection.PostLoginEvent; import com.velocitypowered.api.event.connection.PreLoginEvent; import com.velocitypowered.api.event.player.PlayerChatEvent; import com.velocitypowered.api.event.player.ServerConnectedEvent; +import com.velocitypowered.api.event.player.TabCompleteEvent; import com.velocitypowered.api.proxy.LoginPhaseConnection; import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.ProxyServer; @@ -22,7 +23,7 @@ import java.util.Objects; import java.util.Optional; public final class Listeners { - private static final LegacyComponentSerializer SERIALIZER = LegacyComponentSerializer.builder() + public static final LegacyComponentSerializer SERIALIZER = LegacyComponentSerializer.builder() .character('&') .hexColors() .build(); @@ -65,6 +66,9 @@ public final class Listeners { return; } Player p = e.getPlayer(); + if(p.getCurrentServer().isEmpty()){ + return; + } String message = configuration.getLeaveFormat() .replace("#player#", p.getUsername()); if (luckPermsAPI != null){ diff --git a/src/main/java/me/feusalamander/vmessage/ReloadCommand.java b/src/main/java/me/feusalamander/vmessage/ReloadCommand.java index 653ed8a..74c9179 100644 --- a/src/main/java/me/feusalamander/vmessage/ReloadCommand.java +++ b/src/main/java/me/feusalamander/vmessage/ReloadCommand.java @@ -1,6 +1,8 @@ package me.feusalamander.vmessage; -import com.velocitypowered.api.command.CommandSource; import com.velocitypowered.api.command.SimpleCommand; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.TextColor; + import java.nio.file.Path; import java.util.concurrent.CompletableFuture; import java.util.List; @@ -16,12 +18,14 @@ public final class ReloadCommand implements SimpleCommand { @Override public void execute(final Invocation invocation) { String[] args = invocation.arguments(); - if(args.length == 1){ + if(args.length == 0){ + invocation.source().sendMessage(Component.text("§cUsage: /vmessage reload")); return; } String s = args[0]; if(s.equalsIgnoreCase("reload")){ config.reload(); + invocation.source().sendMessage(Component.text("The Vmessage's config has been succefully reloaded")); } }