fixed leave message, fixed reload command

This commit is contained in:
FeuSalamander 2023-01-01 20:50:57 +01:00
parent 103cac68fb
commit 6e24ca0dfc
3 changed files with 29 additions and 14 deletions

View File

@ -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");
}
}

View File

@ -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){

View File

@ -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"));
}
}