Update booster page, proper booster rewards
This commit is contained in:
parent
42c35063b3
commit
2421fd1cfe
@ -9,15 +9,24 @@ import mineplex.core.boosters.event.BoosterUpdateEvent;
|
|||||||
import mineplex.core.boosters.gui.BoosterShop;
|
import mineplex.core.boosters.gui.BoosterShop;
|
||||||
import mineplex.core.boosters.redis.BoosterUpdateRepository;
|
import mineplex.core.boosters.redis.BoosterUpdateRepository;
|
||||||
import mineplex.core.boosters.tips.BoosterTipManager;
|
import mineplex.core.boosters.tips.BoosterTipManager;
|
||||||
|
import mineplex.core.common.util.C;
|
||||||
import mineplex.core.common.util.Callback;
|
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.donation.DonationManager;
|
||||||
import mineplex.core.inventory.InventoryManager;
|
import mineplex.core.inventory.InventoryManager;
|
||||||
|
import mineplex.core.itemstack.ItemStackFactory;
|
||||||
import mineplex.core.updater.UpdateType;
|
import mineplex.core.updater.UpdateType;
|
||||||
import mineplex.core.updater.event.UpdateEvent;
|
import mineplex.core.updater.event.UpdateEvent;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.EventHandler;
|
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 org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -29,6 +38,10 @@ import java.util.*;
|
|||||||
*/
|
*/
|
||||||
public class BoosterManager extends MiniPlugin
|
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 BoosterRepository _repository;
|
||||||
private CoreClientManager _clientManager;
|
private CoreClientManager _clientManager;
|
||||||
private DonationManager _donationManager;
|
private DonationManager _donationManager;
|
||||||
@ -38,6 +51,8 @@ public class BoosterManager extends MiniPlugin
|
|||||||
private BoosterShop _shop;
|
private BoosterShop _shop;
|
||||||
private String _boosterGroup;
|
private String _boosterGroup;
|
||||||
|
|
||||||
|
private boolean _giveInterfaceItem;
|
||||||
|
|
||||||
private long _cacheLastUpdated;
|
private long _cacheLastUpdated;
|
||||||
private Map<String, List<Booster>> _boosterCache = new HashMap<>();
|
private Map<String, List<Booster>> _boosterCache = new HashMap<>();
|
||||||
|
|
||||||
@ -64,6 +79,8 @@ public class BoosterManager extends MiniPlugin
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_giveInterfaceItem = canActivateBoosters();
|
||||||
|
|
||||||
new BoosterUpdateRepository(plugin);
|
new BoosterUpdateRepository(plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -181,6 +198,11 @@ public class BoosterManager extends MiniPlugin
|
|||||||
return time;
|
return time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Booster getActiveBooster()
|
||||||
|
{
|
||||||
|
return getActiveBoosterFromCache(_boosterGroup);
|
||||||
|
}
|
||||||
|
|
||||||
public Booster getActiveBoosterFromCache(String boosterGroup)
|
public Booster getActiveBoosterFromCache(String boosterGroup)
|
||||||
{
|
{
|
||||||
List<Booster> boosters = _boosterCache.get(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)
|
public void activateBooster(String serverGroup, Player player, Callback<BoosterApiResponse> callback)
|
||||||
{
|
{
|
||||||
String playerName = player.getName();
|
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)
|
public void openShop(Player player)
|
||||||
{
|
{
|
||||||
_shop.attemptShopOpen(player);
|
_shop.attemptShopOpen(player);
|
||||||
@ -247,7 +279,7 @@ public class BoosterManager extends MiniPlugin
|
|||||||
*/
|
*/
|
||||||
public int getAvailableBoosterCount(Player player)
|
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;
|
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
|
public static void main(String[] args) throws IOException, URISyntaxException, InterruptedException
|
||||||
{
|
{
|
||||||
BoosterRepository repository = new BoosterRepository();
|
BoosterRepository repository = new BoosterRepository();
|
||||||
|
@ -4,6 +4,7 @@ import mineplex.core.boosters.BoosterApiResponse;
|
|||||||
import mineplex.core.boosters.BoosterManager;
|
import mineplex.core.boosters.BoosterManager;
|
||||||
import mineplex.core.common.util.C;
|
import mineplex.core.common.util.C;
|
||||||
import mineplex.core.common.util.Callback;
|
import mineplex.core.common.util.Callback;
|
||||||
|
import mineplex.core.common.util.F;
|
||||||
import mineplex.core.common.util.UtilTime;
|
import mineplex.core.common.util.UtilTime;
|
||||||
import mineplex.core.shop.item.IButton;
|
import mineplex.core.shop.item.IButton;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -27,21 +28,26 @@ public class ActivateBoosterButton implements IButton
|
|||||||
public void onClick(Player player, ClickType clickType)
|
public void onClick(Player player, ClickType clickType)
|
||||||
{
|
{
|
||||||
player.closeInventory();
|
player.closeInventory();
|
||||||
_boosterManager.activateBooster("Testing", player, new Callback<BoosterApiResponse>()
|
|
||||||
{
|
_boosterManager.chargeBooster(player, data -> {
|
||||||
@Override
|
if (data)
|
||||||
public void run(BoosterApiResponse response)
|
|
||||||
{
|
{
|
||||||
if (response.isSuccess())
|
_boosterManager.activateBooster(player, response -> {
|
||||||
{
|
if (response.isSuccess())
|
||||||
long timeToStart = response.getStartTime().getTime() - System.currentTimeMillis();
|
{
|
||||||
if (timeToStart <= 0) player.sendMessage(C.cGreen + "Booster activated and enabled now!");
|
long timeToStart = response.getStartTime().getTime() - System.currentTimeMillis();
|
||||||
else player.sendMessage(C.cGreen + "Booster activated. Enabled in " + UtilTime.convertString(timeToStart, 2, UtilTime.TimeUnit.FIT));
|
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
|
}
|
||||||
{
|
else
|
||||||
player.sendMessage(C.cRed + "There was an error trying to enable your booster :(");
|
{
|
||||||
}
|
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!"));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -34,25 +34,41 @@ public class BoosterPage extends ShopPageBase<BoosterManager, BoosterShop>
|
|||||||
|
|
||||||
int count = getPlugin().getAvailableBoosterCount(getPlayer());
|
int count = getPlugin().getAvailableBoosterCount(getPlayer());
|
||||||
lore.add(" ");
|
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)
|
if (getPlugin().canActivateBoosters() && count > 0)
|
||||||
{
|
{
|
||||||
|
List<Booster> boosters = getPlugin().getBoosters();
|
||||||
lore.add(" ");
|
lore.add(" ");
|
||||||
lore.add(C.cWhite + "Click to Activate");
|
|
||||||
|
|
||||||
long waitTime = getPlugin().getBoostTime();
|
long waitTime = getPlugin().getBoostTime();
|
||||||
if (waitTime == 0)
|
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
|
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);
|
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();
|
addActiveBoosters();
|
||||||
}
|
}
|
||||||
@ -70,24 +86,25 @@ public class BoosterPage extends ShopPageBase<BoosterManager, BoosterShop>
|
|||||||
|
|
||||||
int index = 18 + startIndex + i;
|
int index = 18 + startIndex + i;
|
||||||
long timeActivatedDif = System.currentTimeMillis() - booster.getActivationTime().getTime();
|
long timeActivatedDif = System.currentTimeMillis() - booster.getActivationTime().getTime();
|
||||||
|
String activationTime = UtilTime.convertString(timeActivatedDif, 2, UtilTime.TimeUnit.FIT);
|
||||||
|
|
||||||
List<String> lore = new ArrayList<String>();
|
List<String> lore = new ArrayList<String>();
|
||||||
lore.add(" ");
|
|
||||||
if (active)
|
if (active)
|
||||||
{
|
{
|
||||||
lore.add(C.cGreen + "Active");
|
lore.add(C.cWhite + "Active");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
long timeToActive = booster.getStartTime().getTime() - System.currentTimeMillis();
|
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,
|
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);
|
setItem(index, shopItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,10 @@ import mineplex.core.boosters.BoosterManager;
|
|||||||
import mineplex.core.donation.DonationManager;
|
import mineplex.core.donation.DonationManager;
|
||||||
import mineplex.core.shop.ShopBase;
|
import mineplex.core.shop.ShopBase;
|
||||||
import mineplex.core.shop.page.ShopPageBase;
|
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.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Shaun Bennett
|
* @author Shaun Bennett
|
||||||
@ -22,4 +25,13 @@ public class BoosterShop extends ShopBase<BoosterManager>
|
|||||||
{
|
{
|
||||||
return new BoosterPage(getPlugin(), this, getClientManager(), getDonationManager(), player);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -194,6 +194,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation
|
|||||||
private Punish _punishmentManager;
|
private Punish _punishmentManager;
|
||||||
private BrandingManager _brandingManager;
|
private BrandingManager _brandingManager;
|
||||||
private BonusManager _bonusManager;
|
private BonusManager _bonusManager;
|
||||||
|
private BoosterManager _boosterManager;
|
||||||
|
|
||||||
private IncognitoManager _incognitoManager;
|
private IncognitoManager _incognitoManager;
|
||||||
|
|
||||||
@ -246,6 +247,8 @@ public class ArcadeManager extends MiniPlugin implements IRelation
|
|||||||
|
|
||||||
_brandingManager = new BrandingManager(plugin);
|
_brandingManager = new BrandingManager(plugin);
|
||||||
|
|
||||||
|
_boosterManager = boosterManager;
|
||||||
|
|
||||||
//Dont see a reason to ever just use the normal one
|
//Dont see a reason to ever just use the normal one
|
||||||
// if (serverConfig.GameList.contains(GameType.ChampionsDominate)
|
// if (serverConfig.GameList.contains(GameType.ChampionsDominate)
|
||||||
// || serverConfig.GameList.contains(GameType.ChampionsTDM)
|
// || serverConfig.GameList.contains(GameType.ChampionsTDM)
|
||||||
@ -1452,6 +1455,11 @@ public class ArcadeManager extends MiniPlugin implements IRelation
|
|||||||
return _youtube.contains(player);
|
return _youtube.contains(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BoosterManager getBoosterManager()
|
||||||
|
{
|
||||||
|
return _boosterManager;
|
||||||
|
}
|
||||||
|
|
||||||
public void toggleUnlockKits(Player caller)
|
public void toggleUnlockKits(Player caller)
|
||||||
{
|
{
|
||||||
if (_youtube.remove(caller))
|
if (_youtube.remove(caller))
|
||||||
|
@ -180,10 +180,11 @@ public class GameGemManager implements Listener
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Gem Boooster
|
//Gem Boooster
|
||||||
/*
|
Booster booster = Manager.getBoosterManager().getActiveBooster();
|
||||||
if (game.GemBoosterEnabled && game.getGemBooster() != null)
|
if (game.GemBoosterEnabled && booster != null)
|
||||||
total += (int)(earned * game.getGemBooster().getMultiplier());
|
{
|
||||||
*/
|
total *= booster.getMultiplier();
|
||||||
|
}
|
||||||
|
|
||||||
int shards = total;
|
int shards = total;
|
||||||
|
|
||||||
@ -309,16 +310,15 @@ public class GameGemManager implements Listener
|
|||||||
int totalGems = earnedGems;
|
int totalGems = earnedGems;
|
||||||
|
|
||||||
//Gem Booster
|
//Gem Booster
|
||||||
/*
|
Booster booster = Manager.getBoosterManager().getActiveBooster();
|
||||||
Booster gemBooster = game.getGemBooster();
|
if (game.GemBoosterEnabled && booster != null)
|
||||||
if (game.GemBoosterEnabled && gemBooster != null)
|
|
||||||
{
|
{
|
||||||
UtilPlayer.message(player, F.elem(C.cGreen + "+" + (int) (earnedGems * gemBooster.getMultiplier()) + " Gems") + " for gem booster from "
|
int addedGems = (int) (earnedGems * booster.getMultiplier()) - earnedGems;
|
||||||
+ F.name(gemBooster.getPlayerName()));
|
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;
|
int shards = totalGems;
|
||||||
|
|
||||||
|
@ -86,8 +86,6 @@ public class GameLobbyManager implements Listener
|
|||||||
|
|
||||||
private Location spawn;
|
private Location spawn;
|
||||||
|
|
||||||
private Location _boosterLocation;
|
|
||||||
|
|
||||||
private NautHashMap<Entity, LobbyEnt> _kits = new NautHashMap<Entity, LobbyEnt>();
|
private NautHashMap<Entity, LobbyEnt> _kits = new NautHashMap<Entity, LobbyEnt>();
|
||||||
private NautHashMap<Block, Material> _kitBlocks = new NautHashMap<Block, Material>();
|
private NautHashMap<Block, Material> _kitBlocks = new NautHashMap<Block, Material>();
|
||||||
|
|
||||||
@ -1337,6 +1335,7 @@ public class GameLobbyManager implements Listener
|
|||||||
|
|
||||||
//Cosmetic Menu
|
//Cosmetic Menu
|
||||||
Manager.getCosmeticManager().giveInterfaceItem(player);
|
Manager.getCosmeticManager().giveInterfaceItem(player);
|
||||||
|
Manager.getBoosterManager().giveInterfaceItem(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user