Could not pass event PlayerJoinEvent problem!

Discussion in 'Plugin Development' started by harhar4932843098234, May 2, 2016.

Thread Status:
Not open for further replies.
  1. I have been getting this error while trying to run my plugin to send the user a message when they join.

    Code:
    C:\Users\Edgar\Desktop\Server>java -Xms4G -Xmx4G -jar bukkit.jar nogui
    Loading libraries, please wait...
    [13:32:20 INFO]: Starting minecraft server version 1.8.8
    [13:32:20 INFO]: Loading properties
    [13:32:20 INFO]: Default game type: SURVIVAL
    [13:32:20 INFO]: Generating keypair
    [13:32:20 INFO]: Starting Minecraft server on *:25565
    [13:32:20 INFO]: Using default channel type
    [13:32:20 INFO]: This server is running CraftBukkit version git-Bukkit-efe04b8 (MC: 1.8.8) (Implementing API version 1.8.8-R0.1-SNAPSHOT)
    [13:32:20 WARN]: Plugin `Tutorial_Plugin v1.0' uses the space-character (0x20) in its name `Tutorial Plugin' - this is discouraged
    [13:32:21 INFO]: [PermissionsEx] Loading PermissionsEx v1.23.4
    [13:32:21 INFO]: [KeyPlugin] Loading KeyPlugin v1.0
    [13:32:21 INFO]: [Tutorial_Plugin] Loading Tutorial_Plugin v1.0
    [13:32:21 INFO]: [ChatMod] Loading ChatMod v3.0
    [13:32:21 INFO]: Preparing level "world"
    [13:32:21 INFO]: Preparing start region for level 0 (Seed: -7610043799451013904)
    [13:32:21 INFO]: Preparing start region for level 1 (Seed: 6921811553263457330)
    [13:32:22 INFO]: Preparing start region for level 2 (Seed: 6921811553263457330)
    [13:32:22 INFO]: [PermissionsEx] Enabling PermissionsEx v1.23.4
    [13:32:22 INFO]: [PermissionsEx] Initializing file backend
    [13:32:22 INFO]: [PermissionsEx] Permissions file successfully reloaded
    [13:32:22 INFO]: [KeyPlugin] Enabling KeyPlugin v1.0
    [13:32:22 INFO]: [KeyPlugin] KeyPlugin has been enabled (V.1.0)
    [13:32:22 INFO]: [Tutorial_Plugin] Enabling Tutorial_Plugin v1.0
    [13:32:22 INFO]: [Tutorial_Plugin] Tutorial_Plugin has been enabled (V.1.0)
    [13:32:22 INFO]: [ChatMod] Enabling ChatMod v3.0
    [13:32:22 INFO]: [ChatMod] ChatMod has been enabled (V.3.0)
    [13:32:22 INFO]: Server permissions file permissions.yml is empty, ignoring it
    [13:32:22 INFO]: Done (1.466s)! For help, type "help" or "?"
    [13:32:26 INFO]: UUID of player Pigwitash is f26fb96f-10a1-477c-b1f3-a33636a43bdb
    [13:32:26 ERROR]: Could not pass event PlayerJoinEvent to KeyPlugin v1.0
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302) ~[bukkit.jar:git-Bukkit-efe04b8]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[bukkit.jar:git-Bukkit-efe04b8]
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:501) [bukkit.jar:git-Bukkit-efe04b8]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:486) [bukkit.jar:git-Bukkit-efe04b8]
            at net.minecraft.server.v1_8_R3.PlayerList.onPlayerJoin(PlayerList.java:282) [bukkit.jar:git-Bukkit-efe04b8]
            at net.minecraft.server.v1_8_R3.PlayerList.a(PlayerList.java:142) [bukkit.jar:git-Bukkit-efe04b8]
            at net.minecraft.server.v1_8_R3.LoginListener.b(LoginListener.java:115) [bukkit.jar:git-Bukkit-efe04b8]
            at net.minecraft.server.v1_8_R3.LoginListener.c(LoginListener.java:53) [bukkit.jar:git-Bukkit-efe04b8]
            at net.minecraft.server.v1_8_R3.NetworkManager.a(NetworkManager.java:222) [bukkit.jar:git-Bukkit-efe04b8]
            at net.minecraft.server.v1_8_R3.ServerConnection.c(SourceFile:168) [bukkit.jar:git-Bukkit-efe04b8]
            at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:745) [bukkit.jar:git-Bukkit-efe04b8]
            at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:335) [bukkit.jar:git-Bukkit-efe04b8]
            at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:629) [bukkit.jar:git-Bukkit-efe04b8]
            at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:537) [bukkit.jar:git-Bukkit-efe04b8]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_77]
    Caused by: java.lang.NullPointerException
            at me.pigwitash.key.Main.onPlayerJoin(Main.java:48) ~[?:?]
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_77]
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_77]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_77]
            at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_77]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:300) ~[bukkit.jar:git-Bukkit-efe04b8]
            ... 14 more
    [13:32:26 INFO]: Pigwitash[/127.0.0.1:53468] logged in with entity id 294 at ([world]-53.75104131556955, 72.0, -65.65860375524048)
    >
    My code:
    Code:
    public void onPlayerJoin(PlayerJoinEvent e) {
            final HashMap<UUID, Long> hashmap = new HashMap<UUID, Long>();
            Player player = e.getPlayer();
            //Date now = new Date();
            long systime = System.currentTimeMillis();
            hashmap.put(player.getUniqueId(), systime);
            //Added systime and UUID to hashmap
            player.sendMessage("Hi!");
            player.sendMessage(ChatColor.RED + "False.");
            player.sendMessage(Long.toString(systime));
            player.sendMessage(Long.toString(hashmap.get(0)));
           
            while (!(System.currentTimeMillis() - (hashmap.get(1)) == 1000)) {
                player.sendMessage("Hi2");
                //Run get key code
                if (System.currentTimeMillis() - (hashmap.get(1)) == 1000) {
                    player.sendMessage(ChatColor.BLUE + "You have been on the server long enough to earn yourself a key!");
                }
            }
           
           
                   
        }
     
  2. Offline

    mine-care

    For more information about this issue refer to this post.
    Also, please refer to the docs about Maps and how they are used / what they do.
     
  3. Offline

    KingDragonRider

    HashMaps are not indexed like ArrayLists. Therefore you aren't able to get an item at index 0 like you are trying to do with this:

    hashmap.get(0);

    And therefore it's returning null as there is no value associated with the key of "0". You will have to create your own implementation, perhaps by creating a class that has add/remove methods, which add/remove keys to both the map and an ArrayList.
     
  4. Offline

    I Al Istannen

    @harhar4932843098234
    And you are lucky it had a NPE. You used a while loop to check for the time. And you did so on the main thread AFAIK.

    The while loop runs as fast as it can and NO other action can be done by the server until the while loop ends. So you tell the server to run this loop over and over again. This means the server won't have time to process things like player movement, physics and generally everything. The result is a time out for every player and maybe a crash of the server. This is most likely not what you want (at least I hope so :D).

    You will need to use a Repeating task (with a BukkitRunnable or the Scheduler directly). The explanation of this can be found here. It would be better to not create a new Task for every joining player, to save resources.

    You had the right idea, but you probably failed at your Java knowledge. You need to make the Map a field to be able to a) check them from the whole class and b) to not create a new one at every login event. Then add the player to the map if he joins and check the Map in a repeating task.

    I know you are quite new to Java, so ask if you didn't understand something. And please continue learning Java, as many errors can be solved by knowing Java a bit better.
     
    harhar4932843098234 likes this.
  5. Helpful, I know my knowledge is limited and it bugs me, could you please give me a direct code fix for this and then explain?
     
  6. Offline

    mine-care

    @KingDragonRider
    :p
    Also I don't see how a collection of map is needed there anyway.
     
Thread Status:
Not open for further replies.

Share This Page