From 4107b10f4b4467fef2faf6ad118a6afcecbb89c8 Mon Sep 17 00:00:00 2001 From: Andrzej Pomirski Date: Sat, 12 Apr 2014 13:57:39 +0200 Subject: [PATCH] More UUID changes --- .../com/Acrobot/Breeze/Utils/BlockUtil.java | 5 +- .../java/com/Acrobot/ChestShop/ChestShop.java | 14 ++--- .../Events/Economy/CurrencyAddEvent.java | 4 +- .../Events/Economy/CurrencyAmountEvent.java | 4 +- .../Events/Economy/CurrencyCheckEvent.java | 4 +- .../Events/Economy/CurrencyHoldEvent.java | 4 +- .../Events/Economy/CurrencySubtractEvent.java | 4 +- .../Listeners/Block/Break/SignBreak.java | 2 +- .../Listeners/Player/PlayerConnect.java | 4 +- .../Listeners/Player/PlayerInteract.java | 6 +- .../Listeners/Player/ShortNameSaver.java | 16 ----- .../PostTransaction/EconomicModule.java | 6 +- .../TransactionMessageSender.java | 4 +- .../PreShopCreation/NameChecker.java | 11 +++- .../PreTransaction/AmountAndPriceChecker.java | 4 +- .../PartialTransactionModule.java | 6 +- .../ShopRemoval/ShopRefundListener.java | 4 +- .../Acrobot/ChestShop/Plugins/ChestShop.java | 4 +- .../Acrobot/ChestShop/Plugins/Lockette.java | 5 +- .../java/com/Acrobot/ChestShop/Security.java | 4 +- .../ChestShop/Signs/ChestShopSign.java | 4 +- .../{UUIDSaver.java => NameManager.java} | 9 ++- .../com/Acrobot/ChestShop/Utils/uName.java | 58 ------------------- 23 files changed, 62 insertions(+), 124 deletions(-) delete mode 100644 src/main/java/com/Acrobot/ChestShop/Listeners/Player/ShortNameSaver.java rename src/main/java/com/Acrobot/ChestShop/UUIDs/{UUIDSaver.java => NameManager.java} (91%) delete mode 100644 src/main/java/com/Acrobot/ChestShop/Utils/uName.java diff --git a/src/main/java/com/Acrobot/Breeze/Utils/BlockUtil.java b/src/main/java/com/Acrobot/Breeze/Utils/BlockUtil.java index 28461dd..de81a7e 100644 --- a/src/main/java/com/Acrobot/Breeze/Utils/BlockUtil.java +++ b/src/main/java/com/Acrobot/Breeze/Utils/BlockUtil.java @@ -1,12 +1,13 @@ package com.Acrobot.Breeze.Utils; -import org.bukkit.block.*; +import org.bukkit.block.Block; import org.bukkit.block.Chest; +import org.bukkit.block.DoubleChest; import org.bukkit.block.Sign; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; -import org.bukkit.material.*; +import org.bukkit.material.Attachable; /** * @author Acrobot diff --git a/src/main/java/com/Acrobot/ChestShop/ChestShop.java b/src/main/java/com/Acrobot/ChestShop/ChestShop.java index 65ef4b9..9f99583 100644 --- a/src/main/java/com/Acrobot/ChestShop/ChestShop.java +++ b/src/main/java/com/Acrobot/ChestShop/ChestShop.java @@ -19,7 +19,10 @@ import com.Acrobot.ChestShop.Listeners.Item.ItemMoveListener; import com.Acrobot.ChestShop.Listeners.ItemInfoListener; import com.Acrobot.ChestShop.Listeners.Modules.DiscountModule; import com.Acrobot.ChestShop.Listeners.Modules.PriceRestrictionModule; -import com.Acrobot.ChestShop.Listeners.Player.*; +import com.Acrobot.ChestShop.Listeners.Player.PlayerConnect; +import com.Acrobot.ChestShop.Listeners.Player.PlayerInteract; +import com.Acrobot.ChestShop.Listeners.Player.PlayerInventory; +import com.Acrobot.ChestShop.Listeners.Player.PlayerTeleport; import com.Acrobot.ChestShop.Listeners.PostShopCreation.CreationFeeGetter; import com.Acrobot.ChestShop.Listeners.PostShopCreation.MessageSender; import com.Acrobot.ChestShop.Listeners.PostShopCreation.ShopCreationLogger; @@ -34,8 +37,7 @@ import com.Acrobot.ChestShop.Listeners.ShopRemoval.ShopRemovalLogger; import com.Acrobot.ChestShop.Logging.FileFormatter; import com.Acrobot.ChestShop.Metadata.ItemDatabase; import com.Acrobot.ChestShop.Signs.RestrictedSign; -import com.Acrobot.ChestShop.UUIDs.UUIDSaver; -import com.Acrobot.ChestShop.Utils.uName; +import com.Acrobot.ChestShop.UUIDs.NameManager; import com.avaje.ebean.EbeanServer; import com.lennardf1989.bukkitex.Database; import com.nijikokun.register.payment.forChestShop.Methods; @@ -86,10 +88,7 @@ public class ChestShop extends JavaPlugin { itemDatabase = new ItemDatabase(); - uName.file = loadFile("longName.storage"); - uName.load(); - - UUIDSaver.load(); + NameManager.load(); Methods.setPreferred(Properties.PREFERRED_ECONOMY_PLUGIN); @@ -196,7 +195,6 @@ public class ChestShop extends JavaPlugin { registerEvent(new ItemInfoListener()); registerEvent(new RestrictedSign()); - registerEvent(new ShortNameSaver()); if (!Properties.TURN_OFF_HOPPER_PROTECTION) { registerEvent(new ItemMoveListener()); 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 cdacc14..bf9ea8a 100644 --- a/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencyAddEvent.java +++ b/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencyAddEvent.java @@ -1,6 +1,6 @@ package com.Acrobot.ChestShop.Events.Economy; -import com.Acrobot.ChestShop.UUIDs.UUIDSaver; +import com.Acrobot.ChestShop.UUIDs.NameManager; import org.bukkit.World; import org.bukkit.entity.Player; import org.bukkit.event.Event; @@ -29,7 +29,7 @@ public class CurrencyAddEvent extends Event { } public CurrencyAddEvent(BigDecimal amount, Player target) { - this(amount, UUIDSaver.getUsername(target.getUniqueId()), target.getWorld()); + this(amount, NameManager.getUsername(target.getUniqueId()), target.getWorld()); } /** 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 1830296..0263808 100644 --- a/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencyAmountEvent.java +++ b/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencyAmountEvent.java @@ -1,6 +1,6 @@ package com.Acrobot.ChestShop.Events.Economy; -import com.Acrobot.ChestShop.UUIDs.UUIDSaver; +import com.Acrobot.ChestShop.UUIDs.NameManager; import org.bukkit.World; import org.bukkit.entity.Player; import org.bukkit.event.Event; @@ -26,7 +26,7 @@ public class CurrencyAmountEvent extends Event { } public CurrencyAmountEvent(Player player) { - this(UUIDSaver.getUsername(player.getUniqueId()), player.getWorld()); + this(NameManager.getUsername(player.getUniqueId()), player.getWorld()); } /** 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 3d519ba..304f40d 100644 --- a/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencyCheckEvent.java +++ b/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencyCheckEvent.java @@ -1,6 +1,6 @@ package com.Acrobot.ChestShop.Events.Economy; -import com.Acrobot.ChestShop.UUIDs.UUIDSaver; +import com.Acrobot.ChestShop.UUIDs.NameManager; import org.bukkit.World; import org.bukkit.entity.Player; import org.bukkit.event.Event; @@ -29,7 +29,7 @@ public class CurrencyCheckEvent extends Event { } public CurrencyCheckEvent(BigDecimal amount, Player player) { - this(amount, UUIDSaver.getUsername(player.getUniqueId()), player.getWorld()); + this(amount, NameManager.getUsername(player.getUniqueId()), player.getWorld()); } /** 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 7a0be69..d4d28d3 100644 --- a/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencyHoldEvent.java +++ b/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencyHoldEvent.java @@ -1,6 +1,6 @@ package com.Acrobot.ChestShop.Events.Economy; -import com.Acrobot.ChestShop.UUIDs.UUIDSaver; +import com.Acrobot.ChestShop.UUIDs.NameManager; import org.bukkit.World; import org.bukkit.entity.Player; import org.bukkit.event.Event; @@ -29,7 +29,7 @@ public class CurrencyHoldEvent extends Event { } public CurrencyHoldEvent(BigDecimal amount, Player target) { - this(amount, UUIDSaver.getUsername(target.getUniqueId()), target.getWorld()); + this(amount, NameManager.getUsername(target.getUniqueId()), target.getWorld()); } /** 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 6973220..f6dc869 100644 --- a/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencySubtractEvent.java +++ b/src/main/java/com/Acrobot/ChestShop/Events/Economy/CurrencySubtractEvent.java @@ -1,6 +1,6 @@ package com.Acrobot.ChestShop.Events.Economy; -import com.Acrobot.ChestShop.UUIDs.UUIDSaver; +import com.Acrobot.ChestShop.UUIDs.NameManager; import org.bukkit.World; import org.bukkit.entity.Player; import org.bukkit.event.Event; @@ -29,7 +29,7 @@ public class CurrencySubtractEvent extends Event { } public CurrencySubtractEvent(BigDecimal amount, Player target) { - this(amount, UUIDSaver.getUsername(target.getUniqueId()), target.getWorld()); + this(amount, NameManager.getUsername(target.getUniqueId()), target.getWorld()); } /** diff --git a/src/main/java/com/Acrobot/ChestShop/Listeners/Block/Break/SignBreak.java b/src/main/java/com/Acrobot/ChestShop/Listeners/Block/Break/SignBreak.java index c2ef842..14914fd 100644 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/Block/Break/SignBreak.java +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/Block/Break/SignBreak.java @@ -38,7 +38,7 @@ import static com.Acrobot.Breeze.Utils.BlockUtil.isSign; import static com.Acrobot.ChestShop.Permission.ADMIN; import static com.Acrobot.ChestShop.Permission.MOD; import static com.Acrobot.ChestShop.Signs.ChestShopSign.NAME_LINE; -import static com.Acrobot.ChestShop.Utils.uName.canUseName; +import static com.Acrobot.ChestShop.UUIDs.NameManager.canUseName; /** * @author Acrobot diff --git a/src/main/java/com/Acrobot/ChestShop/Listeners/Player/PlayerConnect.java b/src/main/java/com/Acrobot/ChestShop/Listeners/Player/PlayerConnect.java index 308abe6..0800d62 100644 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/Player/PlayerConnect.java +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/Player/PlayerConnect.java @@ -3,7 +3,7 @@ package com.Acrobot.ChestShop.Listeners.Player; import com.Acrobot.ChestShop.ChestShop; import com.Acrobot.ChestShop.Permission; import com.Acrobot.ChestShop.Signs.ChestShopSign; -import com.Acrobot.ChestShop.UUIDs.UUIDSaver; +import com.Acrobot.ChestShop.UUIDs.NameManager; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; @@ -30,6 +30,6 @@ public class PlayerConnect implements Listener { @EventHandler public static void onPlayerConnect(PlayerJoinEvent event) { - UUIDSaver.storeUsername(event.getPlayer()); + NameManager.storeUsername(event.getPlayer()); } } diff --git a/src/main/java/com/Acrobot/ChestShop/Listeners/Player/PlayerInteract.java b/src/main/java/com/Acrobot/ChestShop/Listeners/Player/PlayerInteract.java index 98258d7..b198de2 100644 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/Player/PlayerInteract.java +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/Player/PlayerInteract.java @@ -10,7 +10,7 @@ import com.Acrobot.ChestShop.Permission; import com.Acrobot.ChestShop.Plugins.ChestShop; import com.Acrobot.ChestShop.Security; import com.Acrobot.ChestShop.Signs.ChestShopSign; -import com.Acrobot.ChestShop.UUIDs.UUIDSaver; +import com.Acrobot.ChestShop.UUIDs.NameManager; import com.Acrobot.ChestShop.Utils.uBlock; import org.bukkit.Bukkit; import org.bukkit.GameMode; @@ -115,8 +115,8 @@ public class PlayerInteract implements Listener { String prices = sign.getLine(PRICE_LINE); String material = sign.getLine(ITEM_LINE); - String ownerName = UUIDSaver.getFullUsername(name); - OfflinePlayer owner = Bukkit.getOfflinePlayer(UUIDSaver.getUUID(ownerName)); + String ownerName = NameManager.getFullUsername(name); + OfflinePlayer owner = Bukkit.getOfflinePlayer(NameManager.getUUID(ownerName)); Action buy = Properties.REVERSE_BUTTONS ? LEFT_CLICK_BLOCK : RIGHT_CLICK_BLOCK; double price = (action == buy ? PriceUtil.getBuyPrice(prices) : PriceUtil.getSellPrice(prices)); diff --git a/src/main/java/com/Acrobot/ChestShop/Listeners/Player/ShortNameSaver.java b/src/main/java/com/Acrobot/ChestShop/Listeners/Player/ShortNameSaver.java deleted file mode 100644 index 59c9296..0000000 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/Player/ShortNameSaver.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.Acrobot.ChestShop.Listeners.Player; - -import com.Acrobot.ChestShop.Events.ShopCreatedEvent; -import com.Acrobot.ChestShop.Utils.uName; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; - -/** - * @author Acrobot - */ -public class ShortNameSaver implements Listener { - @EventHandler - public static void onShopCreated(ShopCreatedEvent event) { - uName.saveName(event.getPlayer().getName()); - } -} 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 27fda03..4dbab7f 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,7 @@ 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.UUIDSaver; +import com.Acrobot.ChestShop.UUIDs.NameManager; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -24,7 +24,7 @@ public class EconomicModule implements Listener { } CurrencyAddEvent currencyAddEvent = new CurrencyAddEvent(BigDecimal.valueOf(event.getPrice()), - UUIDSaver.getUsername(event.getOwner().getUniqueId()), + NameManager.getUsername(event.getOwner().getUniqueId()), event.getSign().getWorld()); ChestShop.callEvent(currencyAddEvent); @@ -39,7 +39,7 @@ public class EconomicModule implements Listener { } CurrencySubtractEvent currencySubtractEvent = new CurrencySubtractEvent(BigDecimal.valueOf(event.getPrice()), - UUIDSaver.getUsername(event.getOwner().getUniqueId()), + NameManager.getUsername(event.getOwner().getUniqueId()), event.getSign().getWorld()); ChestShop.callEvent(currencySubtractEvent); diff --git a/src/main/java/com/Acrobot/ChestShop/Listeners/PostTransaction/TransactionMessageSender.java b/src/main/java/com/Acrobot/ChestShop/Listeners/PostTransaction/TransactionMessageSender.java index 324e76b..aae0d18 100644 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/PostTransaction/TransactionMessageSender.java +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/PostTransaction/TransactionMessageSender.java @@ -6,7 +6,7 @@ import com.Acrobot.ChestShop.Configuration.Messages; import com.Acrobot.ChestShop.Configuration.Properties; import com.Acrobot.ChestShop.Economy.Economy; import com.Acrobot.ChestShop.Events.TransactionEvent; -import com.Acrobot.ChestShop.UUIDs.UUIDSaver; +import com.Acrobot.ChestShop.UUIDs.NameManager; import com.google.common.base.Joiner; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -89,7 +89,7 @@ public class TransactionMessageSender implements Listener { private static void sendMessageToOwner(String message, TransactionEvent event) { String owner = event.getOwner().getName(); - owner = UUIDSaver.getFullUsername(owner); + owner = NameManager.getFullUsername(owner); Player player = Bukkit.getPlayerExact(owner); diff --git a/src/main/java/com/Acrobot/ChestShop/Listeners/PreShopCreation/NameChecker.java b/src/main/java/com/Acrobot/ChestShop/Listeners/PreShopCreation/NameChecker.java index 6a991c3..e78fadc 100644 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/PreShopCreation/NameChecker.java +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/PreShopCreation/NameChecker.java @@ -1,8 +1,9 @@ package com.Acrobot.ChestShop.Listeners.PreShopCreation; +import com.Acrobot.Breeze.Utils.NameUtil; import com.Acrobot.ChestShop.Events.PreShopCreationEvent; import com.Acrobot.ChestShop.Permission; -import com.Acrobot.ChestShop.Utils.uName; +import com.Acrobot.ChestShop.UUIDs.NameManager; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -20,8 +21,12 @@ public class NameChecker implements Listener { String name = event.getSignLine(NAME_LINE); Player player = event.getPlayer(); - if (name.isEmpty() || (!uName.canUseName(player, name) && !Permission.has(player, Permission.ADMIN))) { - String shortName = uName.stripName(player); + if (name.isEmpty()) { + return; + } + + if (!NameManager.canUseName(player, name) && !Permission.has(player, Permission.ADMIN)) { + String shortName = NameUtil.stripUsername(NameManager.getUsername(player.getUniqueId())); event.setSignLine(NAME_LINE, shortName); } } 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 ad6d36a..4abddd9 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,7 @@ 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.UUIDSaver; +import com.Acrobot.ChestShop.UUIDs.NameManager; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.inventory.Inventory; @@ -53,7 +53,7 @@ public class AmountAndPriceChecker implements Listener { Inventory clientInventory = event.getClientInventory(); CurrencyCheckEvent currencyCheckEvent = new CurrencyCheckEvent(BigDecimal.valueOf(event.getPrice()), - UUIDSaver.getUsername(event.getOwner().getUniqueId()), + NameManager.getUsername(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 337f5cd..f5eefab 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,7 @@ 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.UUIDSaver; +import com.Acrobot.ChestShop.UUIDs.NameManager; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -61,7 +61,7 @@ public class PartialTransactionModule implements Listener { event.setStock(getCountedItemStack(stock, amountAffordable)); } - String seller = UUIDSaver.getUsername(event.getOwner().getUniqueId()); + String seller = NameManager.getUsername(event.getOwner().getUniqueId()); CurrencyHoldEvent currencyHoldEvent = new CurrencyHoldEvent(BigDecimal.valueOf(price), seller, client.getWorld()); ChestShop.callEvent(currencyHoldEvent); @@ -94,7 +94,7 @@ public class PartialTransactionModule implements Listener { } Player client = event.getClient(); - String ownerName = UUIDSaver.getUsername(event.getOwner().getUniqueId()); + String ownerName = NameManager.getUsername(event.getOwner().getUniqueId()); ItemStack[] stock = event.getStock(); double price = event.getPrice(); 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 2301bac..74cc276 100644 --- a/src/main/java/com/Acrobot/ChestShop/Listeners/ShopRemoval/ShopRefundListener.java +++ b/src/main/java/com/Acrobot/ChestShop/Listeners/ShopRemoval/ShopRefundListener.java @@ -7,7 +7,7 @@ import com.Acrobot.ChestShop.Economy.Economy; import com.Acrobot.ChestShop.Events.Economy.CurrencyAddEvent; import com.Acrobot.ChestShop.Events.ShopDestroyedEvent; import com.Acrobot.ChestShop.Permission; -import com.Acrobot.ChestShop.UUIDs.UUIDSaver; +import com.Acrobot.ChestShop.UUIDs.NameManager; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; @@ -29,7 +29,7 @@ public class ShopRefundListener implements Listener { return; } - String owner = UUIDSaver.getFullUsername(event.getSign().getLine(NAME_LINE)); + String owner = NameManager.getFullUsername(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/Plugins/ChestShop.java b/src/main/java/com/Acrobot/ChestShop/Plugins/ChestShop.java index 5055e38..5856a28 100644 --- a/src/main/java/com/Acrobot/ChestShop/Plugins/ChestShop.java +++ b/src/main/java/com/Acrobot/ChestShop/Plugins/ChestShop.java @@ -3,8 +3,8 @@ package com.Acrobot.ChestShop.Plugins; import com.Acrobot.ChestShop.Events.Protection.ProtectionCheckEvent; import com.Acrobot.ChestShop.Permission; import com.Acrobot.ChestShop.Signs.ChestShopSign; +import com.Acrobot.ChestShop.UUIDs.NameManager; import com.Acrobot.ChestShop.Utils.uBlock; -import com.Acrobot.ChestShop.Utils.uName; import org.bukkit.block.Block; import org.bukkit.block.Chest; import org.bukkit.block.Sign; @@ -67,6 +67,6 @@ public class ChestShop implements Listener { } private static boolean isShopMember(Player player, Sign sign) { - return uName.canUseName(player, sign.getLine(0)); + return NameManager.canUseName(player, sign.getLine(ChestShopSign.NAME_LINE)); } } diff --git a/src/main/java/com/Acrobot/ChestShop/Plugins/Lockette.java b/src/main/java/com/Acrobot/ChestShop/Plugins/Lockette.java index f40ad1f..d175534 100644 --- a/src/main/java/com/Acrobot/ChestShop/Plugins/Lockette.java +++ b/src/main/java/com/Acrobot/ChestShop/Plugins/Lockette.java @@ -1,7 +1,8 @@ package com.Acrobot.ChestShop.Plugins; +import com.Acrobot.Breeze.Utils.NameUtil; import com.Acrobot.ChestShop.Events.Protection.ProtectionCheckEvent; -import com.Acrobot.ChestShop.Utils.uName; +import com.Acrobot.ChestShop.UUIDs.NameManager; import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.event.Event; @@ -25,7 +26,7 @@ public class Lockette implements Listener { return; } - String shortPlayerName = uName.stripName(player); + String shortPlayerName = NameUtil.stripUsername(NameManager.getUsername(player.getUniqueId())); if (!org.yi.acru.bukkit.Lockette.Lockette.isUser(block, shortPlayerName, true)) { event.setResult(Event.Result.DENY); diff --git a/src/main/java/com/Acrobot/ChestShop/Security.java b/src/main/java/com/Acrobot/ChestShop/Security.java index b817f51..73fbbf2 100644 --- a/src/main/java/com/Acrobot/ChestShop/Security.java +++ b/src/main/java/com/Acrobot/ChestShop/Security.java @@ -6,7 +6,7 @@ import com.Acrobot.ChestShop.Configuration.Properties; import com.Acrobot.ChestShop.Events.Protection.ProtectBlockEvent; import com.Acrobot.ChestShop.Events.Protection.ProtectionCheckEvent; import com.Acrobot.ChestShop.Signs.ChestShopSign; -import com.Acrobot.ChestShop.UUIDs.UUIDSaver; +import com.Acrobot.ChestShop.UUIDs.NameManager; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.block.Sign; @@ -64,7 +64,7 @@ public class Security { } private static boolean anotherShopFound(Block baseBlock, Block signBlock, Player player) { - String playerName = UUIDSaver.getUsername(player.getUniqueId()); + String playerName = NameManager.getUsername(player.getUniqueId()); String shortName = NameUtil.stripUsername(playerName); for (BlockFace face : SIGN_CONNECTION_FACES) { diff --git a/src/main/java/com/Acrobot/ChestShop/Signs/ChestShopSign.java b/src/main/java/com/Acrobot/ChestShop/Signs/ChestShopSign.java index c44be3e..9ea2488 100644 --- a/src/main/java/com/Acrobot/ChestShop/Signs/ChestShopSign.java +++ b/src/main/java/com/Acrobot/ChestShop/Signs/ChestShopSign.java @@ -3,8 +3,8 @@ package com.Acrobot.ChestShop.Signs; import com.Acrobot.Breeze.Utils.BlockUtil; import com.Acrobot.ChestShop.Configuration.Properties; import com.Acrobot.ChestShop.Containers.AdminInventory; +import com.Acrobot.ChestShop.UUIDs.NameManager; import com.Acrobot.ChestShop.Utils.uBlock; -import com.Acrobot.ChestShop.Utils.uName; import org.bukkit.block.Block; import org.bukkit.block.Chest; import org.bukkit.block.DoubleChest; @@ -81,7 +81,7 @@ public class ChestShopSign { if (player == null) return false; if (sign == null) return true; - return uName.canUseName(player, sign.getLine(0)); + return NameManager.canUseName(player, sign.getLine(NAME_LINE)); } public static boolean isValidPreparedSign(String[] lines) { diff --git a/src/main/java/com/Acrobot/ChestShop/UUIDs/UUIDSaver.java b/src/main/java/com/Acrobot/ChestShop/UUIDs/NameManager.java similarity index 91% rename from src/main/java/com/Acrobot/ChestShop/UUIDs/UUIDSaver.java rename to src/main/java/com/Acrobot/ChestShop/UUIDs/NameManager.java index 0113676..2ba0289 100644 --- a/src/main/java/com/Acrobot/ChestShop/UUIDs/UUIDSaver.java +++ b/src/main/java/com/Acrobot/ChestShop/UUIDs/NameManager.java @@ -4,6 +4,7 @@ import com.Acrobot.Breeze.Utils.NameUtil; import com.Acrobot.ChestShop.ChestShop; import com.Acrobot.ChestShop.Database.Account; import com.Acrobot.ChestShop.Database.ConnectionManager; +import com.Acrobot.ChestShop.Permission; import com.j256.ormlite.dao.Dao; import com.j256.ormlite.dao.DaoManager; import com.j256.ormlite.jdbc.JdbcConnectionSource; @@ -20,7 +21,7 @@ import java.util.UUID; * * @author Andrzej Pomirski (Acrobot) */ -public class UUIDSaver { +public class NameManager { private static Dao accounts; public static UUID getUUID(String username) { @@ -102,6 +103,12 @@ public class UUIDSaver { } } + public static boolean canUseName(Player player, String name) { + String shortenedName = NameUtil.stripUsername(getUsername(player.getUniqueId())); + + return shortenedName.equals(name) || Permission.otherName(player, name); + } + public static void load() { File databaseFile = ChestShop.loadFile("users.db"); String uri = ConnectionManager.getURI(databaseFile); diff --git a/src/main/java/com/Acrobot/ChestShop/Utils/uName.java b/src/main/java/com/Acrobot/ChestShop/Utils/uName.java deleted file mode 100644 index b32c515..0000000 --- a/src/main/java/com/Acrobot/ChestShop/Utils/uName.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.Acrobot.ChestShop.Utils; - -import com.Acrobot.ChestShop.Permission; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.entity.Player; - -import java.io.File; -import java.io.IOException; - -/** - * @author Acrobot - */ -public class uName { - public static YamlConfiguration config; - public static File file; - - public static String getName(String shortName) { - return config.getString(shortName, shortName); - } - - public static void saveName(String name) { - if (name.length() <= 15) { - return; - } - - config.set(stripName(name), name); - reload(); - } - - public static String stripName(String name) { - if (name.length() > 15) { - return name.substring(0, 15); - } - - return name; - } - - public static String stripName(Player player) { - return stripName(player.getName()); - } - - public static boolean canUseName(Player player, String name) { - return stripName(player).equals(name) || Permission.otherName(player, name); - } - - public static void load() { - config = YamlConfiguration.loadConfiguration(file); - } - - public static void reload() { - try { - config.save(file); - } catch (IOException e) { - e.printStackTrace(); - } - load(); - } -}