adding entity spectating by right clicking and right clicking head in compass menu.

This commit is contained in:
Sarah 2016-01-24 20:00:05 +01:00
parent 5ed9295944
commit 00f01e09af
3 changed files with 125 additions and 1 deletions

View File

@ -311,6 +311,8 @@ public abstract class Game implements Listener
public boolean EnableTutorials = false;
public boolean FixSpawnFacing = true;
public boolean AllowEntitySpectate = true;
private IPacketHandler _useEntityPacketHandler;
private int _deadBodyCount;

View File

@ -1,10 +1,13 @@
package nautilus.game.arcade.gui.spectatorMenu.button;
import org.bukkit.GameMode;
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.F;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.shop.item.IButton;
import nautilus.game.arcade.ArcadeManager;
@ -33,7 +36,25 @@ public class SpectatorButton implements IButton
if (_arcadeManager.IsAlive(_target))
{
_player.teleport(_target.getLocation().add(0, 1, 0));
if(clickType == ClickType.RIGHT)
{
_player.closeInventory();
_player.teleport(_target.getLocation().add(0, 1, 0));
_arcadeManager.runSyncLater(new Runnable()
{
@Override
public void run()
{
_player.setGameMode(GameMode.SPECTATOR);
_player.setSpectatorTarget(_target);
UtilPlayer.message(_player, F.main("Game", "Sneak to stop spectating"));
}
}, 3);
}
else
{
_player.teleport(_target.getLocation().add(0, 1, 0));
}
}
else
{

View File

@ -1,14 +1,23 @@
package nautilus.game.arcade.managers;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.disguise.PlayerDisguiseManager;
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.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
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;
public class GameSpectatorManager implements Listener
@ -51,7 +60,99 @@ public class GameSpectatorManager implements Listener
}
if (!Manager.GetGame().IsAlive(player))
{
event.setCancelled(true);
if(Manager.GetGame().IsLive())
{
if(Manager.GetGame().AllowEntitySpectate)
{
player.setGameMode(GameMode.SPECTATOR);
player.setSpectatorTarget(event.getRightClicked());
UtilPlayer.message(player, F.main("Game", "Sneak to stop spectating"));
}
}
}
}
@EventHandler
public void updateSpecEntitys(UpdateEvent event)
{
if(event.getType() != UpdateType.FASTER)
return;
if(Manager.GetGame() == null)
return;
if(Manager.GetGame().IsLive() || Manager.GetGame().GetState() == GameState.End)
{
if(Manager.GetGame().AllowEntitySpectate)
{
for(Player player : UtilServer.getPlayers())
{
if (!Manager.GetGame().IsAlive(player))
{
if(player.getGameMode() == GameMode.SPECTATOR)
{
if(player.getSpectatorTarget() == null)
{
player.setGameMode(GameMode.SURVIVAL);
player.setAllowFlight(true);
}
}
}
}
}
}
}
@EventHandler(priority = EventPriority.LOW)
public void spectatedEntityDeath(PlayerDeathEvent event)
{
if(Manager.GetGame() == null)
return;
if(Manager.GetGame().IsLive() || Manager.GetGame().GetState() == GameState.End)
{
if(Manager.GetGame().AllowEntitySpectate)
{
for(Player player : UtilServer.getPlayers())
{
if (!Manager.GetGame().IsAlive(player))
{
if(player.getGameMode() == GameMode.SPECTATOR)
{
if(player.getSpectatorTarget() == event.getEntity())
{
player.setGameMode(GameMode.SURVIVAL);
player.setAllowFlight(true);
}
}
}
}
}
}
}
@EventHandler(priority = EventPriority.LOW)
public void dismountEntity(PlayerToggleSneakEvent event)
{
if(Manager.GetGame() == null)
return;
if(Manager.GetGame().IsLive() || Manager.GetGame().GetState() == GameState.End)
{
if(Manager.GetGame().AllowEntitySpectate)
{
if(!Manager.GetGame().IsAlive(event.getPlayer()))
{
if(event.getPlayer().getGameMode() == GameMode.SPECTATOR)
{
event.getPlayer().setGameMode(GameMode.SURVIVAL);
event.getPlayer().setAllowFlight(true);
}
}
}
}
}
@EventHandler(priority = EventPriority.LOW)