Check if player's server has a certain plugin

Discussion in 'BungeeCord Plugin Development' started by xEmirr, Apr 15, 2021.

  1. How can i get list of plugins from player.getServer()
     
  2. You can use Bukkit.getServer().getPluginManager().getPlugins()
    or if player, player.getServer().getPluginManager().getPlugins()
     
  3. we are in bungeecord plugin development, there is no method like getPluginManager in bungeecord
     
  4. I need to check if there is a certain plugin in the players server from my bungeecord plugin. How can i do that???
     
  5. Listen for the event, that gets fired when a new MC server gets added to BC and then fetch the plugins from the server using messaging channels and cache the result.

    Then you have instant access when you need it.
     
  6. which event i can use for that
     
  7. Code (Text):
    @EventHandler
        public void onCommand(PluginMessageEvent e)  {
            if (e.getReceiver() instanceof ProxiedPlayer) {
                ProxiedPlayer p = (ProxiedPlayer) e.getReceiver();
                ByteArrayDataInput input = ByteStreams.newDataInput(e.getData());
                String subchannel = input.readUTF();
                if (subchannel.equalsIgnoreCase("ServerContainsMenuPlugin")) {
                    short len = input.readShort();
                    byte[] msgbytes = new byte[len];
                    input.readFully(msgbytes);
                    DataInputStream msgin = new DataInputStream(new ByteArrayInputStream(msgbytes));
                    try {
                        plugin.serversWithMenuPlugin.add(msgin.readUTF());
                    } catch (IOException ioException) {}
                }
            }
        }
    I did something like this, when a player joins the server i check if the plugin is there and if it is i send plugin message but it gives this error:
    Line 39 is String subchannel = input.readUTF();

    Code (Text):
    19.04 15:17:07 [Server] WARNING Error dispatching event PluginMessageEvent(super=TargetedEvent([email protected], receiver=xEmir), cancelled=false, tag=minecraft:brand) to listener [email protected]
    19.04 15:17:07 [Server] INFO java.lang.IllegalStateException: java.io.EOFException
    19.04 15:17:07 [Server] INFO at com.google.common.io.ByteStreams$ByteArrayDataInputStream.readUTF(ByteStreams.java:408)
    19.04 15:17:07 [Server] INFO at com.emiv.gfp.CommandFromMenus.onCommand(CommandFromMenus.java:39)
    19.04 15:17:07 [Server] INFO at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    19.04 15:17:07 [Server] INFO at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    19.04 15:17:07 [Server] INFO at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    19.04 15:17:07 [Server] INFO at java.lang.reflect.Method.invoke(Method.java:498)
    19.04 15:17:07 [Server] INFO at net.md_5.bungee.event.EventHandlerMethod.invoke(EventHandlerMethod.java:19)
    19.04 15:17:07 [Server] INFO at net.md_5.bungee.event.EventBus.post(EventBus.java:46)
    19.04 15:17:07 [Server] INFO at net.md_5.bungee.api.plugin.PluginManager.callEvent(PluginManager.java:412)
    19.04 15:17:07 [Server] INFO at net.md_5.bungee.connection.DownstreamBridge.handle(DownstreamBridge.java:256)
    19.04 15:17:07 [Server] INFO at net.md_5.bungee.protocol.packet.PluginMessage.handle(PluginMessage.java:88)
    19.04 15:17:07 [Server] INFO at net.md_5.bungee.netty.HandlerBoss.channelRead(HandlerBoss.java:105)
    19.04 15:17:07 [Server] INFO at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
    19.04 15:17:07 [Server] INFO at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
    19.04 15:17:07 [Server] INFO at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
    19.04 15:17:07 [Server] INFO at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
    19.04 15:17:07 [Server] INFO at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
    19.04 15:17:07 [Server] INFO at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
    19.04 15:17:07 [Server] INFO at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
    19.04 15:17:07 [Server] INFO at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
    19.04 15:17:07 [Server] INFO at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
    19.04 15:17:07 [Server] INFO at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
    19.04 15:17:07 [Server] INFO at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
    19.04 15:17:07 [Server] INFO at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:324)
    19.04 15:17:07 [Server] INFO at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:296)
    19.04 15:17:07 [Server] INFO at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
    19.04 15:17:07 [Server] INFO at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
    19.04 15:17:07 [Server] INFO at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
    19.04 15:17:07 [Server] INFO at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:286)
    19.04 15:17:07 [Server] INFO at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
    19.04 15:17:07 [Server] INFO at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
    19.04 15:17:07 [Server] INFO at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357)
    19.04 15:17:07 [Server] INFO at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
    19.04 15:17:07 [Server] INFO at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
    19.04 15:17:07 [Server] INFO at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365)
    19.04 15:17:07 [Server] INFO at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
    19.04 15:17:07 [Server] INFO at io.netty.channel.epoll.AbstractEpollStreamChannel$EpollStreamUnsafe.epollInReady(AbstractEpollStreamChannel.java:795)
    19.04 15:17:07 [Server] INFO at io.netty.channel.epoll.EpollEventLoop.processReady(EpollEventLoop.java:480)
    19.04 15:17:07 [Server] INFO at io.netty.channel.epoll.EpollEventLoop.run(EpollEventLoop.java:378)
    19.04 15:17:07 [Server] INFO at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
    19.04 15:17:07 [Server] INFO at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
    19.04 15:17:07 [Server] INFO at java.lang.Thread.run(Thread.java:748)
    19.04 15:17:07 [Server] INFO Caused by: java.io.EOFException
    19.04 15:17:07 [Server] INFO at java.io.DataInputStream.readFully(DataInputStream.java:197)
    19.04 15:17:07 [Server] INFO at java.io.DataInputStream.readUTF(DataInputStream.java:609)
    19.04 15:17:07 [Server] INFO at java.io.DataInputStream.readUTF(DataInputStream.java:564)
    19.04 15:17:07 [Server] INFO at com.google.common.io.ByteStreams$ByteArrayDataInputStream.readUTF(ByteStreams.java:406)
    19.04 15:17:07 [Server] INFO ... 41 more
     
  8. Looks like I mixed something up. The event I was thinking of doesn't exist...
    Then you have to query the result from the server once when it gets requested the first time and then cache it for later use.

    Your exception looks like you try to read more data than actually present in your buffer. Make sure that you only read the data you sent previously.
     
  9. it cant read the subchannel though? if (subchannel.equalsIgnoreCase("ServerContainsMenuPlugin")) doesnt even get called.