Solved Send custom mesage from Bungeecord to spigot

Discussion in 'BungeeCord Plugin Development' started by KarmaConfigs, Feb 11, 2020.

  1. Hi, I've been searching a lot and I found the way to send a plugin message from bungeecord to spigot, but for some reason, I'm getting a NullPointerException


    Code (Text):
    Error dispatching event PostLoginEvent(player=EdwinCrack) to listener [email protected]
    java.lang.NullPointerException
        at io.github.karmaconfigs.Bungee.Utils.Proxy.sendData.sendCustomData(sendData.java:31)
        at io.github.karmaconfigs.Bungee.Events.JoinEvent.OnJoin(JoinEvent.java:45)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at net.md_5.bungee.event.EventHandlerMethod.invoke(EventHandlerMethod.java:19)
        at net.md_5.bungee.event.EventBus.post(EventBus.java:46)
        at net.md_5.bungee.api.plugin.PluginManager.callEvent(PluginManager.java:400)
        at net.md_5.bungee.connection.InitialHandler$6$1.run(InitialHandler.java:525)
        at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:164)
        at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:472)
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:497)
        at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
        at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
        at java.lang.Thread.run(Unknown Source)
    My sendCustomData void is this

    (https://www.spigotmc.org/wiki/sending-a-custom-plugin-message-from-bungeecord/)

    Code (Java):
    public void sendCustomData(ProxiedPlayer player, String data1, int data2)
        {
            Collection<ProxiedPlayer> networkPlayers = ProxyServer.getInstance().getPlayers();
            if ( networkPlayers == null || networkPlayers.isEmpty()) return;

            ByteArrayDataOutput out = ByteStreams.newDataOutput();
            out.writeUTF( "RegStatus" );
            out.writeUTF( data1 );
            out.writeInt( data2 );

            player.getServer().getInfo().sendData( "ll:pinfo", out.toByteArray() );
        }
    And I registered the channel


    Code (Java):
    @Override
        public void onEnable() {
            new Main().onEnable();
            getProxy().registerChannel( "ll:pinfo" );
        }
    I'm sending the message when the player joins the server

    Why is it getting me a Null error?
     
  2. Fixed by myself by scheduling the task of sending the message
     
    • Like Like x 1