Class VaultEconomyProvider
- All Implemented Interfaces:
EconomyProvider
EconomyProvider's only implementation in 6.3.0 (D-08/D-09).
Every net.milkbowl.vault reference in this class lives inside a method body as a local
variable, never as a declared return type, parameter type, or field type — none of this class's
own methods need an allowlist entry in buildtools.SoftDependencySignatureInvariantTest's
structural guard, unlike EconomyUtils (which keeps a genuine Vault-typed public
signature for backward compatibility and therefore does need one). This split is deliberate:
it is exactly what lets the container reflect over this class — and every other class in the
framework — without the eager Class.getDeclaredMethods() signature resolution that
caused #451, while still concentrating every Vault type reference in one small, obviously-named
class instead of scattering it across the framework. Deliberately no shared private helper
returning Economy/RegisteredServiceProvider<Economy> either — that would put a
Vault-typed signature back on this class and need the very allowlist entry this design avoids;
vaultInstalled() exists for exactly this reason, returning a plain boolean.
Every public method re-checks Vault's presence and the registered provider on every call — the
state is never cached — because Vault, and the economy plugin that registers the provider, can
load after this framework does; Bukkit does not guarantee plugin load order beyond declared
dependencies. vaultInstalled() guards every method both against a live
Bukkit.getServer() not existing yet at all (measured: DependenceManagersTest
invokes the real initCoreServices() — which now wires this class in — against a bare
Mockito JavaPlugin with no Bukkit.setServer(...) call, exactly the environment
this guard exists for) and against no plugin named "Vault" being installed at all
(Codex P1, PR #463: Economy.class is a provided-scope Vault type — on a live
server missing Vault's jar, evaluating that class literal throws NoClassDefFoundError
before the registration == null fallback check below it ever runs; a live-but-non-null
Bukkit.getServer() alone says nothing about whether Vault itself is on the classpath).
vaultInstalled() is the single guard every method below calls — see its own javadoc for
why that call must happen strictly before the Economy.class reference, never sharing an
expression with it, and why this class does not instead have a shared private helper that
returns an Economy/RegisteredServiceProvider<Economy>-typed value.
- Since:
- 6.3.0
- Author:
- wisdomme
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.ultikits.ultitools.services.EconomyProvider
EconomyProvider.State -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleandeposit(org.bukkit.OfflinePlayer player, double amount) format(double amount) doublegetBalance(org.bukkit.OfflinePlayer player) The active provider's display name, for the framework's start-up log line.getState()The current state, re-evaluated on every call rather than cached — a provider can register (or Vault can be installed) after this framework has already started, since plugin load order is not guaranteed.booleanhas(org.bukkit.OfflinePlayer player, double amount) private static booleanThe single guard every method below calls, strictly before referencingEconomy.classanywhere in that method — never in a shared expression evaluated ahead of this check, since aldcclass-literal reference resolves lazily at the bytecode site where it executes, so guarding here is exactly what keeps that reference unreached (and therefore unresolved) when Vault is absent.booleanwithdraw(org.bukkit.OfflinePlayer player, double amount)
-
Field Details
-
VAULT_PLUGIN_NAME
- See Also:
-
-
Constructor Details
-
VaultEconomyProvider
public VaultEconomyProvider()
-
-
Method Details
-
vaultInstalled
private static boolean vaultInstalled()The single guard every method below calls, strictly before referencingEconomy.classanywhere in that method — never in a shared expression evaluated ahead of this check, since aldcclass-literal reference resolves lazily at the bytecode site where it executes, so guarding here is exactly what keeps that reference unreached (and therefore unresolved) when Vault is absent.Deliberately a plain
boolean, not a shared private helper returningEconomy/RegisteredServiceProvider<Economy>— see the class javadoc for why a Vault-typed return here would put a Vault-typed signature back on this class and need the verySoftDependencySignatureInvariantTestallowlist entry this design avoids.- Returns:
falsewhen no liveServeris set yet, or when no plugin named"Vault"is installed — every method below treats both cases identically, as Vault being unavailable
-
getState
Description copied from interface:EconomyProviderThe current state, re-evaluated on every call rather than cached — a provider can register (or Vault can be installed) after this framework has already started, since plugin load order is not guaranteed.- Specified by:
getStatein interfaceEconomyProvider- Returns:
- the current economy-availability state
-
getProviderName
Description copied from interface:EconomyProviderThe active provider's display name, for the framework's start-up log line.- Specified by:
getProviderNamein interfaceEconomyProvider- Returns:
- the provider's name, or
nullwhenEconomyProvider.getState()is notEconomyProvider.State.AVAILABLE
-
getBalance
public double getBalance(org.bukkit.OfflinePlayer player) - Specified by:
getBalancein interfaceEconomyProvider- Parameters:
player- the player to query- Returns:
- the player's balance, or
0when unavailable
-
has
public boolean has(org.bukkit.OfflinePlayer player, double amount) - Specified by:
hasin interfaceEconomyProvider- Parameters:
player- the player to queryamount- the amount to check- Returns:
trueif the player has at leastamount,falsewhen unavailable or insufficient
-
deposit
public boolean deposit(org.bukkit.OfflinePlayer player, double amount) - Specified by:
depositin interfaceEconomyProvider- Parameters:
player- the player to creditamount- the amount to deposit- Returns:
trueif the deposit succeeded
-
withdraw
public boolean withdraw(org.bukkit.OfflinePlayer player, double amount) - Specified by:
withdrawin interfaceEconomyProvider- Parameters:
player- the player to debitamount- the amount to withdraw- Returns:
trueif the withdrawal succeeded
-
format
- Specified by:
formatin interfaceEconomyProvider- Parameters:
amount- the amount to format- Returns:
- the provider's own formatted string, or a plain two-decimal fallback when unavailable
-
getCurrencyNameSingular
- Specified by:
getCurrencyNameSingularin interfaceEconomyProvider- Returns:
- the provider's singular currency name, or a fallback when unavailable
-
getCurrencyNamePlural
- Specified by:
getCurrencyNamePluralin interfaceEconomyProvider- Returns:
- the provider's plural currency name, or a fallback when unavailable
-