From 7fe944536060f7333cf7d6176a4638b96e775f61 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Tue, 3 Nov 2015 18:31:12 +0100 Subject: [PATCH] Bugfix --- .../MinePacks/Database/Database.java | 34 ++++++++++++++----- .../MinePacks/Database/MySQL.java | 9 ++++- .../MinePacks/Database/SQLite.java | 1 + .../MinePacks/EventListener.java | 6 ++++ .../pcgamingfreaks/MinePacks/MinePacks.java | 6 ++++ .../pcgamingfreaks/MinePacks/OnCommand.java | 6 ++++ 6 files changed, 52 insertions(+), 10 deletions(-) diff --git a/src/at/pcgamingfreaks/MinePacks/Database/Database.java b/src/at/pcgamingfreaks/MinePacks/Database/Database.java index 263fc85..3ec2a6d 100644 --- a/src/at/pcgamingfreaks/MinePacks/Database/Database.java +++ b/src/at/pcgamingfreaks/MinePacks/Database/Database.java @@ -120,10 +120,14 @@ public void getBackpack(final OfflinePlayer player, final Callback cal @Override public void onResult(Backpack backpack) { - if(backpack == null) - { - backpack = new Backpack(player); - } + backpacks.put(player, backpack); + callback.onResult(backpack); + } + + @Override + public void onFail() + { + Backpack backpack = new Backpack(player); backpacks.put(player, backpack); callback.onResult(backpack); } @@ -149,12 +153,14 @@ public void asyncLoadBackpack(final OfflinePlayer player) @Override public void onResult(Backpack backpack) { - if(backpack == null) - { - backpack = new Backpack(player); - } backpacks.put(player, backpack); } + + @Override + public void onFail() + { + backpacks.put(player, new Backpack(player)); + } }); } } @@ -176,11 +182,21 @@ public void saveBackpack(Backpack backpack) {} protected void loadBackpack(final OfflinePlayer player, final Callback callback) { - callback.onResult(loadBackpack(player)); + Backpack loadedBackpack = loadBackpack(player); + if(loadedBackpack == null) + { + callback.onFail(); + } + else + { + callback.onResult(loadedBackpack); + } } public interface Callback { void onResult(T done); + + void onFail(); } } \ No newline at end of file diff --git a/src/at/pcgamingfreaks/MinePacks/Database/MySQL.java b/src/at/pcgamingfreaks/MinePacks/Database/MySQL.java index f96ab3d..b7b692b 100644 --- a/src/at/pcgamingfreaks/MinePacks/Database/MySQL.java +++ b/src/at/pcgamingfreaks/MinePacks/Database/MySQL.java @@ -215,7 +215,14 @@ public void run() public void run() { ItemStack[] its = (data != null) ? itsSerializer.deserialize(data, version) : null; - callback.onResult((its != null) ? new Backpack(player, its, bpID) : null); + if(its != null) + { + callback.onResult(new Backpack(player, its, bpID)); + } + else + { + callback.onFail(); + } } }); rs.close(); diff --git a/src/at/pcgamingfreaks/MinePacks/Database/SQLite.java b/src/at/pcgamingfreaks/MinePacks/Database/SQLite.java index 198f9ec..ad6830b 100644 --- a/src/at/pcgamingfreaks/MinePacks/Database/SQLite.java +++ b/src/at/pcgamingfreaks/MinePacks/Database/SQLite.java @@ -60,6 +60,7 @@ protected void updateQuerysForDialect() } Query_DeleteOldBackpacks = "DELETE FROM `{TableBackpacks}` WHERE `{FieldBPLastUpdate}` < DATE('now', '-{VarMaxAge} days')"; Query_UpdateBP = Query_UpdateBP.replaceAll("\\{NOW\\}", "DATE('now')"); + Query_UpdatePlayerAdd = Query_UpdatePlayerAdd.replaceAll("INSERT IGNORE INTO", "INSERT OR IGNORE INTO"); } @Override diff --git a/src/at/pcgamingfreaks/MinePacks/EventListener.java b/src/at/pcgamingfreaks/MinePacks/EventListener.java index 55356b6..a9177ba 100644 --- a/src/at/pcgamingfreaks/MinePacks/EventListener.java +++ b/src/at/pcgamingfreaks/MinePacks/EventListener.java @@ -69,6 +69,12 @@ public void onResult(Backpack backpack) } backpack.save(); // We have to save it now! } + + @Override + public void onFail() + { + + } }); } } diff --git a/src/at/pcgamingfreaks/MinePacks/MinePacks.java b/src/at/pcgamingfreaks/MinePacks/MinePacks.java index ad4c196..09c0381 100644 --- a/src/at/pcgamingfreaks/MinePacks/MinePacks.java +++ b/src/at/pcgamingfreaks/MinePacks/MinePacks.java @@ -99,6 +99,12 @@ public void onResult(Backpack backpack) { openBackpack(opener, backpack, editable); } + + @Override + public void onFail() + { + + } }); } diff --git a/src/at/pcgamingfreaks/MinePacks/OnCommand.java b/src/at/pcgamingfreaks/MinePacks/OnCommand.java index 58c1bbb..ec98931 100644 --- a/src/at/pcgamingfreaks/MinePacks/OnCommand.java +++ b/src/at/pcgamingfreaks/MinePacks/OnCommand.java @@ -136,6 +136,12 @@ public void onResult(Backpack backpack) player.sendMessage(plugin.Message_InvalidBackpack); } } + + @Override + public void onFail() + { + player.sendMessage(plugin.Message_InvalidBackpack); + } }); } else