From 79efdcd489614ea8842474ee2a786c5753a1208f Mon Sep 17 00:00:00 2001 From: Erik Date: Tue, 9 Jun 2015 16:12:41 -0700 Subject: [PATCH] Fix for economy discounts --- .../java/com/griefcraft/model/Protection.java | 11 +++++- .../main/java/com/griefcraft/sql/PhysDB.java | 39 +++++++++++++++++++ .../com/griefcraft/lwc/EconomyModule.java | 4 +- 3 files changed, 52 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/com/griefcraft/model/Protection.java b/core/src/main/java/com/griefcraft/model/Protection.java index f56e7d22a..541b7b546 100644 --- a/core/src/main/java/com/griefcraft/model/Protection.java +++ b/core/src/main/java/com/griefcraft/model/Protection.java @@ -919,7 +919,16 @@ public World getBukkitWorld() { * @return the Bukkit Player object of the owner */ public Player getBukkitOwner() { - return Bukkit.getServer().getPlayer(owner); + + UUID uuid = UUIDRegistry.getUUID(owner); + if(uuid == null) { + uuid = UUID.fromString(owner); + } + + if(uuid == null) { + return Bukkit.getServer().getPlayer(owner); + } + return Bukkit.getServer().getPlayer(uuid); } /** diff --git a/core/src/main/java/com/griefcraft/sql/PhysDB.java b/core/src/main/java/com/griefcraft/sql/PhysDB.java index 5e7abc39a..210adef17 100644 --- a/core/src/main/java/com/griefcraft/sql/PhysDB.java +++ b/core/src/main/java/com/griefcraft/sql/PhysDB.java @@ -164,6 +164,11 @@ public int getHistoryCount() { public int getProtectionCount(String player) { int count = 0; + UUID uuid = UUIDRegistry.getUUID(player); + if(uuid != null) { + player = uuid.toString(); + } + try { PreparedStatement statement = prepare("SELECT COUNT(*) as count FROM " + prefix + "protections WHERE owner = ?"); statement.setString(1, player); @@ -190,6 +195,11 @@ public int getProtectionCount(String player) { */ public int getHistoryCount(String player) { int count = 0; + + UUID uuid = UUIDRegistry.getUUID(player); + if(uuid != null) { + player = uuid.toString(); + } try { PreparedStatement statement = prepare("SELECT COUNT(*) AS count FROM " + prefix + "history WHERE LOWER(player) = LOWER(?)"); @@ -217,6 +227,11 @@ public int getHistoryCount(String player) { */ public int getProtectionCount(String player, int blockId) { int count = 0; + + UUID uuid = UUIDRegistry.getUUID(player); + if(uuid != null) { + player = uuid.toString(); + } try { PreparedStatement statement = prepare("SELECT COUNT(*) AS count FROM " + prefix + "protections WHERE owner = ? AND blockId = ?"); @@ -1071,6 +1086,11 @@ public List loadProtections(String world, int x1, int x2, int y1, in */ public List loadProtectionsByPlayer(String player) { List protections = new ArrayList(); + + UUID uuid = UUIDRegistry.getUUID(player); + if(uuid != null) { + player = uuid.toString(); + } try { PreparedStatement statement = prepare("SELECT id, owner, type, x, y, z, data, blockId, world, password, date, last_accessed FROM " + prefix + "protections WHERE owner = ?"); @@ -1359,6 +1379,15 @@ public List loadHistory(String player) { if (!LWC.getInstance().isHistoryEnabled()) { return temp; } + + UUID uuid = UUIDRegistry.getUUID(player); + if(uuid == null) { + uuid = UUID.fromString(player); + } + + if(uuid != null) { + player = uuid.toString(); + } try { PreparedStatement statement = prepare("SELECT * FROM " + prefix + "history WHERE LOWER(player) = LOWER(?) ORDER BY id DESC"); @@ -1441,6 +1470,11 @@ public List loadHistory(String player, int start, int count) { if (!LWC.getInstance().isHistoryEnabled()) { return temp; } + + UUID uuid = UUIDRegistry.getUUID(player); + if(uuid != null) { + player = uuid.toString(); + } try { PreparedStatement statement = prepare("SELECT * FROM " + prefix + "history WHERE LOWER(player) = LOWER(?) ORDER BY id DESC LIMIT ?,?"); @@ -1589,6 +1623,11 @@ public List loadHistory(String player, int x, int y, int z) { if (!LWC.getInstance().isHistoryEnabled()) { return temp; } + + UUID uuid = UUIDRegistry.getUUID(player); + if(uuid != null) { + player = uuid.toString(); + } try { PreparedStatement statement = prepare("SELECT * FROM " + prefix + "history WHERE LOWER(player) = LOWER(?) AND x = ? AND y = ? AND z = ?"); diff --git a/modules/economy/src/main/java/com/griefcraft/lwc/EconomyModule.java b/modules/economy/src/main/java/com/griefcraft/lwc/EconomyModule.java index d74874319..570966a5d 100644 --- a/modules/economy/src/main/java/com/griefcraft/lwc/EconomyModule.java +++ b/modules/economy/src/main/java/com/griefcraft/lwc/EconomyModule.java @@ -265,7 +265,9 @@ public void onPostRegistration(LWCProtectionRegistrationPostEvent event) { history.addMetaData("discount=true"); // Was the discount's id non-null? - String discountId = resolveValue(protection.getBukkitOwner(), "discount.id"); + Player puuid = protection.getBukkitOwner(); + + String discountId = resolveValue(puuid, "discount.id"); if (!discountId.isEmpty()) { history.addMetaData("discountId=" + discountId);