net.milkbowl.vault.economy.Economy Java Examples

The following examples show how to use net.milkbowl.vault.economy.Economy. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VaultHook.java    From FunnyGuilds with Apache License 2.0 6 votes vote down vote up
public static void initHooks() {
    RegisteredServiceProvider<Economy> economyProvider = Bukkit.getServer().getServicesManager().getRegistration(Economy.class);
    RegisteredServiceProvider<Permission> permissionProvider = Bukkit.getServer().getServicesManager().getRegistration(Permission.class);

    if (economyProvider != null) {
        economyHook = economyProvider.getProvider();
    }
    else {
        FunnyGuilds.getInstance().getPluginLogger().warning("No economy provider found, some features may not be available");
    }

    if (permissionProvider != null) {
        permissionHook = permissionProvider.getProvider();
    }
    else {
        FunnyGuilds.getInstance().getPluginLogger().warning("No permission provider found, some features may not be available");
    }
}
 
Example #2
Source File: BridgeImpl.java    From TabooLib with MIT License 6 votes vote down vote up
public BridgeImpl() {
    if (Bukkit.getPluginManager().getPlugin("Vault") != null) {
        economy = getRegisteredService(Economy.class);
        permission = getRegisteredService(Permission.class);
    }
    if (Bukkit.getPluginManager().getPlugin("WorldGuard") != null) {
        if (!WorldGuardPlugin.inst().getDescription().getVersion().startsWith("7")) {
            try {
                getRegionManager = WorldGuardPlugin.class.getDeclaredMethod("getRegionManager", World.class);
                getRegionManager.setAccessible(true);
            } catch (NoSuchMethodException e) {
                e.printStackTrace();
            }
        }
        worldguard = true;
    }
    placeholder = Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null;
}
 
Example #3
Source File: OffsetBounty.java    From GlobalWarming with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void cancel(GPlayer gPlayer) {
    int refund = 0;
    OffsetTable offsetTable = GlobalWarming.getInstance().getTableManager().getOffsetTable();
    List<OffsetBounty> cancelledBounties = offsetTable.cancel(gPlayer);
    Economy economy = GlobalWarming.getInstance().getEconomy();
    if (economy != null) {
        for (OffsetBounty bounty : cancelledBounties) {
            economy.depositPlayer(gPlayer.getOfflinePlayer(), bounty.getReward());
            refund += bounty.getReward();
        }
    }

    gPlayer.sendMsg(String.format(
            Lang.BOUNTY_CANCELLED.get(),
            cancelledBounties.size(),
            refund));
}
 
Example #4
Source File: OffsetBounty.java    From GlobalWarming with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Update the remaining blocks for an active bounty
 * - Requires a Vault-economy plugin to deposit funds
 */
public static OffsetBounty update(GPlayer hunter, int blocksCompleted) {
    OffsetTable offsetTable = GlobalWarming.getInstance().getTableManager().getOffsetTable();
    OffsetBounty bounty = offsetTable.update(hunter, blocksCompleted);
    if (bounty != null && bounty.getTimeCompleted() != 0) {
        Economy economy = GlobalWarming.getInstance().getEconomy();
        if (economy != null) {
            economy.depositPlayer(hunter.getOfflinePlayer(), bounty.getReward());
            notify(
                    bounty,
                    hunter,
                    String.format(Lang.BOUNTY_COMPLETEDBY.get(), hunter.getOfflinePlayer().getName()),
                    String.format(Lang.BOUNTY_COMPLETED.get(), bounty.getReward()));
        }
    }

    return bounty;
}
 
Example #5
Source File: Econ.java    From ClaimChunk with MIT License 6 votes vote down vote up
boolean setupEconomy(ClaimChunk instance) {
    this.instance = instance;

    // Check if Vault is present
    if (instance.getServer().getPluginManager().getPlugin("Vault") == null) return false;

    // Get the Vault service if it is present
    RegisteredServiceProvider<Economy> rsp = instance.getServer().getServicesManager().getRegistration(Economy.class);

    // Check if the service is valid
    if (rsp == null) return false;

    // Update current economy handler
    econ = rsp.getProvider();

    // Success
    return true;
}
 
Example #6
Source File: VaultIntegrator.java    From BetonQuest with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void hook() {
    RegisteredServiceProvider<Permission> permissionProvider = Bukkit.getServer().getServicesManager()
            .getRegistration(net.milkbowl.vault.permission.Permission.class);
    if (permissionProvider != null) {
        permission = permissionProvider.getProvider();
    }
    RegisteredServiceProvider<Economy> economyProvider = Bukkit.getServer().getServicesManager()
            .getRegistration(net.milkbowl.vault.economy.Economy.class);
    if (economyProvider != null) {
        economy = economyProvider.getProvider();
    }
    if (economy != null) {
        plugin.registerEvents("money", MoneyEvent.class);
        plugin.registerConditions("money", MoneyCondition.class);
        plugin.registerVariable("money", MoneyVariable.class);
    } else {
        LogUtils.getLogger().log(Level.WARNING, "There is no economy plugin on the server!");
    }
    if (permission != null) {
        plugin.registerEvents("permission", PermissionEvent.class);
    } else {
        LogUtils.getLogger().log(Level.WARNING, "Could not get permission provider!");
    }
}
 
Example #7
Source File: Vault.java    From Crazy-Auctions with MIT License 5 votes vote down vote up
public static boolean setupEconomy() {
    if (Bukkit.getServer().getPluginManager().getPlugin("Vault") == null) {
        return false;
    }
    RegisteredServiceProvider<Economy> rsp = Bukkit.getServer().getServicesManager().getRegistration(Economy.class);
    if (rsp == null) {
        return false;
    }
    econ = rsp.getProvider();
    return econ != null;
}
 
Example #8
Source File: VaultHelper.java    From askyblock with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets up the economy instance
 * 
 * @return true if successful
 */
public static boolean setupEconomy() {
    RegisteredServiceProvider<Economy> economyProvider = ASkyBlock.getPlugin().getServer().getServicesManager()
            .getRegistration(net.milkbowl.vault.economy.Economy.class);
    if (economyProvider != null) {
        econ = economyProvider.getProvider();
    }
    return econ != null;
}
 
Example #9
Source File: VaultHook.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("null")
@Override
protected boolean init() {
	economy = Bukkit.getServicesManager().getRegistration(Economy.class) == null ? null : Bukkit.getServicesManager().getRegistration(Economy.class).getProvider();
	chat = Bukkit.getServicesManager().getRegistration(Chat.class) == null ? null : Bukkit.getServicesManager().getRegistration(Chat.class).getProvider();
	permission = Bukkit.getServicesManager().getRegistration(Permission.class) == null ? null : Bukkit.getServicesManager().getRegistration(Permission.class).getProvider();
	return economy != null || chat != null || permission != null;
}
 
Example #10
Source File: VaultHandler.java    From Parties with GNU Affero General Public License v3.0 5 votes vote down vote up
private boolean setupEconomy() {
	boolean ret = false;
	RegisteredServiceProvider<Economy> rsp = Bukkit.getServer().getServicesManager().getRegistration(Economy.class);
	if (rsp != null) {
		economy = rsp.getProvider();
		ret = economy != null;
	}
	return ret;
}
 
Example #11
Source File: VaultEconomy.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
private Optional<Economy> setupEconomy() {
    RegisteredServiceProvider<Economy> rsp =
        plugin.getServer().getServicesManager().getRegistration(Economy.class);
    if (rsp != null) {
        economy = rsp.getProvider();
        return Optional.of(economy);
    }

    return Optional.empty();
}
 
Example #12
Source File: VaultEconomy.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
@SuppressWarnings("unused")
public void onEconomyRegister(ServiceRegisterEvent event) {
    if (event.getProvider().getProvider() instanceof Economy) {
        setupEconomy().ifPresent((economy) -> this.economy = economy);
    }
}
 
Example #13
Source File: VaultManager.java    From UhcCore with GNU General Public License v3.0 5 votes vote down vote up
public static void setupEconomy(){
  	if(!GameManager.getGameManager().getConfiguration().getVaultLoaded()){
  		return;
}

  	RegisteredServiceProvider<Economy> economyProvider = Bukkit.getServer().getServicesManager().getRegistration(Economy.class);
   if (economyProvider != null) {
       economy = economyProvider.getProvider();
   }else{
   	Bukkit.getLogger().severe("[UhcCore] Error trying to load economy provider. Check that you have a economy plugin installed");
   }
  }
 
Example #14
Source File: Main.java    From BedWars with GNU Lesser General Public License v3.0 5 votes vote down vote up
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 true;
}
 
Example #15
Source File: AreaShop.java    From AreaShop with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Function to get the Vault plugin.
 * @return Economy
 */
public Economy getEconomy() {
	RegisteredServiceProvider<Economy> economy = getServer().getServicesManager().getRegistration(net.milkbowl.vault.economy.Economy.class);
	if(economy == null || economy.getProvider() == null) {
		error("There is no economy provider to support Vault, make sure you installed an economy plugin");
		return null;
	}
	return economy.getProvider();
}
 
Example #16
Source File: PluginHooks.java    From TAB with Apache License 2.0 5 votes vote down vote up
public static void Vault_loadProviders() {
	RegisteredServiceProvider<Economy> rspEconomy = Bukkit.getServicesManager().getRegistration(Economy.class);
	if (rspEconomy != null) Vault_economy = rspEconomy.getProvider();
	RegisteredServiceProvider<Permission> rspPermission = Bukkit.getServicesManager().getRegistration(Permission.class);
	if (rspPermission != null) Vault_permission = rspPermission.getProvider();
	RegisteredServiceProvider<Chat> rspChat = Bukkit.getServicesManager().getRegistration(Chat.class);
	if (rspChat != null) Vault_chat = rspChat.getProvider();
}
 
Example #17
Source File: VaultEconomy.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
@SuppressWarnings("unused")
public void onEconomyUnregister(ServiceUnregisterEvent event) {
    if (event.getProvider().getProvider() instanceof Economy) {
        this.economy = null;
        setupEconomy().ifPresent((economy) -> this.economy = economy);
    }
}
 
Example #18
Source File: VaultEconomyHook.java    From factions-top with MIT License 5 votes vote down vote up
@Override
public void initialize() {
    RegisteredServiceProvider<Economy> rsp = plugin.getServer().getServicesManager().getRegistration(Economy.class);

    if (rsp == null || (economy = rsp.getProvider()) == null) {
        plugin.getLogger().warning("No economy provider for Vault found!");
        plugin.getLogger().warning("Economy support by Vault is now disabled.");
        return;
    }

    plugin.getServer().getPluginManager().registerEvents(this, plugin);
    runTaskTimer(plugin, liquidUpdateTicks, liquidUpdateTicks);
    enabled = true;
}
 
Example #19
Source File: VaultVariables.java    From ScoreboardStats with MIT License 5 votes vote down vote up
public VaultVariables(ReplacerAPI replaceManager, Plugin plugin) throws UnsupportedPluginException {
    super(replaceManager, plugin);

    RegisteredServiceProvider<Economy> economyProvider = Bukkit.getServicesManager().getRegistration(Economy.class);
    if (economyProvider == null) {
        //check if an economy plugin is installed otherwise it would throw a exception if the want to replace
        throw new UnsupportedPluginException("Cannot find an economy plugin");
    } else {
        economy = economyProvider.getProvider();
    }
}
 
Example #20
Source File: PlayerInteractListener.java    From PetMaster with GNU General Public License v3.0 5 votes vote down vote up
public PlayerInteractListener(PetMaster petMaster) {
	this.plugin = petMaster;
	version = Integer.parseInt(PackageType.getServerVersion().split("_")[1]);
	// Try to retrieve an Economy instance from Vault.
	if (Bukkit.getServer().getPluginManager().getPlugin("Vault") != null) {
		RegisteredServiceProvider<Economy> rsp = Bukkit.getServer().getServicesManager()
				.getRegistration(Economy.class);
		if (rsp != null) {
			economy = rsp.getProvider();
		}
	}
}
 
Example #21
Source File: EconHook.java    From Survival-Games with GNU General Public License v3.0 5 votes vote down vote up
public void executehook(String player, String[] s2) {
	if(EconomyManager.getInstance().econPresent()){
		Economy econ = EconomyManager.getInstance().getEcon();
		String split[] = s2[1].split(" ");
		if(split.length == 3){
			Player p = Bukkit.getServer().getPlayer(split[1]);
			int funds = Integer.parseInt(split[2]);
			if(split[0].equals("remove")){
				econ.bankWithdraw(p.getName(), funds);
			}
		}
	}
}
 
Example #22
Source File: FlagEntryFee.java    From HeavySpleef with GNU General Public License v3.0 5 votes vote down vote up
public Economy getEconomy() {
	//Lazy initialization
	if (economy == null) {
		HookManager manager = getHeavySpleef().getHookManager();
		economy = manager.getHook(HookReference.VAULT).getService(Economy.class);
	}
	
	return economy;
}
 
Example #23
Source File: Main.java    From BedWars with GNU Lesser General Public License v3.0 5 votes vote down vote up
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 true;
}
 
Example #24
Source File: VaultHook.java    From AnnihilationPro with MIT License 5 votes vote down vote up
private boolean verifyEcon()
{
	if(Bukkit.getPluginManager().getPlugin("Vault") == null) 
		return false;
	//Bukkit.getLogger().info("Here 1");
	RegisteredServiceProvider<Economy> rsp = Bukkit.getServicesManager().getRegistration(Economy.class);
	if (rsp == null) 
	    return false;
	//Bukkit.getLogger().info("Here 2");
	econ = rsp.getProvider();
	//Bukkit.getLogger().info("Here 3");
	return econ != null;
}
 
Example #25
Source File: ShopChest.java    From ShopChest with MIT License 5 votes vote down vote up
/**
 * Sets up the economy of Vault
 * @return Whether an economy plugin has been registered
 */
private boolean setupEconomy() {
    RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
    if (rsp == null) {
        return false;
    }
    econ = rsp.getProvider();
    return econ != null;
}
 
Example #26
Source File: VaultUtils.java    From SkyWarsReloaded with GNU General Public License v3.0 5 votes vote down vote up
private boolean setupEconomy() {
	if (Bukkit.getServer().getPluginManager().getPlugin("Vault") == null) {
           return false;
       }
       RegisteredServiceProvider<Economy> rsp = Bukkit.getServer().getServicesManager().getRegistration(Economy.class);
       if (rsp == null) {
           return false;
       }
       econ = rsp.getProvider();
       return econ != null;
}
 
Example #27
Source File: VaultUtils.java    From SkyWarsReloaded with GNU General Public License v3.0 5 votes vote down vote up
private boolean setupEconomy() {
	if (Bukkit.getServer().getPluginManager().getPlugin("Vault") == null) {
           return false;
       }
       RegisteredServiceProvider<Economy> rsp = Bukkit.getServer().getServicesManager().getRegistration(Economy.class);
       if (rsp == null) {
           return false;
       }
       econ = rsp.getProvider();
       return econ != null;
}
 
Example #28
Source File: PlayerSerializer.java    From PerWorldInventory with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Deserialize all aspects of a player, and apply their data. See {@link PlayerSerializer#serialize(PWIPlayer)}
 * for an explanation of the data format number.
 *
 * @param data   The saved player information.
 * @param player The Player to apply the deserialized information to.
 */
public void deserialize(final JsonObject data, final Player player, DeserializeCause cause) {
    ConsoleLogger.debug("[SERIALIZER] Deserializing player '" + player.getName()+ "'");

    int format = 0;
    if (data.has("data-format"))
        format = data.get("data-format").getAsInt();

    if (settings.getProperty(PwiProperties.LOAD_ENDER_CHESTS) && data.has("ender-chest"))
        player.getEnderChest().setContents(inventorySerializer.deserializeInventory(data.getAsJsonArray("ender-chest"),
                player.getEnderChest().getSize(), format));
    if (settings.getProperty(PwiProperties.LOAD_INVENTORY) && data.has("inventory"))
        inventorySerializer.setInventory(player, data.getAsJsonObject("inventory"), format);
    if (data.has("stats"))
        statSerializer.deserialize(player, data.getAsJsonObject("stats"), format);
    if (plugin.isEconEnabled()) {
        Economy econ = plugin.getEconomy();
        if (econ == null) {
            ConsoleLogger.warning("Economy saving is turned on, but no economy found!");
            return;
        }

        ConsoleLogger.debug("[ECON] Withdrawing " + econ.getBalance(player) + " from '" + player.getName() + "'!");
        EconomyResponse er = econ.withdrawPlayer(player, econ.getBalance(player));
        if (!er.transactionSuccess()) {
            ConsoleLogger.warning("[ECON] Unable to withdraw funds from '" + player.getName() + "': " + er.errorMessage);
        }

        if (data.has("economy") && er.transactionSuccess()) {
            EconomySerializer.deserialize(econ, data.getAsJsonObject("economy"), player);
        }
    }

    ConsoleLogger.debug("[SERIALIZER] Done deserializing player '" + player.getName()+ "'");

    // Call event to signal loading is done
    InventoryLoadCompleteEvent event = new InventoryLoadCompleteEvent(player, cause);
    bukkitService.callEvent(event);
}
 
Example #29
Source File: EconomyBridge.java    From ChestCommands with GNU General Public License v3.0 5 votes vote down vote up
public static boolean setupEconomy() {
	if (Bukkit.getPluginManager().getPlugin("Vault") == null) {
		return false;
	}
	RegisteredServiceProvider<Economy> rsp = Bukkit.getServicesManager().getRegistration(Economy.class);
	if (rsp == null) {
		return false;
	}
	economy = rsp.getProvider();
	return economy != null;
}
 
Example #30
Source File: Utils.java    From PerWorldInventory with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Set a player's stats to defaults, and optionally clear their inventory.
 *
 * @param plugin {@link PerWorldInventory} for econ.
 * @param player The player to zero.
 * @param clearInventory Clear the player's inventory.
 */
public static void zeroPlayer(PerWorldInventory plugin, Player player, boolean clearInventory) {
    if (clearInventory) {
        player.getInventory().clear();
        player.getEnderChest().clear();
    }

    player.setExp(0f);
    player.setFoodLevel(20);

    if (checkServerVersion(Bukkit.getVersion(), 1, 9, 0)) {
        player.setHealth(player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue());
    } else {
        player.setHealth(player.getMaxHealth());
    }

    player.setLevel(0);
    for (PotionEffect effect : player.getActivePotionEffects()) {
        player.removePotionEffect(effect.getType());
    }
    player.setSaturation(5f);
    player.setFallDistance(0f);
    player.setFireTicks(0);

    if (plugin.isEconEnabled()) {
        Economy econ = plugin.getEconomy();
        econ.bankWithdraw(player.getName(), econ.bankBalance(player.getName()).amount);
        econ.withdrawPlayer(player, econ.getBalance(player));
    }
}