Add UUID support to Vault.

This commit adds UUID support to Vault, allowing plugins to bypass the
OfflinePlayer methods which result in Bukkit trying to resolve a player
to associate with the OfflinePlayer (via the server playercache and if
that player doesn't exist via Mojang.)

This is incredibly useful for any plugin which wants to have an Economy
account that isn't associated with a player. This includes Towny,
Factions, Shops plugins and others.

Most importantly: having UUID methods will give these plugins an avenue
to update from using the String accountName methods deprecated since
Vault 1.4, which doesn't result in slow OfflinePlayer creation.

AbstractEconomy has been updated so that the various Economy plugins
supported internally by Vault will have support for the new methods in
the same manner as when the OfflinePlayer methods were added.

Small javadoc typos have also been fixed up (extra {'s, an additional
{@link, etc.)
This commit is contained in:
Llm Dl 2021-04-04 10:32:25 -05:00
parent af58e675c3
commit 5c61077842
3 changed files with 237 additions and 20 deletions

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>net.milkbowl.vault</groupId>
<artifactId>VaultAPI</artifactId>
<version>1.7</version>
<version>1.8</version>
<name>VaultAPI</name>
<description>Vault is a Permissions &amp; Economy API to allow plugins to more easily hook into these systems without needing to hook each individual system themselves.

View File

@ -1,5 +1,8 @@
package net.milkbowl.vault.economy;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
@SuppressWarnings("deprecation")
@ -16,6 +19,18 @@ public abstract class AbstractEconomy implements Economy {
if (player.getName() == null) return false;
return hasAccount(player.getName(), worldName);
}
@Override
public boolean hasAccount(UUID uuid) {
if (uuid == null) return false;
return hasAccount(Bukkit.getOfflinePlayer(uuid));
}
@Override
public boolean hasAccount(UUID uuid, String worldName) {
if (uuid == null) return false;
return hasAccount(Bukkit.getOfflinePlayer(uuid), worldName);
}
@Override
public double getBalance(OfflinePlayer player) {
@ -23,8 +38,18 @@ public abstract class AbstractEconomy implements Economy {
}
@Override
public double getBalance(OfflinePlayer player, String world) {
return getBalance(player.getName(), world);
public double getBalance(OfflinePlayer player, String worldName) {
return getBalance(player.getName(), worldName);
}
@Override
public double getBalance(UUID uuid) {
return getBalance(Bukkit.getOfflinePlayer(uuid));
}
@Override
public double getBalance(UUID uuid, String worldName) {
return getBalance(Bukkit.getOfflinePlayer(uuid), worldName);
}
@Override
@ -38,6 +63,18 @@ public abstract class AbstractEconomy implements Economy {
if (player.getName() == null) return false;
return has(player.getName(), worldName, amount);
}
@Override
public boolean has(UUID uuid, double amount) {
if (uuid == null) return false;
return has(Bukkit.getOfflinePlayer(uuid), amount);
}
@Override
public boolean has(UUID uuid, String worldName, double amount) {
if (uuid == null) return false;
return has(Bukkit.getOfflinePlayer(uuid), worldName, amount);
}
@Override
public EconomyResponse withdrawPlayer(OfflinePlayer player, double amount) {
@ -49,6 +86,16 @@ public abstract class AbstractEconomy implements Economy {
return withdrawPlayer(player.getName(), worldName, amount);
}
@Override
public EconomyResponse withdrawPlayer(UUID uuid, double amount) {
return withdrawPlayer(Bukkit.getOfflinePlayer(uuid), amount);
}
@Override
public EconomyResponse withdrawPlayer(UUID uuid, String worldName, double amount) {
return withdrawPlayer(Bukkit.getOfflinePlayer(uuid), worldName, amount);
}
@Override
public EconomyResponse depositPlayer(OfflinePlayer player, double amount) {
return depositPlayer(player.getName(), amount);
@ -59,20 +106,45 @@ public abstract class AbstractEconomy implements Economy {
return depositPlayer(player.getName(), worldName, amount);
}
@Override
public EconomyResponse depositPlayer(UUID uuid, double amount) {
return depositPlayer(Bukkit.getOfflinePlayer(uuid), amount);
}
@Override
public EconomyResponse depositPlayer(UUID uuid, String worldName, double amount) {
return depositPlayer(Bukkit.getOfflinePlayer(uuid), worldName, amount);
}
@Override
public EconomyResponse createBank(String name, OfflinePlayer player) {
return createBank(name, player.getName());
}
@Override
public EconomyResponse createBank(String name, UUID uuid) {
return createBank(name, Bukkit.getOfflinePlayer(uuid));
}
@Override
public EconomyResponse isBankOwner(String name, OfflinePlayer player) {
return isBankOwner(name, player.getName());
}
@Override
public EconomyResponse isBankOwner(String name, UUID uuid) {
return isBankOwner(name, Bukkit.getOfflinePlayer(uuid));
}
@Override
public EconomyResponse isBankMember(String name, OfflinePlayer player) {
return isBankMember(name, player.getName());
}
@Override
public EconomyResponse isBankMember(String name, UUID uuid ) {
return isBankMember(name, Bukkit.getOfflinePlayer(uuid));
}
@Override
public boolean createPlayerAccount(OfflinePlayer player) {
@ -84,4 +156,13 @@ public abstract class AbstractEconomy implements Economy {
return createPlayerAccount(player.getName(), worldName);
}
@Override
public boolean createPlayerAccount(UUID uuid) {
return createPlayerAccount(Bukkit.getOfflinePlayer(uuid));
}
@Override
public boolean createPlayerAccount(UUID uuid, String worldName) {
return createPlayerAccount(Bukkit.getOfflinePlayer(uuid), worldName);
}
}

View File

@ -17,6 +17,7 @@
package net.milkbowl.vault.economy;
import java.util.List;
import java.util.UUID;
import org.bukkit.OfflinePlayer;
@ -80,7 +81,7 @@ public interface Economy {
/**
*
* @deprecated As of VaultAPI 1.4 use {@link #hasAccount(OfflinePlayer)} instead.
* @deprecated As of VaultAPI 1.4 use {@link #hasAccount(OfflinePlayer)} or {@link #hasAccount(UUID)} instead.
*/
@Deprecated
public boolean hasAccount(String playerName);
@ -96,7 +97,15 @@ public interface Economy {
public boolean hasAccount(OfflinePlayer player);
/**
* @deprecated As of VaultAPI 1.4 use {@link #hasAccount(OfflinePlayer, String)} instead.
* Checks if this uuid has an account yet
*
* @param uuid to check
* @return if the uuid has an account
*/
public boolean hasAccount(UUID uuid);
/**
* @deprecated As of VaultAPI 1.4 use {@link #hasAccount(OfflinePlayer, String)} or {@link #hasAccount(UUID, String)} instead.
*/
@Deprecated
public boolean hasAccount(String playerName, String worldName);
@ -113,7 +122,16 @@ public interface Economy {
public boolean hasAccount(OfflinePlayer player, String worldName);
/**
* @deprecated As of VaultAPI 1.4 use {@link #getBalance(OfflinePlayer)} instead.
* Checks if this uuid has an account yet on the given world
*
* @param uuid to check
* @param worldName world-specific account
* @return if the uuid has an account
*/
public boolean hasAccount(UUID uuid, String worldName);
/**
* @deprecated As of VaultAPI 1.4 use {@link #getBalance(OfflinePlayer)} or {@link #getBalance(UUID)} instead.
*/
@Deprecated
public double getBalance(String playerName);
@ -127,7 +145,15 @@ public interface Economy {
public double getBalance(OfflinePlayer player);
/**
* @deprecated As of VaultAPI 1.4 use {@link #getBalance(OfflinePlayer, String)} instead.
* Gets balance of a UUID
*
* @param uuid of the account to get a balance for
* @return Amount currently held in account associated with the given UUID
*/
public double getBalance(UUID uuid);
/**
* @deprecated As of VaultAPI 1.4 use {@link #getBalance(OfflinePlayer, String)} or {@link #getBalance(UUID, String)} instead.
*/
@Deprecated
public double getBalance(String playerName, String world);
@ -142,7 +168,16 @@ public interface Economy {
public double getBalance(OfflinePlayer player, String world);
/**
* @deprecated As of VaultAPI 1.4 use {@link #has(OfflinePlayer, double)} instead.
* Gets balance of a UUID on the specified world.
* IMPLEMENTATION SPECIFIC - if an economy plugin does not support this the global balance will be returned.
* @param uuid of the account to get a balance for
* @param world name of the world
* @return Amount currently held in account associated with the given UUID
*/
public double getBalance(UUID uuid, String world);
/**
* @deprecated As of VaultAPI 1.4 use {@link #has(OfflinePlayer, double)} or {@link #has(UUID, double)} instead.
*/
@Deprecated
public boolean has(String playerName, double amount);
@ -157,7 +192,16 @@ public interface Economy {
public boolean has(OfflinePlayer player, double amount);
/**
* @deprecated As of VaultAPI 1.4 use @{link {@link #has(OfflinePlayer, String, double)} instead.
* Checks if the account associated with the given UUID has the amount - DO NOT USE NEGATIVE AMOUNTS
*
* @param uuid to check
* @param amount to check for
* @return True if <b>UUID</b> has <b>amount</b>, False else wise
*/
public boolean has(UUID uuid, double amount);
/**
* @deprecated As of VaultAPI 1.4 use {@link #has(OfflinePlayer, String, double)} or {@link #has(UUID, String, double)} instead.
*/
@Deprecated
public boolean has(String playerName, String worldName, double amount);
@ -169,12 +213,23 @@ public interface Economy {
* @param player to check
* @param worldName to check with
* @param amount to check for
* @return True if <b>player</b> has <b>amount</b>, False else wise
* @return True if <b>player</b> has <b>amount</b> in the given <b>world</b>, False else wise
*/
public boolean has(OfflinePlayer player, String worldName, double amount);
/**
* @deprecated As of VaultAPI 1.4 use {@link #withdrawPlayer(OfflinePlayer, double)} instead.
* Checks if the account associated with the given UUID has the amount in the given world - DO NOT USE NEGATIVE AMOUNTS
* IMPLEMENTATION SPECIFIC - if an economy plugin does not support this the global balance will be returned.
*
* @param uuid to check
* @param worldName to check with
* @param amount to check for
* @return True if <b>UUID</b> has <b>amount</b> in the given <b>world</b>, False else wise
*/
public boolean has(UUID uuid, String worldName, double amount);
/**
* @deprecated As of VaultAPI 1.4 use {@link #withdrawPlayer(OfflinePlayer, double)} or {@link #withdrawPlayer(UUID, double)} instead.
*/
@Deprecated
public EconomyResponse withdrawPlayer(String playerName, double amount);
@ -189,7 +244,16 @@ public interface Economy {
public EconomyResponse withdrawPlayer(OfflinePlayer player, double amount);
/**
* @deprecated As of VaultAPI 1.4 use {@link #withdrawPlayer(OfflinePlayer, String, double)} instead.
* Withdraw an amount from an account associated with a UUID - DO NOT USE NEGATIVE AMOUNTS
*
* @param uuid to withdraw from
* @param amount Amount to withdraw
* @return Detailed response of transaction
*/
public EconomyResponse withdrawPlayer(UUID uuid, double amount);
/**
* @deprecated As of VaultAPI 1.4 use {@link #withdrawPlayer(OfflinePlayer, String, double)} or {@link #withdrawPlayer(UUID, String, double)} instead.
*/
@Deprecated
public EconomyResponse withdrawPlayer(String playerName, String worldName, double amount);
@ -205,7 +269,17 @@ public interface Economy {
public EconomyResponse withdrawPlayer(OfflinePlayer player, String worldName, double amount);
/**
* @deprecated As of VaultAPI 1.4 use {@link #depositPlayer(OfflinePlayer, double)} instead.
* Withdraw an amount from an account associated with a UUID on a given world - DO NOT USE NEGATIVE AMOUNTS
* IMPLEMENTATION SPECIFIC - if an economy plugin does not support this the global balance will be returned.
* @param uuid to withdraw from
* @param worldName - name of the world
* @param amount Amount to withdraw
* @return Detailed response of transaction
*/
public EconomyResponse withdrawPlayer(UUID uuid, String worldName, double amount);
/**
* @deprecated As of VaultAPI 1.4 use {@link #depositPlayer(OfflinePlayer, double)} or {@link #depositPlayer(UUID, double)} instead.
*/
@Deprecated
public EconomyResponse depositPlayer(String playerName, double amount);
@ -220,13 +294,22 @@ public interface Economy {
public EconomyResponse depositPlayer(OfflinePlayer player, double amount);
/**
* @deprecated As of VaultAPI 1.4 use {@link #depositPlayer(OfflinePlayer, String, double)} instead.
* Deposit an amount to an account associated with the given UUID - DO NOT USE NEGATIVE AMOUNTS
*
* @param uuid to deposit to
* @param amount Amount to deposit
* @return Detailed response of transaction
*/
public EconomyResponse depositPlayer(UUID uuid, double amount);
/**
* @deprecated As of VaultAPI 1.4 use {@link #depositPlayer(OfflinePlayer, String, double)} or {@link #depositPlayer(UUID, String, double)} instead.
*/
@Deprecated
public EconomyResponse depositPlayer(String playerName, String worldName, double amount);
/**
* Deposit an amount to a player - DO NOT USE NEGATIVE AMOUNTS
* Deposit an amount to a player on a given world - DO NOT USE NEGATIVE AMOUNTS
* IMPLEMENTATION SPECIFIC - if an economy plugin does not support this the global balance will be returned.
*
* @param player to deposit to
@ -237,7 +320,18 @@ public interface Economy {
public EconomyResponse depositPlayer(OfflinePlayer player, String worldName, double amount);
/**
* @deprecated As of VaultAPI 1.4 use {{@link #createBank(String, OfflinePlayer)} instead.
* Deposit an amount from an account associated with a UUID on a given world - DO NOT USE NEGATIVE AMOUNTS
* IMPLEMENTATION SPECIFIC - if an economy plugin does not support this the global balance will be returned.
*
* @param uuid to deposit to
* @param worldName name of the world
* @param amount Amount to deposit
* @return Detailed response of transaction
*/
public EconomyResponse depositPlayer(UUID uuid, String worldName, double amount);
/**
* @deprecated As of VaultAPI 1.4 use {@link #createBank(String, OfflinePlayer)} or {@link #createBank(String, UUID)} instead.
*/
@Deprecated
public EconomyResponse createBank(String name, String player);
@ -249,6 +343,14 @@ public interface Economy {
* @return EconomyResponse Object
*/
public EconomyResponse createBank(String name, OfflinePlayer player);
/**
* Creates a bank account with the specified name and the given UUID as the owner
* @param name of account
* @param uuid the account should be linked to
* @return EconomyResponse Object
*/
public EconomyResponse createBank(String name, UUID uuid);
/**
* Deletes a bank account with the specified name.
@ -292,7 +394,7 @@ public interface Economy {
public EconomyResponse bankDeposit(String name, double amount);
/**
* @deprecated As of VaultAPI 1.4 use {{@link #isBankOwner(String, OfflinePlayer)} instead.
* @deprecated As of VaultAPI 1.4 use {@link #isBankOwner(String, OfflinePlayer)} or {@link #isBankOwner(String, UUID)} instead.
*/
@Deprecated
public EconomyResponse isBankOwner(String name, String playerName);
@ -305,9 +407,18 @@ public interface Economy {
* @return EconomyResponse Object
*/
public EconomyResponse isBankOwner(String name, OfflinePlayer player);
/**
* Check if a uuid is the owner of a bank account
*
* @param name of the account
* @param uuid to check for ownership
* @return EconomyResponse Object
*/
public EconomyResponse isBankOwner(String name, UUID uuid);
/**
* @deprecated As of VaultAPI 1.4 use {{@link #isBankMember(String, OfflinePlayer)} instead.
* @deprecated As of VaultAPI 1.4 use {@link #isBankMember(String, OfflinePlayer)} or {@link #isBankMember(String, UUID)} instead.
*/
@Deprecated
public EconomyResponse isBankMember(String name, String playerName);
@ -320,6 +431,15 @@ public interface Economy {
* @return EconomyResponse Object
*/
public EconomyResponse isBankMember(String name, OfflinePlayer player);
/**
* Check if the uuid is a member of the bank account
*
* @param name of the account
* @param uuid to check membership
* @return EconomyResponse Object
*/
public EconomyResponse isBankMember(String name, UUID uuid);
/**
* Gets the list of banks
@ -328,7 +448,7 @@ public interface Economy {
public List<String> getBanks();
/**
* @deprecated As of VaultAPI 1.4 use {{@link #createPlayerAccount(OfflinePlayer)} instead.
* @deprecated As of VaultAPI 1.4 use {@link #createPlayerAccount(OfflinePlayer)} or {@link #createPlayerAccount(UUID)} instead.
*/
@Deprecated
public boolean createPlayerAccount(String playerName);
@ -341,7 +461,14 @@ public interface Economy {
public boolean createPlayerAccount(OfflinePlayer player);
/**
* @deprecated As of VaultAPI 1.4 use {{@link #createPlayerAccount(OfflinePlayer, String)} instead.
* Attempts to create a account for the given uuid
* @param uuid associated with the account
* @return if the account creation was successful
*/
public boolean createPlayerAccount(UUID uuid);
/**
* @deprecated As of VaultAPI 1.4 use {@link #createPlayerAccount(OfflinePlayer, String)} or {@link #createPlayerAccount(UUID, String)} instead.
*/
@Deprecated
public boolean createPlayerAccount(String playerName, String worldName);
@ -354,4 +481,13 @@ public interface Economy {
* @return if the account creation was successful
*/
public boolean createPlayerAccount(OfflinePlayer player, String worldName);
/**
* Attempts to create an account for the given UUID on the specified world
* IMPLEMENTATION SPECIFIC - if an economy plugin does not support this then false will always be returned.
* @param uuid associated with the account
* @param worldName String name of the world
* @return if the account creation was successful
*/
public boolean createPlayerAccount(UUID uuid, String worldName);
}