adding spectator rotation.

This commit is contained in:
Sarah 2016-01-25 04:30:42 +01:00
parent 00f01e09af
commit 9e63c9000a
2 changed files with 108 additions and 5 deletions

View File

@ -5,9 +5,11 @@ import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilTextBottom;
import mineplex.core.shop.item.IButton;
import nautilus.game.arcade.ArcadeManager;
@ -47,6 +49,7 @@ public class SpectatorButton implements IButton
{
_player.setGameMode(GameMode.SPECTATOR);
_player.setSpectatorTarget(_target);
UtilTextBottom.display(C.cYellow + "You are spectating " + F.game(_target.getName()), player);
UtilPlayer.message(_player, F.main("Game", "Sneak to stop spectating"));
}
}, 3);

View File

@ -1,24 +1,33 @@
package nautilus.game.arcade.managers;
import java.util.List;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilRadar;
import mineplex.core.common.util.UtilServer;
import mineplex.core.disguise.PlayerDisguiseManager;
import mineplex.core.common.util.UtilTextBottom;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.game.Game.GameState;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerToggleSneakEvent;
import org.bukkit.event.vehicle.VehicleDamageEvent;
import org.bukkit.inventory.ItemStack;
public class GameSpectatorManager implements Listener
{
@ -31,7 +40,7 @@ public class GameSpectatorManager implements Listener
Manager.getPluginManager().registerEvents(this, Manager.getPlugin());
}
@EventHandler(priority = EventPriority.LOW)
@EventHandler(priority = EventPriority.LOW, ignoreCancelled=true)
public void interactCancel(PlayerInteractEvent event)
{
if (Manager.GetGame() == null)
@ -41,6 +50,46 @@ public class GameSpectatorManager implements Listener
if (!Manager.GetGame().IsAlive(player))
event.setCancelled(true);
if(!Manager.GetGame().AllowEntitySpectate)
return;
if(!Manager.GetGame().IsLive())
return;
if(player.getGameMode() != GameMode.SPECTATOR)
return;
if(player.getSpectatorTarget() == null)
return;
if(!(player.getSpectatorTarget() instanceof Player))
return;
List<Player> players = Manager.GetGame().GetPlayers(true);
int currentPlayer = 0;
for(Player otherPlayer : players)
{
currentPlayer++;
if(((Player) player.getSpectatorTarget()) == otherPlayer)
break;
}
if(event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK)
currentPlayer = currentPlayer - 2;
if(currentPlayer < 0)
currentPlayer = players.size() - 1;
if(currentPlayer >= players.size())
currentPlayer = 0;
if(players.get(currentPlayer) == null)
return;
Player specPlayer = players.get(currentPlayer);
setSpectating(player, specPlayer);
}
@EventHandler(priority = EventPriority.LOW)
@ -66,9 +115,14 @@ public class GameSpectatorManager implements Listener
{
if(Manager.GetGame().AllowEntitySpectate)
{
player.setGameMode(GameMode.SPECTATOR);
player.setSpectatorTarget(event.getRightClicked());
UtilPlayer.message(player, F.main("Game", "Sneak to stop spectating"));
setSpectating(player, event.getRightClicked());
// player.setGameMode(GameMode.SPECTATOR);
// player.setSpectatorTarget(event.getRightClicked());
// UtilPlayer.message(player, F.main("Game", "Sneak to stop spectating"));
// if(event.getRightClicked() instanceof Player)
// {
// UtilTextBottom.display(C.cYellow + "You are spectating " + F.game(((Player) event.getRightClicked()).getName()), player);
// }
}
}
}
@ -97,6 +151,10 @@ public class GameSpectatorManager implements Listener
{
player.setGameMode(GameMode.SURVIVAL);
player.setAllowFlight(true);
for(int i = 1; i <= 7; i++)
{
player.getInventory().setItem(i, null);
}
}
}
}
@ -123,8 +181,17 @@ public class GameSpectatorManager implements Listener
{
if(player.getSpectatorTarget() == event.getEntity())
{
if(Manager.GetGame().GetPlayers(true).size() >= 1)
{
setSpectating(player, Manager.GetGame().GetPlayers(true).get(UtilMath.r(Manager.GetGame().GetPlayers(true).size())));
return;
}
player.setGameMode(GameMode.SURVIVAL);
player.setAllowFlight(true);
for(int i = 1; i <= 7; i++)
{
player.getInventory().setItem(i, null);
}
}
}
}
@ -149,12 +216,45 @@ public class GameSpectatorManager implements Listener
{
event.getPlayer().setGameMode(GameMode.SURVIVAL);
event.getPlayer().setAllowFlight(true);
for(int i = 1; i <= 7; i++)
{
event.getPlayer().getInventory().setItem(i, null);
}
}
}
}
}
}
private void setSpectating(Player player, Entity target)
{
player.setGameMode(GameMode.SURVIVAL);
player.teleport(target.getLocation().add(0, 1, 0));
player.getInventory().setHeldItemSlot(5);
for(int i = 1; i <= 7; i++)
{
player.getInventory().setItem(i, new ItemStack(Material.STONE));
}
Manager.runSyncLater(new Runnable()
{
@Override
public void run()
{
if(target instanceof Player)
{
if(!Manager.GetGame().IsAlive(target))
return;
}
player.setGameMode(GameMode.SPECTATOR);
player.setSpectatorTarget(target);
if(target instanceof Player)
UtilTextBottom.display(C.cYellow + "You are spectating " + F.game(((Player) target).getName()), player);
UtilPlayer.message(player, F.main("Game", "Sneak to stop spectating"));
}
}, 3);
}
@EventHandler(priority = EventPriority.LOW)
public void vehicleDamage(VehicleDamageEvent event)
{