Solved Economy/vault issue

Discussion in 'Plugin Help/Development/Requests' started by Scorpionvssub, Nov 11, 2015.

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

    Scorpionvssub

    With alot of trial and error.............

    i ended up with this:

    Code:
        @EventHandler
        public void signclick(PlayerInteractEvent e) {
            if ((e.getClickedBlock() != null) &&
                    (e.getAction().equals(Action.RIGHT_CLICK_BLOCK)) && (
                    (e.getClickedBlock().getType().equals(Material.SIGN_POST)) ||
                            (e.getClickedBlock().getType().equals(Material.WALL_SIGN)))) {
                Sign s = (Sign) e.getClickedBlock().getState();
                System.out.println("signssss");
                if (s.getLine(0).equalsIgnoreCase(ChatColor.translateAlternateColorCodes('&', getConfig().getString("Settings.prefix")))) {
                    System.out.println("helloooo");
                    Double prize;
                    prize = Double.valueOf(s.getLine(3).replaceAll(ChatColor.translateAlternateColorCodes('&' , getConfig().getString("Settings.prizecolor")), ""));
                    e.getPlayer().sendMessage(prize + "prize");
                    Player p = e.getPlayer();
                    EconomyResponse r = econ.withdrawPlayer(p, prize);
                    if (r.transactionSuccess()) {
                        e.getPlayer().sendMessage(prize + "transsuccess");
                    } else {
                        e.getPlayer().sendMessage("no luck");
                    }
                }
            }
        }
    now there is a huge error related to the econ.withdrawPlayer(p, prize); which is that p is null while the other ways are still returning everything..

    The p is also filled when i do p.sendMessage("hello"); but not on withdraw...for some reason hope anyone got an idea
     
  2. Offline

    timtower Administrator Administrator Moderator

  3. Offline

    Scorpionvssub

    @timtower that....i didnt think off what is the best way to test?

    if it helps any...


    Code:
        public void onEnable() {
            getConfig().options().copyDefaults(true);
            saveConfig();
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
            prefix = (ChatColor.translateAlternateColorCodes('&', (getConfig().getString("Settings.Prefix"))));
            if (!setupEconomy()) {
                getLogger().severe(String.format("[%s] - ADD VAULT TO ENABLE MONEY VOTING!", getDescription().getName()));
            }
        }
        private boolean setupEconomy() {
            if (getServer().getPluginManager().getPlugin("Vault") == null) {
                return false;
            }
            RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
            if (rsp == null) {
                return false;
            }
            Economy Economy = rsp.getProvider();
            return Economy != null;
        }
     
  4. Offline

    timtower Administrator Administrator Moderator

    @Scorpionvssub I am sure that it is null actually.
    1. field names starting with lowercase please, don't copy class names.
    2. economy should be a field, not a local variable.
     
  5. Offline

    Scorpionvssub

  6. Offline

    timtower Administrator Administrator Moderator

    Don't start variable names with uppercase, so "economy" not "Economy", it makes me think that it is a class instead.
    You have it as variable in the method, it should be a variable in the class
     
  7. Offline

    Scorpionvssub

    @timtower Adjusted the 2 lines at the bottom where it says Economy Economy to to Economy economy

    Code:
            if (!setupEconomy()) {
                getLogger().severe(String.format("[%s] - Missing Vault", getDescription().getName()));
            }
        }
    
        private boolean setupEconomy() {
            if (getServer().getPluginManager().getPlugin("Vault") == null) {
                return false;
            }
            RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
            if (rsp == null) {
                return false;
            }
            Economy economy = rsp.getProvider();
            return economy != null;
        }
    That is all i have on enable for the vault
     
  8. Offline

    timtower Administrator Administrator Moderator

    @Scorpionvssub
    Economy economy = rsp.getProvider();
    That is a local var, the one in your class will be null
     
  9. Offline

    Scorpionvssub

    @timtower
    Code:
        public static Economy econ = null;
    
        public void onEnable() {
            getConfig().options().copyDefaults(true);
            saveConfig();
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
            prefix = (ChatColor.translateAlternateColorCodes('&', (getConfig().getString("Settings.Prefix"))));
            if (!setupEconomy() ) {
                getLogger().severe(String.format("[%s] - Disabled due to no Vault dependency found!", getDescription().getName()));
                getServer().getPluginManager().disablePlugin(this);
            }
        }
    
        private boolean setupEconomy() {
            if (getServer().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;
        }
    
    Took another look at the vaults page and tried their exact thing unless its outdated?
     
  10. Offline

    timtower Administrator Administrator Moderator

  11. Offline

    Scorpionvssub

  12. Offline

    timtower Administrator Administrator Moderator

  13. Offline

    Scorpionvssub

    @timtower Everything is in the same class its the main class no sub classes just main class + config file and plugin file


    Edit: econ is deff null..
    idk how best to fix
     
    Last edited: Nov 11, 2015
  14. Offline

    timtower Administrator Administrator Moderator

    @Scorpionvssub Don't make it static, you don't need it to be, could you post the entire class?
     
  15. Offline

    Scorpionvssub

    @Ruptur Thanks!! saved the day :p

    @timtower Rupt suggested the pluginmanager to be under it all after noticing the econ was null. and that fixed it it seems :confused:


    Edit: except it keeps uhm... going after 0

    Code:
                    EconomyResponse r = econ.withdrawPlayer(p, prize);
                    if (r.transactionSuccess()) {
                        e.getPlayer().sendMessage(prize + "transsuccess");
                    } else {
                        e.getPlayer().sendMessage("no luck");
                    }
                }
    From what ive read on the page this should take the money but it always takes even below 0
     
    Last edited: Nov 11, 2015
Thread Status:
Not open for further replies.

Share This Page