not_pratik7
📎 1 file 2,000 chars
📄
pasted-code-1771344678437.txt
txt 91 lines
▶
Fix prefix issue and add dynamic / command feature.

DO NOT change:
- config.yml
- messages.yml
- Any message format
- Any placeholders
- Any color codes

========================================
1️⃣ PREFIX FIX
========================================

Problem:
Admins are getting the Owner prefix in /adminchat and /staffchat.

Fix prefix resolution logic properly.

Requirements:

1. If LuckPerms is installed:
   - Use LuckPerms API
   - user.getCachedData().getMetaData().getPrefix()
   - Must return highest priority prefix automatically
   - Do NOT manually check permissions
   - Do NOT hardcode ranks

2. If LuckPerms is not installed:
   - Fallback to Vault (if available)
   - Otherwise return empty string

3. {prefix} must resolve dynamically (real-time) in:
   - staffchat
   - adminchat
   - staffjoin
   - stafflist
   - stream

4. Do NOT cache prefix permanently at login.
   Fetch when sending message.

Create a clean PrefixService class.

========================================
2️⃣ DYNAMIC / COMMAND FEATURE
========================================

Add automatic dynamic commands for every Velocity server.

Example:
- /lobby
- /survival
- /lifesteal

Requirements:

1. Automatically register a command for each server from:
   proxyServer.getAllServers()

2. When player runs /:
   - If server exists → connect player
   - If already connected → show:
       movecommands_already_connected
   - If server not available → show:
       movecommands_server_not_found

3. Permission format:
   mcnp.server.

   Example:
   - mcnp.server.lobby
   - mcnp.server.survival

4. Console cannot use command.

5. Use:
   player.createConnectionRequest(server).fireAndForget()

6. Do NOT hardcode server names.

7. Create ServerCommandManager class.

=============================

Output only:
- PrefixService implementation
- Integration example
- Dynamic command registration logic
- Proper registration in main class

Do NOT regenerate entire plugin.
Kodari AI
KodariFeb 17 at 4:13 pm 9,195 (v2)

I need to read the existing plugin files first to understand the current structure and implement the fixes properly.

The project is empty, but I understand you want the specific classes to integrate into your existing Velocity plugin. I’ll create the PrefixService and ServerCommandManager with proper integration examples.

MCNetworkPlus
A comprehensive Velocity proxy plugin providing staff communication tools, prefix management via LuckPerms, dynamic server commands, and administrative utilities. Features include staff chat channels, player tracking, automatic server command registration, and integrated permission handling for multi-server network management.

Created PrefixService and ServerCommandManager with complete integration guide. The PrefixService uses LuckPerms API to fetch the highest priority prefix dynamically (no caching), and ServerCommandManager automatically registers commands for all Velocity servers with proper permission checks.

Kodari can make mistakes. Review important code before using.
Files
src
INTEGRATION_EXAMPLE.txt
Code
3 335
src/main/java/com/mcnetworkplus/command/ServerCommandManager.java
package com.mcnetworkplus.command;

import com.velocitypowered.api.command.SimpleCommand;
import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.ProxyServer;
import com.velocitypowered.api.proxy.server.RegisteredServer;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;

public class ServerCommandManager {
    
    private final ProxyServer proxyServer;
    private final Function<String, String> messageProvider;
    private final Function<String, Component> colorizer;
    
    public ServerCommandManager(ProxyServer proxyServer, Function<String, String> messageProvider, Function<String, Component> colorizer) {
        this.proxyServer = proxyServer;
        this.messageProvider = messageProvider;
        this.colorizer = colorizer;
    }
    
    public void registerAllServerCommands() {
        for (RegisteredServer server : proxyServer.getAllServers()) {
            String serverName = server.getServerInfo().getName().toLowerCase();
            registerServerCommand(serverName);
        }
    }
    
    private void registerServerCommand(String serverName) {
        proxyServer.getCommandManager().register(
            proxyServer.getCommandManager().metaBuilder(serverName)
                .build(),
            new DynamicServerCommand(serverName)
        );
    }
    
    private class DynamicServerCommand implements SimpleCommand {
        
        private final String targetServerName;
        
        public DynamicServerCommand(String targetServerName) {
            this.targetServerName = targetServerName;
        }
        
        @Override
        public void execute(Invocation invocation) {
            if (!(invocation.source() instanceof Player)) {
                return;
            }
            
            Player player = (Player) invocation.source();
            
            Optional<RegisteredServer> serverOptional = proxyServer.getServer(targetServerName);
            
            if (!serverOptional.isPresent()) {
                String message = messageProvider.apply("movecommands_server_not_found")
                    .replace("{server}", targetServerName);
                player.sendMessage(colorizer.apply(message));
                return;
            }
            
            RegisteredServer targetServer = serverOptional.get();
            
            if (player.getCurrentServer().isPresent() && 
                player.getCurrentServer().get().getServer().equals(targetServer)) {
                String message = messageProvider.apply("movecommands_already_connected")
                    .replace("{server}", targetServerName);
                player.sendMessage(colorizer.apply(message));
                return;
            }
            
            player.createConnectionRequest(targetServer).fireAndForget();
        }
        
        @Override
        public boolean hasPermission(Invocation invocation) {
            return invocation.source().hasPermission("mcnp.server." + targetServerName);
        }
        
        @Override
        public List<String> suggest(Invocation invocation) {
            return new ArrayList<>();
        }
    }
}