Merging spectator gui with main branch

This commit is contained in:
Shaun Bennett 2014-11-13 16:03:14 -06:00
parent c5a873ffab
commit 8b73b89a17
8 changed files with 304 additions and 10 deletions

View File

@ -0,0 +1,69 @@
package mineplex.core.common.util;
import org.bukkit.ChatColor;
/**
* Created by Shaun on 11/12/2014.
*/
public class UtilColor
{
public static byte chatColorToClayData(ChatColor chatColor)
{
//TODO
return 1;
}
public static byte chatColorToWoolData(ChatColor chatColor)
{
switch (chatColor)
{
// 0: white
// 1: orange
// 2: magenta
// 3: light blue
// 4: yellow
// 5: lime
// 6: pink
// 7: gray
// 8: light gray
// 9: cyan
// 10: purple
// 11: blue
// 12: brown
// 13: green
// 14: red
// 15: black
case BLACK:
return 1;
case DARK_BLUE:
return 11;
case DARK_GREEN:
return 13;
case DARK_AQUA:
return 9;
case DARK_PURPLE:
return 10;
case GOLD:
return 1;
case GRAY:
return 8;
case DARK_GRAY:
return 7;
case BLUE:
return 11;
case GREEN:
return 5;
case AQUA:
return 3;
case RED:
return 14;
case LIGHT_PURPLE:
return 2;
case YELLOW:
return 4;
default:
return 0;
}
}
}

View File

@ -6,6 +6,8 @@ import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.Action;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
@ -28,16 +30,21 @@ import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.game.GameTeam;
import nautilus.game.arcade.gui.SpectatorShop;
public class CompassAddon extends MiniPlugin
{
public ArcadeManager Manager;
private SpectatorShop _spectatorShop;
public CompassAddon(JavaPlugin plugin, ArcadeManager manager)
{
super("Compass Addon", plugin);
Manager = manager;
_spectatorShop = new SpectatorShop(this, manager, manager.GetClients(), manager.GetDonation());
}
@EventHandler
@ -179,6 +186,7 @@ public class CompassAddon extends MiniPlugin
@EventHandler
public void SpectatorTeleport(PlayerInteractEvent event)
{
System.out.println("interact event");
if (Manager.GetGame() == null)
return;
@ -192,12 +200,29 @@ public class CompassAddon extends MiniPlugin
event.setCancelled(true);
if (!Recharge.Instance.use(player, "Spectate", 5000, true, false))
if (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK || !Manager.GetGame().CompassSpectatorMenu)
{
return;
}
// Teleport to nearest player when you left click compass
GameTeam team = Manager.GetGame().GetTeam(player);
System.out.println("a");
if (!Recharge.Instance.use(player, "Spectate", 5000, true, false))
{
return;
}
spectateNearestPlayer(player);
}
else
{
// Right click - open spectator menu
_spectatorShop.attemptShopOpen(player);
}
}
private void spectateNearestPlayer(Player spectator)
{
GameTeam team = Manager.GetGame().GetTeam(spectator);
Player target = null;
double bestDist = 0;
@ -207,10 +232,10 @@ public class CompassAddon extends MiniPlugin
GameTeam otherTeam = Manager.GetGame().GetTeam(other);
//Same Team (Not Solo Game) && Alive
if (Manager.GetGame().GetTeamList().size() > 1 && (team != null && team.equals(otherTeam)) && Manager.GetGame().IsAlive(player))
if (Manager.GetGame().GetTeamList().size() > 1 && (team != null && team.equals(otherTeam)) && Manager.GetGame().IsAlive(spectator))
continue;
double dist = UtilMath.offset(player, other);
double dist = UtilMath.offset(spectator, other);
if (target == null || dist < bestDist)
{
@ -221,7 +246,26 @@ public class CompassAddon extends MiniPlugin
if (target != null)
{
player.teleport(target.getLocation().add(0, 1, 0));
spectator.teleport(target.getLocation().add(0, 1, 0));
}
}
@EventHandler
public void updateShop(UpdateEvent event)
{
if (event.getType() != UpdateType.SEC)
return;
_spectatorShop.update();
}
// This prevents other modules from cancelling clicks in
@EventHandler(priority = EventPriority.HIGH)
public void onInventoryClick(InventoryClickEvent event)
{
if (event.getWhoClicked().getGameMode() == GameMode.CREATIVE && event.getClickedInventory().getTitle().equals("Spectate Menu"))
{
event.setCancelled(false);
}
}
}

View File

@ -56,6 +56,7 @@ import nautilus.game.arcade.world.WorldData;
public abstract class Game implements Listener
{
public long getGameLiveTime()
{
return _gameLiveTime;
@ -209,6 +210,7 @@ public abstract class Game implements Listener
//Addons
public boolean CompassEnabled = false;
public boolean CompassGiveItem = true;
public boolean CompassSpectatorMenu = true;
public boolean SoupEnabled = true;
public boolean TeamArmor = false;

View File

@ -0,0 +1,41 @@
package nautilus.game.arcade.gui;
import org.bukkit.entity.Player;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.CurrencyType;
import mineplex.core.donation.DonationManager;
import mineplex.core.shop.ShopBase;
import mineplex.core.shop.page.ShopPageBase;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.addons.CompassAddon;
import nautilus.game.arcade.gui.page.SpectatorPage;
/**
* Created by shaun on 14-09-24.
*/
public class SpectatorShop extends ShopBase<CompassAddon>
{
private ArcadeManager _arcadeManager;
public SpectatorShop(CompassAddon plugin, ArcadeManager arcadeManager, CoreClientManager clientManager, DonationManager donationManager, CurrencyType... currencyTypes)
{
super(plugin, clientManager, donationManager, "Spectate Menu", currencyTypes);
_arcadeManager = arcadeManager;
}
@Override
protected ShopPageBase<CompassAddon, ? extends ShopBase<CompassAddon>> BuildPagesFor(Player player)
{
return new SpectatorPage(Plugin, _arcadeManager, this, ClientManager, DonationManager, player);
}
public void update()
{
for (ShopPageBase<CompassAddon, ? extends ShopBase<CompassAddon>> shopPage : PlayerPageMap.values())
{
shopPage.Refresh();
}
}
}

View File

@ -0,0 +1,39 @@
package nautilus.game.arcade.gui.button;
import org.bukkit.entity.Player;
import mineplex.core.common.util.F;
import mineplex.core.shop.item.SingleButton;
import nautilus.game.arcade.ArcadeManager;
/**
* Created by shaun on 14-09-26.
*/
public class SpectatorButton extends SingleButton
{
private ArcadeManager _arcadeManager;
private Player _player;
private Player _target;
public SpectatorButton(ArcadeManager arcadeManager, Player player, Player target)
{
_arcadeManager = arcadeManager;
_player = player;
_target = target;
}
@Override
public void Clicked(Player player)
{
if (_arcadeManager.IsAlive(_target))
{
_player.teleport(_target.getLocation());
_player.sendMessage("Teleported to " + _target);
}
else
{
_player.sendMessage(F.main("Spectate", F.name(_target.getName()) + " is no longer alive."));
}
System.out.println("click");
// player.closeInventory();
}
}

View File

@ -0,0 +1,88 @@
package nautilus.game.arcade.gui.page;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilColor;
import mineplex.core.common.util.UtilMath;
import mineplex.core.donation.DonationManager;
import mineplex.core.shop.item.ShopItem;
import mineplex.core.shop.page.ShopPageBase;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.addons.CompassAddon;
import nautilus.game.arcade.game.GameTeam;
import nautilus.game.arcade.gui.SpectatorShop;
import nautilus.game.arcade.gui.button.SpectatorButton;
/**
* Created by shaun on 14-09-24.
*/
public class SpectatorPage extends ShopPageBase<CompassAddon, SpectatorShop>
{
private ArcadeManager _arcadeManager;
public SpectatorPage(CompassAddon plugin, ArcadeManager arcadeManager, SpectatorShop shop, CoreClientManager clientManager, DonationManager donationManager, Player player)
{
super(plugin, shop, clientManager, donationManager, "Spectator Menu", player);
_arcadeManager = arcadeManager;
BuildPage();
}
@Override
protected void BuildPage()
{
HashMap<GameTeam, ArrayList<Player>> teamPlayerMap = new HashMap<GameTeam, ArrayList<Player>>();
for (GameTeam team : _arcadeManager.GetGame().GetTeamList())
{
teamPlayerMap.put(team, new ArrayList<Player>());
}
for (Player other : _arcadeManager.GetGame().GetPlayers(true))
{
GameTeam otherTeam = _arcadeManager.GetGame().GetTeam(other);
teamPlayerMap.get(otherTeam).add(other);
}
int currentRow = 0;
for (Map.Entry<GameTeam, ArrayList<Player>> entry : teamPlayerMap.entrySet())
{
GameTeam team = entry.getKey();
ArrayList<Player> teamPlayers = entry.getValue();
int rowsNeeded = (teamPlayers.size() / 8) + 1;
for (int row = 0; row < rowsNeeded; row++)
{
int woolSlot = (row * 9) + (currentRow * 9);
ItemStack woolItem = new ItemStack(Material.WOOL, 1, (short) 0, UtilColor.chatColorToWoolData(team.GetColor()));
setItem(woolSlot, woolItem);
for (int playerIndex = 0; playerIndex < teamPlayers.size() && playerIndex < 9; playerIndex++)
{
int slot = (row * 9) + woolSlot + 1 + playerIndex;
Player other = teamPlayers.get(playerIndex + (row * 9));
double distance = UtilMath.offset(Player, other);
double heightDifference = other.getLocation().getY() - Player.getLocation().getY();
ItemStack item = new ItemStack(Material.SKULL_ITEM, 1, (byte) 3);
ArrayList<String> lore = new ArrayList<String>();
lore.add(" ");
lore.add(ChatColor.RESET + "Kit: " + C.cYellow + _arcadeManager.GetGame().GetKit(other).GetName());
lore.add(ChatColor.RESET + "Distance: " + C.cYellow + UtilMath.trim(1, distance));
lore.add(ChatColor.RESET + "Height Difference: " + C.cYellow + UtilMath.trim(1, heightDifference));
lore.add(" ");
lore.add(ChatColor.RESET + "Click to Spectate");
SkullMeta skullMeta = ((SkullMeta) item.getItemMeta());
skullMeta.setOwner(other.getName());
skullMeta.setDisplayName(team.GetColor() + other.getName());
skullMeta.setLore(lore);
item.setItemMeta(skullMeta);
ShopItem shopItem = new ShopItem(item, other.getName(), other.getName(), 1, false, false);
shopItem.SetLore(lore.toArray(new String[0]));
AddButton(slot, shopItem, new SpectatorButton(_arcadeManager, Player, other));
}
}
currentRow += rowsNeeded;
}
}
}

View File

@ -163,7 +163,7 @@ public class GamePlayerManager implements Listener
if (event.getWhoClicked().getGameMode() == GameMode.CREATIVE)
{
event.setCancelled(true);
event.getWhoClicked().closeInventory();
// event.getWhoClicked().closeInventory();
System.out.println(this.getClass().getName() + " 153");
}
}

View File

@ -81,17 +81,28 @@ public class MiscManager implements Listener
if (player.getGameMode() != GameMode.SURVIVAL && !player.isOp())
{
event.setCancelled(true);
player.closeInventory();
// player.closeInventory();
System.out.println(this.getClass().getName() + " 84");
}
else if (Manager.GetGame().IsLive() && !Manager.GetGame().IsAlive(player) && !((CraftPlayer)player).getHandle().spectating)
{
event.setCancelled(true);
player.closeInventory();
// player.closeInventory();
System.out.println(this.getClass().getName() + " 91");
}
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void InventoryClickClose(InventoryClickEvent event)
{
Player player = UtilPlayer.searchExact(event.getWhoClicked().getName());
if (player == null)
return;
if (event.getClickedInventory().getViewers().contains(player))
player.closeInventory();
}
@EventHandler
public void addClockPrevent(InventoryOpenEvent event)