Solved Could not pass event PlayerJoinEvent to Waypoints v1.0.0

Discussion in 'Plugin Development' started by mccrafter1212, May 27, 2017.

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

    mccrafter1212

    So, I'm getting this error (It's in the title). It's pretty self-explanatory. Here's my code in my class called AllEvents:

    Code:
    package me.mccrafter1212.AdminWaypoints.Events;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    
    import me.mccrafter1212.AdminWaypoints.Main;
    
    public class AllEvents implements Listener {
       
        Main plugin;
       
        public AllEvents(Main instance) {
            this.plugin = instance;
        }
       
        public void teleportToLocation(Player player, int x, int y, int z) {
            player.teleport(new Location(player.getWorld(), x, y, z));
        }
       
        public void runWaypointGUI(Player player) {
            Inventory inv = Bukkit.createInventory(null, 9, ChatColor.GREEN + "Waypoints");
           
            for (int i = 0; i < plugin.getConfig().getList("waypoints").size(); i++) {
                ItemStack newItem = new ItemStack(Material.BEACON);
                ItemMeta newItemMeta = newItem.getItemMeta();
               
                String name = plugin.getConfig().getString("waypoints." + plugin.getConfig().getConfigurationSection("waypoints").getKeys(false).toArray()[i] + ".name");
               
                newItemMeta.setDisplayName(ChatColor.DARK_PURPLE + name);
            }
           
           
           
        }
       
        @EventHandler
        public void giveCompass(PlayerJoinEvent e) {
            Player plr = e.getPlayer();
           
            Bukkit.getServer().broadcastMessage(ChatColor.GREEN + "Player Joined: " + plr.getName());
           
            plr.getInventory().addItem(new ItemStack(Material.COMPASS));
           
            String waypointName = plugin.getConfig().getList("waypoints").get(0).toString();
            plr.sendMessage(ChatColor.GREEN + waypointName);
           
        }
       
        @EventHandler
        public void onPlayerInteract(PlayerInteractEvent e) {
            Action a = e.getAction();
            ItemStack is = e.getItem();
           
            if (a == Action.PHYSICAL || is == null || is.getType() == Material.AIR)
                return;
           
            if (is.getType() == Material.COMPASS)
                runWaypointGUI(e.getPlayer());
           
        }
    }
    
    My main class:
    Code:
    package me.mccrafter1212.AdminWaypoints;
    
    import org.bukkit.plugin.java.JavaPlugin;
    
    import me.mccrafter1212.AdminWaypoints.Events.AllEvents;
    
    public class Main extends JavaPlugin {
       
        public void onEnable() {
            System.out.println("[AW] AdminWaypoints has started up successfully!");
            getConfig().options().copyDefaults(true);
            saveConfig();
            getServer().getPluginManager().registerEvents(new AllEvents(this), this);
        }
       
        public void onDisable() {
            System.out.println("[AW] AdminWaypoints has shutdown successfully!");
            saveConfig();
        }
       
    }
    
    The error:
    Code:
    [12:39:51 ERROR]: Could not pass event PlayerJoinEvent to AdminWaypoints v1.0.0
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:298) ~[craftbukkit.jar:git-Bukkit-6e3cec8]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[craftbukkit.jar:git-Bukkit-6e3cec8]
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:501) [craftbukkit.jar:git-Bukkit-6e3cec8]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:486) [craftbukkit.jar:git-Bukkit-6e3cec8]
            at net.minecraft.server.v1_11_R1.PlayerList.onPlayerJoin(PlayerList.java:311) [craftbukkit.jar:git-Bukkit-6e3cec8]
            at net.minecraft.server.v1_11_R1.PlayerList.a(PlayerList.java:145) [craftbukkit.jar:git-Bukkit-6e3cec8]
            at net.minecraft.server.v1_11_R1.LoginListener.b(LoginListener.java:119) [craftbukkit.jar:git-Bukkit-6e3cec8]
            at net.minecraft.server.v1_11_R1.LoginListener.F_(LoginListener.java:57) [craftbukkit.jar:git-Bukkit-6e3cec8]
            at net.minecraft.server.v1_11_R1.NetworkManager.a(NetworkManager.java:224) [craftbukkit.jar:git-Bukkit-6e3cec8]
            at net.minecraft.server.v1_11_R1.ServerConnection.c(SourceFile:187) [craftbukkit.jar:git-Bukkit-6e3cec8]
            at net.minecraft.server.v1_11_R1.MinecraftServer.D(MinecraftServer.java:765) [craftbukkit.jar:git-Bukkit-6e3cec8]
            at net.minecraft.server.v1_11_R1.DedicatedServer.D(DedicatedServer.java:360) [craftbukkit.jar:git-Bukkit-6e3cec8]
            at net.minecraft.server.v1_11_R1.MinecraftServer.C(MinecraftServer.java:650) [craftbukkit.jar:git-Bukkit-6e3cec8]
            at net.minecraft.server.v1_11_R1.MinecraftServer.run(MinecraftServer.java:554) [craftbukkit.jar:git-Bukkit-6e3cec8]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_131]
    Caused by: java.lang.NullPointerException
            at me.mccrafter1212.AdminWaypoints.Events.AllEvents.giveCompass(AllEvents.java:55) ~[?:?]
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_131]
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_131]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_131]
            at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_131]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:296) ~[craftbukkit.jar:git-Bukkit-6e3cec8]
            ... 14 more
    
    Finally, my config.yml:
    Code:
    # AdminWaypoints by astrealdev
    # This is the configuration file.
    # It comes with a default waypoint (Spawn) and default values put in.
    # Editing shouldn't be too hard. Contact me on Bukkit if you have any questions.
    # NOTE: The compass is the item used to open the waypoint GUI. As of version 1.0.0 this can't be changed. In future versions it might be custom.
    
    waypoints:
      Spawn:
        x: 0
        y: 50
        z: 0
        name: Spawn
      Test:
        x: 5
        y: 50
        z: 5
        name: Spawn
    
    Hope someone can help me! I'm really not sure what's causing this.
     
  2. Offline

    timtower Administrator Administrator Moderator

    @mccrafter1212 waypoints is not a list, it is a ConfigurationSection.
    You need to use getKeys(false) on it, then you get the keys, you can loop over them.
     
    mccrafter1212 likes this.
  3. Offline

    mccrafter1212

Thread Status:
Not open for further replies.

Share This Page