SOLVED - Keep Getting Errors

Discussion in 'Spigot Plugin Development' started by TechWiz, Jun 2, 2015.

  1. I keep getting errors in my plugin when I try to handle the event. Code:

    Code (Text):
    package me.techwiz.penceperkill;
    import net.milkbowl.vault.economy.Economy;
    import net.milkbowl.vault.economy.EconomyResponse;
    import org.bukkit.ChatColor;
    import org.bukkit.entity.LivingEntity;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.EntityDeathEvent;
    import org.bukkit.plugin.RegisteredServiceProvider;
    import org.bukkit.plugin.java.JavaPlugin;
    public class Main extends JavaPlugin implements Listener {

        @Override
        public void onEnable() {
           
            getServer().getPluginManager().registerEvents(this, this);
        }
        public void setupVaultEconomy(){
           
            RegisteredServiceProvider<Economy> economyProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
            if (economyProvider != null) {
            economyProvider.getProvider();
                   
            }
        }
        public static Economy economy = null;
       
       
        @SuppressWarnings("unused")
        private boolean setupEconomy() {
          RegisteredServiceProvider<Economy> economyProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
           if (economyProvider != null) {
             economy = economyProvider.getProvider();
           }
           return (economy != null);
        }
         
        @EventHandler
        public static void onEntityDeathEvent(EntityDeathEvent event) {
           
            LivingEntity entity = event.getEntity();
            Player killer = entity.getKiller();
           
              if (killer instanceof Player) {
               
                EconomyResponse response = economy.depositPlayer(killer, 0.5);
                if (response.transactionSuccess()) {
                  killer.sendMessage(ChatColor.GREEN + "Good Job, " + killer.getDisplayName() + "! You killed a " + entity.getName() + "and recieved" + ChatColor.RED + "£0.50");
               
                }
            }
        }
    }
     
    I've tried everything like calling the method, which I couldn't do. In the error it says
    Caused by: java.lang.NullPointerException at me.techwiz.penceperkill.Main.onEntityDeathEvent(Main.java:57)

    Line 57? I can't see any errors within that line or any code that interfere's with it. Please help!
     
  2. Line 57 is:
     
  3. Code (Text):
       Player killer = entity.getKiller();
         
               if (killer instanceof Player) {
    Wut ?

    To fix this, call setupEconomy() in the onEnable() and go learn some Java.
     
    • Agree Agree x 1
  4. Thank You So Much!