Vault NullPointerException

Status
This thread has been locked.

Clems02

Feedback score
0
Posts
15
Reactions
0
Resources
0
Hi,
I have a NullPointerException in the console why I call a method in a class with eco.withdraw... (vault)
I don't know why because in other class like my listener it's work...

Code:
[12:54:30 ERROR]: Could not pass event InventoryClickEvent to PickaxeTestYML v1.0
org.bukkit.event.EventException: null
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot.jar:git-Spigot-dcd1643-e60fc34]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-dcd1643-e60fc34]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:500) [spigot.jar:git-Spigot-dcd1643-e60fc34]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:485) [spigot.jar:git-Spigot-dcd1643-e60fc34]
        at net.minecraft.server.v1_12_R1.PlayerConnection.a(PlayerConnection.java:1891) [spigot.jar:git-Spigot-dcd1643-e60fc34]
        at net.minecraft.server.v1_12_R1.PacketPlayInWindowClick.a(SourceFile:33) [spigot.jar:git-Spigot-dcd1643-e60fc34]
        at net.minecraft.server.v1_12_R1.PacketPlayInWindowClick.a(SourceFile:10) [spigot.jar:git-Spigot-dcd1643-e60fc34]
        at net.minecraft.server.v1_12_R1.PlayerConnectionUtils$1.run(SourceFile:13) [spigot.jar:git-Spigot-dcd1643-e60fc34]
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_211]
        at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_211]
        at net.minecraft.server.v1_12_R1.SystemUtils.a(SourceFile:46) [spigot.jar:git-Spigot-dcd1643-e60fc34]
        at net.minecraft.server.v1_12_R1.MinecraftServer.D(MinecraftServer.java:748) [spigot.jar:git-Spigot-dcd1643-e60fc34]
        at net.minecraft.server.v1_12_R1.DedicatedServer.D(DedicatedServer.java:406) [spigot.jar:git-Spigot-dcd1643-e60fc34]
        at net.minecraft.server.v1_12_R1.MinecraftServer.C(MinecraftServer.java:679) [spigot.jar:git-Spigot-dcd1643-e60fc34]
        at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:577) [spigot.jar:git-Spigot-dcd1643-e60fc34]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_211]
Caused by: java.lang.NullPointerException
        at fr.clems.pickaxe.Anvil.anvilUSE(Anvil.java:49) ~[?:?]
        at fr.clems.pickaxe.EventListener.onClickInventory(EventListener.java:154) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_211]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_211]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_211]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_211]
        at org.bukkit

Code:
public class Main extends JavaPlugin {
   
    public static Economy economy = null;
   
    private Book book = new Book(this);
    private Gui gui = new Gui(this);
    private Anvil anvil = new Anvil(this);
       
    @Override
    public void onEnable() {
        setupEconomy();
       
        getConfig().options().copyDefaults(true);
        saveDefaultConfig();
       
        getServer().getPluginManager().registerEvents(new EventListener(this), this);
       
        getCommand("efficiency").setExecutor(new Commands(this));
        getCommand("fortune").setExecutor(new Commands(this));
        getCommand("unbreaking").setExecutor(new Commands(this));
       
        getCommand("set").setExecutor(new CommandsAdmin());
    }
   
    public void onDisable() {       
    }
   
    private boolean setupEconomy() {
        RegisteredServiceProvider<Economy> economyProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
        if (economyProvider != null) {
            economy = economyProvider.getProvider();
        }
        return (economy != null);
    }


}

Code:
    private FileConfiguration config;
    private Main main;
    private Economy eco;
   
    public Anvil(Main main) {
        this.main = main;
        this.config = main.getConfig();
        this.eco = Main.economy;
    }


    public void anvilUSE(Player p) {
        p.getInventory().getItem(0).setDurability((short) 0);
        eco.withdrawPlayer(p, 1000);
        System.out.println("test");
    }

Code:
            if(nameItem.equalsIgnoreCase("§aRepair")) {
                new Anvil().anvilUSE(p);
            }

Can you help me please ? Thank's a lot
 
PebbleHost
High performance, consistent uptime and fast support. Minecraft hosting that just works.

Clems02

Feedback score
0
Posts
15
Reactions
0
Resources
0
I know I need to do it, I'll do it after. But I already want to withdraw 1000 before making the loop.

And when I try the plugin, I have 1000 :p
 

Clems02

Feedback score
0
Posts
15
Reactions
0
Resources
0
Don't working. The problem is the vault plugin.
When I use "eco." in this class, it's make me an error.
 

BidoofIsBae

Feedback score
3
Posts
49
Reactions
16
Resources
0
It might be because the economy did not load properly, you call the boolean method "setupEconomy" yet you do not check it's value, if you try to call a method on a null object it will cause a NullPointerException, so likely the economy did not start up well, and since you didn't check the return value of setupEconomy you have no way of knowing.
 
Status
This thread has been locked.
Top