Solved Error in PostLoginEvent

Discussion in 'BungeeCord Plugin Development' started by KalebP, May 1, 2017.

  1. Hey guys, I have this really weird error that I have no idea how to fix. Any help is appreciated! :D

    Code (Text):
    30.04 23:47:50 [Server] INFO Netty is not using direct IO buffers.
    30.04 23:47:50 [Server] WARNING Event PostLoginEvent(player=Kraft) took 305,460,846ns to process!
    30.04 23:47:50 [Server] INFO at java.lang.Thread.run(Thread.java:745)
    30.04 23:47:50 [Server] INFO at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:858)
    30.04 23:47:50 [Server] INFO at io.netty.channel.epoll.EpollEventLoop.run(EpollEventLoop.java:304)
    30.04 23:47:50 [Server] INFO at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:403)
    30.04 23:47:50 [Server] INFO at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163)
    30.04 23:47:50 [Server] INFO at net.md_5.bungee.connection.InitialHandler$6$1.run(InitialHandler.java:504)
    30.04 23:47:50 [Server] INFO at net.md_5.bungee.api.plugin.PluginManager.callEvent(PluginManager.java:377)
    30.04 23:47:50 [Server] INFO at net.md_5.bungee.event.EventBus.post(EventBus.java:46)
    30.04 23:47:50 [Server] INFO at net.md_5.bungee.event.EventHandlerMethod.invoke(EventHandlerMethod.java:19)
    30.04 23:47:50 [Server] INFO at java.lang.reflect.Method.invoke(Method.java:498)
    30.04 23:47:50 [Server] INFO at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    30.04 23:47:50 [Server] INFO at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    30.04 23:47:50 [Server] INFO at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    30.04 23:47:50 [Server] INFO at com.github.kraftykaleb.listeners.onJoin.onJoin(onJoin.java:55)
    30.04 23:47:50 [Server] INFO java.lang.NullPointerException
    30.04 23:47:50 [Server] INFO WARNING: Error dispatching event PostLoginEvent(player=Kraft) to listener [email protected]
    30.04 23:47:50 [Server] SEVERE Apr 30, 2017 11:47:49 PM net.md_5.bungee.event.EventBus post
     
  2. show your code

    specifically line 55, in method onJoin
     
  3. Code (Text):
    package com.github.kraftykaleb.listeners;

    import com.github.kraftykaleb.Main;
    import net.alpenblock.bungeeperms.BungeePerms;
    import net.md_5.bungee.api.ChatColor;
    import net.md_5.bungee.api.ProxyServer;
    import net.md_5.bungee.api.chat.TextComponent;
    import net.md_5.bungee.api.connection.ProxiedPlayer;
    import net.md_5.bungee.api.event.PlayerDisconnectEvent;
    import net.md_5.bungee.api.event.PostLoginEvent;
    import net.md_5.bungee.api.plugin.Listener;
    import net.md_5.bungee.config.Configuration;
    import net.md_5.bungee.config.ConfigurationProvider;
    import net.md_5.bungee.config.YamlConfiguration;
    import net.md_5.bungee.event.EventHandler;

    import java.text.DateFormat;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    import java.util.List;
    import java.util.concurrent.TimeUnit;

    /**
    * Created by Kraft on 4/19/2017.
    */
    public class onJoin implements Listener {

        private Main plugin;
        public onJoin(Main ins) { plugin = ins; }
        private ProxiedPlayer p;
        private ProxiedPlayer pl;

        @EventHandler
        public void onJoin(PostLoginEvent e) {
            p = e.getPlayer();
            plugin.findHypixelPlayer(p);
            plugin.findHypixelGuild(p);

            /*if (plugin.config.getString(p.getUniqueId().toString() + ".ip") != null) {
                if (!(p.getAddress().getAddress().toString().equals(plugin.config.getString(p.getUniqueId().toString() + ".ip")))) {
                    if (BungeePerms.getInstance().getPermissionsChecker().hasPerm(p.getName(), "soontm.staff")) {
                        p.disconnect(new TextComponent(ChatColor.RED + "You have been permanently banned from this server. \nYour account might be compromised, since this is a staff account. \nPlease contact a guild admin to be unbanned."));
                        return;
                    }
                }
            } else *///{

                //FIRST JOIN OF THE SERVER
            if (plugin.config.get(p.getUniqueId().toString()) == null) {
                List<String> names = null;
                DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
                Date date = new Date();
                //System.out.println(dateFormat.format(date));

                names.add(p.getName());

                plugin.config.set(p.getUniqueId().toString() + ".aliases", names);
                plugin.config.set(p.getUniqueId().toString() + ".ip", p.getAddress().getAddress());
                plugin.config.set(p.getUniqueId().toString() + ".lastlogin", dateFormat.format(date));
                plugin.saveFile(plugin, plugin.config, "config.yml");
            }

            if (!(plugin.config.getList(p.getUniqueId() + ".aliases").contains(p.getName()))) {

                List<String> configList = (List<String>) plugin.config.getList(p.getUniqueId() + ".aliases");
                configList.add(p.getName());
                plugin.config.set(p.getUniqueId() + ".aliases", configList);
                plugin.saveFile(plugin, plugin.config, "config.yml");
            }

            ProxyServer.getInstance().getScheduler().schedule(plugin, new Runnable() {
                public void run() {
                    staffJoin(p);
                }
            }, 1, TimeUnit.SECONDS);
        }

        @EventHandler
        public void onLeave(PlayerDisconnectEvent event) {
            pl = event.getPlayer();
            ProxyServer.getInstance().getScheduler().schedule(plugin, new Runnable() {
                public void run() {
                    staffLeave(pl);
                }
            }, 1, TimeUnit.SECONDS);
        }

        public void staffJoin (ProxiedPlayer player) {
            if (BungeePerms.getInstance().getPermissionsManager().getUser(player.getName()).hasPerm("soontm.staff") || player.getDisplayName().contains("ADMIN") || player.getDisplayName().contains("MOD") || player.getDisplayName().contains("HELPER")) {
                for (ProxiedPlayer player1 : ProxyServer.getInstance().getPlayers()) {
                    if (BungeePerms.getInstance().getPermissionsManager().getUser(player1.getName()).hasPerm("soontm.staff")) {
                        player1.sendMessage(new TextComponent(ChatColor.DARK_GREEN + "[STAFF] " + player.getDisplayName() + ChatColor.YELLOW + " joined."));
                    }
                }
            }
        }

        public void staffLeave (ProxiedPlayer player) {
            if (BungeePerms.getInstance().getPermissionsManager().getUser(player.getName()).hasPerm("soontm.staff") || player.getDisplayName().contains("ADMIN") || player.getDisplayName().contains("MOD") || player.getDisplayName().contains("HELPER")) {
                for (ProxiedPlayer player1 : ProxyServer.getInstance().getPlayers()) {
                    if (BungeePerms.getInstance().getPermissionsManager().getUser(player1.getName()).hasPerm("soontm.staff")) {
                        player1.sendMessage(new TextComponent(ChatColor.DARK_GREEN + "[STAFF] " + player.getDisplayName() + ChatColor.YELLOW + " left."));
                    }
                }
            }
        }
    }
    Line 55 is names.add(p.getName());
     
  4. line 55:
    Code (Text):
     names.add(p.getName());
    some lines before you said names = null so this line throw a NullpointerException
     
    • Like Like x 1
  5. Code (Java):

    List<String> names = null;
    names.add(p.getName());
     
  6. LOL thanks XD