Need help with vault and essentials economy

Status
This thread has been locked.

Phaze

Plugin Developer
Banned
Feedback score
0
Posts
70
Reactions
10
Resources
0
[code] [14:44:32 ERROR]: Could not pass event PlayerInteractEvent to Cells v2
org.bukkit.event.EventException
at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot.jar:git-Spigot-db6de12-18fbb24]
at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot.jar:git-Spigot-db6de12-18fbb24]
at org.bukkit.craftbukkit.v1_8_R3.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:228) [spigot.jar:git-Spigot-db6de12-18fbb24]
at net.minecraft.server.v1_8_R3.PlayerInteractManager.interact(PlayerInteractManager.java:463) [spigot.jar:git-Spigot-db6de12-18fbb24]
at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:759) [spigot.jar:git-Spigot-db6de12-18fbb24]
at net.minecraft.server.v1_8_R3.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:52) [spigot.jar:git-Spigot-db6de12-18fbb24]
at net.minecraft.server.v1_8_R3.PacketPlayInBlockPlace.a(PacketPlayInBlockPlace.java:1) [spigot.jar:git-Spigot-db6de12-18fbb24]
at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [spigot.jar:git-Spigot-db6de12-18fbb24]
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_151]
at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_151]
at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [spigot.jar:git-Spigot-db6de12-18fbb24]
at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:715) [spigot.jar:git-Spigot-db6de12-18fbb24]
at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [spigot.jar:git-Spigot-db6de12-18fbb24]
at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [spigot.jar:git-Spigot-db6de12-18fbb24]
at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [spigot.jar:git-Spigot-db6de12-18fbb24]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_151]
Caused by: java.lang.RuntimeException: Essentials API is called before Essentials is loaded.
at com.earth2me.essentials.api.Economy.getUserByName(Economy.java:80) ~[?:?]
at com.earth2me.essentials.api.Economy.getMoneyExact(Economy.java:104) ~[?:?]
at com.earth2me.essentials.api.Economy.getMoney(Economy.java:99) ~[?:?]
at net.milkbowl.vault.economy.plugins.Economy_Essentials.getBalance(Economy_Essentials.java:79) ~[?:?]
at net.milkbowl.vault.economy.AbstractEconomy.getBalance(AbstractEconomy.java:20) ~[?:?]
at me.falconseeker.cells.cell.signs.listeners.CellRent.onClickEvent(CellRent.java:63) ~[?:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_151]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_151]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_151]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_151]
at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot.jar:git-Spigot-db6de12-18fbb24] [/code]

This is my plugin.yml
Code:
name: Cells
version: 2
author: Phaze
depend: [Vault, FastAsyncWorldEdit]
soft-depend: [Essentials]
main: me.falconseeker.cells.CellPlugin
commands:
  cells:
    description: Protects the spawn region after selecting with gold axe.
    usage: /cells

I followed the vault tutorial directly from the wiki, I don't think that is the issue
https://www.spigotmc.org/threads/need-help-with-vault-and-essentials-economy.371920/
 
PebbleHost
High performance, consistent uptime and fast support. Minecraft hosting that just works.

Norska

Java Developer (https://norska.dev)
Supreme
Feedback score
68
Posts
901
Reactions
1,407
Resources
14
Show us the code that uses methods from Essentials.
 

Phaze

Plugin Developer
Banned
Feedback score
0
Posts
70
Reactions
10
Resources
0
Show us the code that uses methods from Essentials.
None of the code uses methods directly from essentials, only from vault

Code:
        if (economy.getBalance(p) < price) {
 
Banned forever. Reason: Scamming (https://builtbybit.com/threads/phaze-scam-report.509219/)

sores

MineBOI
Premium
Feedback score
5
Posts
305
Reactions
210
Resources
0
Caused by: java.lang.RuntimeException: Essentials API is called before Essentials is loaded.
 

Phaze

Plugin Developer
Banned
Feedback score
0
Posts
70
Reactions
10
Resources
0
Caused by: java.lang.RuntimeException: Essentials API is called before Essentials is loaded.
Yep, I don't know why this is happening since I am hooking only into vault and dont use any of the essential methods
 
Banned forever. Reason: Scamming (https://builtbybit.com/threads/phaze-scam-report.509219/)

Phaze

Plugin Developer
Banned
Feedback score
0
Posts
70
Reactions
10
Resources
0
Post the class where the error is occurring.
This is part of it, where the error occurs
Code:
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.BlockState;
import org.bukkit.block.Chest;
import org.bukkit.block.Sign;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;

import me.falconseeker.cells.CellPlugin;
import me.falconseeker.cells.CellsAPI;
import me.falconseeker.cells.auctions.AuctionHouseManager;
import me.falconseeker.cells.auctions.AuctionSign;
import me.falconseeker.cells.cell.Cell;
import me.falconseeker.cells.cell.CellManager;
import me.falconseeker.cells.utils.Messages;
import me.falconseeker.cells.utils.gui.Menu;
import me.falconseeker.cells.utils.time.Cooldown;
import net.milkbowl.vault.economy.Economy;

public class CellRent implements Listener {

    private CellManager cellManager;
    private AuctionHouseManager auctionManager;
    private CellsAPI cellAPI;
    private Economy economy;
 
    public CellRent(CellPlugin main) {
        this.cellManager = main.getCellManager();
        this.auctionManager = main.getAuctionManager();
        this.cellAPI = main.getAPI();
        this.economy = main.getEconomy();
    
        Bukkit.getPluginManager().registerEvents(this, main);
    }
 
    @EventHandler
    public void onClickEvent(PlayerInteractEvent e) {
        Player p = e.getPlayer();

        if (e.getClickedBlock() == null) return;

        BlockState b = e.getClickedBlock().getState();
    
        if (!(b instanceof Sign)) return;
    
        if (cellManager.getCellFromSign(e.getClickedBlock().getLocation()) == null) return;
 
        Cell cell = cellManager.getCellFromSign(e.getClickedBlock().getLocation());
    
        int price = cell.getPrice();
    
        if (economy.getBalance(p) < price) { //Error line
            p.sendMessage(Messages.NOT_ENOUGH_MONEY.toString());
            return;
        }
    
        economy.withdrawPlayer(p, price);
    
        if (p.isSneaking())    {
            cellAPI.unRentCell(p, cell);
            return;
        }
        cellAPI.rentCell(p, cell);
    }
}

Then I do new CellRent(this); in my main class
 
Last edited:
Banned forever. Reason: Scamming (https://builtbybit.com/threads/phaze-scam-report.509219/)

sores

MineBOI
Premium
Feedback score
5
Posts
305
Reactions
210
Resources
0
This is part of it, where the error occurs
Code:
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.BlockState;
import org.bukkit.block.Chest;
import org.bukkit.block.Sign;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;

import me.falconseeker.cells.CellPlugin;
import me.falconseeker.cells.CellsAPI;
import me.falconseeker.cells.auctions.AuctionHouseManager;
import me.falconseeker.cells.auctions.AuctionSign;
import me.falconseeker.cells.cell.Cell;
import me.falconseeker.cells.cell.CellManager;
import me.falconseeker.cells.utils.Messages;
import me.falconseeker.cells.utils.gui.Menu;
import me.falconseeker.cells.utils.time.Cooldown;
import net.milkbowl.vault.economy.Economy;

public class CellRent implements Listener {

    private CellManager cellManager;
    private AuctionHouseManager auctionManager;
    private CellsAPI cellAPI;
    private Economy economy;
 
    public CellRent(CellPlugin main) {
        this.cellManager = main.getCellManager();
        this.auctionManager = main.getAuctionManager();
        this.cellAPI = main.getAPI();
        this.economy = main.getEconomy();
   
        Bukkit.getPluginManager().registerEvents(this, main);
    }
 
    @EventHandler
    public void onClickEvent(PlayerInteractEvent e) {
        Player p = e.getPlayer();

        if (e.getClickedBlock() == null) return;

        BlockState b = e.getClickedBlock().getState();
   
        if (!(b instanceof Sign)) return;
   
        if (cellManager.getCellFromSign(e.getClickedBlock().getLocation()) == null) return;
 
        Cell cell = cellManager.getCellFromSign(e.getClickedBlock().getLocation());
   
        int price = cell.getPrice();
   
        if (economy.getBalance(p) < price) { //Error line
            p.sendMessage(Messages.NOT_ENOUGH_MONEY.toString());
            return;
        }
   
        economy.withdrawPlayer(p, price);
   
        if (p.isSneaking())    {
            cellAPI.unRentCell(p, cell);
            return;
        }
        cellAPI.rentCell(p, cell);
    }
}

Then I do new CellRent(this); in my main class

And Vault is setup correctly in the plugin?
 

Phaze

Plugin Developer
Banned
Feedback score
0
Posts
70
Reactions
10
Resources
0
And Vault is setup correctly in the plugin?
Yes, directly from the wiki
Code:
package me.falconseeker.cells;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.block.Chest;
import org.bukkit.block.Sign;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;

import me.falconseeker.cells.auctions.AuctionHouseManager;
import me.falconseeker.cells.auctions.AuctionSign;
import me.falconseeker.cells.cell.Cell;
import me.falconseeker.cells.cell.CellManager;
import me.falconseeker.cells.cell.signs.listeners.CellRent;
import me.falconseeker.cells.commands.*;
import me.falconseeker.cells.commands.subcommands.*;
import me.falconseeker.cells.listeners.BlockCancel;
import me.falconseeker.cells.listeners.UtilsListeners;
import me.falconseeker.cells.utils.Messages;
import me.falconseeker.cells.utils.gui.ItemBuilders;
import me.falconseeker.cells.utils.time.Cooldown;
import net.md_5.bungee.api.ChatColor;
import net.milkbowl.vault.economy.Economy;
/**
 *
 * @author Falcon_Seeker / Phaze.
 *
 * You do not have permission to re-sell this plugin
 * or claim it as your own.
 *
 */
public class CellPlugin extends JavaPlugin {

    public static YamlConfiguration LANG;
    public static File LANG_FILE;
    private CellsAPI cellsAPI;
    private CellManager cellManager;
    private AuctionHouseManager auctionManager;
    private Economy econ;

    @Override
    public void onEnable() {
       
        if(!new AdvancedLicense("U8W2-H1UP-AO3U-UTA0", "https://falconseeker.000webhostapp.com/verify.php", this).register()) {
            this.getLogger().severe("Disabled due to an inactive license. Contact Phaze on discord if you believe this is an error");
            return;
        }
       
        if (!setupEconomy()) {
            this.getLogger().severe("Disabled due to no Vault dependency found!");
            return;
        }
 
        setupEconomy();

        this.cellManager = new CellManager(this);
        this.auctionManager = new AuctionHouseManager(this);
        this.cellsAPI = new CellsAPI(this);

       
        loadLang();

        cellManager.loadCells();
        auctionManager.loadAuctions();
       
        new CellRent(this); //listeners
        new BlockCancel(this);
        new UtilsListeners(this);
       
        CommandHandler handler = new CommandHandler(this);

        handler.register("cells", new BaseCommand());

        handler.register("addsign", new CommandAddSign());
        handler.register("create", new CommandCreateCell());
        handler.register("evict", new CommandEvict());
        handler.register("groupadd", new CommandGroupAdd());
        handler.register("pos1", new CommandPos1());
        handler.register("pos2", new CommandPos2());
        handler.register("ahcreate", new CommandCreateAuction());
        handler.register("ahremove", new CommandRemoveAuction());
        handler.register("remove", new CommandRemoveCell());
        handler.register("groupslist", new CommandGroupList());
        handler.register("removegroup", new CommandGroupRemove());
        handler.register("cellslist", new CommandCellsList());
        handler.register("ahlist", new CommandAuctionsList());
        handler.register("refreshsigns", new CommandRefreshSigns());
        handler.register("reload", new CommandReload());
        handler.register("removesign", new CommandRemoveSign());
        handler.register("rent", new CommandRent());
        handler.register("reset", new CommandReset());
        handler.register("setcost", new CommandSetCost());
        handler.register("setdays", new CommandSetDays());
        handler.register("unrent", new CommandUnrent());
        handler.register("help", new CommandUnrent());

 
        getCommand("cells").setExecutor(handler);
       
        startCellSigns();
        startAuctionSigns();
       
       
    }
    @Override
    public void onDisable() {
        cellManager.saveCells();
        auctionManager.saveAuctions();
    }
   
    private boolean setupEconomy() {
        if (Bukkit.getPluginManager().getPlugin("Vault") == null) {
            return false;
        }

        RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
        if (rsp == null) {
            return false;
        }
        econ = rsp.getProvider();
        return econ != null;
    }
   
    public Economy getEconomy() {
        return econ;
    }
    /**
     * Gets the CellsAPI class
     * @return The CellsAPI class
     */
    public CellsAPI getAPI() {
        return cellsAPI;
    }
   
    /**
     * Gets the CellManager class
     * @return The CellManager class  
     */
    public CellManager getCellManager() {
        return cellManager;
    }
    /**
     * Gets the AuctionHouseManager class
     * @return The AuctionHouseManager class
     */
    public AuctionHouseManager getAuctionManager() {
        return auctionManager;
    }
    /**
    * Gets the lang.yml config.
    * @return The lang.yml config.
    */
    public YamlConfiguration getLang() {
        return LANG;
    }
   
    /**
    * Get the lang.yml file.
    * @return The lang.yml file.
    */
    public File getLangFile() {
        return LANG_FILE;
    }
    /**
     * Load the lang.yml file.
     * @return
     * @return The lang.yml config.
     */
    public YamlConfiguration loadLang() {
        File lang = new File(getDataFolder(), "lang.yml");
        if (!lang.exists()) {
            try {
                getDataFolder().mkdir();
                lang.createNewFile();
                InputStream defConfigStream = this.getResource("lang.yml");
                if (defConfigStream != null) {
                    YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
                    defConfig.save(lang);
                    Messages.setFile(defConfig);
                    return defConfig;
                }
            } catch(IOException e) {
                e.printStackTrace();
                this.setEnabled(false);
            }
        }
        YamlConfiguration conf = YamlConfiguration.loadConfiguration(lang);
       
        for(Messages item : Messages.values()) {
            if (conf.getString(item.getPath()) == null) {
                conf.set(item.getPath(), item.getDefault());
            }
        }
        Messages.setFile(conf);
        LANG = conf;
        LANG_FILE = lang;
        try {
            conf.save(getLangFile());
        } catch(IOException e) {
            e.printStackTrace();
        }
        return conf;
    }
   
    private final void startCellSigns() {
       
        new BukkitRunnable() {
           
            @Override
            public void run() {
               
                for (Cell cell : cellManager.getCells()) {
                    if (cell.getOwner() == null) continue;
                    if (Cooldown.getCooldown(cell.getId()) == null) continue;

                    if (cell.getSignLocation() != null) {
                        if (cell.getSignLocation().getBlock() != null) {
                            if (cell.getSignLocation().getBlock().getState() instanceof Sign) {
                   
                                long seconds = Cooldown.getCooldown(cell.getId()).getCooldownTime() / 1000;
                                long minutes = seconds / 60;
                                long hours = minutes / 60;
                                long days = hours / 24;
                                String time = days + ":" + hours % 24 + ":" + minutes % 60;
                               
                                Sign s = (Sign) cell.getSignLocation().getBlock().getState();
                   
                                s.setLine(0, ChatColor.DARK_RED + "[" + cell.getId() + "]");
                               
                                s.setLine(2, ChatColor.ITALIC + time);
                                s.setLine(1, ChatColor.GRAY + "" + Bukkit.getOfflinePlayer(cell.getOwner()).getName() + "");
                                s.setLine(3, ChatColor.DARK_BLUE + "$" + cell.getPrice() + "");

                                s.update();                  
                            }
                        }
                    }
                   
                Cooldown.getCooldown(cell.getId()).ifFinished(() -> {
                        getConfig().set("cells." + cell.getId() + ".timeLeft", 0);
                        cellsAPI.startAH(cell);
                        cellsAPI.resetCell(cell);
                       
                    });
                }
               
            }
        }.runTaskTimer(this, 20L, 20L); //Cooldowns not required to be async
    }
    private final void startAuctionSigns() {
       
        new BukkitRunnable() {
           
            @Override
            public void run() {
               
                    for (AuctionSign sign : auctionManager.getAuctionSigns()) {
                        if (sign.getSignLocation().getBlock().getState() instanceof Sign) {
                           
                            if (Cooldown.getCooldown(sign.getChest().toString()) == null) continue;
                           
                            long seconds = Cooldown.getCooldown(sign.getChest().toString()).getCooldownTime() / 1000;
                            long minutes = seconds / 60;
                            long hours = minutes / 60;
                            long days = hours / 24;
                            String time = days + ":" + minutes % 60 + ":" + seconds % 60;
                           
                            Sign s = (Sign) sign.getSignLocation().getBlock().getState();
               
                            s.setLine(0, ChatColor.YELLOW + "[BuyChest]");
                           
                            s.setLine(1, ChatColor.GRAY + Bukkit.getOfflinePlayer(sign.getOwner()).getName());
                            s.setLine(2, ChatColor.GRAY + time);
                            s.setLine(3, ChatColor.DARK_PURPLE + "$" + sign.getPrice());

                            if (sign.getBuyer() != null) {
                                s.setLine(1, ChatColor.GOLD + Bukkit.getOfflinePlayer(sign.getBuyer()).getName());
                                s.setLine(2, " ");
                                s.setLine(3, time);
                            }
                           
                            s.update();                  
                        }
                        if (Cooldown.getCooldown(sign.getChest().toString()) != null) {
                        Cooldown.getCooldown(sign.getChest().toString()).ifFinished(() -> {
                            sign.getSignLocation().getBlock().setType(Material.AIR);
                            Chest c = (Chest) sign.getChest().getBlock().getState();
                       
                            c.getBlockInventory().setContents((ItemStack[]) Arrays.asList(new ItemBuilders(Material.AIR).buildItem()).toArray());
                            sign.getChest().getBlock().setType(Material.AIR);
                            });
                        }
                    }
               
            }
        }.runTaskTimer(this, 20L, 20L); //Cooldowns not required to be async
    }
}

I could probably optimize the last 2 methods, il make it into one at a later date
 
Last edited:
Banned forever. Reason: Scamming (https://builtbybit.com/threads/phaze-scam-report.509219/)
Status
This thread has been locked.
Top