This commit is contained in:
BuildTools 2015-11-03 18:31:12 +01:00
parent a7c12782d5
commit 7fe9445360
6 changed files with 52 additions and 10 deletions

View File

@ -120,10 +120,14 @@ public void getBackpack(final OfflinePlayer player, final Callback<Backpack> 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<Backpack> callback)
{
callback.onResult(loadBackpack(player));
Backpack loadedBackpack = loadBackpack(player);
if(loadedBackpack == null)
{
callback.onFail();
}
else
{
callback.onResult(loadedBackpack);
}
}
public interface Callback<T>
{
void onResult(T done);
void onFail();
}
}

View File

@ -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();

View File

@ -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

View File

@ -69,6 +69,12 @@ public void onResult(Backpack backpack)
}
backpack.save(); // We have to save it now!
}
@Override
public void onFail()
{
}
});
}
}

View File

@ -99,6 +99,12 @@ public void onResult(Backpack backpack)
{
openBackpack(opener, backpack, editable);
}
@Override
public void onFail()
{
}
});
}

View File

@ -136,6 +136,12 @@ public void onResult(Backpack backpack)
player.sendMessage(plugin.Message_InvalidBackpack);
}
}
@Override
public void onFail()
{
player.sendMessage(plugin.Message_InvalidBackpack);
}
});
}
else