8

Make This Plugin Compatible for Velocity Proxy Server. and make sure VoidSpawn feature work perfectly use your own knowledge to work features perfectly.

Kodari AI
KodariJul 6 at 11:55 am 26

Quick technical reality check before I touch code: Velocity is a proxy — it has zero concept of worlds, chunk generators, blocks, flight, or PlayerJoinEvent teleports. Those only exist on the backend (Spigot/Paper) server. Your VoidSpawn feature (custom void world + chunk generator + flight) is 100% Bukkit-only machinery — there is no way to “port” it to Velocity, because the proxy never touches a world at all.

So “make this plugin Velocity-compatible” and “make VoidSpawn work perfectly” are mutually exclusive for this codebase. What I can actually do:

  • Keep PmcAuth as a Paper/Spigot plugin (where VoidSpawn lives) and fix VoidSpawn properly there.

  • If you separately want a Velocity-side auth companion (e.g. blocking server-switch/commands until the backend confirms login, forwarding login state across backend servers in a network), that would be a new, separate Velocity plugin with no blocks/worlds/flight — just proxy login-gating logic.

Let me fix VoidSpawn on the Bukkit side first since that’s concrete and fixable now.

VoidSpawn fixes — real bugs found:

  1. VoidWorldGenerator doesn’t disable vanilla mob-spawning/structure/decoration/cave generation, so the server still runs those passes every chunk even though nothing can render (wastes CPU, and can still spawn flying mobs like phantoms above the void).

  2. Spawn locations are hard-set to y=0 with no fixed-spawn override — Bukkit’s safe-spawn scanner has to search an all-air chunk on world creation, which is slow/unreliable. Should use getFixedSpawnLocation and spawn at y=64.

  3. In both AuthListener.startAuthProcess and AuthManager.startAuthProcess, the player is teleported into the void before flight is enabled — on lag or plugin conflicts this creates a one-tick fall window. Flight must be set before the teleport.

  4. Missing DO_MOB_SPAWNING gamerule disable for the void world.

VoidSpawn fixes applied:

  • VoidWorldGenerator now disables caves/decorations/mobs/structures/noise/surface/bedrock generation and returns a getFixedSpawnLocation at (0,64,0), so world creation no longer has to scan an empty chunk for a “safe” spot and nothing wastefully generates in it.

  • Void world spawn + all teleport targets moved from y=0 → y=64 (clear of any height-limit edge cases).

  • Flight is now enabled before teleporting the player into the void in both AuthListener.startAuthProcess and AuthManager.startAuthProcess, closing the one-tick fall window.

  • DO_MOB_SPAWNING gamerule disabled on the void world.

On Velocity: not doable for this feature/plugin as explained — Velocity has no worlds/blocks/flight, so VoidSpawn can only exist on the Bukkit/Paper side, which is what I fixed above. If you want an auth-gating layer on your Velocity proxy (e.g., preventing server switches or lobby access before the backend confirms login), tell me and I’ll scope a separate Velocity plugin for that — it would need a different mechanism entirely (plugin messaging channel between backend and proxy, not the void world).

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
manifest.kod
PERFORMANCE_OPTIMIZATIONS.md
Code
35 3,830
src/main/java/com/pmcnetwork/pmcauth/PmcAuth.java
package com.pmcnetwork.pmcauth;

import com.pmcnetwork.pmcauth.command.ChangePassCommand;
import com.pmcnetwork.pmcauth.command.EndSessionCommand;
import com.pmcnetwork.pmcauth.command.LoginCommand;
import com.pmcnetwork.pmcauth.command.PmcAuthCommand;
import com.pmcnetwork.pmcauth.command.RegisterCommand;
import com.pmcnetwork.pmcauth.command.SetAuthLocationCommand;
import com.pmcnetwork.pmcauth.command.UnregisterCommand;
import com.pmcnetwork.pmcauth.listener.AuthListener;
import com.pmcnetwork.pmcauth.manager.AuthManager;
import com.pmcnetwork.pmcauth.manager.BossBarManager;
import com.pmcnetwork.pmcauth.manager.ConfigManager;
import com.pmcnetwork.pmcauth.manager.DatabaseManager;
import com.pmcnetwork.pmcauth.manager.IPBanManager;
import com.pmcnetwork.pmcauth.manager.IsolationManager;
import com.pmcnetwork.pmcauth.manager.LocationManager;
import com.pmcnetwork.pmcauth.manager.MessagesManager;
import com.pmcnetwork.pmcauth.manager.MultiLoginManager;
import com.pmcnetwork.pmcauth.manager.PlayerDataManager;
import com.pmcnetwork.pmcauth.manager.ReminderManager;
import com.pmcnetwork.pmcauth.manager.SeasonManager;
import com.pmcnetwork.pmcauth.manager.SessionManager;
import com.pmcnetwork.pmcauth.util.ConsoleFilter;
import com.pmcnetwork.pmcauth.util.PremiumChecker;
import com.pmcnetwork.pmcauth.util.VoidWorldGenerator;
import lombok.Getter;
import org.bukkit.World;
import org.bukkit.WorldCreator;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.TabCompleter;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.logging.Filter;
import java.util.logging.Logger;

@Getter
public class PmcAuth extends JavaPlugin {

    private ConfigManager configManager;
    private MessagesManager messagesManager;
    private DatabaseManager databaseManager;
    private AuthManager authManager;
    private PlayerDataManager playerDataManager;
    private SeasonManager seasonManager;
    private SessionManager sessionManager;
    private BossBarManager bossBarManager;
    private IsolationManager isolationManager;
    private LocationManager locationManager;
    private IPBanManager ipBanManager;
    private ReminderManager reminderManager;
    private MultiLoginManager multiLoginManager;
    private PremiumChecker premiumChecker;
    private World voidWorld;

    @Override
    public void onEnable() {
        installConsoleFilter();
        saveDefaultConfig();

        this.configManager = new ConfigManager(this);
        this.messagesManager = new MessagesManager(this);
        this.databaseManager = new DatabaseManager(this);
        this.playerDataManager = new PlayerDataManager(this);
        this.sessionManager = new SessionManager(this);
        this.authManager = new AuthManager(this);
        this.seasonManager = new SeasonManager(this);
        this.bossBarManager = new BossBarManager(this);
        this.isolationManager = new IsolationManager(this);
        this.locationManager = new LocationManager(this);
        this.ipBanManager = new IPBanManager(this);
        this.reminderManager = new ReminderManager(this);
        this.multiLoginManager = new MultiLoginManager();
        this.premiumChecker = new PremiumChecker();

        if (configManager.isVoidSpawnEnabled()) {
            loadVoidWorld();
        }

        getServer().getPluginManager().registerEvents(new AuthListener(this), this);

        LoginCommand loginCmd = new LoginCommand(this);
        RegisterCommand registerCmd = new RegisterCommand(this);
        PmcAuthCommand pmcAuthCmd = new PmcAuthCommand(this);
        ChangePassCommand changePassCmd = new ChangePassCommand(this);
        UnregisterCommand unregisterCmd = new UnregisterCommand(this);
        EndSessionCommand endSessionCmd = new EndSessionCommand(this);

        registerCommand("login", loginCmd, loginCmd);
        registerCommand("register", registerCmd, registerCmd);
        registerCommand("pmcauth", pmcAuthCmd, pmcAuthCmd);
        registerCommand("setauthlocation", new SetAuthLocationCommand(this), null);
        registerCommand("changepass", changePassCmd, changePassCmd);
        registerCommand("unregister", unregisterCmd, unregisterCmd);
        registerCommand("endsession", endSessionCmd, null);

        getLogger().info("PmcAuth has been enabled! PMC NETWORK ON TOP");
    }

    private void registerCommand(String name, CommandExecutor executor, TabCompleter completer) {
        org.bukkit.command.PluginCommand cmd = getCommand(name);
        if (cmd == null) {
            getLogger().severe("Failed to register command: " + name + " (command not found in plugin.yml)");
            return;
        }
        cmd.setExecutor(executor);
        if (completer != null) {
            cmd.setTabCompleter(completer);
        }
        getLogger().info("Registered command: /" + name);
    }

    private void loadVoidWorld() {
        org.bukkit.World.Environment environment;
        try {
            environment = org.bukkit.World.Environment.valueOf(configManager.getVoidEnvironment().toUpperCase());
        } catch (IllegalArgumentException e) {
            environment = org.bukkit.World.Environment.NORMAL;
        }
        WorldCreator creator = new WorldCreator("pmcauth_void")
                .generator(new VoidWorldGenerator())
                .environment(environment);
        this.voidWorld = creator.createWorld();
        if (this.voidWorld != null) {
            this.voidWorld.setSpawnLocation(0, 64, 0);
            this.voidWorld.setTime(configManager.getVoidTime());
            this.voidWorld.setGameRule(org.bukkit.GameRule.DO_DAYLIGHT_CYCLE, false);
            this.voidWorld.setGameRule(org.bukkit.GameRule.DO_WEATHER_CYCLE, false);
            this.voidWorld.setGameRule(org.bukkit.GameRule.DO_MOB_SPAWNING, false);
            getLogger().info("[PmcAuth] Void world loaded.");
        }
    }

    private void installConsoleFilter() {
        ConsoleFilter filter = new ConsoleFilter();
        Logger rootLogger = Logger.getLogger("");
        Filter existing = rootLogger.getFilter();
        if (!(existing instanceof ConsoleFilter)) {
            rootLogger.setFilter(filter);
        }
        java.util.logging.Handler[] handlers = rootLogger.getHandlers();
        for (java.util.logging.Handler handler : handlers) {
            Filter handlerFilter = handler.getFilter();
            if (!(handlerFilter instanceof ConsoleFilter)) {
                handler.setFilter(filter);
            }
        }
    }

    @Override
    public void onDisable() {
        if (reminderManager != null) {
            reminderManager.stopAllReminders();
        }
        if (bossBarManager != null) {
            bossBarManager.removeAllBossBars();
        }
        if (isolationManager != null) {
            isolationManager.clearAll();
        }
        if (sessionManager != null) {
            if (!configManager.isPersistSessionsOnRestart()) {
                sessionManager.clearAllSessions();
            }
        }
        if (playerDataManager != null) {
            playerDataManager.saveAll();
        }
        if (databaseManager != null) {
            databaseManager.close();
        }
        getLogger().info("PmcAuth has been disabled!");
    }
}