Added Gold saving/retrieval from mysql.
Converted DonationManager to MiniDbClientPlugin. Fixed bug in DonationRepository with gold.
This commit is contained in:
parent
2480361421
commit
5a57c5f372
@ -1,5 +1,7 @@
|
||||
package mineplex.core.donation;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
@ -8,38 +10,31 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import mineplex.core.MiniPlugin;
|
||||
import mineplex.core.account.event.ClientUnloadEvent;
|
||||
import mineplex.core.MiniDbClientPlugin;
|
||||
import mineplex.core.account.CoreClientManager;
|
||||
import mineplex.core.account.event.ClientWebResponseEvent;
|
||||
import mineplex.core.common.CurrencyType;
|
||||
import mineplex.core.common.util.Callback;
|
||||
import mineplex.core.common.util.NautHashMap;
|
||||
import mineplex.core.donation.repository.DonationRepository;
|
||||
import mineplex.core.donation.repository.token.DonorTokenWrapper;
|
||||
import mineplex.core.server.remotecall.JsonWebCall;
|
||||
import mineplex.core.server.util.TransactionResponse;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
|
||||
public class DonationManager extends MiniPlugin
|
||||
public class DonationManager extends MiniDbClientPlugin<Donor>
|
||||
{
|
||||
private DonationRepository _repository;
|
||||
|
||||
private NautHashMap<String, Donor> _donors;
|
||||
|
||||
private Object _donorLock = new Object();
|
||||
|
||||
private NautHashMap<Player, NautHashMap<String, Integer>> _gemQueue = new NautHashMap<Player, NautHashMap<String, Integer>>();
|
||||
private NautHashMap<Player, NautHashMap<String, Integer>> _coinQueue = new NautHashMap<Player, NautHashMap<String, Integer>>();
|
||||
private NautHashMap<Player, NautHashMap<String, Integer>> _goldQueue = new NautHashMap<Player, NautHashMap<String, Integer>>();
|
||||
|
||||
public DonationManager(JavaPlugin plugin, String webAddress)
|
||||
public DonationManager(JavaPlugin plugin, CoreClientManager clientManager, String webAddress)
|
||||
{
|
||||
super("Donation", plugin);
|
||||
super("Donation", plugin, clientManager);
|
||||
|
||||
_repository = new DonationRepository(plugin, webAddress);
|
||||
|
||||
_donors = new NautHashMap<String, Donor>();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -55,31 +50,11 @@ public class DonationManager extends MiniPlugin
|
||||
DonorTokenWrapper token = new Gson().fromJson(event.GetResponse(), DonorTokenWrapper.class);
|
||||
LoadDonor(token, event.getUniqueId());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void UnloadDonor(ClientUnloadEvent event)
|
||||
{
|
||||
synchronized (_donorLock)
|
||||
{
|
||||
_donors.remove(event.GetName());
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadDonor(DonorTokenWrapper token, UUID uuid)
|
||||
{
|
||||
synchronized (_donorLock)
|
||||
{
|
||||
_donors.put(token.Name, new Donor(token.DonorToken));
|
||||
//_repository.updateGemsAndCoins(uuid, Get(token.Name).GetGems(), Get(token.Name).getCoins());
|
||||
}
|
||||
}
|
||||
|
||||
public Donor Get(String name)
|
||||
{
|
||||
synchronized (_donorLock)
|
||||
{
|
||||
return _donors.get(name);
|
||||
}
|
||||
Get(token.Name).loadToken(token.DonorToken);
|
||||
//_repository.updateGemsAndCoins(uuid, Get(token.Name).GetGems(), Get(token.Name).getCoins());
|
||||
}
|
||||
|
||||
public void PurchaseUnknownSalesPackage(final Callback<TransactionResponse> callback, final String name, final UUID uuid, final String packageName, final boolean coinPurchase, final int cost, boolean oneTimePurchase)
|
||||
@ -324,10 +299,14 @@ public class DonationManager extends MiniPlugin
|
||||
donor.addGold(amount);
|
||||
}
|
||||
}
|
||||
|
||||
if (callback != null)
|
||||
callback.run(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println("REWARD GOLD FAILED...");
|
||||
}
|
||||
|
||||
if (callback != null)
|
||||
callback.run(true);
|
||||
}
|
||||
}, caller, name, uuid.toString(), amount);
|
||||
}
|
||||
@ -388,4 +367,22 @@ public class DonationManager extends MiniPlugin
|
||||
{
|
||||
_repository.applyKits(playerName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processLoginResultSet(String playerName, ResultSet resultSet) throws SQLException
|
||||
{
|
||||
Get(playerName).addGold(_repository.retrieveDonorInfo(resultSet).getGold());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getQuery(String uuid, String name)
|
||||
{
|
||||
return "SELECT gold FROM accounts WHERE uuid = '" + uuid + "';";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Donor AddPlayer(String player)
|
||||
{
|
||||
return new Donor();
|
||||
}
|
||||
}
|
||||
|
@ -14,14 +14,16 @@ public class Donor
|
||||
private int _coins;
|
||||
private int _gold;
|
||||
private boolean _donated;
|
||||
private List<Integer> _salesPackagesOwned;
|
||||
private List<String> _unknownSalesPackagesOwned;
|
||||
private List<TransactionToken> _transactions;
|
||||
private List<CoinTransactionToken> _coinTransactions;
|
||||
private List<Integer> _salesPackagesOwned = new ArrayList<Integer>();
|
||||
private List<String> _unknownSalesPackagesOwned = new ArrayList<String>();
|
||||
private List<TransactionToken> _transactions = new ArrayList<TransactionToken>();
|
||||
private List<CoinTransactionToken> _coinTransactions = new ArrayList<CoinTransactionToken>();
|
||||
|
||||
private boolean _update = true;
|
||||
|
||||
public Donor(DonorToken token)
|
||||
public Donor() { }
|
||||
|
||||
public void loadToken(DonorToken token)
|
||||
{
|
||||
_gems = token.Gems;
|
||||
_coins = token.Coins;
|
||||
@ -31,26 +33,6 @@ public class Donor
|
||||
_unknownSalesPackagesOwned = token.UnknownSalesPackages;
|
||||
_transactions = token.Transactions;
|
||||
_coinTransactions = token.CoinRewards;
|
||||
|
||||
if (_salesPackagesOwned == null)
|
||||
{
|
||||
_salesPackagesOwned = new ArrayList<Integer>();
|
||||
}
|
||||
|
||||
if (_unknownSalesPackagesOwned == null)
|
||||
{
|
||||
_unknownSalesPackagesOwned = new ArrayList<String>();
|
||||
}
|
||||
|
||||
if (_transactions == null)
|
||||
{
|
||||
_transactions = new ArrayList<TransactionToken>();
|
||||
}
|
||||
|
||||
if (_coinTransactions == null)
|
||||
{
|
||||
_coinTransactions = new ArrayList<CoinTransactionToken>();
|
||||
}
|
||||
}
|
||||
|
||||
public int GetGems()
|
||||
|
@ -1,5 +1,7 @@
|
||||
package mineplex.core.donation.repository;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
@ -10,6 +12,7 @@ import mineplex.core.database.DatabaseRunnable;
|
||||
import mineplex.core.database.RepositoryBase;
|
||||
import mineplex.core.database.column.ColumnInt;
|
||||
import mineplex.core.database.column.ColumnVarChar;
|
||||
import mineplex.core.donation.Donor;
|
||||
import mineplex.core.donation.repository.token.GemRewardToken;
|
||||
import mineplex.core.donation.repository.token.PurchaseToken;
|
||||
import mineplex.core.donation.repository.token.UnknownPurchaseToken;
|
||||
@ -178,12 +181,7 @@ public class DonationRepository extends RepositoryBase
|
||||
}
|
||||
|
||||
public void rewardGold(final Callback<Boolean> callback, final String giver, final String name, final String uuid, final int gold)
|
||||
{
|
||||
final GemRewardToken token = new GemRewardToken();
|
||||
token.Source = giver;
|
||||
token.Name = name;
|
||||
token.Amount = gold;
|
||||
|
||||
{
|
||||
handleDatabaseCall(new DatabaseRunnable(new Runnable()
|
||||
{
|
||||
public void run()
|
||||
@ -191,7 +189,10 @@ public class DonationRepository extends RepositoryBase
|
||||
if (executeUpdate(UPDATE_ACCOUNT_GOLD, new ColumnInt("gold", gold), new ColumnVarChar("uuid", 100, uuid)) < 1)
|
||||
{
|
||||
Logger.Instance.log("Account gold wasn't updated for " + name);
|
||||
callback.run(false);
|
||||
}
|
||||
else
|
||||
callback.run(true);
|
||||
}
|
||||
}), "Error updating player gold amount in DonationRepository : ");
|
||||
}
|
||||
@ -223,4 +224,16 @@ public class DonationRepository extends RepositoryBase
|
||||
{
|
||||
new AsyncJsonWebCall(_webAddress + "PlayerAccount/ApplyKits").Execute(playerName);
|
||||
}
|
||||
|
||||
public Donor retrieveDonorInfo(ResultSet resultSet) throws SQLException
|
||||
{
|
||||
Donor donor = new Donor();
|
||||
|
||||
while (resultSet.next())
|
||||
{
|
||||
donor.addGold(resultSet.getInt(1));
|
||||
}
|
||||
|
||||
return donor;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user