Understand the squid disguise code (#217)

This commit is contained in:
Sam Sun 2016-10-04 15:28:12 -04:00 committed by Shaun Bennett
parent e867a09b5c
commit 5d8c079be6

View File

@ -13,6 +13,7 @@ import mineplex.core.disguise.disguises.DisguiseBlock;
import mineplex.core.disguise.disguises.DisguiseInsentient;
import mineplex.core.disguise.disguises.DisguiseLiving;
import mineplex.core.disguise.disguises.DisguisePlayer;
import mineplex.core.disguise.disguises.DisguiseSquid;
import mineplex.core.packethandler.IPacketHandler;
import mineplex.core.packethandler.PacketHandler;
import mineplex.core.packethandler.PacketInfo;
@ -85,10 +86,6 @@ public class DisguiseManager extends MiniPlugin implements IPacketHandler
// The map of which players should a disguise be shown to
private Map<DisguiseBase, Predicate<Player>> _disguisePlayerMap = new HashMap<>();
// todo understand how this works
private Map<Integer, PacketPlayOutEntityVelocity> _movePacketMap = new HashMap<>();
private Set<Integer> _goingUp = new HashSet<>();
private HashSet<String> _blockedNames = new HashSet<>();
private boolean _handlingPacket = false;
@ -106,9 +103,7 @@ public class DisguiseManager extends MiniPlugin implements IPacketHandler
PacketPlayOutSpawnEntityLiving.class,
PacketPlayOutUpdateAttributes.class,
PacketPlayOutEntityEquipment.class,
PacketPlayOutEntityVelocity.class,
PacketPlayOutEntity.PacketPlayOutRelEntityMove.class,
PacketPlayOutEntity.PacketPlayOutRelEntityMoveLook.class
PacketPlayOutEntityVelocity.class
);
createBedChunk();
@ -441,127 +436,18 @@ public class DisguiseManager extends MiniPlugin implements IPacketHandler
}
}
}
// honestly im not really sure how this works or what it's really meant to do
// it unbreaks squid in SSM though so I guess it's useful
// todo understand how it works
else if (packet instanceof PacketPlayOutEntityVelocity)
{
PacketPlayOutEntityVelocity velocityPacket = (PacketPlayOutEntityVelocity) packet;
// Only for viewers
if (velocityPacket.a == owner.getEntityId())
{
if (velocityPacket.c > 0)
_goingUp.add(velocityPacket.a);
}
else if (velocityPacket.b == 0 && velocityPacket.c == 0 && velocityPacket.d == 0)
{
return;
}
else if (_spawnPacketMap.containsKey(velocityPacket.a))
DisguiseBase latestDisguise = getActiveDisguise(velocityPacket.a);
// Squids will move using their current velocity every tick. So let's just not give them any velocities
if (latestDisguise != null && latestDisguise instanceof DisguiseSquid && getActiveDisguise(owner) != latestDisguise)
{
packetInfo.setCancelled(true);
}
}
else if (packet instanceof PacketPlayOutEntity.PacketPlayOutRelEntityMove)
{
final PacketPlayOutEntity.PacketPlayOutRelEntityMove movePacket = (PacketPlayOutEntity.PacketPlayOutRelEntityMove) packet;
// Only for viewers
if (movePacket.a == owner.getEntityId())
return;
if (_goingUp.contains(movePacket.a) && movePacket.c != 0 && movePacket.c < 20)
{
_goingUp.remove(movePacket.a);
_movePacketMap.remove(movePacket.a);
}
if (!containsSpawnDisguise(owner, getActiveDisguise(movePacket.a)))
return;
final PacketPlayOutEntityVelocity velocityPacket = new PacketPlayOutEntityVelocity();
velocityPacket.a = movePacket.a;
velocityPacket.b = movePacket.b * 100;
velocityPacket.c = movePacket.c * 100;
velocityPacket.d = movePacket.d * 100;
if (_movePacketMap.containsKey(movePacket.a))
{
PacketPlayOutEntityVelocity lastVelocityPacket = _movePacketMap.get(movePacket.a);
velocityPacket.b = (int) (.8 * lastVelocityPacket.b);
velocityPacket.c = (int) (.8 * lastVelocityPacket.c);
velocityPacket.d = (int) (.8 * lastVelocityPacket.d);
}
_movePacketMap.put(movePacket.a, velocityPacket);
packetVerifier.bypassProcess(velocityPacket);
if (_goingUp.contains(movePacket.a) && movePacket.c != 0 && movePacket.c > 20)
{
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(getPlugin(), new Runnable()
{
public void run()
{
packetVerifier.bypassProcess(velocityPacket);
}
});
}
if (getActiveDisguise(movePacket.a) instanceof DisguiseBlock)
{
}
}
else if (packet instanceof PacketPlayOutEntity.PacketPlayOutRelEntityMoveLook)
{
final PacketPlayOutEntity.PacketPlayOutRelEntityMoveLook movePacket = (PacketPlayOutEntity.PacketPlayOutRelEntityMoveLook) packet;
// Only for viewers
if (movePacket.a == owner.getEntityId())
return;
if (_goingUp.contains(movePacket.a) && movePacket.c != 0 && movePacket.c <= 20)
{
_goingUp.remove(movePacket.a);
_movePacketMap.remove(movePacket.a);
}
if (!containsSpawnDisguise(owner, getActiveDisguise(movePacket.a)))
return;
final PacketPlayOutEntityVelocity velocityPacket = new PacketPlayOutEntityVelocity();
velocityPacket.a = movePacket.a;
velocityPacket.b = movePacket.b * 100;
velocityPacket.c = movePacket.c * 100;
velocityPacket.d = movePacket.d * 100;
if (_movePacketMap.containsKey(movePacket.a))
{
PacketPlayOutEntityVelocity lastVelocityPacket = _movePacketMap.get(movePacket.a);
velocityPacket.b = (int) (.8 * lastVelocityPacket.b);
velocityPacket.c = (int) (.8 * lastVelocityPacket.c);
velocityPacket.d = (int) (.8 * lastVelocityPacket.d);
}
_movePacketMap.put(movePacket.a, velocityPacket);
packetVerifier.bypassProcess(velocityPacket);
if (_goingUp.contains(movePacket.a) && movePacket.c != 0 && movePacket.c > 20)
{
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(getPlugin(), new Runnable()
{
public void run()
{
packetVerifier.bypassProcess(velocityPacket);
}
});
}
}
}
private void handlePacket(Packet packet, PacketVerifier verifier)