From 9fa2f92ef8684f33da0ec6117d63e93a8af1163a Mon Sep 17 00:00:00 2001 From: Andrzej Pomirski Date: Sat, 14 Jun 2014 20:46:59 +0200 Subject: [PATCH] Switch Vault from names to UUIDs --- .../java/com/Acrobot/ChestShop/ChestShop.java | 3 -- .../Acrobot/ChestShop/Economy/Economy.java | 7 ++-- .../Events/Economy/AccountCheckEvent.java | 10 +++--- .../Events/Economy/CurrencyAddEvent.java | 10 +++--- .../Events/Economy/CurrencyAmountEvent.java | 10 +++--- .../Events/Economy/CurrencyCheckEvent.java | 12 +++---- .../Events/Economy/CurrencyHoldEvent.java | 12 +++---- .../Events/Economy/CurrencySubtractEvent.java | 10 +++--- .../Events/Economy/CurrencyTransferEvent.java | 13 +++---- .../Economy/Plugins/VaultListener.java | 18 +++++----- .../Economy/ServerAccountCorrector.java | 34 ++++++++++--------- .../Listeners/Economy/TaxModule.java | 14 ++++---- .../PostTransaction/EconomicModule.java | 5 ++- .../PreTransaction/AmountAndPriceChecker.java | 3 +- .../PartialTransactionModule.java | 10 +++--- .../ShopRemoval/ShopRefundListener.java | 3 +- .../Acrobot/ChestShop/UUIDs/NameManager.java | 4 +++ 17 files changed, 93 insertions(+), 85 deletions(-) diff --git a/src/main/java/com/Acrobot/ChestShop/ChestShop.java b/src/main/java/com/Acrobot/ChestShop/ChestShop.java index d37648d..cb2e4d5 100644 --- a/src/main/java/com/Acrobot/ChestShop/ChestShop.java +++ b/src/main/java/com/Acrobot/ChestShop/ChestShop.java @@ -39,7 +39,6 @@ import com.Acrobot.ChestShop.UUIDs.NameManager; import com.Acrobot.ChestShop.Updater.Updater; import com.avaje.ebean.EbeanServer; import com.lennardf1989.bukkitex.Database; -import com.nijikokun.register.payment.forChestShop.Methods; import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Marker; @@ -105,8 +104,6 @@ public class ChestShop extends JavaPlugin { NameManager.load(); - Methods.setPreferred(Properties.PREFERRED_ECONOMY_PLUGIN); - Dependencies.loadPlugins(); registerEvents(); diff --git a/src/main/java/com/Acrobot/ChestShop/Economy/Economy.java b/src/main/java/com/Acrobot/ChestShop/Economy/Economy.java index 7060195..7ebaece 100644 --- a/src/main/java/com/Acrobot/ChestShop/Economy/Economy.java +++ b/src/main/java/com/Acrobot/ChestShop/Economy/Economy.java @@ -11,6 +11,7 @@ import org.bukkit.World; import org.bukkit.inventory.Inventory; import java.math.BigDecimal; +import java.util.UUID; /** * @author Acrobot @@ -25,21 +26,21 @@ public class Economy { return !ChestShopSign.isAdminShop(inventory) || !getServerAccountName().isEmpty(); } - public static boolean add(String name, World world, double amount) { + public static boolean add(UUID name, World world, double amount) { CurrencyAddEvent event = new CurrencyAddEvent(BigDecimal.valueOf(amount), name, world); ChestShop.callEvent(event); return true; } - public static boolean subtract(String name, World world, double amount) { + public static boolean subtract(UUID name, World world, double amount) { CurrencySubtractEvent event = new CurrencySubtractEvent(BigDecimal.valueOf(amount), name, world); ChestShop.callEvent(event); return true; } - public static boolean hasEnough(String name, World world, double amount) { + public static boolean hasEnough(UUID name, World world, double amount) { CurrencyCheckEvent event = new CurrencyCheckEvent(BigDecimal.valueOf(amount), name, world); ChestShop.callEvent(event); diff --git a/src/main/java/com/Acrobot/ChestShop/Events/Economy/AccountCheckEvent.java b/src/main/java/com/Acrobot/ChestShop/Events/Economy/AccountCheckEvent.java index f0e5398..19d1def 100644 --- a/src/main/java/com/Acrobot/ChestShop/Events/Economy/AccountCheckEvent.java +++ b/src/main/java/com/Acrobot/ChestShop/Events/Economy/AccountCheckEvent.java @@ -4,6 +4,8 @@ import org.bukkit.World; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; +import java.util.UUID; + /** * Checks for the existence of an account * @@ -14,15 +16,15 @@ public class AccountCheckEvent extends Event { boolean outcome; - private String account; + private UUID account; private World world; - public AccountCheckEvent(String account, World world) { + public AccountCheckEvent(UUID account, World world) { this.account = account; this.world = world; } - public AccountCheckEvent(String account) { + public AccountCheckEvent(UUID account) { this.account = account; } @@ -45,7 +47,7 @@ public class AccountCheckEvent extends Event { /** * @return Account which is being checked */ - public String getAccount() { + public UUID getAccount() { return account; } diff --git a/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencyAddEvent.java b/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencyAddEvent.java index bf9ea8a..679e4d7 100644 --- a/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencyAddEvent.java +++ b/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencyAddEvent.java @@ -1,12 +1,12 @@ package com.Acrobot.ChestShop.Events.Economy; -import com.Acrobot.ChestShop.UUIDs.NameManager; import org.bukkit.World; import org.bukkit.entity.Player; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; import java.math.BigDecimal; +import java.util.UUID; /** * Represents an addition of goods to entity @@ -19,17 +19,17 @@ public class CurrencyAddEvent extends Event { boolean added; private BigDecimal amount; - private String target; + private UUID target; private World world; - public CurrencyAddEvent(BigDecimal amount, String target, World world) { + public CurrencyAddEvent(BigDecimal amount, UUID target, World world) { this.amount = amount; this.target = target; this.world = world; } public CurrencyAddEvent(BigDecimal amount, Player target) { - this(amount, NameManager.getUsername(target.getUniqueId()), target.getWorld()); + this(amount, target.getUniqueId(), target.getWorld()); } /** @@ -92,7 +92,7 @@ public class CurrencyAddEvent extends Event { /** * @return Account from which the currency is subtracted */ - public String getTarget() { + public UUID getTarget() { return target; } diff --git a/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencyAmountEvent.java b/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencyAmountEvent.java index 0263808..923a5ae 100644 --- a/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencyAmountEvent.java +++ b/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencyAmountEvent.java @@ -1,12 +1,12 @@ package com.Acrobot.ChestShop.Events.Economy; -import com.Acrobot.ChestShop.UUIDs.NameManager; import org.bukkit.World; import org.bukkit.entity.Player; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; import java.math.BigDecimal; +import java.util.UUID; /** * Checks the amount of currency available @@ -17,16 +17,16 @@ public class CurrencyAmountEvent extends Event { private static final HandlerList handlers = new HandlerList(); private BigDecimal amount = BigDecimal.ZERO; - private String account; + private UUID account; private World world; - public CurrencyAmountEvent(String account, World world) { + public CurrencyAmountEvent(UUID account, World world) { this.account = account; this.world = world; } public CurrencyAmountEvent(Player player) { - this(NameManager.getUsername(player.getUniqueId()), player.getWorld()); + this(player.getUniqueId(), player.getWorld()); } /** @@ -73,7 +73,7 @@ public class CurrencyAmountEvent extends Event { /** * @return Account that is checked */ - public String getAccount() { + public UUID getAccount() { return account; } diff --git a/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencyCheckEvent.java b/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencyCheckEvent.java index 304f40d..ef22b73 100644 --- a/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencyCheckEvent.java +++ b/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencyCheckEvent.java @@ -1,12 +1,12 @@ package com.Acrobot.ChestShop.Events.Economy; -import com.Acrobot.ChestShop.UUIDs.NameManager; import org.bukkit.World; import org.bukkit.entity.Player; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; import java.math.BigDecimal; +import java.util.UUID; /** * Represents a check for the existence of specified currency amount @@ -19,17 +19,17 @@ public class CurrencyCheckEvent extends Event { boolean outcome; private BigDecimal amount; - private String account; + private UUID account; private World world; - public CurrencyCheckEvent(BigDecimal amount, String account, World world) { + public CurrencyCheckEvent(BigDecimal amount, UUID account, World world) { this.amount = amount; this.account = account; this.world = world; } public CurrencyCheckEvent(BigDecimal amount, Player player) { - this(amount, NameManager.getUsername(player.getUniqueId()), player.getWorld()); + this(amount, player.getUniqueId(), player.getWorld()); } /** @@ -92,7 +92,7 @@ public class CurrencyCheckEvent extends Event { /** * @return Account that is checked */ - public String getAccount() { + public UUID getAccount() { return account; } @@ -101,7 +101,7 @@ public class CurrencyCheckEvent extends Event { * * @param account Account name */ - public void setAccount(String account) { + public void setAccount(UUID account) { this.account = account; } diff --git a/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencyHoldEvent.java b/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencyHoldEvent.java index d4d28d3..d645823 100644 --- a/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencyHoldEvent.java +++ b/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencyHoldEvent.java @@ -1,12 +1,12 @@ package com.Acrobot.ChestShop.Events.Economy; -import com.Acrobot.ChestShop.UUIDs.NameManager; import org.bukkit.World; import org.bukkit.entity.Player; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; import java.math.BigDecimal; +import java.util.UUID; /** * Checks if the account can hold the amount of currency @@ -19,17 +19,17 @@ public class CurrencyHoldEvent extends Event { boolean canHold = true; private BigDecimal amount; - private String account; + private UUID account; private World world; - public CurrencyHoldEvent(BigDecimal amount, String account, World world) { + public CurrencyHoldEvent(BigDecimal amount, UUID account, World world) { this.amount = amount; this.account = account; this.world = world; } public CurrencyHoldEvent(BigDecimal amount, Player target) { - this(amount, NameManager.getUsername(target.getUniqueId()), target.getWorld()); + this(amount, target.getUniqueId(), target.getWorld()); } /** @@ -92,7 +92,7 @@ public class CurrencyHoldEvent extends Event { /** * @return Account that is checked */ - public String getAccount() { + public UUID getAccount() { return account; } @@ -101,7 +101,7 @@ public class CurrencyHoldEvent extends Event { * * @param account Account name */ - public void setAccount(String account) { + public void setAccount(UUID account) { this.account = account; } diff --git a/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencySubtractEvent.java b/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencySubtractEvent.java index f6dc869..478c68f 100644 --- a/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencySubtractEvent.java +++ b/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencySubtractEvent.java @@ -1,12 +1,12 @@ package com.Acrobot.ChestShop.Events.Economy; -import com.Acrobot.ChestShop.UUIDs.NameManager; import org.bukkit.World; import org.bukkit.entity.Player; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; import java.math.BigDecimal; +import java.util.UUID; /** * Represents a subtraction of goods from entity @@ -19,17 +19,17 @@ public class CurrencySubtractEvent extends Event { boolean subtracted; private BigDecimal amount; - private String target; + private UUID target; private World world; - public CurrencySubtractEvent(BigDecimal amount, String target, World world) { + public CurrencySubtractEvent(BigDecimal amount, UUID target, World world) { this.amount = amount; this.target = target; this.world = world; } public CurrencySubtractEvent(BigDecimal amount, Player target) { - this(amount, NameManager.getUsername(target.getUniqueId()), target.getWorld()); + this(amount, target.getUniqueId(), target.getWorld()); } /** @@ -92,7 +92,7 @@ public class CurrencySubtractEvent extends Event { /** * @return Account from which the currency is subtracted */ - public String getTarget() { + public UUID getTarget() { return target; } diff --git a/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencyTransferEvent.java b/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencyTransferEvent.java index 760f85d..908b05a 100644 --- a/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencyTransferEvent.java +++ b/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencyTransferEvent.java @@ -5,6 +5,7 @@ import org.bukkit.event.Event; import org.bukkit.event.HandlerList; import java.math.BigDecimal; +import java.util.UUID; /** * Represents a transaction of goods between two entities @@ -16,11 +17,11 @@ public class CurrencyTransferEvent extends Event { private BigDecimal amount; private World world; - private String sender; - private String receiver; + private UUID sender; + private UUID receiver; private boolean success; - public CurrencyTransferEvent(BigDecimal amount, String sender, String receiver, World world) { + public CurrencyTransferEvent(BigDecimal amount, UUID sender, UUID receiver, World world) { this.amount = amount; this.world = world; @@ -28,7 +29,7 @@ public class CurrencyTransferEvent extends Event { this.receiver = receiver; } - public CurrencyTransferEvent(double amount, String sender, String receiver, World world) { + public CurrencyTransferEvent(double amount, UUID sender, UUID receiver, World world) { this(BigDecimal.valueOf(amount), sender, receiver, world); } @@ -92,14 +93,14 @@ public class CurrencyTransferEvent extends Event { /** * @return Sender of the money */ - public String getSender() { + public UUID getSender() { return sender; } /** * @return Receiver of the money */ - public String getReceiver() { + public UUID getReceiver() { return receiver; } diff --git a/src/main/java/com/Acrobot/ChestShop/Listeners/Economy/Plugins/VaultListener.java b/src/main/java/com/Acrobot/ChestShop/Listeners/Economy/Plugins/VaultListener.java index 2734521..5d4729f 100644 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/Economy/Plugins/VaultListener.java +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/Economy/Plugins/VaultListener.java @@ -60,7 +60,7 @@ public class VaultListener implements Listener { return; } - double balance = provider.getBalance(event.getAccount(), event.getWorld().getName()); + double balance = provider.getBalance(Bukkit.getOfflinePlayer(event.getAccount()), event.getWorld().getName()); if (balance > Double.MAX_VALUE) { balance = Double.MAX_VALUE; @@ -77,7 +77,7 @@ public class VaultListener implements Listener { World world = event.getWorld(); - if (provider.has(event.getAccount(), world.getName(), event.getDoubleAmount())) { + if (provider.has(Bukkit.getOfflinePlayer(event.getAccount()), world.getName(), event.getDoubleAmount())) { event.hasEnough(true); } } @@ -90,7 +90,7 @@ public class VaultListener implements Listener { World world = event.getWorld(); - if (!provider.hasAccount(event.getAccount(), world.getName())) { + if (!provider.hasAccount(Bukkit.getOfflinePlayer(event.getAccount()), world.getName())) { event.hasAccount(false); } } @@ -114,7 +114,7 @@ public class VaultListener implements Listener { World world = event.getWorld(); - provider.depositPlayer(event.getTarget(), world.getName(), event.getDoubleAmount()); + provider.depositPlayer(Bukkit.getOfflinePlayer(event.getTarget()), world.getName(), event.getDoubleAmount()); } @EventHandler @@ -125,7 +125,7 @@ public class VaultListener implements Listener { World world = event.getWorld(); - provider.withdrawPlayer(event.getTarget(), world.getName(), event.getDoubleAmount()); + provider.withdrawPlayer(Bukkit.getOfflinePlayer(event.getTarget()), world.getName(), event.getDoubleAmount()); } @EventHandler @@ -147,22 +147,22 @@ public class VaultListener implements Listener { @EventHandler public void onCurrencyHoldCheck(CurrencyHoldEvent event) { - if (event.getAccount().isEmpty() || !transactionCanFail()) { + if (event.getAccount() == null || !transactionCanFail()) { return; } - if (!provider.hasAccount(event.getAccount(), event.getWorld().getName())) { + if (!provider.hasAccount(Bukkit.getOfflinePlayer(event.getAccount()), event.getWorld().getName())) { event.canHold(false); return; } - EconomyResponse response = provider.depositPlayer(event.getAccount(), event.getWorld().getName(), event.getDoubleAmount()); + EconomyResponse response = provider.depositPlayer(Bukkit.getOfflinePlayer(event.getAccount()), event.getWorld().getName(), event.getDoubleAmount()); if (!response.transactionSuccess()) { event.canHold(false); return; } - provider.withdrawPlayer(event.getAccount(), event.getWorld().getName(), event.getDoubleAmount()); + provider.withdrawPlayer(Bukkit.getOfflinePlayer(event.getAccount()), event.getWorld().getName(), event.getDoubleAmount()); } } diff --git a/src/main/java/com/Acrobot/ChestShop/Listeners/Economy/ServerAccountCorrector.java b/src/main/java/com/Acrobot/ChestShop/Listeners/Economy/ServerAccountCorrector.java index 903d2db..e73b240 100644 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/Economy/ServerAccountCorrector.java +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/Economy/ServerAccountCorrector.java @@ -2,12 +2,14 @@ package com.Acrobot.ChestShop.Listeners.Economy; import com.Acrobot.ChestShop.ChestShop; import com.Acrobot.ChestShop.Events.Economy.*; -import com.Acrobot.ChestShop.Signs.ChestShopSign; +import com.Acrobot.ChestShop.UUIDs.NameManager; +import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import java.math.BigDecimal; +import java.util.UUID; import static com.Acrobot.ChestShop.Configuration.Properties.SERVER_ECONOMY_ACCOUNT; @@ -18,9 +20,9 @@ public class ServerAccountCorrector implements Listener { @EventHandler(priority = EventPriority.LOWEST) public static void onCurrencyAdd(CurrencyAddEvent event) { - String target = event.getTarget(); + UUID target = event.getTarget(); - if (!ChestShopSign.isAdminShop(target) || event.getTarget().equals(SERVER_ECONOMY_ACCOUNT)) { + if (!NameManager.isAdminShop(target) || Bukkit.getOfflinePlayer(target).getName().equals(SERVER_ECONOMY_ACCOUNT)) { return; } @@ -28,7 +30,7 @@ public class ServerAccountCorrector implements Listener { event.setAdded(true); return; } else { - target = SERVER_ECONOMY_ACCOUNT; + target = Bukkit.getOfflinePlayer(SERVER_ECONOMY_ACCOUNT).getUniqueId(); } event.setAdded(true); @@ -39,9 +41,9 @@ public class ServerAccountCorrector implements Listener { @EventHandler(priority = EventPriority.LOWEST) public static void onCurrencySubtract(CurrencySubtractEvent event) { - String target = event.getTarget(); + UUID target = event.getTarget(); - if (!ChestShopSign.isAdminShop(target) || event.getTarget().equals(SERVER_ECONOMY_ACCOUNT)) { + if (!NameManager.isAdminShop(target) || Bukkit.getOfflinePlayer(target).getName().equals(SERVER_ECONOMY_ACCOUNT)) { return; } @@ -49,7 +51,7 @@ public class ServerAccountCorrector implements Listener { event.setSubtracted(true); return; } else { - target = SERVER_ECONOMY_ACCOUNT; + target = Bukkit.getOfflinePlayer(SERVER_ECONOMY_ACCOUNT).getUniqueId(); } event.setSubtracted(true); @@ -60,9 +62,9 @@ public class ServerAccountCorrector implements Listener { @EventHandler(priority = EventPriority.LOWEST) public static void onCurrencyCheck(CurrencyCheckEvent event) { - String target = event.getAccount(); + UUID target = event.getAccount(); - if (!ChestShopSign.isAdminShop(target) || event.getAccount().equals(SERVER_ECONOMY_ACCOUNT)) { + if (!NameManager.isAdminShop(target) || Bukkit.getOfflinePlayer(target).getName().equals(SERVER_ECONOMY_ACCOUNT)) { return; } @@ -70,7 +72,7 @@ public class ServerAccountCorrector implements Listener { event.hasEnough(true); return; } else { - target = SERVER_ECONOMY_ACCOUNT; + target = Bukkit.getOfflinePlayer(SERVER_ECONOMY_ACCOUNT).getUniqueId(); } CurrencyCheckEvent currencyCheckEvent = new CurrencyCheckEvent(event.getAmount(), target, event.getWorld()); @@ -81,21 +83,21 @@ public class ServerAccountCorrector implements Listener { @EventHandler(priority = EventPriority.LOWEST) public static void onCurrencyHoldCheck(CurrencyHoldEvent event) { - String target = event.getAccount(); + UUID target = event.getAccount(); - if (!ChestShopSign.isAdminShop(target) || event.getAccount().equals(SERVER_ECONOMY_ACCOUNT)) { + if (!NameManager.isAdminShop(target) || Bukkit.getOfflinePlayer(target).getName().equals(SERVER_ECONOMY_ACCOUNT)) { return; } event.canHold(true); - event.setAccount(""); + event.setAccount(null); } @EventHandler(priority = EventPriority.LOWEST) public static void onBalanceCheck(CurrencyAmountEvent event) { - String target = event.getAccount(); + UUID target = event.getAccount(); - if (!ChestShopSign.isAdminShop(target) || event.getAccount().equals(SERVER_ECONOMY_ACCOUNT)) { + if (!NameManager.isAdminShop(target) || Bukkit.getOfflinePlayer(target).getName().equals(SERVER_ECONOMY_ACCOUNT)) { return; } @@ -103,7 +105,7 @@ public class ServerAccountCorrector implements Listener { event.setAmount(BigDecimal.valueOf(Double.MAX_VALUE)); return; } else { - target = SERVER_ECONOMY_ACCOUNT; + target = Bukkit.getOfflinePlayer(SERVER_ECONOMY_ACCOUNT).getUniqueId(); } CurrencyAmountEvent currencyAmountEvent = new CurrencyAmountEvent(target, event.getWorld()); diff --git a/src/main/java/com/Acrobot/ChestShop/Listeners/Economy/TaxModule.java b/src/main/java/com/Acrobot/ChestShop/Listeners/Economy/TaxModule.java index 266aa2a..d3530be 100644 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/Economy/TaxModule.java +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/Economy/TaxModule.java @@ -4,12 +4,14 @@ import com.Acrobot.ChestShop.ChestShop; import com.Acrobot.ChestShop.Configuration.Properties; import com.Acrobot.ChestShop.Economy.Economy; import com.Acrobot.ChestShop.Events.Economy.CurrencyAddEvent; -import com.Acrobot.ChestShop.Signs.ChestShopSign; +import com.Acrobot.ChestShop.UUIDs.NameManager; +import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import java.math.BigDecimal; +import java.util.UUID; /** * @author Acrobot @@ -20,8 +22,8 @@ public class TaxModule implements Listener { return price.multiply(BigDecimal.valueOf(taxAmount).divide(BigDecimal.valueOf(100))); } - private static boolean isServerAccount(String name) { - return ChestShopSign.isAdminShop(name); + private static boolean isServerAccount(UUID name) { + return NameManager.isAdminShop(name); } @EventHandler(priority = EventPriority.LOW) @@ -30,9 +32,9 @@ public class TaxModule implements Listener { return; } - String target = event.getTarget(); + UUID target = event.getTarget(); - if (target.equals(Economy.getServerAccountName())) { + if (Bukkit.getOfflinePlayer(target).getName().equals(Economy.getServerAccountName())) { return; } @@ -45,7 +47,7 @@ public class TaxModule implements Listener { BigDecimal tax = getTax(event.getAmount(), taxAmount); if (!Economy.getServerAccountName().isEmpty()) { - CurrencyAddEvent currencyAddEvent = new CurrencyAddEvent(tax, Economy.getServerAccountName(), event.getWorld()); + CurrencyAddEvent currencyAddEvent = new CurrencyAddEvent(tax, Bukkit.getOfflinePlayer(Economy.getServerAccountName()).getUniqueId(), event.getWorld()); ChestShop.callEvent(currencyAddEvent); } diff --git a/src/main/java/com/Acrobot/ChestShop/Listeners/PostTransaction/EconomicModule.java b/src/main/java/com/Acrobot/ChestShop/Listeners/PostTransaction/EconomicModule.java index 4dbab7f..44beac1 100644 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/PostTransaction/EconomicModule.java +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/PostTransaction/EconomicModule.java @@ -4,7 +4,6 @@ import com.Acrobot.ChestShop.ChestShop; import com.Acrobot.ChestShop.Events.Economy.CurrencyAddEvent; import com.Acrobot.ChestShop.Events.Economy.CurrencySubtractEvent; import com.Acrobot.ChestShop.Events.TransactionEvent; -import com.Acrobot.ChestShop.UUIDs.NameManager; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -24,7 +23,7 @@ public class EconomicModule implements Listener { } CurrencyAddEvent currencyAddEvent = new CurrencyAddEvent(BigDecimal.valueOf(event.getPrice()), - NameManager.getUsername(event.getOwner().getUniqueId()), + event.getOwner().getUniqueId(), event.getSign().getWorld()); ChestShop.callEvent(currencyAddEvent); @@ -39,7 +38,7 @@ public class EconomicModule implements Listener { } CurrencySubtractEvent currencySubtractEvent = new CurrencySubtractEvent(BigDecimal.valueOf(event.getPrice()), - NameManager.getUsername(event.getOwner().getUniqueId()), + event.getOwner().getUniqueId(), event.getSign().getWorld()); ChestShop.callEvent(currencySubtractEvent); diff --git a/src/main/java/com/Acrobot/ChestShop/Listeners/PreTransaction/AmountAndPriceChecker.java b/src/main/java/com/Acrobot/ChestShop/Listeners/PreTransaction/AmountAndPriceChecker.java index 4abddd9..d1c37af 100644 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/PreTransaction/AmountAndPriceChecker.java +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/PreTransaction/AmountAndPriceChecker.java @@ -4,7 +4,6 @@ import com.Acrobot.Breeze.Utils.InventoryUtil; import com.Acrobot.ChestShop.ChestShop; import com.Acrobot.ChestShop.Events.Economy.CurrencyCheckEvent; import com.Acrobot.ChestShop.Events.PreTransactionEvent; -import com.Acrobot.ChestShop.UUIDs.NameManager; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.inventory.Inventory; @@ -53,7 +52,7 @@ public class AmountAndPriceChecker implements Listener { Inventory clientInventory = event.getClientInventory(); CurrencyCheckEvent currencyCheckEvent = new CurrencyCheckEvent(BigDecimal.valueOf(event.getPrice()), - NameManager.getUsername(event.getOwner().getUniqueId()), + event.getOwner().getUniqueId(), event.getSign().getWorld()); ChestShop.callEvent(currencyCheckEvent); diff --git a/src/main/java/com/Acrobot/ChestShop/Listeners/PreTransaction/PartialTransactionModule.java b/src/main/java/com/Acrobot/ChestShop/Listeners/PreTransaction/PartialTransactionModule.java index f5eefab..73e1ff1 100644 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/PreTransaction/PartialTransactionModule.java +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/PreTransaction/PartialTransactionModule.java @@ -8,7 +8,6 @@ import com.Acrobot.ChestShop.Events.Economy.CurrencyAmountEvent; import com.Acrobot.ChestShop.Events.Economy.CurrencyCheckEvent; import com.Acrobot.ChestShop.Events.Economy.CurrencyHoldEvent; import com.Acrobot.ChestShop.Events.PreTransactionEvent; -import com.Acrobot.ChestShop.UUIDs.NameManager; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -19,6 +18,7 @@ import org.bukkit.inventory.ItemStack; import java.math.BigDecimal; import java.util.LinkedList; import java.util.List; +import java.util.UUID; import static com.Acrobot.ChestShop.Events.PreTransactionEvent.TransactionOutcome.*; import static com.Acrobot.ChestShop.Events.TransactionEvent.TransactionType.BUY; @@ -61,7 +61,7 @@ public class PartialTransactionModule implements Listener { event.setStock(getCountedItemStack(stock, amountAffordable)); } - String seller = NameManager.getUsername(event.getOwner().getUniqueId()); + UUID seller = event.getOwner().getUniqueId(); CurrencyHoldEvent currencyHoldEvent = new CurrencyHoldEvent(BigDecimal.valueOf(price), seller, client.getWorld()); ChestShop.callEvent(currencyHoldEvent); @@ -94,19 +94,19 @@ public class PartialTransactionModule implements Listener { } Player client = event.getClient(); - String ownerName = NameManager.getUsername(event.getOwner().getUniqueId()); + UUID owner = event.getOwner().getUniqueId(); ItemStack[] stock = event.getStock(); double price = event.getPrice(); double pricePerItem = event.getPrice() / InventoryUtil.countItems(stock); - CurrencyAmountEvent currencyAmountEvent = new CurrencyAmountEvent(ownerName, client.getWorld()); + CurrencyAmountEvent currencyAmountEvent = new CurrencyAmountEvent(owner, client.getWorld()); ChestShop.callEvent(currencyAmountEvent); BigDecimal walletMoney = currencyAmountEvent.getAmount(); if (Economy.isOwnerEconomicallyActive(event.getOwnerInventory())) { - CurrencyCheckEvent currencyCheckEvent = new CurrencyCheckEvent(BigDecimal.valueOf(price), ownerName, client.getWorld()); + CurrencyCheckEvent currencyCheckEvent = new CurrencyCheckEvent(BigDecimal.valueOf(price), owner, client.getWorld()); ChestShop.callEvent(currencyCheckEvent); if (!currencyCheckEvent.hasEnough()) { diff --git a/src/main/java/com/Acrobot/ChestShop/Listeners/ShopRemoval/ShopRefundListener.java b/src/main/java/com/Acrobot/ChestShop/Listeners/ShopRemoval/ShopRefundListener.java index 74cc276..bbb0b3f 100644 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/ShopRemoval/ShopRefundListener.java +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/ShopRemoval/ShopRefundListener.java @@ -13,6 +13,7 @@ import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import java.math.BigDecimal; +import java.util.UUID; import static com.Acrobot.ChestShop.Permission.NOFEE; import static com.Acrobot.ChestShop.Signs.ChestShopSign.NAME_LINE; @@ -29,7 +30,7 @@ public class ShopRefundListener implements Listener { return; } - String owner = NameManager.getFullUsername(event.getSign().getLine(NAME_LINE)); + UUID owner = NameManager.getUUID(event.getSign().getLine(NAME_LINE)); CurrencyAddEvent currencyEvent = new CurrencyAddEvent(BigDecimal.valueOf(refundPrice), owner, event.getSign().getWorld()); ChestShop.callEvent(currencyEvent); diff --git a/src/main/java/com/Acrobot/ChestShop/UUIDs/NameManager.java b/src/main/java/com/Acrobot/ChestShop/UUIDs/NameManager.java index fbc33ab..2e48f78 100644 --- a/src/main/java/com/Acrobot/ChestShop/UUIDs/NameManager.java +++ b/src/main/java/com/Acrobot/ChestShop/UUIDs/NameManager.java @@ -158,6 +158,10 @@ public class NameManager { return shortenedName.equals(name) || Permission.otherName(player, name); } + public static boolean isAdminShop(UUID uuid) { + return getUsername(uuid).equals(Properties.ADMIN_SHOP_NAME); + } + public static void load() { File databaseFile = ChestShop.loadFile("users.db"); String uri = ConnectionManager.getURI(databaseFile);