Ir para conteúdo
  • 0

Plugin de economia co Vault. Como fazer?


TequilAxBr

Pergunta

Olá, eu estou tentando desenvolver meu próprio plugin de economia com Vault, porem estou tendo problemas...


Sim, eu já criei uma classe que implementa a interface Economy do Vault, e também registrei no onEnable.


E quando entro no servidor e digito '/vault-info' o meu plugin de economia se encontra lá, mas quando outros plugins que fazem hook com Vaut(ChestShop e etc) quando tentam acessar a interface do Vault para pegar o money do player por exemplo, da erro. O erro que da é o NullPointerExpection.


 


Eu criei um plugin de teste e implementei a interface Economy só para testar, ou seja, está com os métodos padrões, com retornos padrões.


 


Forma que registro no onEnable:



if(getServer().getPluginManager().isPluginEnabled("Vault")) {
economy = new VaultEconomy(this); //inicializei a variavel em cima do onEnable.
Bukkit.getServer().getServicesManager().register(Economy.class, economy, this, ServicePriority.Highest);
}

Link para o comentário
Compartilhar em outros sites

8 respostass a esta questão

Posts Recomendados

 

Olá, eu estou tentando desenvolver meu próprio plugin de economia com Vault, porem estou tendo problemas...

Sim, eu já criei uma classe que implementa a interface Economy do Vault, e também registrei no onEnable.

E quando entro no servidor e digito '/vault-info' o meu plugin de economia se encontra lá, mas quando outros plugins que fazem hook com Vaut(ChestShop e etc) quando tentam acessar a interface do Vault para pegar o money do player por exemplo, da erro. O erro que da é o NullPointerExpection.

 

Eu criei um plugin de teste e implementei a interface Economy só para testar, ou seja, está com os métodos padrões, com retornos padrões.

 

Forma que registro no onEnable:

        if(getServer().getPluginManager().isPluginEnabled("Vault")) {
        	economy = new VaultEconomy(this); //inicializei a variavel em cima do onEnable.
            Bukkit.getServer().getServicesManager().register(Economy.class, economy, this, ServicePriority.Highest);
        }

public class VaultEconomy implements Economy, Economia
{
    private Map<String, Account> rank;
    
    public VaultEconomy() {
        this.rank = new LinkedHashMap<String, Account>();
    }
    
    public boolean createPlayerAccount(final String name) {
        final Map<String, Account> map = Main.getAccounts();
        if (map.get(name) != null) {
            return false;
        }
        map.put(name, new Account(name, new Balance()));
        return true;
    }
    
    public boolean createPlayerAccount(final OfflinePlayer player) {
        final Map<String, Account> map = Main.getAccounts();
        if (map.get(player.getName()) != null) {
            return false;
        }
        map.put(player.getName(), new Account(player.getName(), new Balance()));
        return true;
    }
    
    public boolean createPlayerAccount(final String name, final String value) {
        final Map<String, Account> map = Main.getAccounts();
        if (map.get(name) != null) {
            return false;
        }
        map.put(name, new Account(name, new Balance(Double.valueOf(value))));
        return true;
    }
    
    public boolean createPlayerAccount(final OfflinePlayer player, final String value) {
        final Map<String, Account> map = Main.getAccounts();
        if (map.get(player.getName()) != null) {
            return false;
        }
        map.put(player.getName(), new Account(player.getName(), new Balance(Double.valueOf(value))));
        return true;
    }
    
    public String currencyNamePlural() {
        return Main.instance.getConfig().getString("Seila").concat("s");
    }
    
    public String currencyNameSingular() {
        return Main.instance.getConfig().getString("Seila");
    }
    
    public EconomyResponse deleteBank(final String arg0) {
        return null;
    }
    
    public EconomyResponse depositPlayer(final String name, final double value) {
        final Account account = Main.getAccounts().get(name);
        if (account == null) {
            return null;
        }
        account.getBalance().addValue(value);
        return new EconomyResponse(value, account.getBalance().getValue(), EconomyResponse.ResponseType.SUCCESS, "");
    }
    
    public EconomyResponse depositPlayer(final OfflinePlayer player, final double value) {
        return this.depositPlayer(player.getName(), value);
    }
    
    public EconomyResponse depositPlayer(final String name, final String bank, final double value) {
        return this.depositPlayer(name, value);
    }
    
    public EconomyResponse depositPlayer(final OfflinePlayer player, final String bank, final double value) {
        return this.depositPlayer(player.getName(), value);
    }
    
    public String format(final double value) {
        if (value <= 1.0) {
            return Main.numberFormat.format(value).concat(" ").concat(this.currencyNameSingular());
        }
        return Main.numberFormat.format(value).concat(" ").concat(this.currencyNamePlural());
    }
    
    public int fractionalDigits() {
        return this.getName().length();
    }
    
    public double getBalance(final String name) {
        final Account account = Main.getAccounts().get(name);
        if (account == null) {
            return 0.0;
        }
        return account.getBalance().getValue();
    }
    
    public double getBalance(final OfflinePlayer player) {
        return this.getBalance(player.getName());
    }
    
    public double getBalance(final String name, final String bank) {
        return this.getBalance(name);
    }
    
    public double getBalance(final OfflinePlayer player, final String bank) {
        return this.getBalance(player.getName());
    }
    
    public List<String> getBanks() {
        return null;
    }
    
    public String getName() {
        return "SeuPlugin'-'";
    }
    
    public boolean has(final String name, final double value) {
        return this.getBalance(name) >= value;
    }
    
    public boolean has(final OfflinePlayer player, final double value) {
        return this.has(player.getName(), value);
    }
    
    public boolean has(final String name, final String bank, final double value) {
        return this.has(name, value);
    }
    
    public boolean has(final OfflinePlayer player, final String bank, final double value) {
        return this.has(player.getName(), value);
    }
    
    public boolean hasAccount(final String name) {
        final Account account = Main.getAccounts().get(name);
        return account != null;
    }
    
    public boolean hasAccount(final OfflinePlayer player) {
        return this.hasAccount(player.getName());
    }
    
    public boolean hasAccount(final String name, final String bank) {
        return this.hasAccount(name);
    }
    
    public boolean hasAccount(final OfflinePlayer player, final String bank) {
        return this.hasAccount(player.getName());
    }
    
    public boolean hasBankSupport() {
        return false;
    }
    
    public EconomyResponse isBankMember(final String arg0, final String arg1) {
        return null;
    }
    
    public EconomyResponse isBankMember(final String arg0, final OfflinePlayer arg1) {
        return null;
    }
    
    public EconomyResponse isBankOwner(final String arg0, final String arg1) {
        return null;
    }
    
    public EconomyResponse isBankOwner(final String arg0, final OfflinePlayer arg1) {
        return null;
    }
    
    public boolean isEnabled() {
        return Main.instance.isEnabled();
    }
    
    public EconomyResponse withdrawPlayer(final String name, final double value) {
        final Account account = Main.getAccounts().get(name);
        if (account == null) {
            return null;
        }
        account.getBalance().removeValue(value);
        return new EconomyResponse(value, account.getBalance().getValue(), EconomyResponse.ResponseType.SUCCESS, "");
    }
    
    public EconomyResponse withdrawPlayer(final OfflinePlayer player, final double value) {
        return this.withdrawPlayer(player.getName(), value);
    }
    
    public EconomyResponse withdrawPlayer(final String name, final String bank, final double value) {
        return this.withdrawPlayer(name, value);
    }
    
    public EconomyResponse withdrawPlayer(final OfflinePlayer player, final String bank, final double value) {
        return this.withdrawPlayer(player.getName(), value);
    }
    
    public EconomyResponse bankBalance(final String arg0) {
        return null;
    }
    
    public EconomyResponse bankDeposit(final String arg0, final double arg1) {
        return null;
    }
    
    public EconomyResponse bankHas(final String arg0, final double arg1) {
        return null;
    }
    
    public EconomyResponse bankWithdraw(final String arg0, final double arg1) {
        return null;
    }
    
    public EconomyResponse createBank(final String arg0, final String arg1) {
        return null;
    }
    
    public EconomyResponse createBank(final String arg0, final OfflinePlayer arg1) {
        return null;
    }
    
    public Account getAccount(final String name) {
        return Main.getAccounts().get(name);
    }
    
    public boolean createAccount(final String name) {
        return this.createAccount(name, 0.0);
    }
    
    public boolean createAccount(final String name, final double value) {
        if (this.getAccount(name) != null) {
            return false;
        }
        if (name.length() > 40) {
            return false;
        }
        Main.getAccounts().put(name, new Account(name, new Balance(value)));
        Main.save(this.getAccount(name));
        return true;
    }
    
    public boolean deleteAccount(final String name) {
        if (this.getAccount(name) == null) {
            return false;
        }
        Main.getAccounts().remove(name);
        return true;
    }
    
    public boolean reloadRank(final int size) {
        try {
            this.rank.clear();
            final List<Account> accounts = this.getAccounts();
            Collections.sort(accounts);
            for (int i = 0; i < size; ++i) {
                try {
                    final Account acc = accounts.get(i);
                    if (acc != null && acc.getName().length() <= 40) {
                        final Account accTop = new Account(acc.getName(), new Balance(acc.getBalance().getValue()));
                        this.rank.put(accTop.getName(), accTop);
                    }
                }
                catch (Exception exception2) {
                    break;
                }
            }
        }
        catch (Exception exception) {
            exception.printStackTrace();
        }
        return false;
    }
    
    public Map<String, Account> getRank() {
        return this.rank;
    }
    
    public List<Account> getAccounts() {
        final List<Account> accounts = new ArrayList<Account>();
        for (final Account account : Main.getAccounts().values()) {
            if (account != null) {
                accounts.add(account);
            }
        }
        return accounts;
    }
}

    public static Plugin instance;
    private static Map<String, Account> accounts;
    private static VaultEconomy economy;
    


    public static VaultEconomy getEconomy() {
        return Main.economy;
    }



    public void onEnable() {
        Main.instance = (Plugin)this;
        Main.accounts = new HashMap<String, Account>();
    }


    
    public static Map<String, Account> getAccounts() {
        return Main.accounts;
    }


Editado por tecs
Link para o comentário
Compartilhar em outros sites

Você colocou o Vault como dependência na plugin.yml? Pode ser que seu plugin esteja carregando antes do Vault...

Sim.

plugin.yml

name: MCEconomy
version: 1.0
main: br.com.mceconomy.MCEconomy
author: TequilAxBr
softdepend: [Vault]
commands:
    money:

public class VaultEconomy implements Economy, Economia
{
    private Map<String, Account> rank;
    
    public VaultEconomy() {
        this.rank = new LinkedHashMap<String, Account>();
    }
    
    public boolean createPlayerAccount(final String name) {
        final Map<String, Account> map = Main.getAccounts();
        if (map.get(name) != null) {
            return false;
        }
        map.put(name, new Account(name, new Balance()));
        return true;
    }
    
    public boolean createPlayerAccount(final OfflinePlayer player) {
        final Map<String, Account> map = Main.getAccounts();
        if (map.get(player.getName()) != null) {
            return false;
        }
        map.put(player.getName(), new Account(player.getName(), new Balance()));
        return true;
    }
    
    public boolean createPlayerAccount(final String name, final String value) {
        final Map<String, Account> map = Main.getAccounts();
        if (map.get(name) != null) {
            return false;
        }
        map.put(name, new Account(name, new Balance(Double.valueOf(value))));
        return true;
    }
    
    public boolean createPlayerAccount(final OfflinePlayer player, final String value) {
        final Map<String, Account> map = Main.getAccounts();
        if (map.get(player.getName()) != null) {
            return false;
        }
        map.put(player.getName(), new Account(player.getName(), new Balance(Double.valueOf(value))));
        return true;
    }
    
    public String currencyNamePlural() {
        return Main.instance.getConfig().getString("Seila").concat("s");
    }
    
    public String currencyNameSingular() {
        return Main.instance.getConfig().getString("Seila");
    }
    
    public EconomyResponse deleteBank(final String arg0) {
        return null;
    }
    
    public EconomyResponse depositPlayer(final String name, final double value) {
        final Account account = Main.getAccounts().get(name);
        if (account == null) {
            return null;
        }
        account.getBalance().addValue(value);
        return new EconomyResponse(value, account.getBalance().getValue(), EconomyResponse.ResponseType.SUCCESS, "");
    }
    
    public EconomyResponse depositPlayer(final OfflinePlayer player, final double value) {
        return this.depositPlayer(player.getName(), value);
    }
    
    public EconomyResponse depositPlayer(final String name, final String bank, final double value) {
        return this.depositPlayer(name, value);
    }
    
    public EconomyResponse depositPlayer(final OfflinePlayer player, final String bank, final double value) {
        return this.depositPlayer(player.getName(), value);
    }
    
    public String format(final double value) {
        if (value <= 1.0) {
            return Main.numberFormat.format(value).concat(" ").concat(this.currencyNameSingular());
        }
        return Main.numberFormat.format(value).concat(" ").concat(this.currencyNamePlural());
    }
    
    public int fractionalDigits() {
        return this.getName().length();
    }
    
    public double getBalance(final String name) {
        final Account account = Main.getAccounts().get(name);
        if (account == null) {
            return 0.0;
        }
        return account.getBalance().getValue();
    }
    
    public double getBalance(final OfflinePlayer player) {
        return this.getBalance(player.getName());
    }
    
    public double getBalance(final String name, final String bank) {
        return this.getBalance(name);
    }
    
    public double getBalance(final OfflinePlayer player, final String bank) {
        return this.getBalance(player.getName());
    }
    
    public List<String> getBanks() {
        return null;
    }
    
    public String getName() {
        return "SeuPlugin'-'";
    }
    
    public boolean has(final String name, final double value) {
        return this.getBalance(name) >= value;
    }
    
    public boolean has(final OfflinePlayer player, final double value) {
        return this.has(player.getName(), value);
    }
    
    public boolean has(final String name, final String bank, final double value) {
        return this.has(name, value);
    }
    
    public boolean has(final OfflinePlayer player, final String bank, final double value) {
        return this.has(player.getName(), value);
    }
    
    public boolean hasAccount(final String name) {
        final Account account = Main.getAccounts().get(name);
        return account != null;
    }
    
    public boolean hasAccount(final OfflinePlayer player) {
        return this.hasAccount(player.getName());
    }
    
    public boolean hasAccount(final String name, final String bank) {
        return this.hasAccount(name);
    }
    
    public boolean hasAccount(final OfflinePlayer player, final String bank) {
        return this.hasAccount(player.getName());
    }
    
    public boolean hasBankSupport() {
        return false;
    }
    
    public EconomyResponse isBankMember(final String arg0, final String arg1) {
        return null;
    }
    
    public EconomyResponse isBankMember(final String arg0, final OfflinePlayer arg1) {
        return null;
    }
    
    public EconomyResponse isBankOwner(final String arg0, final String arg1) {
        return null;
    }
    
    public EconomyResponse isBankOwner(final String arg0, final OfflinePlayer arg1) {
        return null;
    }
    
    public boolean isEnabled() {
        return Main.instance.isEnabled();
    }
    
    public EconomyResponse withdrawPlayer(final String name, final double value) {
        final Account account = Main.getAccounts().get(name);
        if (account == null) {
            return null;
        }
        account.getBalance().removeValue(value);
        return new EconomyResponse(value, account.getBalance().getValue(), EconomyResponse.ResponseType.SUCCESS, "");
    }
    
    public EconomyResponse withdrawPlayer(final OfflinePlayer player, final double value) {
        return this.withdrawPlayer(player.getName(), value);
    }
    
    public EconomyResponse withdrawPlayer(final String name, final String bank, final double value) {
        return this.withdrawPlayer(name, value);
    }
    
    public EconomyResponse withdrawPlayer(final OfflinePlayer player, final String bank, final double value) {
        return this.withdrawPlayer(player.getName(), value);
    }
    
    public EconomyResponse bankBalance(final String arg0) {
        return null;
    }
    
    public EconomyResponse bankDeposit(final String arg0, final double arg1) {
        return null;
    }
    
    public EconomyResponse bankHas(final String arg0, final double arg1) {
        return null;
    }
    
    public EconomyResponse bankWithdraw(final String arg0, final double arg1) {
        return null;
    }
    
    public EconomyResponse createBank(final String arg0, final String arg1) {
        return null;
    }
    
    public EconomyResponse createBank(final String arg0, final OfflinePlayer arg1) {
        return null;
    }
    
    public Account getAccount(final String name) {
        return Main.getAccounts().get(name);
    }
    
    public boolean createAccount(final String name) {
        return this.createAccount(name, 0.0);
    }
    
    public boolean createAccount(final String name, final double value) {
        if (this.getAccount(name) != null) {
            return false;
        }
        if (name.length() > 40) {
            return false;
        }
        Main.getAccounts().put(name, new Account(name, new Balance(value)));
        Main.save(this.getAccount(name));
        return true;
    }
    
    public boolean deleteAccount(final String name) {
        if (this.getAccount(name) == null) {
            return false;
        }
        Main.getAccounts().remove(name);
        return true;
    }
    
    public boolean reloadRank(final int size) {
        try {
            this.rank.clear();
            final List<Account> accounts = this.getAccounts();
            Collections.sort(accounts);
            for (int i = 0; i < size; ++i) {
                try {
                    final Account acc = accounts.get(i);
                    if (acc != null && acc.getName().length() <= 40) {
                        final Account accTop = new Account(acc.getName(), new Balance(acc.getBalance().getValue()));
                        this.rank.put(accTop.getName(), accTop);
                    }
                }
                catch (Exception exception2) {
                    break;
                }
            }
        }
        catch (Exception exception) {
            exception.printStackTrace();
        }
        return false;
    }
    
    public Map<String, Account> getRank() {
        return this.rank;
    }
    
    public List<Account> getAccounts() {
        final List<Account> accounts = new ArrayList<Account>();
        for (final Account account : Main.getAccounts().values()) {
            if (account != null) {
                accounts.add(account);
            }
        }
        return accounts;
    }
}

    public static Plugin instance;
    private static Map<String, Account> accounts;
    private static VaultEconomy economy;
    


    public static VaultEconomy getEconomy() {
        return Main.economy;
    }



    public void onEnable() {
        Main.instance = (Plugin)this;
        Main.accounts = new HashMap<String, Account>();
    }


    
    public static Map<String, Account> getAccounts() {
        return Main.accounts;
    }


Esse é o código do BlackEconomy, faço da mesma forma.

Além do mais, isso não irá funcionar. Não está registrando no onEnable, faltou você copiar o método que registra no JD-GUI do BlackEconomy.

Editado por TequilAxBr
Link para o comentário
Compartilhar em outros sites

 

Algo bem bobo provavelmente

Tenta isso kkk

 

na plugin yaml

load: STARTUP

Realmente, era isso.

Porem estou com outro problema:

Quando por exemplo, tento comprar algo no ChestShop ele não remove o money, eu sei é erro na minha classe que implementa a interface Economy.

O que estou fazendo de errado? Classe:

Classe que implementa a Economy: https://hastebin.com/uyuyesakav.java

Classe AccountManager: https://hastebin.com/ixapexefob.java

Link para o comentário
Compartilhar em outros sites

Realmente, era isso.

Porem estou com outro problema:

Quando por exemplo, tento comprar algo no ChestShop ele não remove o money, eu sei é erro na minha classe que implementa a interface Economy.

O que estou fazendo de errado? Classe:

Classe que implementa a Economy: https://hastebin.com/uyuyesakav.java

Classe AccountManager: https://hastebin.com/ixapexefob.java

Acho que vc tem que trocar onde eu botei a anotação ali

 

@Override
public boolean removeMoney(String name, double amount) {
Account account = this.accounts.get(name);
double newMoney = account.getMoney() - amount;
if(newMoney < 0.0) { //acho que vc tem que trocar para MAIOR OU IGUAL (>=)
this.accounts.get(name).setMoney(newMoney);
return true;
}
return false;
}
Link para o comentário
Compartilhar em outros sites

Visitante
Este tópico está impedido de receber novos posts.
×
×
  • Criar Novo...