Merge branch 'update/clans' of github.com:Mineplex-LLC/Minecraft-PC into update/clans

This commit is contained in:
AlexTheCoder 2016-07-28 19:11:39 -04:00
commit 853fe31fbe
1 changed files with 41 additions and 32 deletions

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);
}
}
}
});
}
}