Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package mc.CushyPro.AddonMoney;
- import org.bukkit.plugin.RegisteredServiceProvider;
- import org.luaj.vm2.LuaTable;
- import org.luaj.vm2.LuaValue;
- import org.luaj.vm2.lib.OneArgFunction;
- import org.luaj.vm2.lib.TwoArgFunction;
- import org.luaj.vm2.lib.ZeroArgFunction;
- import mc.CushyPro.HanaBot.APIS.HanaAddon;
- import net.milkbowl.vault.economy.Economy;
- public class Main extends HanaAddon {
- private static Economy econ = null;
- public void onEnable() {
- if (setupEconomy()) {
- System.out.print("Fail to Load Economy");
- return;
- }
- System.out.print("Load Economy Successful");
- AddLibrary("money", new Money());
- }
- public class Money extends ZeroArgFunction {
- @Override
- public LuaValue call() {
- LuaTable table = new LuaTable();
- table.set("get", new getMoney());
- return table;
- }
- public class setMoney extends TwoArgFunction {
- @SuppressWarnings("deprecation")
- @Override
- public LuaValue call(LuaValue args0,LuaValue args1) {
- if (args0.isstring() && args1.isnumber()) {
- double newmo = args1.checkdouble();
- double money = econ.getBalance(args0.checkjstring());
- if (money > newmo) {
- double a = money - newmo;
- econ.withdrawPlayer(args0.checkjstring(), a);
- return LuaValue.valueOf(money - a);
- } else if (newmo > money) {
- double a = newmo - money;
- econ.depositPlayer(args0.checkjstring(), a);
- return LuaValue.valueOf(a + money);
- }
- }
- return LuaValue.valueOf("getMoney(string playername) double");
- }
- }
- public class getMoney extends OneArgFunction {
- @SuppressWarnings("deprecation")
- @Override
- public LuaValue call(LuaValue args) {
- if (args.isstring()) {
- return LuaValue.valueOf(econ.getBalance(args.checkjstring()));
- }
- return LuaValue.valueOf("getMoney(string playername) double");
- }
- }
- }
- 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;
- }
- }
Add Comment
Please, Sign In to add comment