Flags, change to packets

This commit is contained in:
libraryaddict 2015-09-25 17:15:09 +12:00
parent 5f45e8c1d3
commit 88a48277c0
3 changed files with 133 additions and 103 deletions

View File

@ -259,6 +259,11 @@ public class CaptureTheFlag extends TeamGame
{ {
getArcadeManager().getPacketHandler().removePacketHandler( getArcadeManager().getPacketHandler().removePacketHandler(
_flagItemListener); _flagItemListener);
for (Flag flag : this._flags)
{
flag.gameEnd();
}
} }
} }
@Override @Override

View File

@ -73,8 +73,8 @@ public class Flag
_name = new Hologram(Host.getArcadeManager().getHologramManager(), spawn, team.GetColor() + team.GetName() + "'s Flag".replace("s's", "s'")); _name = new Hologram(Host.getArcadeManager().getHologramManager(), spawn, team.GetColor() + team.GetName() + "'s Flag".replace("s's", "s'"));
_time = new Hologram(Host.getArcadeManager().getHologramManager(), spawn, ""); _time = new Hologram(Host.getArcadeManager().getHologramManager(), spawn, "");
_flagEntity = new FlagEntity(_representation, _spawn, Host.getArcadeManager().GetDisguise()); _flagEntity = new FlagEntity(_representation, _spawn);
SpawnFlag(spawn, team.GetColor() == ChatColor.RED, true); SpawnFlag(spawn, team.GetColor() == ChatColor.RED);
} }
public GameTeam getTeam() public GameTeam getTeam()
@ -157,7 +157,7 @@ public class Flag
_moved = false; _moved = false;
_dropped = false; _dropped = false;
SpawnFlag(_spawn, _team.GetColor() == ChatColor.RED, false); SpawnFlag(_spawn, _team.GetColor() == ChatColor.RED);
AnnounceReturn(); AnnounceReturn();
@ -214,11 +214,9 @@ public class Flag
return ChatColor.RED; return ChatColor.RED;
} }
public void SpawnFlag(Location loc, boolean red, boolean initial) public void SpawnFlag(Location loc, boolean red)
{ {
if (!initial) Host.CreatureAllowOverride = true;
_flagEntity.teleport(loc); _flagEntity.teleport(loc);
if (!initial) Host.CreatureAllowOverride = false;
if (!_moved) if (!_moved)
{ {
@ -307,7 +305,7 @@ public class Flag
{ {
Recharge.Instance.recharge(player, "Flag Pickup"); Recharge.Instance.recharge(player, "Flag Pickup");
Recharge.Instance.use(player, "Flag Pickup", 3000, false, false); Recharge.Instance.use(player, "Flag Pickup", 3000, false, false);
SpawnFlag(player.getLocation(), _team.GetColor() == ChatColor.RED, false); SpawnFlag(player.getLocation(), _team.GetColor() == ChatColor.RED);
AnnounceDrop(player); AnnounceDrop(player);
_holding = null; _holding = null;
_dropped = true; _dropped = true;
@ -350,10 +348,15 @@ public class Flag
_dropped = false; _dropped = false;
_dropTime = 0; _dropTime = 0;
_holding = null; _holding = null;
SpawnFlag(_spawn, _team.GetColor() == ChatColor.RED, false); SpawnFlag(_spawn, _team.GetColor() == ChatColor.RED);
} }
} }
} }
} }
public void gameEnd()
{
_flagEntity.despawn();
}
} }

View File

@ -1,37 +1,40 @@
package nautilus.game.arcade.game.games.common.ctf_data; package nautilus.game.arcade.game.games.common.ctf_data;
import mineplex.core.common.util.UtilEnt; import java.util.ArrayList;
import mineplex.core.common.util.UtilServer; import java.util.Iterator;
import mineplex.core.disguise.DisguiseManager;
import mineplex.core.disguise.disguises.DisguiseArmorStand; import mineplex.core.common.util.UtilPlayer;
import mineplex.minecraft.game.core.damage.CustomDamageEvent; import net.minecraft.server.v1_7_R4.DataWatcher;
import nautilus.game.arcade.GameType; import net.minecraft.server.v1_7_R4.Packet;
import nautilus.game.arcade.events.GameStateChangeEvent; import net.minecraft.server.v1_7_R4.PacketPlayOutEntityDestroy;
import nautilus.game.arcade.game.Game.GameState; import net.minecraft.server.v1_7_R4.PacketPlayOutEntityEquipment;
import net.minecraft.server.v1_7_R4.PacketPlayOutSpawnEntityLiving;
import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.EntityType; import org.bukkit.craftbukkit.v1_7_R4.inventory.CraftItemStack;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;
public class FlagEntity implements Listener public class FlagEntity implements Listener
{ {
private ItemStack _holding; private ItemStack _holding;
private Location _loc; private Location _loc;
private LivingEntity _entity; private int _entityId;
private DisguiseManager _manager; private boolean _display;
private ArrayList<Player> _playersTracking = new ArrayList<Player>();
private Packet[] _spawnPackets = new Packet[2];
private PacketPlayOutEntityDestroy _despawnPacket;
public FlagEntity(ItemStack hand, Location loc, DisguiseManager manager) public FlagEntity(ItemStack hand, Location loc)
{ {
_manager = manager;
_holding = hand; _holding = hand;
_loc = loc; _loc = loc;
toggle(true); _despawnPacket = new PacketPlayOutEntityDestroy(new int[]
{
_entityId
});
} }
public Location getLocation() public Location getLocation()
@ -41,86 +44,105 @@ public class FlagEntity implements Listener
public void spawn() public void spawn()
{ {
_entity = (LivingEntity) _loc.getWorld().spawnEntity(_loc, EntityType.CHICKEN); _display = true;
//_entity.teleport(_loc.clone().subtract(0, 1.5, 0));
UtilEnt.Vegetate(_entity, true); PacketPlayOutSpawnEntityLiving packet = new PacketPlayOutSpawnEntityLiving();
UtilEnt.ghost(_entity, true, true); DataWatcher watcher = new DataWatcher(null);
DisguiseArmorStand disguise = new DisguiseArmorStand(_entity);
//DisguisePlayer d = new DisguisePlayer(_entity, new GameProfile(UUID.randomUUID(), "defek7")); packet.a = _entityId;
//d.setInvisible(true); packet.b = 30;
//d.setBoots(_holding); packet.c = (int) (getLocation().getX() * 32);
disguise.setHelmet(_holding); packet.d = (int) ((getLocation().getY() - 1.5) * 32);
disguise.setInvisible(true); packet.e = (int) (getLocation().getZ() * 32);
_manager.disguise(disguise, UtilServer.getPlayers()); packet.l = watcher;
//_manager.disguise(d, UtilServer.getPlayers());
// Setup datawatcher for armor stand
watcher.a(0, (byte) 32);
for (int i = 11; i <= 16; i++)
{
watcher.a(i, new Vector());
}
_spawnPackets[0] = packet;
PacketPlayOutEntityEquipment packet2 = new PacketPlayOutEntityEquipment();
packet2.a = _entityId;
packet2.b = 4;
packet2.c = CraftItemStack.asNMSCopy(_holding);
_spawnPackets[1] = packet2;
} }
public void despawn() public Packet[] getSpawn()
{ {
//_manager.undisguise(_entity); return _spawnPackets;
_entity.remove();
_entity = null;
}
public void teleport(Location loc)
{
if (_entity != null) despawn();
_loc = loc;
spawn();
} }
public void update() public void update()
{ {
if (_entity != null) if (!_display)
{ {
if (_entity.isDead()) return;
{
despawn();
spawn();
}
_entity.teleport(_loc);
} }
}
private void toggle(boolean on) ArrayList<Player> canSee = new ArrayList<Player>();
{
if (on)
Bukkit.getPluginManager().registerEvents(this, _manager.getPlugin());
else
HandlerList.unregisterAll(this);
}
@EventHandler for (Player player : _loc.getWorld().getPlayers())
public void onHit(EntityDamageEvent event)
{
if (_entity == null) return;
if (event.getEntity().getEntityId() == _entity.getEntityId())
event.setCancelled(true);
}
@EventHandler
public void onHit(CustomDamageEvent event)
{
if (_entity == null) return;
if (event.GetDamageeEntity() == null) return;
if (event.GetDamageeEntity().getEntityId() == _entity.getEntityId())
event.SetCancelled("Flag Entity");
}
@EventHandler
public void onEnd(GameStateChangeEvent event)
{
if (event.GetGame().GetType() == GameType.ChampionsCTF)
{ {
if (event.GetState() == GameState.Dead) if (player.getLocation().distance(_loc) < 120)
{ {
despawn(); canSee.add(player);
toggle(false);
} }
} }
Iterator<Player> iter2 = _playersTracking.iterator();
while (iter2.hasNext())
{
Player player = iter2.next();
if (!canSee.contains(player))
{
iter2.remove();
UtilPlayer.sendPacket(player, getDestroy());
}
}
for (Player player : canSee)
{
if (!_playersTracking.contains(player))
{
_playersTracking.add(player);
UtilPlayer.sendPacket(player, getSpawn());
}
}
}
public PacketPlayOutEntityDestroy getDestroy()
{
return _despawnPacket;
}
public void despawn()
{
for (Player player : _playersTracking)
{
UtilPlayer.sendPacket(player, getDestroy());
}
_playersTracking.clear();
_display = false;
}
public void teleport(Location loc)
{
despawn();
_loc = loc;
spawn();
} }
} }