Reinstate async wrappers for clans gold access

This commit is contained in:
cnr 2016-07-28 14:59:12 -05:00
parent f0be7794f5
commit a498bc13db

View File

@ -1,7 +1,9 @@
package mineplex.game.clans.economy;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.UtilServer;
import mineplex.serverdata.database.DBPool;
import org.bukkit.Bukkit;
import java.sql.Connection;
import java.sql.PreparedStatement;
@ -20,28 +22,32 @@ public class GoldRepository {
public void rewardGold(final Callback<Boolean> callback, final int accountId, final int gold)
{
try (Connection connection = DBPool.getAccount().getConnection())
Bukkit.getScheduler().runTaskAsynchronously(UtilServer.getPlugin(), () ->
{
PreparedStatement statement = connection.prepareStatement(UPDATE_ACCOUNT_GOLD);
statement.setInt(1, _serverId);
statement.setInt(2, accountId);
statement.setInt(3, gold);
statement.setInt(4, gold);
statement.executeUpdate();
if (callback != null)
try (Connection connection = DBPool.getAccount().getConnection())
{
callback.run(true);
}
PreparedStatement statement = connection.prepareStatement(UPDATE_ACCOUNT_GOLD);
statement.setInt(1, _serverId);
statement.setInt(2, accountId);
statement.setInt(3, gold);
statement.setInt(4, gold);
statement.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
if (callback != null)
{
callback.run(true);
}
if (callback != null)
} catch (SQLException e)
{
callback.run(false);
e.printStackTrace();
if (callback != null)
{
callback.run(false);
}
}
}
});
}
public void setGold(final Callback<Boolean> callback, final int accountId, final int gold)
@ -51,26 +57,29 @@ public class GoldRepository {
throw new IllegalArgumentException("gold cannot be negative");
}
try (Connection connection = DBPool.getAccount().getConnection())
Bukkit.getScheduler().runTaskAsynchronously(UtilServer.getPlugin(), () ->
{
PreparedStatement statement = connection.prepareStatement(SET_ACCOUNT_GOLD);
statement.setInt(1, _serverId);
statement.setInt(2, accountId);
statement.setInt(3, gold);
statement.setInt(4, gold);
statement.executeUpdate();
if (callback != null)
try (Connection connection = DBPool.getAccount().getConnection())
{
callback.run(true);
}
PreparedStatement statement = connection.prepareStatement(SET_ACCOUNT_GOLD);
statement.setInt(1, _serverId);
statement.setInt(2, accountId);
statement.setInt(3, gold);
statement.setInt(4, gold);
statement.executeUpdate();
if (callback != null) {
callback.run(true);
}
} catch (SQLException e) {
e.printStackTrace();
if (callback != null)
} catch (SQLException e)
{
callback.run(false);
e.printStackTrace();
if (callback != null)
{
callback.run(false);
}
}
}
});
}
}