Class VaultEconomyProvider

java.lang.Object
com.ultikits.ultitools.services.impl.VaultEconomyProvider
All Implemented Interfaces:
EconomyProvider

@Internal public final class VaultEconomyProvider extends Object implements EconomyProvider
The Vault consumer bridge — 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
    Modifier and Type
    Field
    Description
    private static final String
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    deposit(org.bukkit.OfflinePlayer player, double amount)
     
    format(double amount)
     
    double
    getBalance(org.bukkit.OfflinePlayer player)
     
     
     
    The active provider's display name, for the framework's start-up log line.
    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.
    boolean
    has(org.bukkit.OfflinePlayer player, double amount)
     
    private static boolean
    The single guard every method below calls, strictly before referencing Economy.class anywhere in that method — never in a shared expression evaluated ahead of this check, since a ldc class-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.
    boolean
    withdraw(org.bukkit.OfflinePlayer player, double amount)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • VaultEconomyProvider

      public VaultEconomyProvider()
  • Method Details

    • vaultInstalled

      private static boolean vaultInstalled()
      The single guard every method below calls, strictly before referencing Economy.class anywhere in that method — never in a shared expression evaluated ahead of this check, since a ldc class-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 returning Economy/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 very SoftDependencySignatureInvariantTest allowlist entry this design avoids.

      Returns:
      false when no live Server is set yet, or when no plugin named "Vault" is installed — every method below treats both cases identically, as Vault being unavailable
    • getState

      public EconomyProvider.State getState()
      Description copied from interface: EconomyProvider
      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.
      Specified by:
      getState in interface EconomyProvider
      Returns:
      the current economy-availability state
    • getProviderName

      public String getProviderName()
      Description copied from interface: EconomyProvider
      The active provider's display name, for the framework's start-up log line.
      Specified by:
      getProviderName in interface EconomyProvider
      Returns:
      the provider's name, or null when EconomyProvider.getState() is not EconomyProvider.State.AVAILABLE
    • getBalance

      public double getBalance(org.bukkit.OfflinePlayer player)
      Specified by:
      getBalance in interface EconomyProvider
      Parameters:
      player - the player to query
      Returns:
      the player's balance, or 0 when unavailable
    • has

      public boolean has(org.bukkit.OfflinePlayer player, double amount)
      Specified by:
      has in interface EconomyProvider
      Parameters:
      player - the player to query
      amount - the amount to check
      Returns:
      true if the player has at least amount, false when unavailable or insufficient
    • deposit

      public boolean deposit(org.bukkit.OfflinePlayer player, double amount)
      Specified by:
      deposit in interface EconomyProvider
      Parameters:
      player - the player to credit
      amount - the amount to deposit
      Returns:
      true if the deposit succeeded
    • withdraw

      public boolean withdraw(org.bukkit.OfflinePlayer player, double amount)
      Specified by:
      withdraw in interface EconomyProvider
      Parameters:
      player - the player to debit
      amount - the amount to withdraw
      Returns:
      true if the withdrawal succeeded
    • format

      public String format(double amount)
      Specified by:
      format in interface EconomyProvider
      Parameters:
      amount - the amount to format
      Returns:
      the provider's own formatted string, or a plain two-decimal fallback when unavailable
    • getCurrencyNameSingular

      public String getCurrencyNameSingular()
      Specified by:
      getCurrencyNameSingular in interface EconomyProvider
      Returns:
      the provider's singular currency name, or a fallback when unavailable
    • getCurrencyNamePlural

      public String getCurrencyNamePlural()
      Specified by:
      getCurrencyNamePlural in interface EconomyProvider
      Returns:
      the provider's plural currency name, or a fallback when unavailable