Update booster page, proper booster rewards

This commit is contained in:
Shaun Bennett 2016-06-10 19:40:27 -05:00
parent 42c35063b3
commit 2421fd1cfe
7 changed files with 138 additions and 39 deletions

View File

@ -9,15 +9,24 @@ import mineplex.core.boosters.event.BoosterUpdateEvent;
import mineplex.core.boosters.gui.BoosterShop;
import mineplex.core.boosters.redis.BoosterUpdateRepository;
import mineplex.core.boosters.tips.BoosterTipManager;
import mineplex.core.common.util.C;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.UtilGear;
import mineplex.core.common.util.UtilInv;
import mineplex.core.donation.DonationManager;
import mineplex.core.inventory.InventoryManager;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.IOException;
@ -29,6 +38,10 @@ import java.util.*;
*/
public class BoosterManager extends MiniPlugin
{
public static final String BOOSTER_ITEM = "Game Booster";
public static final ItemStack INTERFACE_ITEM = ItemStackFactory.Instance.CreateStack(Material.EMERALD, (byte)0, 1, ChatColor.RESET + C.cGreen + "Booster Menu");
public static final int INTERFACE_SLOT = 6;
private BoosterRepository _repository;
private CoreClientManager _clientManager;
private DonationManager _donationManager;
@ -38,6 +51,8 @@ public class BoosterManager extends MiniPlugin
private BoosterShop _shop;
private String _boosterGroup;
private boolean _giveInterfaceItem;
private long _cacheLastUpdated;
private Map<String, List<Booster>> _boosterCache = new HashMap<>();
@ -64,6 +79,8 @@ public class BoosterManager extends MiniPlugin
e.printStackTrace();
}
_giveInterfaceItem = canActivateBoosters();
new BoosterUpdateRepository(plugin);
}
@ -181,6 +198,11 @@ public class BoosterManager extends MiniPlugin
return time;
}
public Booster getActiveBooster()
{
return getActiveBoosterFromCache(_boosterGroup);
}
public Booster getActiveBoosterFromCache(String boosterGroup)
{
List<Booster> boosters = _boosterCache.get(boosterGroup);
@ -212,6 +234,11 @@ public class BoosterManager extends MiniPlugin
});
}
public void activateBooster(Player player, Callback<BoosterApiResponse> callback)
{
activateBooster(_boosterGroup, player, callback);
}
public void activateBooster(String serverGroup, Player player, Callback<BoosterApiResponse> callback)
{
String playerName = player.getName();
@ -224,6 +251,11 @@ public class BoosterManager extends MiniPlugin
});
}
public void chargeBooster(Player player, Callback<Boolean> callback)
{
_inventoryManager.addItemToInventory(callback, player, BOOSTER_ITEM, -1);
}
public void openShop(Player player)
{
_shop.attemptShopOpen(player);
@ -247,7 +279,7 @@ public class BoosterManager extends MiniPlugin
*/
public int getAvailableBoosterCount(Player player)
{
return _inventoryManager.Get(player).getItemCount("Game Booster");
return _inventoryManager.Get(player).getItemCount(BOOSTER_ITEM);
}
/**
@ -259,6 +291,31 @@ public class BoosterManager extends MiniPlugin
return _boosterGroup != null && _boosterGroup.length() > 0;
}
public void giveInterfaceItem(Player player)
{
if (_giveInterfaceItem && !UtilGear.isMat(player.getInventory().getItem(INTERFACE_SLOT), Material.EMERALD))
{
player.getInventory().setItem(INTERFACE_SLOT, INTERFACE_ITEM);
UtilInv.Update(player);
}
}
@EventHandler
public void onJoin(PlayerJoinEvent event)
{
giveInterfaceItem(event.getPlayer());
}
@EventHandler
public void onInteract(PlayerInteractEvent event)
{
if (INTERFACE_ITEM.equals(event.getPlayer().getItemInHand()))
{
openShop(event.getPlayer());
}
}
public static void main(String[] args) throws IOException, URISyntaxException, InterruptedException
{
BoosterRepository repository = new BoosterRepository();

View File

@ -4,6 +4,7 @@ import mineplex.core.boosters.BoosterApiResponse;
import mineplex.core.boosters.BoosterManager;
import mineplex.core.common.util.C;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilTime;
import mineplex.core.shop.item.IButton;
import org.bukkit.entity.Player;
@ -27,21 +28,26 @@ public class ActivateBoosterButton implements IButton
public void onClick(Player player, ClickType clickType)
{
player.closeInventory();
_boosterManager.activateBooster("Testing", player, new Callback<BoosterApiResponse>()
{
@Override
public void run(BoosterApiResponse response)
_boosterManager.chargeBooster(player, data -> {
if (data)
{
if (response.isSuccess())
{
long timeToStart = response.getStartTime().getTime() - System.currentTimeMillis();
if (timeToStart <= 0) player.sendMessage(C.cGreen + "Booster activated and enabled now!");
else player.sendMessage(C.cGreen + "Booster activated. Enabled in " + UtilTime.convertString(timeToStart, 2, UtilTime.TimeUnit.FIT));
}
else
{
player.sendMessage(C.cRed + "There was an error trying to enable your booster :(");
}
_boosterManager.activateBooster(player, response -> {
if (response.isSuccess())
{
long timeToStart = response.getStartTime().getTime() - System.currentTimeMillis();
if (timeToStart <= 0) player.sendMessage(F.main("Booster", "Booster Activated!"));
else player.sendMessage(F.main("Booster", "Booster Added. It will start in " + F.elem(UtilTime.convertString(timeToStart, 2, UtilTime.TimeUnit.FIT))));
}
else
{
player.sendMessage(C.cRed + "There was an error trying to enable your booster :(");
}
});
}
else
{
player.sendMessage(F.main("Booster", "There was an error charging your account. Try again later!"));
}
});
}

View File

@ -34,25 +34,41 @@ public class BoosterPage extends ShopPageBase<BoosterManager, BoosterShop>
int count = getPlugin().getAvailableBoosterCount(getPlayer());
lore.add(" ");
lore.add(C.cWhite + "You Own: " + getPlugin().getAvailableBoosterCount(getPlayer()));
lore.add(C.cWhite + "You Own " + C.cGreen + getPlugin().getAvailableBoosterCount(getPlayer()));
if (getPlugin().canActivateBoosters() && count > 0)
{
List<Booster> boosters = getPlugin().getBoosters();
lore.add(" ");
lore.add(C.cWhite + "Click to Activate");
long waitTime = getPlugin().getBoostTime();
if (waitTime == 0)
{
lore.add(C.cWhite + "Booster would activate " + C.cGreen + "now");
lore.add(C.cGray + "Booster would activate " + C.cGreen + "now");
lore.add(" ");
lore.add(C.cWhite + "Click to Activate Booster");
}
else
{
lore.add(C.cWhite + "Booster would activate in " + C.cGreen + UtilTime.convertString(waitTime, 1, UtilTime.TimeUnit.FIT));
if (boosters.size() > 1)
{
lore.add(C.cGray + "There are " + C.cGreen + (boosters.size() - 1) + C.cGray + " boosters in queue");
}
lore.add(C.cGray + "Activation Time: " + C.cGreen + UtilTime.convertColonString(waitTime, UtilTime.TimeUnit.HOURS, UtilTime.TimeUnit.SECONDS));
lore.add(" ");
lore.add(C.cWhite + "Click to Queue Booster");
}
}
ShopItem booster = new ShopItem(Material.SUGAR, "Game Booster", lore.toArray(new String[0]), 0, false, false);
setItem(4, booster);
if (getPlugin().canActivateBoosters())
{
addButton(4, booster, new ActivateBoosterButton(getShop(), getPlugin()));
}
else
{
setItem(4, booster);
}
addActiveBoosters();
}
@ -70,24 +86,25 @@ public class BoosterPage extends ShopPageBase<BoosterManager, BoosterShop>
int index = 18 + startIndex + i;
long timeActivatedDif = System.currentTimeMillis() - booster.getActivationTime().getTime();
String activationTime = UtilTime.convertString(timeActivatedDif, 2, UtilTime.TimeUnit.FIT);
List<String> lore = new ArrayList<String>();
lore.add(" ");
if (active)
{
lore.add(C.cGreen + "Active");
lore.add(C.cWhite + "Active");
}
else
{
long timeToActive = booster.getStartTime().getTime() - System.currentTimeMillis();
lore.add(C.cWhite + "Activates in " + C.cGreen + UtilTime.convertString(timeToActive, 2, UtilTime.TimeUnit.FIT));
lore.add(C.cWhite + "Starts in " + C.cGreen + UtilTime.convertColonString(timeToActive, UtilTime.TimeUnit.HOURS, UtilTime.TimeUnit.SECONDS));
}
String activationTime = UtilTime.convertString(timeActivatedDif, 2, UtilTime.TimeUnit.FIT);
lore.add(" ");
lore.add(C.cGray + "Added " + activationTime + " ago");
ShopItem shopItem = new ShopItem(booster.isActive() ? Material.EMERALD_BLOCK : Material.REDSTONE_BLOCK,
"Added " + activationTime + " ago", lore.toArray(new String[0]), 1, false, false);
"Game Booster", lore.toArray(new String[0]), 1, !active, false);
setItem(index, shopItem);
}
}
}

View File

@ -5,7 +5,10 @@ import mineplex.core.boosters.BoosterManager;
import mineplex.core.donation.DonationManager;
import mineplex.core.shop.ShopBase;
import mineplex.core.shop.page.ShopPageBase;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
/**
* @author Shaun Bennett
@ -22,4 +25,13 @@ public class BoosterShop extends ShopBase<BoosterManager>
{
return new BoosterPage(getPlugin(), this, getClientManager(), getDonationManager(), player);
}
@EventHandler
public void update(UpdateEvent event)
{
if (event.getType() != UpdateType.SEC)
return;
getPlayerPageMap().values().forEach(ShopPageBase::refresh);
}
}

View File

@ -194,6 +194,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation
private Punish _punishmentManager;
private BrandingManager _brandingManager;
private BonusManager _bonusManager;
private BoosterManager _boosterManager;
private IncognitoManager _incognitoManager;
@ -246,6 +247,8 @@ public class ArcadeManager extends MiniPlugin implements IRelation
_brandingManager = new BrandingManager(plugin);
_boosterManager = boosterManager;
//Dont see a reason to ever just use the normal one
// if (serverConfig.GameList.contains(GameType.ChampionsDominate)
// || serverConfig.GameList.contains(GameType.ChampionsTDM)
@ -1452,6 +1455,11 @@ public class ArcadeManager extends MiniPlugin implements IRelation
return _youtube.contains(player);
}
public BoosterManager getBoosterManager()
{
return _boosterManager;
}
public void toggleUnlockKits(Player caller)
{
if (_youtube.remove(caller))

View File

@ -180,10 +180,11 @@ public class GameGemManager implements Listener
}
//Gem Boooster
/*
if (game.GemBoosterEnabled && game.getGemBooster() != null)
total += (int)(earned * game.getGemBooster().getMultiplier());
*/
Booster booster = Manager.getBoosterManager().getActiveBooster();
if (game.GemBoosterEnabled && booster != null)
{
total *= booster.getMultiplier();
}
int shards = total;
@ -309,16 +310,15 @@ public class GameGemManager implements Listener
int totalGems = earnedGems;
//Gem Booster
/*
Booster gemBooster = game.getGemBooster();
if (game.GemBoosterEnabled && gemBooster != null)
Booster booster = Manager.getBoosterManager().getActiveBooster();
if (game.GemBoosterEnabled && booster != null)
{
UtilPlayer.message(player, F.elem(C.cGreen + "+" + (int) (earnedGems * gemBooster.getMultiplier()) + " Gems") + " for gem booster from "
+ F.name(gemBooster.getPlayerName()));
int addedGems = (int) (earnedGems * booster.getMultiplier()) - earnedGems;
UtilPlayer.message(player, F.elem(C.cGreen + "+" + addedGems + " Gems") + " for gem booster from "
+ F.name(booster.getPlayerName()));
totalGems += earnedGems * gemBooster.getMultiplier();
totalGems *= booster.getMultiplier();
}
*/
int shards = totalGems;

View File

@ -86,8 +86,6 @@ public class GameLobbyManager implements Listener
private Location spawn;
private Location _boosterLocation;
private NautHashMap<Entity, LobbyEnt> _kits = new NautHashMap<Entity, LobbyEnt>();
private NautHashMap<Block, Material> _kitBlocks = new NautHashMap<Block, Material>();
@ -1337,6 +1335,7 @@ public class GameLobbyManager implements Listener
//Cosmetic Menu
Manager.getCosmeticManager().giveInterfaceItem(player);
Manager.getBoosterManager().giveInterfaceItem(player);
}
}