diff --git a/README.md b/README.md index 1638f87..230a0b7 100644 --- a/README.md +++ b/README.md @@ -43,8 +43,9 @@ try = [] # keep fallback empty ## ⚡ Commands - **/lobby** - **/hub** +- **/vlobbyconnectreload** -These 2 Instantly teleports the player to the appropriate lobby. +These 3 commands instantly teleport the player to the appropriate lobby or reload the plugin configuration. ## 🛡️ Future Enhancements (Planned Features) - **Customizable Messages** – Modify join/fallback messages in `config.yml`. diff --git a/src/main/java/io/github/kmaba/vLobbyConnect/ReloadCommand.java b/src/main/java/io/github/kmaba/vLobbyConnect/ReloadCommand.java new file mode 100644 index 0000000..8f0ee3e --- /dev/null +++ b/src/main/java/io/github/kmaba/vLobbyConnect/ReloadCommand.java @@ -0,0 +1,80 @@ +package io.github.kmaba.vLobbyConnect; + +import com.velocitypowered.api.command.CommandSource; +import com.velocitypowered.api.command.SimpleCommand; +import com.velocitypowered.api.proxy.ProxyServer; +import net.kyori.adventure.text.Component; +import org.slf4j.Logger; +import org.yaml.snakeyaml.Yaml; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class ReloadCommand implements SimpleCommand { + + private final ProxyServer server; + private final Logger logger; + private final Map> versionLobbies; + + public ReloadCommand(ProxyServer server, Logger logger, Map> versionLobbies) { + this.server = server; + this.logger = logger; + this.versionLobbies = versionLobbies; + } + + @Override + public void execute(Invocation invocation) { + CommandSource source = invocation.source(); + + if (!source.hasPermission("vlobbyconnect.reload")) { + source.sendMessage(Component.text("You do not have permission to use this command.")); + return; + } + + try { + Yaml yaml = new Yaml(); + File configFile = new File("plugins/vLobbyConnect/config.yml"); + if (!configFile.exists()) { + source.sendMessage(Component.text("Configuration file not found.")); + return; + } + + Map config = yaml.load(Files.newInputStream(configFile.toPath())); + Map lobbies = (Map) config.get("lobbies"); + if (lobbies == null) { + source.sendMessage(Component.text("Failed to load valid lobby settings from config file.")); + return; + } + + versionLobbies.clear(); + Pattern pattern = Pattern.compile("^(\\d+\\.\\d+)lobby(\\d+)$"); + for (Map.Entry entry : lobbies.entrySet()) { + Matcher matcher = pattern.matcher(entry.getKey()); + if (matcher.matches()) { + String version = matcher.group(1); + String lobbyName = entry.getValue(); + Optional serverOpt = server.getServer(lobbyName); + if (serverOpt.isPresent()) { + versionLobbies.computeIfAbsent(version, k -> new ArrayList<>()).add(serverOpt.get()); + } else { + logger.warn("Lobby server '{}' not found in Velocity configuration.", lobbyName); + } + } else { + logger.warn("Invalid lobby configuration key: {}", entry.getKey()); + } + } + + source.sendMessage(Component.text("vLobbyConnect configuration reloaded successfully.")); + } catch (IOException e) { + logger.error("Error loading config.yml", e); + source.sendMessage(Component.text("An error occurred while reloading the configuration.")); + } + } +} diff --git a/src/main/java/io/github/kmaba/vLobbyConnect/VelocityPlugin.java b/src/main/java/io/github/kmaba/vLobbyConnect/VelocityPlugin.java index 3a1c94e..a4de9e2 100644 --- a/src/main/java/io/github/kmaba/vLobbyConnect/VelocityPlugin.java +++ b/src/main/java/io/github/kmaba/vLobbyConnect/VelocityPlugin.java @@ -5,7 +5,6 @@ import com.velocitypowered.api.event.PostOrder; import com.velocitypowered.api.event.player.PlayerChooseInitialServerEvent; import com.velocitypowered.api.event.proxy.ProxyInitializeEvent; -import com.velocitypowered.api.plugin.Plugin; import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.server.RegisteredServer; import org.slf4j.Logger; @@ -31,6 +30,8 @@ import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; +import com.velocitypowered.api.plugin.Plugin; + @Plugin( id = "vlobbyconnect", name = "vLobbyConnect", @@ -107,6 +108,7 @@ public void onProxyInitialize(ProxyInitializeEvent event) { // Register commands server.getCommandManager().register("hub", new HubCommand(server, logger)); server.getCommandManager().register("lobby", new LobbyCommand(server, logger)); + server.getCommandManager().register("vlobbyconnectreload", new ReloadCommand(server, logger, versionLobbies)); } @Subscribe(order = PostOrder.FIRST) diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml new file mode 100644 index 0000000..5663505 --- /dev/null +++ b/src/main/resources/plugin.yml @@ -0,0 +1,13 @@ +name: vLobbyConnect +main: io.github.kmaba.vLobbyConnect.VelocityPlugin +version: 2.1.0 +description: A Velocity Plugin for Lobby Connection +authors: [kmaba] +commands: + hub: + description: Teleport to the hub + aliases: [lobby] + vlobbyconnectreload: + description: Reload the vLobbyConnect configuration + permission: vlobbyconnect.reload + default: op