Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
80 changes: 80 additions & 0 deletions src/main/java/io/github/kmaba/vLobbyConnect/ReloadCommand.java
Original file line number Diff line number Diff line change
@@ -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<String, List<RegisteredServer>> versionLobbies;

public ReloadCommand(ProxyServer server, Logger logger, Map<String, List<RegisteredServer>> 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<String, Object> config = yaml.load(Files.newInputStream(configFile.toPath()));
Map<String, String> lobbies = (Map<String, String>) 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<String, String> entry : lobbies.entrySet()) {
Matcher matcher = pattern.matcher(entry.getKey());
if (matcher.matches()) {
String version = matcher.group(1);
String lobbyName = entry.getValue();
Optional<RegisteredServer> 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."));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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",
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -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
Loading