PlayerJoinEvent not working :/

Discussion in 'Plugin Help/Development/Requests' started by AFK Games, Jun 26, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    AFK Games

    Hey, i have a server (craftbukkit 1.8.7) hosted 24/7 - anyway, back to the point i have the java event for PlayerJoinEvent and it just wont seem to work, i have registered the events and i have a PlayerQuitEvent and that works fine but... i think its my static classes or something, please help. Here is everything you need:

    LoginListener.java
    Code:
    package me.AFKGames.AFKGamesNetworkCore;
    
    import org.bukkit.ChatColor;
    import org.bukkit.Color;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerExpChangeEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.event.player.PlayerQuitEvent;
    
    public class LoginListener implements Listener {
       
        DeathsListener death;
        PermissionsManager perms;
        TitleManager title;
       
        @EventHandler(priority=EventPriority.HIGH)
        public void onPlayerJoin(PlayerJoinEvent e)
        {           
            e.getPlayer().setPlayerListName(ChatColor.BLUE + "(" + e.getPlayer().getLevel() + ") " + ChatColor.GRAY + e.getPlayer().getName());
                   
            perms.UpdatePermissions(e.getPlayer());       
            //title.sendTabMenuInfo(e.getPlayer(), "" + ChatColor.BLUE + ChatColor.BOLD + "AFK Games Network v2", ChatColor.YELLOW + "VIP Rank Soon Available @ £3.00/m");       
            //title.SendTitle(e.getPlayer(), ChatColor.BLUE + "Welcome back!", ChatColor.LIGHT_PURPLE + "Thanks for coming back.");
       
            death.LaunchFirework(e.getPlayer().getLocation(), Color.BLUE);
            e.getPlayer().sendMessage(ChatColor.GRAY + "---------------------------------------");
            e.getPlayer().sendMessage(ChatColor.GRAY + "Welcome to AFK Games Network Version 2!");
            e.getPlayer().sendMessage(ChatColor.GRAY + "This server has now turned to survival, we have tpa, homes, exp level system, ranks & more! Become a VIP soon for more exclusive features! :)");
            e.getPlayer().performCommand("/stats");
            e.getPlayer().sendMessage(ChatColor.GRAY + "---------------------------------------");
           
            e.setJoinMessage(ChatColor.GRAY + e.getPlayer().getName() + " has joined the survival.");
        }
       
        @EventHandler
        public void onPlayerQuit(PlayerQuitEvent e)
        {       
            e.setQuitMessage(ChatColor.GRAY + e.getPlayer().getName() + " has left the survival.");
        }
       
        @EventHandler
        public void onExpChange(PlayerExpChangeEvent e)
        {
            e.getPlayer().setPlayerListName(ChatColor.BLUE + "(" + e.getPlayer().getLevel() + ") " + ChatColor.GRAY + e.getPlayer().getName());
        }
    }
    
    
    
    DeathsListener.java
    Code:
    package me.AFKGames.AFKGamesNetworkCore;
    
    import java.lang.reflect.Field;
    
    import org.bukkit.ChatColor;
    import org.bukkit.Color;
    import org.bukkit.FireworkEffect;
    import org.bukkit.FireworkEffect.Type;
    import org.bukkit.Location;
    import org.bukkit.entity.EntityType;
    import org.bukkit.entity.Firework;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.PlayerDeathEvent;
    import org.bukkit.inventory.meta.FireworkMeta;
    
    public class DeathsListener implements Listener {
    
       
        public void LaunchFirework(Location location, Color color)
        {
            Firework fw = (Firework) location.getWorld().spawn(location, Firework.class);
            FireworkEffect effect = FireworkEffect.builder().trail(true).flicker(false).withColor(color).with(Type.BALL_LARGE).build();
            FireworkMeta fwm = fw.getFireworkMeta();
            fwm.clearEffects();
            fwm.addEffect(effect);
           
            Field f;
           
            try
            {
                  f = fwm.getClass().getDeclaredField("power");
                  f.setAccessible(true);
                  f.set(fwm, -2);
            }
            catch(Exception f1)
            {
               
            }
          
            fw.setFireworkMeta(fwm);
        }
       
        @EventHandler
        public void onPlayerDeath(PlayerDeathEvent e)
        {
            e.setDeathMessage(null);
            e.getEntity().sendMessage(ChatColor.GRAY + "------------------------------------");
            e.getEntity().sendMessage(ChatColor.RED + "You were killed! Bad luck.");
            e.getEntity().sendMessage(ChatColor.GREEN + "Better luck next time...");
            e.getEntity().sendMessage(ChatColor.GRAY + "Your exp level was reset to 0.");
            e.getEntity().sendMessage(ChatColor.GRAY + "You have lost all items in your inventory.");       
            e.getEntity().sendMessage(ChatColor.GRAY + "------------------------------------");
           
            LaunchFirework(e.getEntity().getLocation(), Color.RED);   
           
            if(e.getEntity().getKiller().getType().equals(EntityType.PLAYER))
            {
                e.getEntity().getKiller().sendMessage(ChatColor.RED + "You killed " + e.getEntity().getName());
                e.getEntity().getKiller().sendMessage(ChatColor.GREEN + "Well done my friend! Good kill.");
            }
           
            e.getEntity().setPlayerListName(ChatColor.BLUE + "(" + e.getEntity().getLevel() + ") " + ChatColor.GRAY + e.getEntity().getName());
           
        }
       
    }
    
    PermissionsManager.java
    Code:
    package me.AFKGames.AFKGamesNetworkCore;
    
    import org.bukkit.entity.Player;
    import org.bukkit.permissions.PermissionAttachment;
    
    public class PermissionsManager {
       
        static MainClass configGetter;
       
        public void UpdatePermissions(Player p)
        {       
            RankManagement.UpdateRanks();
            PermissionAttachment at = p.addAttachment(configGetter);
           
            if(RankManagement.getRank(p).equalsIgnoreCase("Guest"))
            {
                //DISABLE GUEST COMMANDS ETC AND MVP RANKS ETC... (ALL NON-OPS)
                at.setPermission("bukkit.command.plugins", false);
                at.setPermission("bukkit.command.version", false);
                at.setPermission("bukkit.command.help", false);
                at.setPermission("bukkit.command.kill", false);
                at.setPermission("bukkit.command.me", false);
                at.setPermission("bukkit.command.tell", false);
            }
           
            at.setPermission("bedhome.bed", true);
            at.setPermission("bedhome.world", true);
           
        }
       
    }
    
    TitleManager.java
    Code:
    package me.AFKGames.AFKGamesNetworkCore;
    
    import java.lang.reflect.Field;
    
    import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
    import org.bukkit.entity.Player;
    
    import net.minecraft.server.v1_8_R3.IChatBaseComponent;
    import net.minecraft.server.v1_8_R3.IChatBaseComponent.ChatSerializer;
    import net.minecraft.server.v1_8_R3.PacketPlayOutChat;
    import net.minecraft.server.v1_8_R3.PacketPlayOutPlayerListHeaderFooter;
    import net.minecraft.server.v1_8_R3.PacketPlayOutTitle;
    import net.minecraft.server.v1_8_R3.PacketPlayOutTitle.EnumTitleAction;
    import net.minecraft.server.v1_8_R3.PlayerConnection;
    
    public class TitleManager {
    
        public void SendTitle(Player pl, String title, String subtitle)
        {
            IChatBaseComponent chatTitle = ChatSerializer.a("{\"text\": \"" + title + "\"}");
            IChatBaseComponent chatSubTitle = ChatSerializer.a("{\"text\": \"" + subtitle + "\"}");
            PacketPlayOutTitle p = new PacketPlayOutTitle(EnumTitleAction.TITLE, chatTitle);
            PacketPlayOutTitle p2 = new PacketPlayOutTitle(EnumTitleAction.SUBTITLE, chatSubTitle);
            ((CraftPlayer)pl).getHandle().playerConnection.sendPacket(p);
            ((CraftPlayer)pl).getHandle().playerConnection.sendPacket(p2);         
        }
       
        //FOR ABOVE THE ITEM SELECTION THING AT THE BOTTOM!
        public void sendActionBar(Player player, String message)
        {
            IChatBaseComponent cbc = ChatSerializer.a("{\"text\": \"" + message + "\"}");
            PacketPlayOutChat ppoc = new PacketPlayOutChat(cbc, (byte) 2);
            ((CraftPlayer)player).getHandle().playerConnection.sendPacket(ppoc);
        }
       
        public void sendTabMenuInfo(Player player, String header, String footer)
        {
            PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection;
            IChatBaseComponent tabTitle = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + header + "\"}");
            IChatBaseComponent tabFoot = IChatBaseComponent.ChatSerializer.a("{\"text\": \"" + footer + "\"}");
            PacketPlayOutPlayerListHeaderFooter headerPacket = new PacketPlayOutPlayerListHeaderFooter(tabTitle);
    
            try {
                Field field = headerPacket.getClass().getDeclaredField("b");
                field.setAccessible(true);
                field.set(headerPacket, tabFoot);
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                connection.sendPacket(headerPacket);
            }
        }
       
       
    }
    
     
  2. Offline

    MCMatters

  3. Offline

    AFK Games

    I have registered the events though...
     
  4. Moved to Bukkit Alternates.

    @MCMatters Please report the thread rather than tagging a Moderator.
     
  5. Offline

    Boomer

    And what is "doesn't work"
    Not seeing a particular effect?
    Errors thrown during startup sequence of log?
    Errors thrown when player logs in?
    Somethign that should be shown in yellow is shown in green?
     
  6. Offline

    AFK Games

    Yes:

    Code:
    27.06 12:27:02 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:300) ~[craftbukkit-BT38_1.8.7_06.10.jar:git-Bukkit-1880a9c]
    27.06 12:27:02 [Server] INFO at java.lang.reflect.Method.invoke(Method.java:497) ~[?:1.8.0_45]
    27.06 12:27:02 [Server] INFO at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_45]
    27.06 12:27:02 [Server] INFO at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_45]
    27.06 12:27:02 [Server] INFO at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_45]
    27.06 12:27:02 [Server] INFO at me.AFKGames.AFKGamesNetworkCore.LoginListener.onPlayerJoin(LoginListener.java:24) ~[?:?]
    27.06 12:27:02 [Server] INFO at me.AFKGames.AFKGamesNetworkCore.LoginListener.LoginPlayer(LoginListener.java:29) ~[?:?]
    27.06 12:27:02 [Server] INFO Caused by: java.lang.NullPointerException
    27.06 12:27:02 [Server] INFO at java.lang.Thread.run(Thread.java:745) [?:1.8.0_45]
    27.06 12:27:02 [Server] INFO at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:540) [craftbukkit-BT38_1.8.7_06.10.jar:git-Bukkit-1880a9c]
    27.06 12:27:02 [Server] INFO at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:632) [craftbukkit-BT38_1.8.7_06.10.jar:git-Bukkit-1880a9c]
    27.06 12:27:02 [Server] INFO at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:335) [craftbukkit-BT38_1.8.7_06.10.jar:git-Bukkit-1880a9c]
    27.06 12:27:02 [Server] INFO at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:748) [craftbukkit-BT38_1.8.7_06.10.jar:git-Bukkit-1880a9c]
    27.06 12:27:02 [Server] INFO at net.minecraft.server.v1_8_R3.ServerConnection.c(SourceFile:168) [craftbukkit-BT38_1.8.7_06.10.jar:git-Bukkit-1880a9c]
    27.06 12:27:02 [Server] INFO at net.minecraft.server.v1_8_R3.NetworkManager.a(NetworkManager.java:222) [craftbukkit-BT38_1.8.7_06.10.jar:git-Bukkit-1880a9c]
    27.06 12:27:02 [Server] INFO at net.minecraft.server.v1_8_R3.LoginListener.c(LoginListener.java:53) [craftbukkit-BT38_1.8.7_06.10.jar:git-Bukkit-1880a9c]
    27.06 12:27:02 [Server] INFO at net.minecraft.server.v1_8_R3.LoginListener.b(LoginListener.java:115) [craftbukkit-BT38_1.8.7_06.10.jar:git-Bukkit-1880a9c]
    27.06 12:27:02 [Server] INFO at net.minecraft.server.v1_8_R3.PlayerList.a(PlayerList.java:142) [craftbukkit-BT38_1.8.7_06.10.jar:git-Bukkit-1880a9c]
     
  7. Offline

    Boomer

    that doesn't look like a complete error - but its a good start.
    Code:
    27.06 12:27:02 [Server] INFO at me.AFKGames.AFKGamesNetworkCore.LoginListener.onPlayerJoin(LoginListener.java:24) ~[?:?]
    27.06 12:27:02 [Server] INFO at me.AFKGames.AFKGamesNetworkCore.LoginListener.LoginPlayer(LoginListener.java:29) ~[?:?]
    27.06 12:27:02 [Server] INFO Caused by: java.lang.NullPointerException
    
    Your error looks inconsistant with the line numbering for the code as it implies an error on 24 pr 29, yet 29 is a simple send-message, 24 is the permissions line. 29 has nothing dereferenced except the event/player which wont be null.
    So lets focus on line 24:
    perms.UpdatePermissions(e.getPlayer());

    Two things can throw a null at this point due to dereferencing - dereferencing the event object e - which isn't null - or dereferencing perms to access the method. (To consider all possibilities of null, e.getPlayer() could be null and pass null downstream to the method, but, no, it cant be null in this method). So only one possibility exists on this line for null things -- perms

    You have the perms object defined in the class, but not initialized anywhere in the class, so it IS null when that code is executed. (Nor is deathlistener or titlemanager initialized in that class either)
     
Thread Status:
Not open for further replies.

Share This Page