diff --git a/src/main/java/com/Acrobot/ChestShop/Configuration/Properties.java b/src/main/java/com/Acrobot/ChestShop/Configuration/Properties.java index e1f9c08..d1d6a56 100644 --- a/src/main/java/com/Acrobot/ChestShop/Configuration/Properties.java +++ b/src/main/java/com/Acrobot/ChestShop/Configuration/Properties.java @@ -16,6 +16,7 @@ import java.util.EnumSet; import java.util.LinkedHashSet; import java.util.Locale; import java.util.Set; +import java.util.UUID; import java.util.logging.Level; /** @@ -75,6 +76,23 @@ public class Properties { return object; } }); + Configuration.registerParser("UUID", new ValueParser() { + @Override + public String parseToYAML(Object object) { + if (object instanceof UUID) { + return object.toString(); + } + return super.parseToYAML(object); + } + + @Override + public Object parseToJava(Class type, Object object) { + if (object instanceof String) { + return UUID.fromString((String) object); + } + return object; + } + }); } @ConfigurationComment("Should the plugin log some messages that are useful for debugging?") @@ -136,9 +154,12 @@ public class Properties { @ConfigurationComment("First line of your Admin Shop's sign should look like this:") public static String ADMIN_SHOP_NAME = "Admin Shop"; - @ConfigurationComment("The economy account which Admin Shops should use and to which all taxes will go") + @ConfigurationComment("The name of the economy account which Admin Shops should use and to which all taxes will go") public static String SERVER_ECONOMY_ACCOUNT = ""; + @ConfigurationComment("The uuid of the economy account for the Admin Shop. Useful for fake accounts as normally only accounts of players work") + public static UUID SERVER_ECONOMY_ACCOUNT_UUID = new UUID(0, 0); + @ConfigurationComment("Percent of the price that should go to the server's account. (100 = 100 percent)") public static int TAX_AMOUNT = 0; diff --git a/src/main/java/com/Acrobot/ChestShop/UUIDs/NameManager.java b/src/main/java/com/Acrobot/ChestShop/UUIDs/NameManager.java index e45cfbb..2b5af99 100644 --- a/src/main/java/com/Acrobot/ChestShop/UUIDs/NameManager.java +++ b/src/main/java/com/Acrobot/ChestShop/UUIDs/NameManager.java @@ -55,13 +55,25 @@ public class NameManager implements Listener { * @throws IllegalArgumentException when an invalid player object was passed */ public static Account getOrCreateAccount(OfflinePlayer player) { - Validate.notNull(player.getName(), "Name of player is null?"); - Validate.notNull(player.getUniqueId(), "UUID of player is null?"); - Validate.isTrue(player.getUniqueId().version() == uuidVersion, "Invalid OfflinePlayer! " + player.getUniqueId() + " is not of server version " + uuidVersion); + return getOrCreateAccount(player.getUniqueId(), player.getName()); + } - Account account = getAccount(player.getUniqueId()); + /** + * Get or create an account for a player + * + * @param id The UUID of the player to get or create the account for + * @param name The name of the player to get or create the account fo + * @return The account info + * @throws IllegalArgumentException when id or name are null + */ + public static Account getOrCreateAccount(UUID id, String name) { + Validate.notNull(id, "UUID of player is null?"); + Validate.notNull(name, "Name of player " + id + " is null?"); + Validate.isTrue(uuidVersion > -1 && id.version() == uuidVersion, "Invalid OfflinePlayer! " + id + " is not of server version " + uuidVersion); + + Account account = getAccount(id); if (account == null) { - account = storeUsername(new PlayerDTO(player.getUniqueId(), player.getName())); + account = storeUsername(new PlayerDTO(id, name)); } return account; } @@ -375,10 +387,13 @@ public class NameManager implements Listener { if (!Properties.SERVER_ECONOMY_ACCOUNT.isEmpty()) { serverEconomyAccount = getAccount(Properties.SERVER_ECONOMY_ACCOUNT); - if (serverEconomyAccount == null || serverEconomyAccount.getUuid() == null) { - serverEconomyAccount = null; - ChestShop.getBukkitLogger().log(Level.WARNING, "Server economy account setting '" + Properties.SERVER_ECONOMY_ACCOUNT + "' doesn't seem to be the name of a known player! Please log in at least once in order for the server economy account to work."); - } + } + if (serverEconomyAccount == null && !Properties.SERVER_ECONOMY_ACCOUNT.isEmpty() && !Properties.SERVER_ECONOMY_ACCOUNT_UUID.equals(new UUID(0, 0))) { + serverEconomyAccount = getOrCreateAccount(Properties.SERVER_ECONOMY_ACCOUNT_UUID, Properties.SERVER_ECONOMY_ACCOUNT); + } + if (serverEconomyAccount == null || serverEconomyAccount.getUuid() == null) { + serverEconomyAccount = null; + ChestShop.getBukkitLogger().log(Level.WARNING, "Server economy account setting '" + Properties.SERVER_ECONOMY_ACCOUNT + "' doesn't seem to be the name of a known player! Please log in at least once in order for the server economy account to work."); } } catch (SQLException e) { e.printStackTrace();