Don't use setPacket for the packet listeners. That was a bug. Packets are also no longer delayed by a tick

This commit is contained in:
libraryaddict 2014-03-23 17:57:57 +13:00
parent d141740aa0
commit a2e43e98be

View File

@ -85,26 +85,14 @@ public class PacketsManager {
if (entity == observer) if (entity == observer)
return; return;
PacketContainer[] packets = transformPacket(event.getPacket(), event.getPlayer(), entity); PacketContainer[] packets = transformPacket(event.getPacket(), event.getPlayer(), entity);
if (packets.length == 0) if (packets != null) {
event.setCancelled(true); event.setCancelled(true);
else {
event.setPacket(packets[0]);
final PacketContainer[] delayedPackets = new PacketContainer[packets.length - 1];
for (int i = 1; i < packets.length; i++) {
delayedPackets[i - 1] = packets[i];
}
if (delayedPackets.length > 0) {
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
public void run() {
try { try {
for (PacketContainer packet : delayedPackets) { for (PacketContainer packet : packets) {
ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, false); ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, false);
} }
} catch (InvocationTargetException e) { } catch (InvocationTargetException ex) {
e.printStackTrace(); ex.printStackTrace();
}
}
});
} }
} }
} }
@ -768,6 +756,7 @@ public class PacketsManager {
} }
} }
} else if (event.getPacketType() == PacketType.Play.Server.NAMED_ENTITY_SPAWN) { } else if (event.getPacketType() == PacketType.Play.Server.NAMED_ENTITY_SPAWN) {
event.setCancelled(true);
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA); PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
StructureModifier<Object> mods = packet.getModifier(); StructureModifier<Object> mods = packet.getModifier();
mods.write(0, observer.getEntityId()); mods.write(0, observer.getEntityId());
@ -777,7 +766,11 @@ public class PacketsManager {
b = (byte) (b | 1 << 3); b = (byte) (b | 1 << 3);
watchableList.add(new WrappedWatchableObject(0, b)); watchableList.add(new WrappedWatchableObject(0, b));
packet.getWatchableCollectionModifier().write(0, watchableList); packet.getWatchableCollectionModifier().write(0, watchableList);
event.setPacket(packet); try {
ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet);
} catch (InvocationTargetException e) {
e.printStackTrace();
}
} else if (event.getPacketType() == PacketType.Play.Server.ANIMATION) { } else if (event.getPacketType() == PacketType.Play.Server.ANIMATION) {
if (event.getPacket().getIntegers().read(1) != (LibVersion.is1_7() ? 2 : 3)) { if (event.getPacket().getIntegers().read(1) != (LibVersion.is1_7() ? 2 : 3)) {
event.setCancelled(true); event.setCancelled(true);
@ -1119,14 +1112,17 @@ public class PacketsManager {
} }
/** /**
* Transform the packet magically into the one I have always dreamed off. My true luv!!! * Transform the packet magically into the one I have always dreamed off. My true luv!!! This will return null if its not
* transformed
*/ */
public static PacketContainer[] transformPacket(PacketContainer sentPacket, Player observer, Entity entity) { public static PacketContainer[] transformPacket(PacketContainer sentPacket, Player observer, Entity entity) {
PacketContainer[] packets = new PacketContainer[] { sentPacket }; PacketContainer[] packets = null;
try { try {
Disguise disguise = DisguiseAPI.getDisguise(observer, entity); Disguise disguise = DisguiseAPI.getDisguise(observer, entity);
// If disguised. // If disguised.
if (disguise != null) { if (disguise != null) {
packets = new PacketContainer[] { sentPacket };
// If packet is PacketType.Play.Server.UPDATE_ATTRIBUTES // If packet is PacketType.Play.Server.UPDATE_ATTRIBUTES
// This packet sends attributes // This packet sends attributes
if (sentPacket.getType() == PacketType.Play.Server.UPDATE_ATTRIBUTES) { if (sentPacket.getType() == PacketType.Play.Server.UPDATE_ATTRIBUTES) {
@ -1272,6 +1268,10 @@ public class PacketsManager {
pitch).createPacket(entity.getEntityId(), yaw, pitch), rotation }; pitch).createPacket(entity.getEntityId(), yaw, pitch), rotation };
} }
} }
else {
packets = null;
}
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();