diff --git a/Plugins/Mineplex.Core/src/mineplex/core/pet/repository/PetRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/pet/repository/PetRepository.java index 2ed20694b..85973eeb9 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/pet/repository/PetRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/pet/repository/PetRepository.java @@ -26,14 +26,34 @@ public class PetRepository extends RepositoryBase _webAddress = webAddress; } - public void AddPet(PetChangeToken token) + public void AddPet(final PetChangeToken token) { new AsyncJsonWebCall(_webAddress + "Pets/AddPet").Execute(token); + + Plugin.getServer().getScheduler().runTaskAsynchronously(Plugin, new Runnable() + { + public void run() + { + executeInsert("INSERT INTO accountPets(petName, petId, accountId) VALUES (?, ?, ?);", null, new ColumnVarChar("petName", 32, token.PetName) + , new ColumnInt("petId", token.PetId) + , new ColumnInt("accountId", token.AccountId)); + } + }); } - public void RemovePet(PetChangeToken token) + public void RemovePet(final PetChangeToken token) { new AsyncJsonWebCall(_webAddress + "Pets/RemovePet").Execute(token); + + Plugin.getServer().getScheduler().runTaskAsynchronously(Plugin, new Runnable() + { + public void run() + { + executeUpdate("DELETE FROM accountPets WHERE petId = ? AND accountId = ?;" + , new ColumnInt("petId", token.PetId) + , new ColumnInt("accountId", token.AccountId)); + } + }); } public List GetPetExtras(List petExtraTokens) @@ -41,20 +61,26 @@ public class PetRepository extends RepositoryBase return new JsonWebCall(_webAddress + "Pets/GetPetExtras").Execute(new TypeToken>(){}.getType(), petExtraTokens); } - public void UpdatePet(PetChangeToken token) + public void UpdatePet(final PetChangeToken token) { new AsyncJsonWebCall(_webAddress + "Pets/UpdatePet").Execute(token); - - int rowsChanged = executeUpdate("UPDATE accountPets SET petName = ? WHERE petId = ? AND accountId = ?;", new ColumnVarChar("petName", 32, token.PetName) + + Plugin.getServer().getScheduler().runTaskAsynchronously(Plugin, new Runnable() + { + public void run() + { + int rowsChanged = executeUpdate("UPDATE accountPets SET petName = ? WHERE petId = ? AND accountId = ?;", new ColumnVarChar("petName", 32, token.PetName) + , new ColumnInt("petId", token.PetId) + , new ColumnInt("accountId", token.AccountId)); + + if (rowsChanged < 1) + { + executeInsert("INSERT INTO accountPets(petName, petId, accountId) VALUES (?, ?, ?);", null, new ColumnVarChar("petName", 32, token.PetName) , new ColumnInt("petId", token.PetId) , new ColumnInt("accountId", token.AccountId)); - - if (rowsChanged < 1) - { - executeInsert("INSERT INTO accountPets(petName, petId, accountId) VALUES (?, ?, ?);", null, new ColumnVarChar("petName", 32, token.PetName) - , new ColumnInt("petId", token.PetId) - , new ColumnInt("accountId", token.AccountId)); - } + } + } + }); } @Override