R

Create a Velocity proxy plugin for Minecraft that assigns specific players to specific backend servers.

Requirements:

* Use a configurable config.yml file * Allow assigning multiple players to different servers, e.g.:

players:

Steve: survival Alex: minigame Notch: lobby locked: true

* On player join, automatically send them to their assigned server * If "locked" is true, prevent players from switching servers * If they try to switch, redirect them back to their assigned server * Support multiple players and servers *i want to add assign more player

Kodari AI
KodariApr 13 at 11:38 pm 10,055 (v2)

I’ll create a Velocity proxy plugin that assigns players to specific servers with optional locking.

PlayerServerAssigner
A Velocity proxy plugin that automatically assigns specific players to designated backend servers. Features include configurable player-to-server mappings, optional server locking to prevent player switching, automatic redirection on join, and in-game commands to manage assignments. Administrators can dynamically assign or reassign players to servers without restarting the proxy. Perfect for dedicated server setups or role-based server access.

Created a Velocity proxy plugin with automatic player-to-server assignment, optional locking, and dynamic assignment commands. Players can be assigned to specific servers via config or the /assign <player> <server> command (use /assign <player> remove to unassign). Requires playerserverassigner.assign permission.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
manifest.kod
Code
9 302
src/main/java/com/playerserverassigner/ConfigManager.java
package com.playerserverassigner;

import org.spongepowered.configurate.ConfigurationNode;
import org.spongepowered.configurate.yaml.YamlConfigurationLoader;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Optional;

public class ConfigManager {
    private final PlayerServerAssigner plugin;
    private final Path dataDirectory;
    private final Path configPath;
    private ConfigurationNode config;

    public ConfigManager(PlayerServerAssigner plugin, Path dataDirectory) {
        this.plugin = plugin;
        this.dataDirectory = dataDirectory;
        this.configPath = dataDirectory.resolve("config.yml");
    }

    public void load() {
        try {
            if (!Files.exists(dataDirectory)) {
                Files.createDirectories(dataDirectory);
            }

            if (!Files.exists(configPath)) {
                createDefaultConfig();
            }

            YamlConfigurationLoader loader = YamlConfigurationLoader.builder()
                    .path(configPath)
                    .build();
            config = loader.load();
        } catch (IOException e) {
            plugin.getLogger().error("Failed to load config", e);
        }
    }

    private void createDefaultConfig() throws IOException {
        YamlConfigurationLoader loader = YamlConfigurationLoader.builder()
                .path(configPath)
                .build();
        ConfigurationNode node = loader.createNode();
        
        node.node("players", "Steve").set("survival");
        node.node("players", "Alex").set("minigame");
        node.node("players", "Notch").set("lobby");
        node.node("locked").set(true);
        
        loader.save(node);
    }

    public void save() {
        try {
            YamlConfigurationLoader loader = YamlConfigurationLoader.builder()
                    .path(configPath)
                    .build();
            loader.save(config);
        } catch (IOException e) {
            plugin.getLogger().error("Failed to save config", e);
        }
    }

    public Optional<String> getAssignedServer(String playerName) {
        Object value = config.node("players", playerName).raw();
        return value != null ? Optional.of(String.valueOf(value)) : Optional.empty();
    }

    public boolean isLocked() {
        return config.node("locked").getBoolean(false);
    }

    public void setAssignment(String playerName, String serverName) {
        try {
            config.node("players", playerName).set(serverName);
            save();
        } catch (Exception e) {
            plugin.getLogger().error("Failed to set assignment for " + playerName, e);
        }
    }

    public void removeAssignment(String playerName) {
        try {
            config.node("players", playerName).set(null);
            save();
        } catch (Exception e) {
            plugin.getLogger().error("Failed to remove assignment", e);
        }
    }
}