WiIIiam278 / PAPIProxyBridge

A bridge library plugin for using PlaceholderAPI on proxy servers
https://william278.net/project/papiproxybridge
Apache License 2.0
37 stars 11 forks source link

PAPIProxyBridge or my plugin? #117

Closed JoMiNovi closed 5 months ago

JoMiNovi commented 6 months ago

Hello, I'm new to programming Minecraft Java plugins. I wanted to use your PAPIProxyBridge in a plugin of mine. It's for sending a custom message whenever a player joins or leaves my Velocity proxy. When I don't use PAPI Placeholders in the config everything works fine. But when joining with PAPI Placeholders in the config, the message is sent unformatted. In the console, I get this error: "[myplugin]: Failed to format placeholders for JoMiNovi" Now I wanted to ask, how I can see if the problem is on the ProxyBridge side or if I made a mistake in my code. The PAPIProxyBridge Plugin (V1.5) is installed on the backend paper server and the velocity proxy.

This is a piece of the code of my plugin, where PAPIProxyBridge is used:

@Subscribe
    public void onConnect(ServerConnectedEvent event) {
        RegisteredServer currentServer = event.getServer();
        Optional<RegisteredServer> previousServer = event.getPreviousServer();
        final PlaceholderAPI api = PlaceholderAPI.createInstance();
        final UUID playerUUID = event.getPlayer().getUniqueId();
        String server = currentServer.getServerInfo().getName();
        if (previousServer.isPresent()) {}
        else {
            if (!config.JOIN_ENABLE)
                return;
            api.formatPlaceholders(config.JOIN_FORMAT, playerUUID).thenAccept(formatted -> {
            Component msg = parseMessage(config.JOIN_FORMAT, List.of(
                new ChatTemplate("server", server, false)
            ));
            sendMessage(msg, currentServer);
            });
        }
}
alexdev03 commented 6 months ago

Hi, try delaying the request of 500 ms.

JoMiNovi commented 6 months ago

Doesn't work :) I've tried ScheduledExecutorService and Thread.sleep. When using ScheduledExecutorService, no "Failed to format placeholders for player" is displayed anymore. With Thread.sleep the error is shown, but both solutions don't work. I always get the unformatted message.

alexdev03 commented 6 months ago

Look at the code of velocitab, hope this helps. https://github.com/WiIIiam278/Velocitab/blob/master/src/main/java/net/william278/velocitab/hook/PAPIProxyBridgeHook.java

JoMiNovi commented 5 months ago

I successfully addressed the formatting issue by creating a custom bridge plugin. While working on it, I discovered a potential limitation with PAPIProxyBridge. It seems using onConnect doesn't provide the server information needed for formatting. My plugin utilizes onPostConnect to resolve this, and I believe it might be a suitable solution for PAPIProxyBridge as well.

Thanks, JoMiNovi