Fix gadgets inside the glads arena

This commit is contained in:
Sam 2018-04-19 22:23:07 +01:00 committed by Alexander Meech
parent b91c63e361
commit 317c2ac08e
5 changed files with 6 additions and 198 deletions

View File

@ -16,7 +16,6 @@ import mineplex.core.lifetimes.PhasedLifetime;
import mineplex.core.newnpc.NPC; import mineplex.core.newnpc.NPC;
import mineplex.hub.hubgame.CycledGame.GameState; import mineplex.hub.hubgame.CycledGame.GameState;
import mineplex.hub.hubgame.common.HubGameComponent; import mineplex.hub.hubgame.common.HubGameComponent;
import mineplex.hub.hubgame.ui.HubGamePage;
import mineplex.hub.world.WorldDataModule; import mineplex.hub.world.WorldDataModule;
public abstract class HubGame extends PhasedLifetime<GameState> implements Listener public abstract class HubGame extends PhasedLifetime<GameState> implements Listener
@ -95,9 +94,4 @@ public abstract class HubGame extends PhasedLifetime<GameState> implements Liste
{ {
getAlivePlayers().forEach(player -> player.sendMessage(F.main(getManager().getName(), message))); getAlivePlayers().forEach(player -> player.sendMessage(F.main(getManager().getName(), message)));
} }
public HubGamePage getInformationPage(Player player)
{
return new HubGamePage<>(getManager(), getManager().getShop(), getManager().getClientManager(), getManager().getDonationManager(), player, this);
}
} }

View File

@ -28,6 +28,7 @@ import mineplex.core.gadget.types.GadgetType;
import mineplex.core.newnpc.NPC; import mineplex.core.newnpc.NPC;
import mineplex.core.newnpc.NewNPCManager; import mineplex.core.newnpc.NewNPCManager;
import mineplex.core.newnpc.event.NPCInteractEvent; import mineplex.core.newnpc.event.NPCInteractEvent;
import mineplex.core.recharge.Recharge;
import mineplex.core.updater.UpdateType; import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent; import mineplex.core.updater.event.UpdateEvent;
import mineplex.hub.HubManager; import mineplex.hub.HubManager;
@ -72,7 +73,7 @@ public class HubGameManager extends MiniPlugin
_hubManager = require(HubManager.class); _hubManager = require(HubManager.class);
_hotbarManager = require(HubPlayerManager.class); _hotbarManager = require(HubPlayerManager.class);
_npcManager = require(NewNPCManager.class); _npcManager = require(NewNPCManager.class);
WorldDataModule worldData = require(WorldDataModule.class); WorldDataModule worldData = require(WorldDataModule.class);
_shop = new HubGameShop(this, _clientManager, _donationManager); _shop = new HubGameShop(this, _clientManager, _donationManager);
_games = new ArrayList<>(); _games = new ArrayList<>();
@ -101,7 +102,7 @@ public class HubGameManager extends MiniPlugin
@EventHandler @EventHandler
public void npcInteract(NPCInteractEvent event) public void npcInteract(NPCInteractEvent event)
{ {
if (event.isCancelled()) if (event.isCancelled() || !Recharge.Instance.use(event.getPlayer(), "Hub Game NPC Interact", 1000, false, false))
{ {
return; return;
} }
@ -122,37 +123,20 @@ public class HubGameManager extends MiniPlugin
CycledGame cycledGame = (CycledGame) game; CycledGame cycledGame = (CycledGame) game;
List<Player> queuedPlayers = cycledGame.getQueuedPlayers(); List<Player> queuedPlayers = cycledGame.getQueuedPlayers();
if (event.isLeftClick()) if (queuedPlayers.contains(player))
{ {
if (queuedPlayers.contains(player)) leaveQueue(cycledGame, player, false);
{
leaveQueue(cycledGame, player, false);
}
else
{
joinQueue(cycledGame, player);
}
} }
else else
{ {
showInformationPage(game, player); joinQueue(cycledGame, player);
} }
} }
else
{
showInformationPage(game, player);
}
return; return;
} }
} }
@SuppressWarnings("unchecked")
private void showInformationPage(HubGame game, Player player)
{
_shop.openPageForPlayer(player, game.getInformationPage(player));
}
private void disableGadgets(Player player, GadgetType type) private void disableGadgets(Player player, GadgetType type)
{ {
_gadgetManager.getGadgets(type).forEach(gadget -> gadget.disable(player)); _gadgetManager.getGadgets(type).forEach(gadget -> gadget.disable(player));

View File

@ -136,10 +136,4 @@ public class Duels extends CycledGame
event.setCancelled(true); event.setCancelled(true);
} }
} }
// @Override
// public HubGamePage getInformationPage(Player player)
// {
// return new DuelsUI(getManager(), getManager().getShop(), getManager().getClientManager(), getManager().getDonationManager(), player, this);
// }
} }

View File

@ -1,87 +0,0 @@
package mineplex.hub.hubgame.duel;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilTime;
import mineplex.core.donation.DonationManager;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.hub.hubgame.HubGameManager;
import mineplex.hub.hubgame.common.damage.PVPTrackerComponent;
import mineplex.hub.hubgame.common.damage.PVPTrackerComponent.Match;
import mineplex.hub.hubgame.ui.HubGamePage;
import mineplex.hub.hubgame.ui.HubGameShop;
public class DuelsUI extends HubGamePage<Duels>
{
private static final ItemStack NO_MATCH = new ItemBuilder(Material.STAINED_GLASS_PANE, (byte) 14)
.setTitle(C.cRed + "No match info")
.build();
private static final ItemStack EDIT_KIT = new ItemBuilder(Material.ANVIL)
.setTitle(C.cGreen + "Edit Kit")
.addLore("", "You can edit the order items are", "given to you in the game.", "", C.cRed + "Coming Soon")
.build();
public DuelsUI(HubGameManager plugin, HubGameShop shop, CoreClientManager clientManager, DonationManager donationManager, Player player, Duels game)
{
super(plugin, shop, clientManager, donationManager, player, game, 45);
}
@Override
protected void buildPage()
{
super.buildPage();
PVPTrackerComponent tracker = _game.getComponent(PVPTrackerComponent.class);
int slot = 20;
int index = 0;
for (Match match : tracker.getMatches())
{
index++;
addButton(slot++, getMatchItem(match, getPlayer()), (player, clickType) ->
{
tracker.sendMatch(player, match);
player.closeInventory();
});
}
for (; index < 5; index++)
{
addButtonNoAction(slot++, NO_MATCH);
}
addButtonNoAction(31, EDIT_KIT);
}
private ItemStack getMatchItem(Match match, Player player)
{
Player[] players = match.getPlayers();
boolean playerGame = false;
for (Player other : players)
{
// Player may relog, thus player objects won't be the same
if (other.getUniqueId().equals(player.getUniqueId()))
{
playerGame = true;
break;
}
}
return new ItemBuilder(Material.IRON_SWORD)
.setTitle(C.cGreen + players[0].getName() + C.cWhiteB + " v " + C.cGreen + players[1].getName())
.addLore(
"",
C.cWhite + "Match Time: " + C.mTime + UtilTime.MakeStr(System.currentTimeMillis() - match.getStart()) + C.cWhite + " ago.",
"",
C.cGreen + "Click to find out more information about this match"
)
.setGlow(playerGame)
.build();
}
}

View File

@ -1,77 +0,0 @@
package mineplex.hub.hubgame.ui;
import java.util.List;
import org.bukkit.entity.Player;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.util.C;
import mineplex.core.donation.DonationManager;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.shop.page.ShopPageBase;
import mineplex.hub.hubgame.CycledGame;
import mineplex.hub.hubgame.HubGame;
import mineplex.hub.hubgame.HubGameManager;
import mineplex.hub.hubgame.HubGameType;
public class HubGamePage<T extends HubGame> extends ShopPageBase<HubGameManager, HubGameShop>
{
protected final T _game;
public HubGamePage(HubGameManager plugin, HubGameShop shop, CoreClientManager clientManager, DonationManager donationManager, Player player, T game)
{
this(plugin, shop, clientManager, donationManager, player, game, 27);
}
public HubGamePage(HubGameManager plugin, HubGameShop shop, CoreClientManager clientManager, DonationManager donationManager, Player player, T game, int slots)
{
super(plugin, shop, clientManager, donationManager, game.getGameType().getName(), player, slots);
_game = game;
buildPage();
}
@Override
protected void buildPage()
{
HubGameType gameType = _game.getGameType();
ItemBuilder builder = new ItemBuilder(gameType.getItemStack());
builder.setTitle(C.cYellow + gameType.getName());
builder.addLore("");
builder.addLore(gameType.getDescription());
builder.addLore("", "Alive Players: " + C.cYellow + _game.getAlivePlayers().size());
if (_game instanceof CycledGame)
{
List<Player> queue = ((CycledGame) _game).getQueuedPlayers();
int index = queue.indexOf(getPlayer());
builder.addLore("", "Queue Position: " + C.cYellow + (index == -1 ? "Not in queue" : (index + 1) + C.cGray + "/" + C.cYellow + queue.size()));
builder.addLore("", C.cGreen + (index == -1 ? "Click to join the queue." : "Click to leave the queue."));
}
addButton(13, builder.build(), (player, clickType) ->
{
if (_game instanceof CycledGame)
{
CycledGame game = (CycledGame) _game;
List<Player> queue = game.getQueuedPlayers();
int index = queue.indexOf(getPlayer());
if (index == -1)
{
_game.getManager().joinQueue(game, player);
}
else
{
_game.getManager().leaveQueue(game, player, false);
}
player.closeInventory();
}
});
}
}