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(
_flagItemListener);
for (Flag flag : this._flags)
{
flag.gameEnd();
}
}
}
@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'"));
_time = new Hologram(Host.getArcadeManager().getHologramManager(), spawn, "");
_flagEntity = new FlagEntity(_representation, _spawn, Host.getArcadeManager().GetDisguise());
SpawnFlag(spawn, team.GetColor() == ChatColor.RED, true);
_flagEntity = new FlagEntity(_representation, _spawn);
SpawnFlag(spawn, team.GetColor() == ChatColor.RED);
}
public GameTeam getTeam()
@ -157,7 +157,7 @@ public class Flag
_moved = false;
_dropped = false;
SpawnFlag(_spawn, _team.GetColor() == ChatColor.RED, false);
SpawnFlag(_spawn, _team.GetColor() == ChatColor.RED);
AnnounceReturn();
@ -214,11 +214,9 @@ public class Flag
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);
if (!initial) Host.CreatureAllowOverride = false;
if (!_moved)
{
@ -307,7 +305,7 @@ public class Flag
{
Recharge.Instance.recharge(player, "Flag Pickup");
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);
_holding = null;
_dropped = true;
@ -350,10 +348,15 @@ public class Flag
_dropped = false;
_dropTime = 0;
_holding = null;
SpawnFlag(_spawn, _team.GetColor() == ChatColor.RED, false);
SpawnFlag(_spawn, _team.GetColor() == ChatColor.RED);
}
}
}
}
public void gameEnd()
{
_flagEntity.despawn();
}
}

View File

@ -1,126 +1,148 @@
package nautilus.game.arcade.game.games.common.ctf_data;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilServer;
import mineplex.core.disguise.DisguiseManager;
import mineplex.core.disguise.disguises.DisguiseArmorStand;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import nautilus.game.arcade.GameType;
import nautilus.game.arcade.events.GameStateChangeEvent;
import nautilus.game.arcade.game.Game.GameState;
import java.util.ArrayList;
import java.util.Iterator;
import mineplex.core.common.util.UtilPlayer;
import net.minecraft.server.v1_7_R4.DataWatcher;
import net.minecraft.server.v1_7_R4.Packet;
import net.minecraft.server.v1_7_R4.PacketPlayOutEntityDestroy;
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.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.craftbukkit.v1_7_R4.inventory.CraftItemStack;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;
public class FlagEntity implements Listener
{
private ItemStack _holding;
private Location _loc;
private LivingEntity _entity;
private DisguiseManager _manager;
public FlagEntity(ItemStack hand, Location loc, DisguiseManager manager)
private int _entityId;
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)
{
_manager = manager;
_holding = hand;
_loc = loc;
toggle(true);
_despawnPacket = new PacketPlayOutEntityDestroy(new int[]
{
_entityId
});
}
public Location getLocation()
{
return _loc;
}
public void spawn()
{
_entity = (LivingEntity) _loc.getWorld().spawnEntity(_loc, EntityType.CHICKEN);
//_entity.teleport(_loc.clone().subtract(0, 1.5, 0));
UtilEnt.Vegetate(_entity, true);
UtilEnt.ghost(_entity, true, true);
DisguiseArmorStand disguise = new DisguiseArmorStand(_entity);
//DisguisePlayer d = new DisguisePlayer(_entity, new GameProfile(UUID.randomUUID(), "defek7"));
//d.setInvisible(true);
//d.setBoots(_holding);
disguise.setHelmet(_holding);
disguise.setInvisible(true);
_manager.disguise(disguise, UtilServer.getPlayers());
//_manager.disguise(d, UtilServer.getPlayers());
_display = true;
PacketPlayOutSpawnEntityLiving packet = new PacketPlayOutSpawnEntityLiving();
DataWatcher watcher = new DataWatcher(null);
packet.a = _entityId;
packet.b = 30;
packet.c = (int) (getLocation().getX() * 32);
packet.d = (int) ((getLocation().getY() - 1.5) * 32);
packet.e = (int) (getLocation().getZ() * 32);
packet.l = watcher;
// 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 Packet[] getSpawn()
{
return _spawnPackets;
}
public void update()
{
if (!_display)
{
return;
}
ArrayList<Player> canSee = new ArrayList<Player>();
for (Player player : _loc.getWorld().getPlayers())
{
if (player.getLocation().distance(_loc) < 120)
{
canSee.add(player);
}
}
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()
{
//_manager.undisguise(_entity);
_entity.remove();
_entity = null;
for (Player player : _playersTracking)
{
UtilPlayer.sendPacket(player, getDestroy());
}
_playersTracking.clear();
_display = false;
}
public void teleport(Location loc)
{
if (_entity != null) despawn();
despawn();
_loc = loc;
spawn();
}
public void update()
{
if (_entity != null)
{
if (_entity.isDead())
{
despawn();
spawn();
}
_entity.teleport(_loc);
}
}
private void toggle(boolean on)
{
if (on)
Bukkit.getPluginManager().registerEvents(this, _manager.getPlugin());
else
HandlerList.unregisterAll(this);
}
@EventHandler
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)
{
despawn();
toggle(false);
}
}
}
}