add PPC methods to SupportShop

This commit is contained in:
Spencer 2018-01-05 20:39:54 -05:00 committed by Alexander Meech
parent ed37174e94
commit 0cebc6e494

View File

@ -1,48 +1,43 @@
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.powerplayclub.PowerPlayData;
import mineplex.core.shop.ShopBase;
import mineplex.core.shop.page.ShopPageBase;
import mineplex.staffServer.LinkedTemporaryItem;
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;
private LinkedTemporaryItem<Integer, List<BonusEntry>> _bonusLog;
private LinkedTemporaryItem<Integer, PowerPlayData> _powerPlayData;
public SupportShop(CustomerSupport plugin)
{
super(plugin, plugin.getClientManager(), plugin.getDonationManager(), "Support");
_accountBonusLog = new HashMap<>();
_activeBonusLogs = new HashMap<>();
_bonusLog = new LinkedTemporaryItem<>();
_powerPlayData = new LinkedTemporaryItem<>();
}
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));
});
// Who cares if they fail to load, the barrier
// button will just be there since the HomePage
// knows not to put it in.
loadBonusLog(caller, target.getAccountId(), (bS) ->
loadPowerPlay(caller, target.getAccountId(), (pS) ->
openPageAsync(caller, new SupportHomePage(getPlugin(), this, caller, target))));
}
public void openPageAsync(Player player, SupportPage page)
@ -72,8 +67,7 @@ public class SupportShop extends ShopBase<CustomerSupport>
);
}
_accountBonusLog.put(accountId, bonusEntries);
_activeBonusLogs.put(caller, accountId);
_bonusLog.put(caller, accountId, bonusEntries);
callback.accept(true);
} catch (SQLException e)
{
@ -83,20 +77,31 @@ public class SupportShop extends ShopBase<CustomerSupport>
});
}
public List<BonusEntry> getBonusLog(int accountId)
public void loadPowerPlay(Player caller, int accountId, Consumer<Boolean> callback)
{
return _accountBonusLog.get(accountId);
getPlugin().getPowerPlayRepo().loadData(accountId).thenAccept((PowerPlayData data) ->
{
if (data == null)
{
callback.accept(false);
return;
}
_powerPlayData.put(caller, accountId, data);
callback.accept(true);
});
}
public Map<Integer, List<BonusEntry>> getBonusLog() { return _bonusLog.getPrimaryMap(); }
public Map<Integer, PowerPlayData> getPowerPlayData() { return _powerPlayData.getPrimaryMap(); }
@Override
protected void closeShopForPlayer(Player player)
{
super.closeShopForPlayer(player);
if (_activeBonusLogs.containsKey(player))
{
_accountBonusLog.remove(_activeBonusLogs.remove(player));
}
_bonusLog.remove(player);
}
@Override