Solved Plugin is null?

Discussion in 'BungeeCord Plugin Development' started by DotRar, Jun 10, 2016.

  1. EDIT: Got it, I created 2 instances of AddFriendCommand

    Hi I just got this weird error:

    Code (Text):
    20:04:30 [WARNING] Error in dispatching command
    java.lang.NullPointerException: owner
        at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:226)
        at net.md_5.bungee.scheduler.BungeeScheduler.schedule(BungeeScheduler.java:91)
        at net.md_5.bungee.scheduler.BungeeScheduler.schedule(BungeeScheduler.java:85)
        at com.perkelle.dev.bungee.friendCommands.AddFriendCMD.execute(AddFriendCMD.java:58)
        at com.perkelle.dev.bungee.friendCommands.FriendCommandManager.execute(FriendCommandManager.java:51)
        at net.md_5.bungee.api.plugin.PluginManager.dispatchCommand(PluginManager.java:169)
        at net.md_5.bungee.api.plugin.PluginManager.dispatchCommand(PluginManager.java:116)
        at net.md_5.bungee.connection.UpstreamBridge.handle(UpstreamBridge.java:113)
        at net.md_5.bungee.protocol.packet.Chat.handle(Chat.java:50)
        at net.md_5.bungee.netty.HandlerBoss.channelRead(HandlerBoss.java:77)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:318)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:304)
        at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:318)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:304)
        at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:318)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:304)
        at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:276)
        at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:354)
        at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:244)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:318)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:304)
        at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:318)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:304)
        at io.netty.handler.timeout.ReadTimeoutHandler.channelRead(ReadTimeoutHandler.java:152)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:318)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:304)
        at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:846)
        at io.netty.channel.epoll.AbstractEpollStreamChannel$EpollStreamUnsafe.epollInReady(AbstractEpollStreamChannel.java:823)
        at io.netty.channel.epoll.EpollEventLoop.processReady(EpollEventLoop.java:339)
        at io.netty.channel.epoll.EpollEventLoop.run(EpollEventLoop.java:255)
        at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:112)
        at java.lang.Thread.run(Thread.java:745)
    Here's lines 58 - 64 of the AddFriend class:

    Code (Text):
    ProxyServer.getInstance().getScheduler().schedule(pl, new Runnable() {
                    public void run() {
                        p.sendMessage(new TextComponent("§4>> §fYour friend request to §e"+target.getName()+" §fhas expired."));
                        target.sendMessage(new TextComponent("§4>> §e"+p.getName()+"'s §ffriend request has expired."));
                        requests.remove(p);
                    }
                }, 1L, TimeUnit.MINUTES);
    Because the error is on line 58, this leads me to believe that pl is null.

    However, it is not (At least it isn't). At the top of the class, I have this:

    Code (Text):
    private Plugin pl;

        private DB db = DB.INSTANCE;

        private Map<ProxiedPlayer, ProxiedPlayer> requests = new HashMap<ProxiedPlayer, ProxiedPlayer>();

        public void init(Plugin pl) {
            this.pl = pl;
        }
    which sets pl.

    Now in FriendCommandManager, here's lines 20 - 29:

    Code (Text):
    public void init(Plugin pl) {
            AddFriendCMD addFriendCMD = new AddFriendCMD();
            addFriendCMD.init(pl);
            commands.add(new AddFriendCMD());
            commands.add(new FindFriendCommand());
            commands.add(new FriendMessagesOnlyCMD());
            commands.add(new HelpFriendCMD());
            commands.add(new ListFriendCMD());
            commands.add(new RemoveFriendCMD());
        }
    which as you can see, sets pl.

    Also, here's line 51:
    Code (Text):
    cmd.execute(p, subArgs);
    (p is the ProxiedPlayer)

    Finally, here's my core class if you need it:

    Code (Text):
    package com.perkelle.dev.bungee;

    import com.perkelle.dev.bungee.commands.*;
    import com.perkelle.dev.bungee.friendCommands.FriendCommandManager;
    import com.perkelle.dev.bungee.listeners.Join;
    import com.perkelle.dev.bungee.listeners.Leave;
    import com.perkelle.dev.bungee.party.commands.PartyCommandManager;
    import net.md_5.bungee.api.ProxyServer;
    import net.md_5.bungee.api.plugin.Plugin;

    public class Core extends Plugin {

        @Override
        public void onEnable() {
            FileManager fm = FileManager.INSTANCE;
            DB db = DB.INSTANCE;
            FriendCommandManager friendCmdManager = new FriendCommandManager();
            PartyCommandManager partyCmdManager = new PartyCommandManager();

            fm.setup(this);
            db.openConnection(this);

            ProxyServer.getInstance().getPluginManager().registerCommand(this, new AlertCMD());
            ProxyServer.getInstance().getPluginManager().registerCommand(this, new BungeeCMD());
            ProxyServer.getInstance().getPluginManager().registerCommand(this, new GListCMD());
            ProxyServer.getInstance().getPluginManager().registerCommand(this, new HubCMD());
            ProxyServer.getInstance().getPluginManager().registerCommand(this, new MessageCMD());
            ProxyServer.getInstance().getPluginManager().registerCommand(this, new ReplyCMD());
            ProxyServer.getInstance().getPluginManager().registerCommand(this, new WebsiteCMD());

            friendCmdManager.init(this);
            ProxyServer.getInstance().getPluginManager().registerCommand(this, friendCmdManager);

            partyCmdManager.init(this);
            ProxyServer.getInstance().getPluginManager().registerCommand(this, partyCmdManager);

            ProxyServer.getInstance().getPluginManager().registerListener(this, new Join());
            ProxyServer.getInstance().getPluginManager().registerListener(this, new Leave());
        }

        @Override
        public void onDisable() {
            DB.INSTANCE.closeConnection();
        }
    }
     
    Any ideas?
     
    #1 DotRar, Jun 10, 2016
    Last edited: Jun 10, 2016
  2. If you solved the problem change it to solved.
     
  3.