DisguiseManager: Add DisguiseRabbit

This commit is contained in:
libraryaddict 2015-04-03 20:52:09 +13:00
parent d4e8c0c9a6
commit 66c83397e5
2 changed files with 169 additions and 0 deletions

View File

@ -17,6 +17,7 @@ import net.minecraft.server.v1_7_R4.ChunkAddEntityEvent;
import net.minecraft.server.v1_7_R4.EntityPlayer;
import net.minecraft.server.v1_7_R4.Packet;
import net.minecraft.server.v1_7_R4.PacketPlayOutBed;
import net.minecraft.server.v1_7_R4.PacketPlayOutEntityStatus;
import net.minecraft.server.v1_7_R4.PacketPlayOutMapChunk;
import net.minecraft.server.v1_7_R4.PacketPlayOutMapChunkBulk;
import net.minecraft.server.v1_7_R4.PacketPlayOutNamedEntitySpawn;
@ -62,6 +63,7 @@ import mineplex.core.disguise.disguises.DisguiseBase;
import mineplex.core.disguise.disguises.DisguiseBlock;
import mineplex.core.disguise.disguises.DisguiseInsentient;
import mineplex.core.disguise.disguises.DisguisePlayer;
import mineplex.core.disguise.disguises.DisguiseRabbit;
import mineplex.core.packethandler.IPacketHandler;
import mineplex.core.packethandler.PacketHandler;
import mineplex.core.packethandler.PacketVerifier;
@ -80,6 +82,7 @@ public class DisguiseManager extends MiniPlugin implements IPacketHandler
private NautHashMap<DisguiseBase, HashSet<Player>> _disguisePlayerMap = new NautHashMap<DisguiseBase, HashSet<Player>>();
private HashSet<String> _blockedNames = new HashSet<String>();
private NautHashMap<Integer, Entry<DisguiseBase, Player[]>> _futureDisguises = new NautHashMap<Integer, Entry<DisguiseBase, Player[]>>();
private NautHashMap<Integer, NautHashMap<Integer, Long>> _lastRabbitHop = new NautHashMap<Integer, NautHashMap<Integer, Long>>();
private boolean _handlingPacket = false;
@ -93,6 +96,8 @@ public class DisguiseManager extends MiniPlugin implements IPacketHandler
private Field _bedD;
private Field _xChunk;
private Field _zChunk;
private Field _eStatusId;
private Field _eStatusState;
private Chunk _bedChunk;
private boolean _bedPackets;
@ -121,6 +126,10 @@ public class DisguiseManager extends MiniPlugin implements IPacketHandler
_bedB.setAccessible(true);
_bedD = PacketPlayOutBed.class.getDeclaredField("d");
_bedD.setAccessible(true);
_eStatusId = PacketPlayOutEntityStatus.class.getDeclaredField("a");
_eStatusId.setAccessible(true);
_eStatusState = PacketPlayOutEntityStatus.class.getDeclaredField("b");
_eStatusState.setAccessible(true);
_bedChunk = new Chunk(null, 0, 0);
Field cSection = Chunk.class.getDeclaredField("sections");
@ -221,6 +230,11 @@ public class DisguiseManager extends MiniPlugin implements IPacketHandler
disguise.setEntity(event.GetEntity());
_spawnPacketMap.put(event.GetEntity().getEntityId(), disguise);
_entityDisguiseMap.remove(event.GetEntity().getUniqueId().toString());
if (disguise instanceof DisguiseRabbit)
{
_lastRabbitHop.put(disguise.GetEntityId(), new NautHashMap<Integer, Long>());
}
}
}
@ -325,6 +339,7 @@ public class DisguiseManager extends MiniPlugin implements IPacketHandler
{
_entityDisguiseMap.put(entity.getUniqueId().toString(), _spawnPacketMap.get(entity.getEntityId()));
_spawnPacketMap.remove(entity.getEntityId());
_lastRabbitHop.remove(entity.getEntityId());
}
}
}
@ -374,6 +389,11 @@ public class DisguiseManager extends MiniPlugin implements IPacketHandler
_spawnPacketMap.put(disguise.GetEntityId(), disguise);
_disguisePlayerMap.put(disguise, new HashSet<Player>());
if (disguise instanceof DisguiseRabbit)
{
_lastRabbitHop.put(disguise.GetEntityId(), new NautHashMap<Integer, Long>());
}
for (Player player : players)
addViewerToDisguise(disguise, player, false);
@ -513,6 +533,63 @@ public class DisguiseManager extends MiniPlugin implements IPacketHandler
final Player owner = packetInfo.getPlayer();
final PacketVerifier packetVerifier = packetInfo.getVerifier();
if (UtilPlayer.is1_8(owner)
&& (packet instanceof PacketPlayOutRelEntityMoveLook || packet instanceof PacketPlayOutRelEntityMove))
{
int entityId = -1;
if (packet instanceof PacketPlayOutRelEntityMoveLook)
{
entityId = ((PacketPlayOutRelEntityMoveLook) packet).a;
}/*
else if (packet instanceof PacketPlayOutEntityLook)
{
entityId = ((PacketPlayOutEntityLook) packet).a;
}*/
else if (packet instanceof PacketPlayOutRelEntityMove)
{
PacketPlayOutRelEntityMove rPacket = (PacketPlayOutRelEntityMove) packet;
if (rPacket.b != 0 || rPacket.c != 0 || rPacket.d != 0)
{
entityId = rPacket.a;
}
}
/*else if (packet instanceof PacketPlayOutEntityTeleport)
{
entityId = ((PacketPlayOutEntityTeleport) packet).a;
}*/
if (_lastRabbitHop.containsKey(entityId))
{
NautHashMap<Integer, Long> rabbitHops = _lastRabbitHop.get(entityId);
if (rabbitHops != null)
{
long last = rabbitHops.containsKey(owner.getEntityId()) ? System.currentTimeMillis()
- rabbitHops.get(owner.getEntityId()) : 1000;
if (last > 500 || last < 100)
{
rabbitHops.put(owner.getEntityId(), System.currentTimeMillis());
PacketPlayOutEntityStatus entityStatus = new PacketPlayOutEntityStatus();
try
{
_eStatusId.set(entityStatus, entityId);
_eStatusState.set(entityStatus, (byte) 1);
handlePacket(entityStatus, packetVerifier);
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
}
}
}
if (packet instanceof PacketPlayOutPlayerInfo)
{
if (_blockedNames.contains(((PacketPlayOutPlayerInfo) packet).username))
@ -737,6 +814,12 @@ public class DisguiseManager extends MiniPlugin implements IPacketHandler
private void handleSpawnPackets(PacketInfo packetInfo, DisguiseBase disguise)
{
final Player player = packetInfo.getPlayer();
if (!UtilPlayer.is1_8(player) && disguise instanceof DisguiseRabbit)
{
return;
}
final PacketVerifier packetVerifier = packetInfo.getVerifier();
if (disguise instanceof DisguisePlayer)
@ -795,6 +878,11 @@ public class DisguiseManager extends MiniPlugin implements IPacketHandler
{
_disguisePlayerMap.get(disguise).remove(event.getPlayer());
}
for (Integer disguise : _lastRabbitHop.keySet())
{
_lastRabbitHop.get(disguise).remove(event.getPlayer().getEntityId());
}
}
/*public void reApplyDisguise(final DisguiseBase disguise, final Player player)
@ -1007,6 +1095,7 @@ public class DisguiseManager extends MiniPlugin implements IPacketHandler
if (!_spawnPacketMap.containsKey(entity.getEntityId()))
return;
_lastRabbitHop.remove(entity.getEntityId());
DisguiseBase disguise = _spawnPacketMap.remove(entity.getEntityId());
Collection<? extends Player> players = (disguise.Global ? Bukkit.getOnlinePlayers() : _disguisePlayerMap.remove(disguise));

View File

@ -0,0 +1,80 @@
package mineplex.core.disguise.disguises;
import net.minecraft.server.v1_7_R4.EnumEntitySize;
import net.minecraft.server.v1_7_R4.MathHelper;
import net.minecraft.server.v1_7_R4.Packet;
import net.minecraft.server.v1_7_R4.PacketPlayOutSpawnEntityLiving;
public class DisguiseRabbit extends DisguiseInsentient
{
public DisguiseRabbit(org.bukkit.entity.Entity entity)
{
super(entity);
DataWatcher.a(4, Byte.valueOf((byte) 0));
DataWatcher.a(12, (byte) 0);
DataWatcher.a(15, Byte.valueOf((byte) 0));
DataWatcher.a(18, Byte.valueOf((byte) 0));
}
@Override
public Packet GetSpawnPacket()
{
PacketPlayOutSpawnEntityLiving packet = new PacketPlayOutSpawnEntityLiving();
packet.a = Entity.getId();
packet.b = (byte) 101;
packet.c = (int) EnumEntitySize.SIZE_2.a(Entity.locX);
packet.d = (int) MathHelper.floor(Entity.locY * 32.0D);
packet.e = (int) EnumEntitySize.SIZE_2.a(Entity.locZ);
packet.i = (byte) ((int) (Entity.yaw * 256.0F / 360.0F));
packet.j = (byte) ((int) (Entity.pitch * 256.0F / 360.0F));
packet.k = (byte) ((int) (Entity.yaw * 256.0F / 360.0F));
double var2 = 3.9D;
double var4 = 0;
double var6 = 0;
double var8 = 0;
if (var4 < -var2)
{
var4 = -var2;
}
if (var6 < -var2)
{
var6 = -var2;
}
if (var8 < -var2)
{
var8 = -var2;
}
if (var4 > var2)
{
var4 = var2;
}
if (var6 > var2)
{
var6 = var2;
}
if (var8 > var2)
{
var8 = var2;
}
packet.f = (int) (var4 * 8000.0D);
packet.g = (int) (var6 * 8000.0D);
packet.h = (int) (var8 * 8000.0D);
packet.l = DataWatcher;
packet.m = DataWatcher.b();
return packet;
}
}