Redo the bonus handling code because I don't like it

This commit is contained in:
Spencer 2018-01-04 21:15:07 -05:00 committed by Alexander Meech
parent ce946f7927
commit 0664ea0884
6 changed files with 161 additions and 7 deletions

View File

@ -34,7 +34,7 @@ public class CheckCommand extends CommandBase<CustomerSupport>
Player onlinePlayer = UtilPlayer.searchExact(playerName);
if (onlinePlayer != null && Plugin.getClientManager().Get(onlinePlayer) != null)
{
_supportShop.openPageAsync(caller, new SupportHomePage(Plugin, _supportShop, caller, Plugin.getClientManager().Get(onlinePlayer)));
_supportShop.handleOpen(caller, Plugin.getClientManager().Get(onlinePlayer));
return;
}
@ -46,7 +46,7 @@ public class CheckCommand extends CommandBase<CustomerSupport>
{
if (client != null)
{
_supportShop.openPageAsync(caller, new SupportHomePage(Plugin, _supportShop, caller, client));
_supportShop.handleOpen(caller, client);
}
else
{

View File

@ -1,15 +1,18 @@
package mineplex.staffServer.customerSupport;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.time.LocalDate;
import java.time.YearMonth;
import java.time.format.TextStyle;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.UUID;
import java.util.concurrent.ExecutionException;
import java.util.function.Consumer;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
@ -25,6 +28,8 @@ import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.weather.WeatherChangeEvent;
import org.bukkit.plugin.java.JavaPlugin;
import com.sun.org.apache.xpath.internal.operations.Bool;
import mineplex.core.Managers;
import mineplex.core.MiniPlugin;
import mineplex.core.account.CoreClient;
@ -45,6 +50,8 @@ import mineplex.core.powerplayclub.PowerPlayData;
import mineplex.core.stats.PlayerStats;
import mineplex.core.stats.StatsManager;
import mineplex.serverdata.database.ResultSetCallable;
import mineplex.staffServer.repository.BonusEntry;
import mineplex.staffServer.repository.SupportRepository;
import mineplex.staffServer.salespackage.SalesPackageManager;
public class CustomerSupport extends MiniPlugin implements ResultSetCallable
@ -63,7 +70,7 @@ public class CustomerSupport extends MiniPlugin implements ResultSetCallable
private SalesPackageManager _salesPackageManager;
private InventoryManager _inventoryManager;
private CustomerSupportRepository _repository;
private SupportRepository _repository;
private PowerPlayClubRepository _powerPlayRepo;
private NautHashMap<Integer, List<String>> _accountBonusLog = new NautHashMap<>();
@ -77,7 +84,7 @@ public class CustomerSupport extends MiniPlugin implements ResultSetCallable
_clientManager = clientManager;
_donationManager = donationManager;
_salesPackageManager = salesPackageManager;
_repository = new CustomerSupportRepository(getPlugin());
_repository = new SupportRepository();
_powerPlayRepo = powerPlayRepo;
_inventoryManager = Managers.require(InventoryManager.class);
@ -108,7 +115,7 @@ public class CustomerSupport extends MiniPlugin implements ResultSetCallable
return _clientManager;
}
public CustomerSupportRepository getRepository()
public SupportRepository getRepository()
{
return _repository;
}
@ -165,7 +172,7 @@ public class CustomerSupport extends MiniPlugin implements ResultSetCallable
{
public void run()
{
_repository.loadBonusLogForAccountId(client.getAccountId(), instance);
//_repository.loadBonusLogForAccountId(client.getAccountId(), instance);
PowerPlayData powerPlayData = _powerPlayRepo.loadData(client.getAccountId()).join();
@ -602,7 +609,7 @@ public class CustomerSupport extends MiniPlugin implements ResultSetCallable
{
runAsync(() ->
{
_repository.loadBonusLogForAccountId(client.getAccountId(), CustomerSupport.this);
//_repository.loadBonusLogForAccountId(client.getAccountId(), CustomerSupport.this);
runSync(() ->
{

View File

@ -0,0 +1,39 @@
package mineplex.staffServer.repository;
import java.util.Date;
public class BonusEntry
{
private int _accountId;
private String _itemName;
private int _itemCount;
private Date _time;
public BonusEntry(int accountId, String itemName, int itemCount, Date time)
{
_accountId = accountId;
_itemName = itemName;
_itemCount = itemCount;
_time = time;
}
public int getAccountId()
{
return _accountId;
}
public String getItemName()
{
return _itemName;
}
public int getItemCount()
{
return _itemCount;
}
public Date getTime()
{
return _time;
}
}

View File

@ -0,0 +1,20 @@
package mineplex.staffServer.repository;
import java.sql.ResultSet;
import java.util.function.Consumer;
import mineplex.serverdata.database.DBPool;
import mineplex.serverdata.database.RepositoryBase;
public class SupportRepository extends RepositoryBase
{
public SupportRepository()
{
super(DBPool.getAccount());
}
public void loadBonusLog(int accountId, Consumer<ResultSet> callback)
{
executeQuery("SELECT accountId, items.name, itemChange, time FROM bonusLog INNER JOIN items ON itemId = items.id WHERE accountId = " + accountId + " ORDER BY bonusLog.id DESC;", callback::accept);
}
}

View File

@ -74,5 +74,13 @@ public class SupportHomePage extends SupportPage
C.mBody + "Click to add gems or",
C.mBody + "shards for " + C.cYellow + _target.getName()
}, 1, false, true), SupportCurrencyPage.class);
if (getShop().getBonusLog(_target.getAccountId()) != null)
{
buildPageButton(getSlotIndex(1, 3), new ShopItem(Material.EMERALD, "Currency", new String[] {
C.mBody + "Click to add gems or",
C.mBody + "shards for " + C.cYellow + _target.getName()
}, 1, false, true), SupportCurrencyPage.class);
}
}
}

View File

@ -1,17 +1,48 @@
package mineplex.staffServer.ui;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import mineplex.core.account.CoreClient;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilServer;
import mineplex.core.shop.ShopBase;
import mineplex.core.shop.page.ShopPageBase;
import mineplex.staffServer.customerSupport.CustomerSupport;
import mineplex.staffServer.repository.BonusEntry;
public class SupportShop extends ShopBase<CustomerSupport>
{
private Map<Integer, List<BonusEntry>> _accountBonusLog;
private Map<Player, Integer> _activeBonusLogs;
public SupportShop(CustomerSupport plugin)
{
super(plugin, plugin.getClientManager(), plugin.getDonationManager(), "Support");
_accountBonusLog = new HashMap<>();
_activeBonusLogs = new HashMap<>();
}
public void handleOpen(Player caller, CoreClient target)
{
loadBonusLog(caller, target.getAccountId(), (success) ->
{
if (!success)
{
caller.sendMessage(F.main(getPlugin().getName(), "Unable to load rank bonuses. Please try again later."));
return;
}
openPageAsync(caller, new SupportHomePage(getPlugin(), this, caller, target));
});
}
public void openPageAsync(Player player, SupportPage page)
@ -19,6 +50,55 @@ public class SupportShop extends ShopBase<CustomerSupport>
UtilServer.runAsync(() -> UtilServer.runSync(()-> super.openPageForPlayer(player, page)));
}
public void loadBonusLog(Player caller, int accountId, Consumer<Boolean> callback)
{
getPlugin().getRepository().loadBonusLog(accountId, resultSet ->
{
try
{
List<BonusEntry> bonusEntries = new LinkedList<>();
while (resultSet.next())
{
// 1: accountId
// 2: itemName
// 3: itemChange (int)
// 4: time
bonusEntries.add(new BonusEntry(
resultSet.getInt(1),
resultSet.getString(2),
resultSet.getInt(3),
resultSet.getDate(4))
);
}
_accountBonusLog.put(accountId, bonusEntries);
_activeBonusLogs.put(caller, accountId);
callback.accept(true);
} catch (SQLException e)
{
e.printStackTrace();
callback.accept(false);
}
});
}
public List<BonusEntry> getBonusLog(int accountId)
{
return _accountBonusLog.get(accountId);
}
@Override
protected void closeShopForPlayer(Player player)
{
super.closeShopForPlayer(player);
if (_activeBonusLogs.containsKey(player))
{
_accountBonusLog.remove(_activeBonusLogs.remove(player));
}
}
@Override
protected ShopPageBase<CustomerSupport, ? extends ShopBase<CustomerSupport>> buildPagesFor(Player player)
{