1.15.2 Error when using Economy

Discussion in 'Spigot Plugin Development' started by YJJcoolcool, Apr 11, 2020.

  1. Hi, I'm making a plugin and there is one part which deducts money from a player's account. But when I use the withdrawPlayer or getBalance function, the plugin doesn't work and just throws an error.

    Here is the main class:
    Code (Text):
    package yjjcity.plugins.Cashiers;

    import org.bukkit.Bukkit;
    import org.bukkit.plugin.RegisteredServiceProvider;
    import org.bukkit.plugin.java.JavaPlugin;
    import net.milkbowl.vault.economy.Economy;
    import net.milkbowl.vault.economy.Economy;

    import net.md_5.bungee.api.ChatColor;
    import yjjcity.plugins.Cashiers.Events.EventsClass;

    public class Cashiers extends JavaPlugin {
     
        @Override
        public void onEnable() {
            setupEconomy();
            getServer().getConsoleSender().sendMessage(ChatColor.YELLOW+"\n\nYJJ City Plugins - Cashiers"+ChatColor.GREEN+" has been ENABLED.\n\n");
            getServer().getPluginManager().registerEvents(new EventsClass(), this);
        }
     
        public static Economy economy = null;
       
        private boolean setupEconomy(){

            RegisteredServiceProvider<Economy> economyProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);

            if(economyProvider != null){
                economy = economyProvider.getProvider();
            }

            return (economy != null);

        }
     
        @Override
        public void onDisable() {
            getServer().getConsoleSender().sendMessage(ChatColor.YELLOW+"\n\nYJJ City Plugins - Cashiers"+ChatColor.RED+" has been DISABLED.\n\n");
        }
    }
     
    Here is the part of the Events class code which involves the Economy:
    Code (Text):
    else if (line3.equalsIgnoreCase("Click to Pay")) {
                            double amount = Double.parseDouble(line2.substring(3));
                            player.sendMessage(ChatColor.GREEN+"Amount: YC$"+amount);
                            player.sendMessage(ChatColor.GREEN+"You have YC$"+economy.getBalance(player)+" in your account.");
                            EconomyResponse r = economy.withdrawPlayer(player, amount);
                            player.sendMessage(ChatColor.GREEN+"Deducted YC$"+amount+" from your account.");
                            if (r.transactionSuccess()) {
                                player.sendMessage(ChatColor.GREEN+line2+" has been deducted from your account.");
                            } else {
                                player.sendMessage(ChatColor.RED+"An error occured. Do you have enough money in your account?");
    And here is the error that pops up in the console:
    Code (Text):
    [15:36:50 ERROR]: Could not pass event PlayerInteractEvent to YJJCityPlugins-Cashiers v1.0[/COLOR][/COLOR][/FONT]
    [COLOR=rgb(255, 0, 0)][FONT=Georgia][COLOR=rgb(20, 20, 20)]
    java.lang.NullPointerException: null
            at yjjcity.plugins.Cashiers.Events.EventsClass.onInteract(EventsClass.java:97) ~[?:?]
            at com.destroystokyo.paper.event.executor.asm.generated.GeneratedEventExecutor333.execute(Unknown Source) ~[?:?]
            at org.bukkit.plugin.EventExecutor.lambda$create$1(EventExecutor.java:69) ~[patched_1.15.2.jar:git-Paper-168]
            at co.aikar.timings.TimedEventExecutor.execute(TimedEventExecutor.java:80) ~[patched_1.15.2.jar:git-Paper-168]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:70) ~[patched_1.15.2.jar:git-Paper-168]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:607) ~[patched_1.15.2.jar:git-Paper-168]
            at org.bukkit.craftbukkit.v1_15_R1.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:463) ~[patched_1.15.2.jar:git-Paper-168]
            at net.minecraft.server.v1_15_R1.PlayerInteractManager.a(PlayerInteractManager.java:448) ~[patched_1.15.2.jar:git-Paper-168]
            at net.minecraft.server.v1_15_R1.PlayerConnection.a(PlayerConnection.java:1378) ~[patched_1.15.2.jar:git-Paper-168]
            at net.minecraft.server.v1_15_R1.PacketPlayInUseItem.a(PacketPlayInUseItem.java:27) ~[patched_1.15.2.jar:git-Paper-168]
            at net.minecraft.server.v1_15_R1.PacketPlayInUseItem.a(PacketPlayInUseItem.java:5) ~[patched_1.15.2.jar:git-Paper-168]
            at net.minecraft.server.v1_15_R1.PlayerConnectionUtils.lambda$ensureMainThread$0(PlayerConnectionUtils.java:23) ~[patched_1.15.2.jar:git-Paper-168]
            at net.minecraft.server.v1_15_R1.TickTask.run(SourceFile:18) ~[patched_1.15.2.jar:git-Paper-168]
            at net.minecraft.server.v1_15_R1.IAsyncTaskHandler.executeTask(IAsyncTaskHandler.java:136) ~[patched_1.15.2.jar:git-Paper-168]
            at net.minecraft.server.v1_15_R1.IAsyncTaskHandlerReentrant.executeTask(SourceFile:23) ~[patched_1.15.2.jar:git-Paper-168]
            at net.minecraft.server.v1_15_R1.IAsyncTaskHandler.executeNext(IAsyncTaskHandler.java:109) ~[patched_1.15.2.jar:git-Paper-168]
            at net.minecraft.server.v1_15_R1.MinecraftServer.ba(MinecraftServer.java:1053) ~[patched_1.15.2.jar:git-Paper-168]
            at net.minecraft.server.v1_15_R1.MinecraftServer.executeNext(MinecraftServer.java:1046) ~[patched_1.15.2.jar:git-Paper-168]
            at net.minecraft.server.v1_15_R1.IAsyncTaskHandler.awaitTasks(IAsyncTaskHandler.java:119) ~[patched_1.15.2.jar:git-Paper-168]
            at net.minecraft.server.v1_15_R1.MinecraftServer.sleepForTick(MinecraftServer.java:1016) ~[patched_1.15.2.jar:git-Paper-168]
            at net.minecraft.server.v1_15_R1.MinecraftServer.run(MinecraftServer.java:939) ~[patched_1.15.2.jar:git-Paper-168]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_241]