From 19afebe53da9780788e75bed318b317a15ff866e Mon Sep 17 00:00:00 2001 From: Jonathan Williams Date: Sat, 11 Oct 2014 01:32:22 -0700 Subject: [PATCH] Added in mysql hooks for coins/gems/ranks for database conversion preperation. Added in failover database calls in CoreClient/DonationManager --- .../core/account/CoreClientManager.java | 15 +- .../core/account/command/UpdateRank.java | 2 +- .../account/repository/AccountRepository.java | 90 +++- .../repository/MysqlAccountRepository.java | 35 -- .../account/repository/token/ClientToken.java | 2 + .../core/database/DatabaseRunnable.java | 27 + .../core/database/RepositoryBase.java | 96 +++- .../core/database/column/ColumnBoolean.java | 42 ++ .../core/database/column/ColumnTimestamp.java | 43 ++ .../core/donation/DonationManager.java | 62 +-- .../mineplex/core/donation/GemCommand.java | 2 +- .../repository/DonationRepository.java | 157 +++++- .../core/gadget/gadgets/ItemCoinBomb.java | 2 +- .../core/gadget/gadgets/ItemGemBomb.java | 2 +- .../src/mineplex/core/logger/Logger.java | 2 + .../core/reward/rewards/CoinReward.java | 2 +- .../reward/rewards/UnknownPackageReward.java | 2 +- .../core/shop/page/ConfirmationPage.java | 4 +- .../src/mineplex/enjinTranslator/Enjin.java | 10 +- .../mineplex/hub/modules/ParkourManager.java | 2 +- .../src/mineplex/hub/poll/PollManager.java | 2 +- .../mineplex/hub/server/ui/ServerNpcPage.java | 4 +- .../hub/tutorial/TutorialManager.java | 2 +- .../salespackage/command/BoosterCommand.java | 8 +- .../salespackage/command/CoinCommand.java | 7 +- .../command/GemHunterCommand.java | 8 +- .../command/TreasureChestCommand.java | 8 +- .../command/TreasureKeyCommand.java | 8 +- .../game/games/christmas/Christmas.java | 2 +- .../game/games/halloween/Halloween.java | 2 +- .../managers/GameAchievementManager.java | 2 +- .../game/arcade/managers/GameGemManager.java | 2 +- Website/LOC.Core/Tokens/Client/ClientToken.cs | 7 + .../Models/AccountAdministrator.cs | 69 --- .../LOC.Website.Web.Publish.xml | 472 +++++++++--------- 35 files changed, 774 insertions(+), 428 deletions(-) delete mode 100644 Plugins/Mineplex.Core/src/mineplex/core/account/repository/MysqlAccountRepository.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/database/DatabaseRunnable.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/database/column/ColumnBoolean.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/database/column/ColumnTimestamp.java diff --git a/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java b/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java index 75cfb0a48..a54851a98 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/account/CoreClientManager.java @@ -1,5 +1,7 @@ package mineplex.core.account; +import java.sql.Timestamp; +import java.util.Date; import java.util.HashSet; import java.util.Iterator; import java.util.List; @@ -13,7 +15,6 @@ import mineplex.core.account.event.ClientUnloadEvent; import mineplex.core.account.event.ClientWebResponseEvent; import mineplex.core.account.event.RetrieveClientInformationEvent; import mineplex.core.account.repository.AccountRepository; -import mineplex.core.account.repository.MysqlAccountRepository; import mineplex.core.account.repository.token.ClientToken; import mineplex.core.common.Rank; import mineplex.core.common.util.Callback; @@ -42,7 +43,6 @@ public class CoreClientManager extends MiniPlugin { private JavaPlugin _plugin; private AccountRepository _repository; - private MysqlAccountRepository _mysqlRepository; private NautHashMap _clientList; private HashSet _duplicateLoginGlitchPreventionList; @@ -53,8 +53,7 @@ public class CoreClientManager extends MiniPlugin super("Client Manager", plugin); _plugin = plugin; - _repository = new AccountRepository(webServer); - _mysqlRepository = new MysqlAccountRepository(plugin); + _repository = new AccountRepository(plugin, webServer); _clientList = new NautHashMap(); _duplicateLoginGlitchPreventionList = new HashSet(); } @@ -175,7 +174,7 @@ public class CoreClientManager extends MiniPlugin { public void run() { - _mysqlRepository.login(uuid.toString(), client.GetPlayerName()); + _repository.login(uuid.toString(), client.GetPlayerName()); Bukkit.getServer().getPluginManager().callEvent(clientInformationEvent); clientInformationEvent.decreaseProcessingCount(); @@ -225,7 +224,7 @@ public class CoreClientManager extends MiniPlugin { public void run() { - _mysqlRepository.login(uuid.toString(), client.GetPlayerName()); + _repository.login(uuid.toString(), client.GetPlayerName()); Bukkit.getServer().getPluginManager().callEvent(clientInformationEvent); } @@ -237,6 +236,8 @@ public class CoreClientManager extends MiniPlugin client.SetAccountId(token.AccountId); client.SetRank(Rank.valueOf(token.Rank)); + _repository.updateMysqlRank(token.Name, token.Rank, token.RankPerm, new Timestamp(Date.parse(token.RankExpire)).toString()); + // JSON sql response Bukkit.getServer().getPluginManager().callEvent(new ClientWebResponseEvent(response)); @@ -322,7 +323,7 @@ public class CoreClientManager extends MiniPlugin public void SaveRank(final String name, Rank rank, boolean perm) { - _repository.SaveRank(new Callback() + _repository.saveRank(new Callback() { public void run(Rank newRank) { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/account/command/UpdateRank.java b/Plugins/Mineplex.Core/src/mineplex/core/account/command/UpdateRank.java index 15f9813b8..5bee6a2b5 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/account/command/UpdateRank.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/account/command/UpdateRank.java @@ -86,7 +86,7 @@ public class UpdateRank extends CommandBase return; } - Plugin.getRepository().SaveRank(new Callback() + Plugin.getRepository().saveRank(new Callback() { public void run(Rank rank) { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/account/repository/AccountRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/account/repository/AccountRepository.java index 133dc26b0..51f7c031f 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/account/repository/AccountRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/account/repository/AccountRepository.java @@ -1,26 +1,58 @@ package mineplex.core.account.repository; +import java.sql.Timestamp; import java.util.List; import java.util.UUID; import org.bukkit.craftbukkit.libs.com.google.gson.reflect.TypeToken; +import org.bukkit.plugin.java.JavaPlugin; import mineplex.core.account.repository.token.LoginToken; import mineplex.core.account.repository.token.RankUpdateToken; import mineplex.core.common.Rank; import mineplex.core.common.util.Callback; -import mineplex.core.server.remotecall.AsyncJsonWebCall; +import mineplex.core.common.util.UUIDFetcher; +import mineplex.core.database.DatabaseRunnable; +import mineplex.core.database.RepositoryBase; +import mineplex.core.database.column.ColumnBoolean; +import mineplex.core.database.column.ColumnTimestamp; +import mineplex.core.database.column.ColumnVarChar; import mineplex.core.server.remotecall.JsonWebCall; -public class AccountRepository +public class AccountRepository extends RepositoryBase { + private static String CREATE_ACCOUNT_TABLE = "CREATE TABLE IF NOT EXISTS accounts (id INT NOT NULL AUTO_INCREMENT, uuid VARCHAR(100), name VARCHAR(40), gems INT, rank VARCHAR(40), rankPerm BOOL, rankExpire LONG, lastLogin LONG, totalPlayTime LONG, PRIMARY KEY (id), UNIQUE INDEX uuidIndex (uuid), UNIQUE INDEX nameIndex (name), INDEX rankIndex (rank));"; + private static String ACCOUNT_LOGIN_NEW = "INSERT INTO accounts (uuid, name, lastLogin) values(?, ?, now()) ON DUPLICATE KEY UPDATE name=VALUES(name), lastLogin=VALUES(lastLogin);"; + private static String ACCOUNT_LOGIN_UPDATE = "UPDATE accounts SET uuid=?, name=?, lastLogin=now() WHERE uuid = ?;"; + private static String UPDATE_ACCOUNT_RANK = "UPDATE accounts SET rank=?, rankPerm=false, rankExpire=now() + INTERVAL 1 MONTH WHERE uuid = ?;"; + private static String UPDATE_ACCOUNT_RANK_DONOR = "UPDATE accounts SET rank=?, donorRank=?, rankPerm=false, rankExpire=now() + INTERVAL 1 MONTH WHERE uuid = ?;"; + private static String UPDATE_ACCOUNT_RANK_PERM = "UPDATE accounts SET rank=?, rankPerm=true WHERE uuid = ?;"; + private static String UPDATE_ACCOUNT_RANK_DONOR_PERM = "UPDATE accounts SET rank=?, donorRank=?, rankPerm=true WHERE uuid = ?;"; + private static String UPDATE_ACCOUNT_NULL_RANK = "UPDATE accounts SET rank=?, donorRank=?, rankPerm=?, rankExpire=? WHERE uuid = ? AND rank IS NULL;"; + private String _webAddress; - public AccountRepository(String webAddress) + public AccountRepository(JavaPlugin plugin, String webAddress) { + super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh"); + _webAddress = webAddress; } + @Override + protected void initialize() + { + executeUpdate(CREATE_ACCOUNT_TABLE); + } + + public void login(String uuid, String name) + { + int affectedRows = executeUpdate(ACCOUNT_LOGIN_UPDATE, new ColumnVarChar("uuid", 100, uuid), new ColumnVarChar("name", 40, name), new ColumnVarChar("uuid", 100, uuid)); + + if (affectedRows == 0) + executeUpdate(ACCOUNT_LOGIN_NEW, new ColumnVarChar("uuid", 100, uuid), new ColumnVarChar("name", 40, name)); + } + public String GetClient(String name, UUID uuid, String ipAddress) { LoginToken token = new LoginToken(); @@ -36,14 +68,44 @@ public class AccountRepository return new JsonWebCall(_webAddress + "PlayerAccount/GetAccountByUUID").ExecuteReturnStream(uuid.toString()); } - public void SaveRank(Callback callback, String name, Rank rank, boolean perm) + public void saveRank(final Callback callback, final String name, Rank rank, final boolean perm) { - RankUpdateToken token = new RankUpdateToken(); + final RankUpdateToken token = new RankUpdateToken(); token.Name = name; token.Rank = rank.toString(); token.Perm = perm; - new AsyncJsonWebCall(_webAddress + "PlayerAccount/RankUpdate").Execute(Rank.class, callback, token); + final Callback extraCallback = new Callback() + { + public void run(Rank response) + { + if (response == Rank.ULTRA || response == Rank.HERO) + { + if (perm) + executeUpdate(UPDATE_ACCOUNT_RANK_DONOR_PERM, new ColumnVarChar("rank", 100, response.toString()), new ColumnVarChar("donorRank", 100, response.toString()), new ColumnVarChar("uuid", 100, UUIDFetcher.getUUIDOf(name).toString())); + else + executeUpdate(UPDATE_ACCOUNT_RANK_DONOR, new ColumnVarChar("rank", 100, response.toString()), new ColumnVarChar("donorRank", 100, response.toString()), new ColumnVarChar("uuid", 100, UUIDFetcher.getUUIDOf(name).toString())); + } + else + { + if (perm) + executeUpdate(UPDATE_ACCOUNT_RANK_PERM, new ColumnVarChar("rank", 100, response.toString()), new ColumnVarChar("uuid", 100, UUIDFetcher.getUUIDOf(name).toString())); + else + executeUpdate(UPDATE_ACCOUNT_RANK, new ColumnVarChar("rank", 100, response.toString()), new ColumnVarChar("uuid", 100, UUIDFetcher.getUUIDOf(name).toString())); + } + + callback.run(response); + } + }; + + handleDatabaseCall(new DatabaseRunnable(new Runnable() + { + public void run() + { + new JsonWebCall(_webAddress + "PlayerAccount/RankUpdate").Execute(Rank.class, extraCallback, token); + } + }), "Error saving player " + token.Name + "'s rank in AccountRepository : "); + } public void MatchPlayerName(final Callback> callback, final String userName) @@ -59,4 +121,20 @@ public class AccountRepository asyncThread.start(); } + + @Override + protected void update() + { + } + + public void updateMysqlRank(final String uuid, final String rank, final boolean perm, final String rankExpire) + { + handleDatabaseCall(new DatabaseRunnable(new Runnable() + { + public void run() + { + executeUpdate(UPDATE_ACCOUNT_NULL_RANK, new ColumnVarChar("rank", 100, rank), new ColumnVarChar("donorRank", 100, rank), new ColumnBoolean("rankPerm", perm), new ColumnTimestamp("rankExpire", Timestamp.valueOf(rankExpire)), new ColumnVarChar("uuid", 100, uuid)); + } + }), "Error updating player's mysql rank AccountRepository : "); + } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/account/repository/MysqlAccountRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/account/repository/MysqlAccountRepository.java deleted file mode 100644 index f442a4213..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/account/repository/MysqlAccountRepository.java +++ /dev/null @@ -1,35 +0,0 @@ -package mineplex.core.account.repository; - -import org.bukkit.plugin.java.JavaPlugin; - -import mineplex.core.database.RepositoryBase; -import mineplex.core.database.column.ColumnVarChar; - -public class MysqlAccountRepository extends RepositoryBase -{ - private static String CREATE_ACCOUNT_TABLE = "CREATE TABLE IF NOT EXISTS accounts (id INT NOT NULL AUTO_INCREMENT, uuid VARCHAR(100), name VARCHAR(40), gems INT, rank VARCHAR(40), rankPerm BOOL, rankExpire LONG, lastLogin LONG, totalPlayTime LONG, PRIMARY KEY (id), UNIQUE INDEX uuidIndex (uuid), UNIQUE INDEX nameIndex (name), INDEX rankIndex (rank));"; - private static String ACCOUNT_LOGIN_NEW = "INSERT INTO accounts (uuid, name, lastLogin) values(?, ?, now()) ON DUPLICATE KEY UPDATE name=VALUES(name), lastLogin=VALUES(lastLogin);"; - private static String ACCOUNT_LOGIN_UPDATE = "UPDATE accounts SET uuid=?, name=?, lastLogin=now() WHERE uuid = ?;"; - - public MysqlAccountRepository(JavaPlugin plugin) - { - super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh"); - } - - @Override - protected void initialize() - { - executeUpdate(CREATE_ACCOUNT_TABLE); - } - - @Override - protected void update() { } - - public void login(String uuid, String name) - { - int affectedRows = executeUpdate(ACCOUNT_LOGIN_UPDATE, new ColumnVarChar("uuid", 100, uuid), new ColumnVarChar("name", 40, name), new ColumnVarChar("uuid", 100, uuid)); - - if (affectedRows == 0) - executeUpdate(ACCOUNT_LOGIN_NEW, new ColumnVarChar("uuid", 100, uuid), new ColumnVarChar("name", 40, name)); - } -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/account/repository/token/ClientToken.java b/Plugins/Mineplex.Core/src/mineplex/core/account/repository/token/ClientToken.java index 28c64e80c..3675c3ba1 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/account/repository/token/ClientToken.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/account/repository/token/ClientToken.java @@ -5,6 +5,8 @@ public class ClientToken public int AccountId; public String Name; public String Rank; + public boolean RankPerm; + public String RankExpire; public int EconomyBalance; public AccountToken AccountToken; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/database/DatabaseRunnable.java b/Plugins/Mineplex.Core/src/mineplex/core/database/DatabaseRunnable.java new file mode 100644 index 000000000..f5d1899cd --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/database/DatabaseRunnable.java @@ -0,0 +1,27 @@ +package mineplex.core.database; + +public class DatabaseRunnable +{ + private Runnable _runnable; + private int _failedAttempts = 0; + + public DatabaseRunnable(Runnable runnable) + { + _runnable = runnable; + } + + public void run() + { + _runnable.run(); + } + + public void incrementFailCount() + { + _failedAttempts++; + } + + public int getFailedCounts() + { + return _failedAttempts; + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/database/RepositoryBase.java b/Plugins/Mineplex.Core/src/mineplex/core/database/RepositoryBase.java index e5fb8d38d..9b6cf846a 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/database/RepositoryBase.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/database/RepositoryBase.java @@ -5,24 +5,39 @@ import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.Iterator; +import mineplex.core.common.util.NautHashMap; import mineplex.core.database.column.Column; +import mineplex.core.logger.Logger; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; import org.bukkit.Bukkit; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; import org.bukkit.plugin.java.JavaPlugin; -public abstract class RepositoryBase +public abstract class RepositoryBase implements Listener { protected static Object _connectionLock = new Object(); private Connection _connection = null; + private static Object _queueLock = new Object(); + + private NautHashMap _failedQueue = new NautHashMap(); + private String _connectionString; private String _userName; private String _password; + protected JavaPlugin Plugin; + public RepositoryBase(JavaPlugin plugin, String connectionString, String username, String password) { + Plugin = plugin; + _connectionString = connectionString; _userName = username; _password = password; @@ -38,6 +53,8 @@ public abstract class RepositoryBase } } }); + + plugin.getServer().getPluginManager().registerEvents(this, plugin); } protected abstract void initialize(); @@ -189,4 +206,81 @@ public abstract class RepositoryBase return affectedRows; } + + protected void handleDatabaseCall(final DatabaseRunnable databaseRunnable, final String errorMessage) + { + Thread asyncThread = new Thread(new Runnable() + { + public void run() + { + try + { + databaseRunnable.run(); + } + catch (Exception exception) + { + Logger.Instance.log(errorMessage + exception.getMessage()); + + databaseRunnable.incrementFailCount(); + + synchronized (_queueLock) + { + _failedQueue.put(databaseRunnable, errorMessage); + } + } + } + }); + + asyncThread.start(); + } + + @EventHandler + public void processDatabaseQueue(UpdateEvent event) + { + if (event.getType() != UpdateType.MIN_01) + return; + + processFailedQueue(); + } + + private void processFailedQueue() + { + synchronized (_queueLock) + { + for (Iterator runnablesIterator = _failedQueue.keySet().iterator(); runnablesIterator.hasNext();) + { + final DatabaseRunnable databaseRunnable = runnablesIterator.next(); + + Thread asyncThread = new Thread(new Runnable() + { + public void run() + { + try + { + databaseRunnable.run(); + } + catch (Exception exception) + { + Logger.Instance.log(_failedQueue.get(databaseRunnable) + exception.getMessage()); + + if (databaseRunnable.getFailedCounts() < 4) + { + synchronized (_queueLock) + { + _failedQueue.put(databaseRunnable, _failedQueue.get(databaseRunnable)); + } + } + else + { + Logger.Instance.log("Abandoning database call : " + _failedQueue.get(databaseRunnable)); + } + } + } + }); + + runnablesIterator.remove(); + asyncThread.start(); + } + } + } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/database/column/ColumnBoolean.java b/Plugins/Mineplex.Core/src/mineplex/core/database/column/ColumnBoolean.java new file mode 100644 index 000000000..a7da34f61 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/database/column/ColumnBoolean.java @@ -0,0 +1,42 @@ +package mineplex.core.database.column; + +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; + +public class ColumnBoolean extends Column +{ + public ColumnBoolean(String name) + { + super(name); + } + + public ColumnBoolean(String name, boolean value) + { + super(name, value); + } + + @Override + public String getCreateString() + { + return Name + " BOOLEAN"; + } + + @Override + public Boolean getValue(ResultSet resultSet) throws SQLException + { + return resultSet.getBoolean(Name); + } + + @Override + public void setValue(PreparedStatement preparedStatement, int columnNumber) throws SQLException + { + preparedStatement.setBoolean(columnNumber, Value); + } + + @Override + public ColumnBoolean clone() + { + return new ColumnBoolean(Name, Value); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/database/column/ColumnTimestamp.java b/Plugins/Mineplex.Core/src/mineplex/core/database/column/ColumnTimestamp.java new file mode 100644 index 000000000..1efacd628 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/database/column/ColumnTimestamp.java @@ -0,0 +1,43 @@ +package mineplex.core.database.column; + +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Timestamp; + +public class ColumnTimestamp extends Column +{ + public ColumnTimestamp(String name) + { + super(name); + } + + public ColumnTimestamp(String name, Timestamp value) + { + super(name, value); + } + + @Override + public String getCreateString() + { + return Name + " TIMESTAMP"; + } + + @Override + public Timestamp getValue(ResultSet resultSet) throws SQLException + { + return resultSet.getTimestamp(Name); + } + + @Override + public void setValue(PreparedStatement preparedStatement, int columnNumber) throws SQLException + { + preparedStatement.setTimestamp(columnNumber, Value); + } + + @Override + public ColumnTimestamp clone() + { + return new ColumnTimestamp(Name, Value); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/donation/DonationManager.java b/Plugins/Mineplex.Core/src/mineplex/core/donation/DonationManager.java index fc1ffc9fd..2e5acf719 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/donation/DonationManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/donation/DonationManager.java @@ -1,5 +1,7 @@ package mineplex.core.donation; +import java.util.UUID; + import mineplex.core.MiniPlugin; import mineplex.core.account.event.ClientUnloadEvent; import mineplex.core.account.event.ClientWebResponseEvent; @@ -13,6 +15,7 @@ import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import org.bukkit.craftbukkit.libs.com.google.gson.Gson; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.plugin.java.JavaPlugin; @@ -24,13 +27,13 @@ public class DonationManager extends MiniPlugin private Object _donorLock = new Object(); - private NautHashMap> _gemQueue = new NautHashMap>(); + private NautHashMap> _gemQueue = new NautHashMap>(); public DonationManager(JavaPlugin plugin, String webAddress) { super("Donation", plugin); - _repository = new DonationRepository(webAddress); + _repository = new DonationRepository(plugin, webAddress); _donors = new NautHashMap(); } @@ -62,6 +65,7 @@ public class DonationManager extends MiniPlugin synchronized (_donorLock) { _donors.put(token.Name, new Donor(token.DonorToken)); + _repository.updateGemsAndCoins(token.Name, Get(token.Name).GetGems(), Get(token.Name).getCoins()); } } @@ -73,7 +77,7 @@ public class DonationManager extends MiniPlugin } } - public void PurchaseUnknownSalesPackage(final Callback callback, final String name, final String packageName, final boolean coinPurchase, final int cost, boolean oneTimePurchase) + public void PurchaseUnknownSalesPackage(final Callback callback, final String name, final UUID uuid, final String packageName, final boolean coinPurchase, final int cost, boolean oneTimePurchase) { Donor donor = Get(name); @@ -106,10 +110,10 @@ public class DonationManager extends MiniPlugin if (callback != null) callback.run(response); } - }, name, packageName, coinPurchase, cost); + }, name, uuid.toString(), packageName, coinPurchase, cost); } - public void PurchaseKnownSalesPackage(final Callback callback, final String name, final int salesPackageId) + public void PurchaseKnownSalesPackage(final Callback callback, final String name, final UUID uuid, final int cost, final int salesPackageId) { _repository.PurchaseKnownSalesPackage(new Callback() { @@ -128,17 +132,17 @@ public class DonationManager extends MiniPlugin if (callback != null) callback.run(response); } - }, name, salesPackageId); + }, name, uuid.toString(), cost, salesPackageId); } - public void RewardGems(final Callback callback, final String caller, final String name, final int amount) + public void RewardGems(Callback callback, String caller, String name, UUID uuid, int amount) { - RewardGems(callback, caller, name, amount, true); + RewardGems(callback, caller, name, uuid, amount, true); } - public void RewardGems(final Callback callback, final String caller, final String name, final int amount, final boolean updateTotal) + public void RewardGems(final Callback callback, final String caller, final String name, final UUID uuid, final int amount, final boolean updateTotal) { - _repository.PlayerUpdate(new Callback() + _repository.gemReward(new Callback() { public void run(Boolean success) { @@ -158,23 +162,23 @@ public class DonationManager extends MiniPlugin callback.run(true); } } - }, caller, name, amount); + }, caller, name, uuid.toString(), amount); } - public void RewardGemsLater(final String caller, final String name, final int amount) + public void RewardGemsLater(final String caller, final Player player, final int amount) { - if (!_gemQueue.containsKey(name)) - _gemQueue.put(name, new NautHashMap()); + if (!_gemQueue.containsKey(player)) + _gemQueue.put(player, new NautHashMap()); int totalAmount = amount; - if (_gemQueue.get(name).containsKey(caller)) - totalAmount += _gemQueue.get(name).get(caller); + if (_gemQueue.get(player).containsKey(caller)) + totalAmount += _gemQueue.get(player).get(caller); - _gemQueue.get(name).put(caller, totalAmount); + _gemQueue.get(player).put(caller, totalAmount); //Do Temp Change - Donor donor = Get(name); + Donor donor = Get(player.getName()); if (donor != null) donor.AddGems(amount); @@ -186,39 +190,39 @@ public class DonationManager extends MiniPlugin if (event.getType() != UpdateType.SLOWER) return; - for (String name : _gemQueue.keySet()) + for (Player player : _gemQueue.keySet()) { String caller = null; int total = 0; - for (String curCaller : _gemQueue.get(name).keySet()) + for (String curCaller : _gemQueue.get(player).keySet()) { caller = curCaller; - total += _gemQueue.get(name).get(curCaller); + total += _gemQueue.get(player).get(curCaller); } if (caller == null) continue; - + //Actually Add Gems - RewardGems(null, caller, name, total, false); + RewardGems(null, caller, player.getName(), player.getUniqueId(), total, false); - System.out.println("Queue Added [" + name + "] with Gems [" + total + "] for [" + caller + "]"); + System.out.println("Queue Added [" + player + "] with Gems [" + total + "] for [" + caller + "]"); //Clean - _gemQueue.get(name).clear(); + _gemQueue.get(player).clear(); } //Clean _gemQueue.clear(); } - public void RewardCoins(final Callback callback, final String caller, final String name, final int amount) + public void RewardCoins(Callback callback, String caller, String name, UUID uuid, int amount) { - RewardCoins(callback, caller, name, amount, true); + RewardCoins(callback, caller, name, uuid, amount, true); } - public void RewardCoins(final Callback callback, final String caller, final String name, final int amount, final boolean updateTotal) + public void RewardCoins(final Callback callback, final String caller, final String name, final UUID uuid, final int amount, final boolean updateTotal) { _repository.rewardCoins(new Callback() { @@ -240,6 +244,6 @@ public class DonationManager extends MiniPlugin callback.run(true); } } - }, caller, name, amount); + }, caller, name, uuid.toString(), amount); } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/donation/GemCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/donation/GemCommand.java index 37375bd85..cffda7ad9 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/donation/GemCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/donation/GemCommand.java @@ -41,7 +41,7 @@ public class GemCommand extends CommandBase UtilPlayer.message(caller, F.main("Gem", "You gave " + F.elem(gems + " Gems") + " to " + F.name(target.getName()) + ".")); UtilPlayer.message(target, F.main("Gem", F.name(caller.getName()) + " gave you " + F.elem(gems + " Gems") + ".")); } - }, caller.getName(), target.getName(), gems); + }, caller.getName(), target.getName(), target.getUniqueId(), gems); } catch (Exception e) { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/donation/repository/DonationRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/donation/repository/DonationRepository.java index 3eb91a8a5..dc5277b46 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/donation/repository/DonationRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/donation/repository/DonationRepository.java @@ -1,58 +1,185 @@ package mineplex.core.donation.repository; +import org.bukkit.plugin.java.JavaPlugin; + import mineplex.core.common.util.Callback; +import mineplex.core.common.util.UUIDFetcher; +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.repository.token.GemRewardToken; import mineplex.core.donation.repository.token.PurchaseToken; import mineplex.core.donation.repository.token.UnknownPurchaseToken; -import mineplex.core.server.remotecall.AsyncJsonWebCall; +import mineplex.core.server.remotecall.JsonWebCall; import mineplex.core.server.util.TransactionResponse; -public class DonationRepository +public class DonationRepository extends RepositoryBase { + private static String CREATE_COIN_TRANSACTION_TABLE = "CREATE TABLE IF NOT EXISTS accountCoinTransactions (id INT NOT NULL AUTO_INCREMENT, accounts_uuid VARCHAR(100), reason VARCHAR(100), coins INT, PRIMARY KEY (id), FOREIGN KEY (accounts_uuid) REFERENCES accounts(uuid), INDEX coinUuidIndex (accounts_uuid));"; + private static String CREATE_GEM_TRANSACTION_TABLE = "CREATE TABLE IF NOT EXISTS accountGemTransactions (id INT NOT NULL AUTO_INCREMENT, accounts_uuid VARCHAR(100), reason VARCHAR(100), gems INT, PRIMARY KEY (id), FOREIGN KEY (accounts_uuid) REFERENCES accounts(uuid), INDEX gemUuidIndex (accounts_uuid));"; + private static String INSERT_COIN_TRANSACTION = "INSERT INTO accountCoinTransactions(accounts_uuid, reason, coins) VALUES(?, ?, ?);"; + private static String INSERT_GEM_TRANSACTION = "INSERT INTO accountGemTransactions(accounts_uuid, reason, gems) VALUES(?, ?, ?);"; + private static String UPDATE_ACCOUNT_COINS = "UPDATE accounts SET coins = coins + ? WHERE uuid = ?;"; + private static String UPDATE_ACCOUNT_GEMS = "UPDATE accounts SET gems = gems + ? WHERE uuid = ?;"; + private static String UPDATE_NULL_ACCOUNT_GEMS_AND_COINS_ = "UPDATE accounts SET gems = ?, coins = ? WHERE uuid = ? AND gems IS NULL AND coins IS NULL;"; + private String _webAddress; - public DonationRepository(String webAddress) + public DonationRepository(JavaPlugin plugin, String webAddress) { + super(plugin, "jdbc:mysql://db.mineplex.com:3306/Account?autoReconnect=true&failOverReadOnly=false&maxReconnects=10", "root", "tAbechAk3wR7tuTh"); + _webAddress = webAddress; } - public void PurchaseKnownSalesPackage(Callback callback, String name, int salesPackageId) + public void PurchaseKnownSalesPackage(final Callback callback, String name, final String uuid, final int cost, final int salesPackageId) { - PurchaseToken token = new PurchaseToken(); + final PurchaseToken token = new PurchaseToken(); token.AccountName = name; token.UsingCredits = false; token.SalesPackageId = salesPackageId; - new AsyncJsonWebCall(_webAddress + "PlayerAccount/PurchaseKnownSalesPackage").Execute(TransactionResponse.class, callback, token); + final Callback extraCallback = new Callback() + { + public void run(TransactionResponse response) + { + if (response == TransactionResponse.Success) + executeUpdate(UPDATE_ACCOUNT_GEMS, new ColumnInt("gems", cost), new ColumnVarChar("uuid", 100, uuid)); + + callback.run(response); + } + }; + + handleDatabaseCall(new DatabaseRunnable(new Runnable() + { + public void run() + { + new JsonWebCall(_webAddress + "PlayerAccount/PurchaseKnownSalesPackage").Execute(TransactionResponse.class, extraCallback, token); + } + }), "Error purchasing known sales package in DonationRepository : "); } - public void PurchaseUnknownSalesPackage(Callback callback, String name, String packageName, boolean coinPurchase, int cost) + public void PurchaseUnknownSalesPackage(final Callback callback, final String name, final String uuid, final String packageName, final boolean coinPurchase, final int cost) { - UnknownPurchaseToken token = new UnknownPurchaseToken(); + final UnknownPurchaseToken token = new UnknownPurchaseToken(); token.AccountName = name; token.SalesPackageName = packageName; token.CoinPurchase = coinPurchase; token.Cost = cost; token.Premium = false; - new AsyncJsonWebCall(_webAddress + "PlayerAccount/PurchaseUnknownSalesPackage").Execute(TransactionResponse.class, callback, token); + final Callback extraCallback = new Callback() + { + public void run(TransactionResponse response) + { + if (response == TransactionResponse.Success) + { + if (coinPurchase) + { + executeUpdate(UPDATE_ACCOUNT_COINS, new ColumnInt("coins", -cost), new ColumnVarChar("uuid", 100, uuid)); + executeUpdate(INSERT_COIN_TRANSACTION, new ColumnVarChar("uuid", 100, uuid), new ColumnVarChar("reason", 100, "Purchased " + packageName), new ColumnInt("coins", -cost)); + } + else + { + executeUpdate(UPDATE_ACCOUNT_GEMS, new ColumnInt("gems", -cost), new ColumnVarChar("uuid", 100, uuid)); + executeUpdate(INSERT_GEM_TRANSACTION, new ColumnVarChar("uuid", 100, uuid), new ColumnVarChar("reason", 100, "Purchased " + packageName), new ColumnInt("gems", -cost)); + } + } + + callback.run(response); + } + }; + + handleDatabaseCall(new DatabaseRunnable(new Runnable() + { + public void run() + { + new JsonWebCall(_webAddress + "PlayerAccount/PurchaseUnknownSalesPackage").Execute(TransactionResponse.class, extraCallback, token); + } + }), "Error purchasing unknown sales package in DonationRepository : "); } - public void PlayerUpdate(Callback callback, String giver, String name, int greenGems) + public void gemReward(final Callback callback, final String giver, String name, final String uuid, final int greenGems) { - GemRewardToken token = new GemRewardToken(); + final GemRewardToken token = new GemRewardToken(); token.Source = giver; token.Name = name; token.Amount = greenGems; - new AsyncJsonWebCall(_webAddress + "PlayerAccount/GemReward").Execute(Boolean.class, callback, token); + + final Callback extraCallback = new Callback() + { + public void run(Boolean response) + { + if (response) + { + executeUpdate(UPDATE_ACCOUNT_GEMS, new ColumnInt("gems", greenGems), new ColumnVarChar("uuid", 100, uuid)); + executeUpdate(INSERT_GEM_TRANSACTION, new ColumnVarChar("uuid", 100, uuid), new ColumnVarChar("reason", 100, "Given by " + giver), new ColumnInt("gems", greenGems)); + } + + callback.run(response); + } + }; + + handleDatabaseCall(new DatabaseRunnable(new Runnable() + { + public void run() + { + new JsonWebCall(_webAddress + "PlayerAccount/GemReward").Execute(Boolean.class, extraCallback, token); + } + }), "Error updating player gem amount in DonationRepository : "); } - public void rewardCoins(Callback callback, String giver, String name, int coins) + public void rewardCoins(final Callback callback, final String giver, String name, final String uuid, final int coins) { - GemRewardToken token = new GemRewardToken(); + final GemRewardToken token = new GemRewardToken(); token.Source = giver; token.Name = name; token.Amount = coins; - new AsyncJsonWebCall(_webAddress + "PlayerAccount/CoinReward").Execute(Boolean.class, callback, token); + + final Callback extraCallback = new Callback() + { + public void run(Boolean response) + { + if (response) + { + executeUpdate(UPDATE_ACCOUNT_COINS, new ColumnInt("coins", coins), new ColumnVarChar("uuid", 100, uuid)); + executeUpdate(INSERT_COIN_TRANSACTION, new ColumnVarChar("uuid", 100, uuid), new ColumnVarChar("reason", 100, "Rewarded by " + giver), new ColumnInt("coins", coins)); + } + + callback.run(response); + } + }; + + handleDatabaseCall(new DatabaseRunnable(new Runnable() + { + public void run() + { + new JsonWebCall(_webAddress + "PlayerAccount/CoinReward").Execute(Boolean.class, extraCallback, token); + } + }), "Error updating player coin amount in DonationRepository : "); + } + + @Override + protected void initialize() + { + executeUpdate(CREATE_COIN_TRANSACTION_TABLE); + executeUpdate(CREATE_GEM_TRANSACTION_TABLE); + } + + @Override + protected void update() + { + } + + public void updateGemsAndCoins(final String name, final int gems, final int coins) + { + handleDatabaseCall(new DatabaseRunnable(new Runnable() + { + public void run() + { + executeUpdate(UPDATE_NULL_ACCOUNT_GEMS_AND_COINS_, new ColumnInt("gems", gems), new ColumnInt("coins", coins), new ColumnVarChar("uuid", 100, UUIDFetcher.getUUIDOf(name).toString())); + } + }), "Error updating player's null gems and coins DonationRepository : "); } } \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/ItemCoinBomb.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/ItemCoinBomb.java index 4ad21da87..28a3d27c0 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/ItemCoinBomb.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/ItemCoinBomb.java @@ -108,7 +108,7 @@ public class ItemCoinBomb extends ItemGadget event.setCancelled(true); event.getItem().remove(); - Manager.getDonationManager().RewardCoins(null, this.GetName() + " Pickup", event.getPlayer().getName(), 4); + Manager.getDonationManager().RewardCoins(null, this.GetName() + " Pickup", event.getPlayer().getName(), event.getPlayer().getUniqueId(), 4); event.getPlayer().getWorld().playSound(event.getPlayer().getLocation(), Sound.ORB_PICKUP, 1f, 2f); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/ItemGemBomb.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/ItemGemBomb.java index e21fda7c5..8d64ce1b4 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/ItemGemBomb.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/ItemGemBomb.java @@ -108,7 +108,7 @@ public class ItemGemBomb extends ItemGadget event.setCancelled(true); event.getItem().remove(); - Manager.getDonationManager().RewardGems(null, this.GetName() + " Pickup", event.getPlayer().getName(), 4); + Manager.getDonationManager().RewardGems(null, this.GetName() + " Pickup", event.getPlayer().getName(), event.getPlayer().getUniqueId(), 4); event.getPlayer().getWorld().playSound(event.getPlayer().getLocation(), Sound.ORB_PICKUP, 1f, 2f); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/logger/Logger.java b/Plugins/Mineplex.Core/src/mineplex/core/logger/Logger.java index 48eaf324f..25108a02c 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/logger/Logger.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/logger/Logger.java @@ -52,6 +52,8 @@ public class Logger public void log(final String message) { + System.out.println(message); + Bukkit.getServer().getScheduler().runTaskAsynchronously(_plugin, new Runnable() { public void run() diff --git a/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/CoinReward.java b/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/CoinReward.java index 4ccc599e7..b2405deeb 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/CoinReward.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/CoinReward.java @@ -53,7 +53,7 @@ public class CoinReward extends Reward { } - }, "Treasure Chest", player.getName(), gemsToReward); + }, "Treasure Chest", player.getName(), player.getUniqueId(), gemsToReward); return new RewardData(getRarity().getColor() + gemsToReward + " Coins", new ItemStack(175)); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/UnknownPackageReward.java b/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/UnknownPackageReward.java index 45a20f659..e1fa42c00 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/UnknownPackageReward.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/reward/rewards/UnknownPackageReward.java @@ -31,7 +31,7 @@ public class UnknownPackageReward extends Reward @Override protected RewardData giveRewardCustom(Player player) { - _donationManager.PurchaseUnknownSalesPackage(null, player.getName(), _packageName, true, 0, true); + _donationManager.PurchaseUnknownSalesPackage(null, player.getName(), player.getUniqueId(), _packageName, true, 0, true); return new RewardData(getRarity().getColor() + _name, _itemStack); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/shop/page/ConfirmationPage.java b/Plugins/Mineplex.Core/src/mineplex/core/shop/page/ConfirmationPage.java index e37605cf3..9d825d56b 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/shop/page/ConfirmationPage.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/shop/page/ConfirmationPage.java @@ -146,7 +146,7 @@ public class ConfirmationPage= 3 && args[0].equalsIgnoreCase("unban")) diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/modules/ParkourManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/ParkourManager.java index 6ef2652e3..4c1f318e8 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/modules/ParkourManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/modules/ParkourManager.java @@ -389,7 +389,7 @@ public class ParkourManager extends MiniPlugin //Sound player.playSound(player.getLocation(), Sound.LEVEL_UP, 2f, 1.5f); } - }, "Parkour " + data.Name, player.getName(), data.Gems); + }, "Parkour " + data.Name, player.getName(), player.getUniqueId(), data.Gems); } } } diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/poll/PollManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/poll/PollManager.java index 9da95a10d..6aaa8c18e 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/poll/PollManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/poll/PollManager.java @@ -191,7 +191,7 @@ public class PollManager extends MiniClientPlugin } }); } - }, "Poll", name, poll.getCoinReward()); + }, "Poll", name, uuid, poll.getCoinReward()); } } }); diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/ServerNpcPage.java b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/ServerNpcPage.java index c45bda048..609dffae2 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/ServerNpcPage.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/ServerNpcPage.java @@ -263,12 +263,12 @@ public class ServerNpcPage extends ShopPageBase im private boolean isStarting(ServerInfo serverInfo) { - return (serverInfo.MOTD.contains("Starting") || serverInfo.MOTD.contains("Recruiting") || serverInfo.MOTD.contains("Waiting") || serverInfo.MOTD.contains("Cup")); + return (serverInfo.MOTD.contains("Starting") || serverInfo.MOTD.contains("Recruiting") || serverInfo.MOTD.contains("Waiting") || serverInfo.MOTD.contains("Open")); } private boolean isInProgress(ServerInfo serverInfo) { - return serverInfo.MOTD.contains("In") || serverInfo.MOTD.contains("Restarting"); + return serverInfo.MOTD.contains("Progress") || serverInfo.MOTD.contains("Restarting"); } private boolean hasEnoughSlots(ServerInfo serverInfo, int slotsNeeded) diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/tutorial/TutorialManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/tutorial/TutorialManager.java index 195ed7f34..3d4c0537e 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/tutorial/TutorialManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/tutorial/TutorialManager.java @@ -138,7 +138,7 @@ public class TutorialManager extends MiniPlugin //Sound player.playSound(player.getLocation(), Sound.LEVEL_UP, 2f, 1.5f); } - }, "Tutorial " + tut.GetTutName(), player.getName(), tut.GetGems()); + }, "Tutorial " + tut.GetTutName(), player.getName(), player.getUniqueId(), tut.GetGems()); } } } diff --git a/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/salespackage/command/BoosterCommand.java b/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/salespackage/command/BoosterCommand.java index 06b2791db..492f78307 100644 --- a/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/salespackage/command/BoosterCommand.java +++ b/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/salespackage/command/BoosterCommand.java @@ -1,5 +1,7 @@ package mineplex.staffServer.salespackage.command; +import java.util.UUID; + import org.bukkit.entity.Player; import mineplex.core.command.CommandBase; @@ -24,8 +26,10 @@ public class BoosterCommand extends CommandBase String playerName = args[0]; int amount = Integer.parseInt(args[1]); - Plugin.getDonationManager().PurchaseUnknownSalesPackage(null, playerName, "Gem Booster " + amount, false, 0, false); - Plugin.getInventoryManager().addItemToInventoryForOffline(UUIDFetcher.getUUIDOf(playerName).toString(), "Utility", "Gem Booster", amount); + UUID uuid = UUIDFetcher.getUUIDOf(playerName); + + Plugin.getDonationManager().PurchaseUnknownSalesPackage(null, playerName, uuid, "Gem Booster " + amount, false, 0, false); + Plugin.getInventoryManager().addItemToInventoryForOffline(uuid.toString(), "Utility", "Gem Booster", amount); caller.sendMessage(F.main(Plugin.GetName(), "Added " + amount + " boosters to " + playerName + "'s account!")); } } diff --git a/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/salespackage/command/CoinCommand.java b/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/salespackage/command/CoinCommand.java index 977bfa9eb..117db806c 100644 --- a/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/salespackage/command/CoinCommand.java +++ b/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/salespackage/command/CoinCommand.java @@ -1,10 +1,13 @@ package mineplex.staffServer.salespackage.command; +import java.util.UUID; + import org.bukkit.entity.Player; import mineplex.core.command.CommandBase; import mineplex.core.common.Rank; import mineplex.core.common.util.F; +import mineplex.core.common.util.UUIDFetcher; import mineplex.staffServer.salespackage.SalesPackageManager; public class CoinCommand extends CommandBase @@ -23,7 +26,9 @@ public class CoinCommand extends CommandBase String playerName = args[0]; int amount = Integer.parseInt(args[1]); - Plugin.getDonationManager().RewardCoins(null, caller.getName(), playerName, amount); + UUID uuid = UUIDFetcher.getUUIDOf(playerName); + + Plugin.getDonationManager().RewardCoins(null, caller.getName(), playerName, uuid, amount); caller.sendMessage(F.main(Plugin.GetName(), "Added " + amount + " coins to " + playerName + "'s account!")); } } diff --git a/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/salespackage/command/GemHunterCommand.java b/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/salespackage/command/GemHunterCommand.java index cc1a00fc1..af4c99490 100644 --- a/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/salespackage/command/GemHunterCommand.java +++ b/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/salespackage/command/GemHunterCommand.java @@ -1,5 +1,7 @@ package mineplex.staffServer.salespackage.command; +import java.util.UUID; + import org.bukkit.entity.Player; import mineplex.core.command.CommandBase; @@ -24,8 +26,10 @@ public class GemHunterCommand extends CommandBase String playerName = args[0]; int amount = Integer.parseInt(args[1]); - Plugin.getDonationManager().PurchaseUnknownSalesPackage(null, playerName, "Gem Hunter Level " + amount, false, 0, false); - Plugin.getStatsManager().incrementStat(UUIDFetcher.getUUIDOf(playerName).toString(), "Global.GemsEarned", 5000 + (amount * 5000)); + UUID uuid = UUIDFetcher.getUUIDOf(playerName); + + Plugin.getDonationManager().PurchaseUnknownSalesPackage(null, playerName, uuid, "Gem Hunter Level " + amount, false, 0, false); + Plugin.getStatsManager().incrementStat(uuid.toString(), "Global.GemsEarned", 5000 + (amount * 5000)); caller.sendMessage(F.main(Plugin.GetName(), "Added Level " + amount + " Gem Hunter to " + playerName + "'s account!")); } } diff --git a/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/salespackage/command/TreasureChestCommand.java b/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/salespackage/command/TreasureChestCommand.java index 8a562e236..939544ead 100644 --- a/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/salespackage/command/TreasureChestCommand.java +++ b/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/salespackage/command/TreasureChestCommand.java @@ -1,5 +1,7 @@ package mineplex.staffServer.salespackage.command; +import java.util.UUID; + import org.bukkit.entity.Player; import mineplex.core.command.CommandBase; @@ -24,8 +26,10 @@ public class TreasureChestCommand extends CommandBase String playerName = args[0]; int amount = Integer.parseInt(args[1]); - Plugin.getDonationManager().PurchaseUnknownSalesPackage(null, playerName, "Treasure Chest " + amount, false, 0, false); - Plugin.getInventoryManager().addItemToInventoryForOffline(UUIDFetcher.getUUIDOf(playerName).toString(), "Utility", "Treasure Chest", amount); + UUID uuid = UUIDFetcher.getUUIDOf(playerName); + + Plugin.getDonationManager().PurchaseUnknownSalesPackage(null, playerName, uuid, "Treasure Chest " + amount, false, 0, false); + Plugin.getInventoryManager().addItemToInventoryForOffline(uuid.toString(), "Utility", "Treasure Chest", amount); caller.sendMessage(F.main(Plugin.GetName(), "Added " + amount + " treasure chests to " + playerName + "'s account!")); } } diff --git a/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/salespackage/command/TreasureKeyCommand.java b/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/salespackage/command/TreasureKeyCommand.java index 26072bb11..bbd479bd1 100644 --- a/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/salespackage/command/TreasureKeyCommand.java +++ b/Plugins/Mineplex.StaffServer/src/mineplex/staffServer/salespackage/command/TreasureKeyCommand.java @@ -1,5 +1,7 @@ package mineplex.staffServer.salespackage.command; +import java.util.UUID; + import org.bukkit.entity.Player; import mineplex.core.command.CommandBase; @@ -24,8 +26,10 @@ public class TreasureKeyCommand extends CommandBase String playerName = args[0]; int amount = Integer.parseInt(args[1]); - Plugin.getDonationManager().PurchaseUnknownSalesPackage(null, playerName, "Treasure Key " + amount, false, 0, false); - Plugin.getInventoryManager().addItemToInventoryForOffline(UUIDFetcher.getUUIDOf(playerName).toString(), "Treasure", "Treasure Key", amount); + UUID uuid = UUIDFetcher.getUUIDOf(playerName); + + Plugin.getDonationManager().PurchaseUnknownSalesPackage(null, playerName, uuid, "Treasure Key " + amount, false, 0, false); + Plugin.getInventoryManager().addItemToInventoryForOffline(uuid.toString(), "Treasure", "Treasure Key", amount); caller.sendMessage(F.main(Plugin.GetName(), "Added " + amount + " treasure Keys to " + playerName + "'s account!")); } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/christmas/Christmas.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/christmas/Christmas.java index ff0e12b32..8444bc135 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/christmas/Christmas.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/christmas/Christmas.java @@ -335,7 +335,7 @@ public class Christmas extends SoloGame { for (Player player : GetPlayers(false)) { - Manager.GetDonation().PurchaseUnknownSalesPackage(null, player.getName(), "Snowmans Head", false, 0, true); + Manager.GetDonation().PurchaseUnknownSalesPackage(null, player.getName(), player.getUniqueId(), "Snowmans Head", false, 0, true); Manager.GetGame().AddGems(player, 30, "Slaying the Pumpkin King", false); Manager.GetGame().AddGems(player, 10, "Participation", false); } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/halloween/Halloween.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/halloween/Halloween.java index cd40f17ae..ab6e14220 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/halloween/Halloween.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/halloween/Halloween.java @@ -316,7 +316,7 @@ public class Halloween extends SoloGame { for (Player player : GetPlayers(false)) { - Manager.GetDonation().PurchaseUnknownSalesPackage(null, player.getName(), "Pumpkin Kings Head", false, 0, true); + Manager.GetDonation().PurchaseUnknownSalesPackage(null, player.getName(), player.getUniqueId(), "Pumpkin Kings Head", false, 0, true); Manager.GetGame().AddGems(player, 30, "Killing the Pumpkin King", false); Manager.GetGame().AddGems(player, 10, "Participation", false); } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameAchievementManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameAchievementManager.java index cecba6342..040093611 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameAchievementManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameAchievementManager.java @@ -113,7 +113,7 @@ public class GameAchievementManager implements Listener { Manager.GetTaskManager().completedTask(player, type.getName()); } - }, type.getName(), player.getName(), type.getGemReward()); + }, type.getName(), player.getName(), player.getUniqueId(), type.getGemReward()); } else { diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameGemManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameGemManager.java index 9e75bee95..d25d72cd5 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameGemManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameGemManager.java @@ -174,7 +174,7 @@ public class GameGemManager implements Listener if (DoubleGem) total += earned; - Manager.GetDonation().RewardGems(null, "Earned " + game.GetName(), player.getName(), total); + Manager.GetDonation().RewardGems(null, "Earned " + game.GetName(), player.getName(), player.getUniqueId(), total); //Stats Manager.GetStatsManager().incrementStat(player, "Global.GemsEarned", total); diff --git a/Website/LOC.Core/Tokens/Client/ClientToken.cs b/Website/LOC.Core/Tokens/Client/ClientToken.cs index c06400e72..4a1c02ff1 100644 --- a/Website/LOC.Core/Tokens/Client/ClientToken.cs +++ b/Website/LOC.Core/Tokens/Client/ClientToken.cs @@ -20,6 +20,9 @@ Name = account.Name; Uuid = account.Uuid; Rank = account.Rank.Name; + RankPerm = account.RankPerm; + RankExpire = account.RankExpire.ToShortDateString(); + Time = (long)TimeUtil.GetCurrentMilliseconds(); EconomyBalance = account.EconomyBalance; @@ -123,6 +126,10 @@ public string Rank { get; set; } + public bool RankPerm { get; set; } + + public string RankExpire { get; set; } + public long Time { get; set; } public int EconomyBalance { get; set; } diff --git a/Website/LOC.Website.Common/Models/AccountAdministrator.cs b/Website/LOC.Website.Common/Models/AccountAdministrator.cs index d97655952..4f94fd15d 100644 --- a/Website/LOC.Website.Common/Models/AccountAdministrator.cs +++ b/Website/LOC.Website.Common/Models/AccountAdministrator.cs @@ -566,75 +566,6 @@ account.RankPerm = token.Perm; repository.Edit(account); - - if ((rank.Name == "HERO" || rank.Name == "ULTRA") && token.Perm) - { - addAccountTransaction(repository, account, "Bacon Brawl Bebe Piggles", 0, 0); - addAccountTransaction(repository, account, "Bacon Brawl `Pig`", 0, 0); - addAccountTransaction(repository, account, "A Barbarians Life Barbarian Archer", 0, 0); - addAccountTransaction(repository, account, "A Barbarians Life Bomber", 0, 0); - addAccountTransaction(repository, account, "The Bridges Archer", 0, 0); - addAccountTransaction(repository, account, "The Bridges Bomber", 0, 0); - addAccountTransaction(repository, account, "The Bridges Brawler", 0, 0); - addAccountTransaction(repository, account, "The Bridges Miner", 0, 0); - addAccountTransaction(repository, account, "Castle Siege Castle Assassin", 0, 0); - addAccountTransaction(repository, account, "Castle Siege Castle Brawler", 0, 0); - addAccountTransaction(repository, account, "Castle Siege Castle Knight", 0, 0); - addAccountTransaction(repository, account, "Castle Siege Undead Archer", 0, 0); - addAccountTransaction(repository, account, "Castle Siege Undead Zombie", 0, 0); - addAccountTransaction(repository, account, "Death Tag Runner Archer", 0, 0); - addAccountTransaction(repository, account, "Death Tag Runner Traitor", 0, 0); - addAccountTransaction(repository, account, "Dragon Escape Disruptor", 0, 0); - addAccountTransaction(repository, account, "Dragon Escape Warper", 0, 0); - addAccountTransaction(repository, account, "Dragons Marksman", 0, 0); - addAccountTransaction(repository, account, "Dragons Pyrotechnic", 0, 0); - addAccountTransaction(repository, account, "Block Hunt Instant Hider", 0, 0); - addAccountTransaction(repository, account, "Block Hunt Shocking Hider", 0, 0); - addAccountTransaction(repository, account, "Block Hunt Radar Hunter", 0, 0); - addAccountTransaction(repository, account, "Block Hunt TNT Hunter", 0, 0); - addAccountTransaction(repository, account, "Super Paintball Machine Gun", 0, 0); - addAccountTransaction(repository, account, "Super Paintball Shotgun", 0, 0); - addAccountTransaction(repository, account, "One in the Quiver Brawler", 0, 0); - addAccountTransaction(repository, account, "One in the Quiver Enchanter", 0, 0); - addAccountTransaction(repository, account, "Runner Archer", 0, 0); - addAccountTransaction(repository, account, "Runner Frosty", 0, 0); - addAccountTransaction(repository, account, "Sheep Quest Archer", 0, 0); - addAccountTransaction(repository, account, "Sheep Quest Brute", 0, 0); - addAccountTransaction(repository, account, "Super Smash Mobs Blaze", 0, 0); - addAccountTransaction(repository, account, "Super Smash Mobs Chicken", 0, 0); - addAccountTransaction(repository, account, "Super Smash Mobs Mad Cow", 0, 0); - addAccountTransaction(repository, account, "Super Smash Mobs Creeper", 0, 0); - addAccountTransaction(repository, account, "Super Smash Mobs Enderman", 0, 0); - addAccountTransaction(repository, account, "Super Smash Mobs Undead Knight", 0, 0); - addAccountTransaction(repository, account, "Super Smash Mobs Magma Cube", 0, 0); - addAccountTransaction(repository, account, "Super Smash Mobs Pig", 0, 0); - addAccountTransaction(repository, account, "Super Smash Mobs Skeletal Horse", 0, 0); - addAccountTransaction(repository, account, "Super Smash Mobs Sky Squid", 0, 0); - addAccountTransaction(repository, account, "Super Smash Mobs Snowman", 0, 0); - addAccountTransaction(repository, account, "Super Smash Mobs Witch", 0, 0); - addAccountTransaction(repository, account, "Super Smash Mobs Wither", 0, 0); - addAccountTransaction(repository, account, "Super Smash Mobs Wither Skeleton", 0, 0); - addAccountTransaction(repository, account, "Super Smash Mobs Wolf", 0, 0); - addAccountTransaction(repository, account, "Snake Super Snake", 0, 0); - addAccountTransaction(repository, account, "Snake Other Snake", 0, 0); - addAccountTransaction(repository, account, "Sneaky Assassins Ranged Assassin", 0, 0); - addAccountTransaction(repository, account, "Sneaky Assassins Revealer", 0, 0); - addAccountTransaction(repository, account, "Super Spleef Archer", 0, 0); - addAccountTransaction(repository, account, "Super Spleef Brawler", 0, 0); - addAccountTransaction(repository, account, "Squid Shooter Squid Blaster", 0, 0); - addAccountTransaction(repository, account, "Squid Shooter Squid Sniper", 0, 0); - addAccountTransaction(repository, account, "Survival Games Archer", 0, 0); - addAccountTransaction(repository, account, "Survival Games Assassin", 0, 0); - addAccountTransaction(repository, account, "Survival Games Beastmaster", 0, 0); - addAccountTransaction(repository, account, "Survival Games Bomber", 0, 0); - addAccountTransaction(repository, account, "Survival Games Brawler", 0, 0); - addAccountTransaction(repository, account, "Survival Games Necromancer", 0, 0); - addAccountTransaction(repository, account, "Turf Wars Infiltrator", 0, 0); - addAccountTransaction(repository, account, "Turf Wars Shredder", 0, 0); - addAccountTransaction(repository, account, "Zombie Survival Survivor Archer", 0, 0); - addAccountTransaction(repository, account, "Zombie Survival Survivor Rogue", 0, 0); - } - repository.CommitChanges(); _logger.Log("INFO", "TOKEN " + token.Name + "'s rank has been updated to " + token.Rank + " " + (token.Perm ? "Permanently" : "Monthly") + "." + " Rank expire : " + account.RankExpire.ToString()); diff --git a/Website/LOC.Website.Web/LOC.Website.Web.Publish.xml b/Website/LOC.Website.Web/LOC.Website.Web.Publish.xml index dc38d1feb..317457180 100644 --- a/Website/LOC.Website.Web/LOC.Website.Web.Publish.xml +++ b/Website/LOC.Website.Web/LOC.Website.Web.Publish.xml @@ -1,6 +1,7 @@  + @@ -16,8 +17,10 @@ - + + + @@ -25,21 +28,22 @@ - + - + - + + @@ -47,18 +51,18 @@ + + - - - - + + @@ -69,33 +73,33 @@ - + + - - - + + - - - + + + - + @@ -103,42 +107,41 @@ - + - - + + - - + - - + + - - + - + + @@ -149,52 +152,47 @@ - + - - - - + - - - + - - - + + + - + - - + + @@ -202,26 +200,25 @@ - + - - + + - - + + - - - - + + + @@ -229,47 +226,51 @@ - + - + + - - + + + - - + + - + - - + + - - + + - + + + + - @@ -282,47 +283,47 @@ - - + - - + - - + - + + - + + + @@ -333,22 +334,21 @@ - - + - - + + @@ -356,6 +356,8 @@ + + @@ -363,75 +365,77 @@ - + + - - - - + + - + - + + - - - - + - - + + - + - + + + + + + - - + + @@ -441,98 +445,95 @@ - + - - + + - - + - - + - + - - + + - + - + - + - - + - - + - + - + - - + + - + - - + + - - + + - + + + - @@ -543,23 +544,22 @@ - + - - + - + @@ -567,24 +567,26 @@ + + + - - + @@ -595,22 +597,20 @@ - - + + - - - + @@ -618,184 +618,185 @@ - + - - + + + - - + + - + + + - + + + - + - - + + - - + - - + - + + + + + + - - - - + + + - - + - + - - + - - - + - - + + - + - + - + - + - - - + - + - + - - + - + - + - - + + - + - - + + - - + + - + + + - @@ -806,23 +807,22 @@ - + - - + - + @@ -830,24 +830,26 @@ + + + - - + @@ -858,22 +860,20 @@ - - + + - - - + @@ -881,7 +881,7 @@ - + @@ -889,167 +889,167 @@ + - - + + - + + + - + + + - + - - + + - - + - - + - + + + + + + - - + - - + - + - - + - - - + - - + + - + - + - + - + - - - + - - + - + - + - - + + - + - - + + - - + + - + \ No newline at end of file