fixed leave message, fixed reload command
This commit is contained in:
parent
103cac68fb
commit
6e24ca0dfc
@ -1,7 +1,12 @@
|
|||||||
package me.feusalamander.vmessage;
|
package me.feusalamander.vmessage;
|
||||||
|
|
||||||
import com.moandjiezana.toml.Toml;
|
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.io.InputStream;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
@ -16,7 +21,8 @@ public final class Configuration {
|
|||||||
private boolean joinEnabled;
|
private boolean joinEnabled;
|
||||||
private boolean leaveEnabled;
|
private boolean leaveEnabled;
|
||||||
private boolean changeEnabled;
|
private boolean changeEnabled;
|
||||||
private final Toml config;
|
private Toml config;
|
||||||
|
private static File file;
|
||||||
|
|
||||||
Configuration(Toml config) {
|
Configuration(Toml config) {
|
||||||
messageFormat = config.getString("Message.format", "");
|
messageFormat = config.getString("Message.format", "");
|
||||||
@ -29,13 +35,13 @@ public final class Configuration {
|
|||||||
leaveEnabled = config.getBoolean("Leave.enabled", false);
|
leaveEnabled = config.getBoolean("Leave.enabled", false);
|
||||||
changeEnabled = config.getBoolean("Server-change.enabled", false);
|
changeEnabled = config.getBoolean("Server-change.enabled", false);
|
||||||
this.config = config;
|
this.config = config;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static Configuration load(Path dataDirectory) {
|
static Configuration load(Path dataDirectory) {
|
||||||
Path f = createConfig(dataDirectory);
|
Path f = createConfig(dataDirectory);
|
||||||
if (f != null) {
|
if (f != null) {
|
||||||
Toml config = new Toml().read(f.toFile());
|
file = f.toFile();
|
||||||
|
Toml config = new Toml().read(file);
|
||||||
return new Configuration(config);
|
return new Configuration(config);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@ -91,14 +97,15 @@ public final class Configuration {
|
|||||||
return this.changeEnabled;
|
return this.changeEnabled;
|
||||||
}
|
}
|
||||||
void reload(){
|
void reload(){
|
||||||
messageFormat = config.getString("Message.format", "");
|
config = config.read(file);
|
||||||
joinFormat = config.getString("Join.format", "");
|
this.messageFormat = config.getString("Message.format");
|
||||||
leaveFormat = config.getString("Leave.format", "");
|
this.joinFormat = config.getString("Join.format");
|
||||||
changeFormat = config.getString("Server-change.format", "");
|
this.leaveFormat = config.getString("Leave.format");
|
||||||
|
this.changeFormat = config.getString("Server-change.format");
|
||||||
|
|
||||||
messageEnabled = config.getBoolean("Message.enabled", false);
|
this.messageEnabled = config.getBoolean("Message.enabled");
|
||||||
joinEnabled = config.getBoolean("Join.enabled", false);
|
this.joinEnabled = config.getBoolean("Join.enabled");
|
||||||
leaveEnabled = config.getBoolean("Leave.enabled", false);
|
this.leaveEnabled = config.getBoolean("Leave.enabled");
|
||||||
changeEnabled = config.getBoolean("Server-change.enabled", false);
|
this.changeEnabled = config.getBoolean("Server-change.enabled");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import com.velocitypowered.api.event.connection.PostLoginEvent;
|
|||||||
import com.velocitypowered.api.event.connection.PreLoginEvent;
|
import com.velocitypowered.api.event.connection.PreLoginEvent;
|
||||||
import com.velocitypowered.api.event.player.PlayerChatEvent;
|
import com.velocitypowered.api.event.player.PlayerChatEvent;
|
||||||
import com.velocitypowered.api.event.player.ServerConnectedEvent;
|
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.LoginPhaseConnection;
|
||||||
import com.velocitypowered.api.proxy.Player;
|
import com.velocitypowered.api.proxy.Player;
|
||||||
import com.velocitypowered.api.proxy.ProxyServer;
|
import com.velocitypowered.api.proxy.ProxyServer;
|
||||||
@ -22,7 +23,7 @@ import java.util.Objects;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public final class Listeners {
|
public final class Listeners {
|
||||||
private static final LegacyComponentSerializer SERIALIZER = LegacyComponentSerializer.builder()
|
public static final LegacyComponentSerializer SERIALIZER = LegacyComponentSerializer.builder()
|
||||||
.character('&')
|
.character('&')
|
||||||
.hexColors()
|
.hexColors()
|
||||||
.build();
|
.build();
|
||||||
@ -65,6 +66,9 @@ public final class Listeners {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Player p = e.getPlayer();
|
Player p = e.getPlayer();
|
||||||
|
if(p.getCurrentServer().isEmpty()){
|
||||||
|
return;
|
||||||
|
}
|
||||||
String message = configuration.getLeaveFormat()
|
String message = configuration.getLeaveFormat()
|
||||||
.replace("#player#", p.getUsername());
|
.replace("#player#", p.getUsername());
|
||||||
if (luckPermsAPI != null){
|
if (luckPermsAPI != null){
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package me.feusalamander.vmessage;
|
package me.feusalamander.vmessage;
|
||||||
import com.velocitypowered.api.command.CommandSource;
|
|
||||||
import com.velocitypowered.api.command.SimpleCommand;
|
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.nio.file.Path;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -16,12 +18,14 @@ public final class ReloadCommand implements SimpleCommand {
|
|||||||
@Override
|
@Override
|
||||||
public void execute(final Invocation invocation) {
|
public void execute(final Invocation invocation) {
|
||||||
String[] args = invocation.arguments();
|
String[] args = invocation.arguments();
|
||||||
if(args.length == 1){
|
if(args.length == 0){
|
||||||
|
invocation.source().sendMessage(Component.text("§cUsage: /vmessage reload"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String s = args[0];
|
String s = args[0];
|
||||||
if(s.equalsIgnoreCase("reload")){
|
if(s.equalsIgnoreCase("reload")){
|
||||||
config.reload();
|
config.reload();
|
||||||
|
invocation.source().sendMessage(Component.text("The Vmessage's config has been succefully reloaded"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user