Read desc

Fixed disguises facing direction not updating automatically to the
correct direction.
Its not 100% perfect, but the alternative is to delay the packet another
tick which is not realistic as people could change disguises in that
time.
This commit is contained in:
libraryaddict 2013-11-23 15:53:17 +13:00
parent 2f85d35df1
commit 94a7237803

View File

@ -80,13 +80,16 @@ public class PacketsManager {
else { else {
event.setPacket(packets[0]); event.setPacket(packets[0]);
final PacketContainer[] delayedPackets = new PacketContainer[packets.length - 1]; final PacketContainer[] delayedPackets = new PacketContainer[packets.length - 1];
for (int i = 1; i < packets.length; i++) for (int i = 1; i < packets.length; i++) {
delayedPackets[i - 1] = packets[i]; delayedPackets[i - 1] = packets[i];
}
if (delayedPackets.length > 0) {
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
public void run() { public void run() {
try { try {
for (PacketContainer packet : delayedPackets) for (PacketContainer packet : delayedPackets) {
ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet); ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, false);
}
} catch (InvocationTargetException e) { } catch (InvocationTargetException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -94,6 +97,7 @@ public class PacketsManager {
}); });
} }
} }
}
}); });
// Now add a client listener to cancel them interacting with uninteractable disguised entitys. // Now add a client listener to cancel them interacting with uninteractable disguised entitys.
// You ain't supposed to be allowed to 'interact' with a item that cannot be clicked. // You ain't supposed to be allowed to 'interact' with a item that cannot be clicked.
@ -290,7 +294,7 @@ public class PacketsManager {
spawnPackets[1] = new PacketContainer(Packets.Server.ENTITY_HEAD_ROTATION); spawnPackets[1] = new PacketContainer(Packets.Server.ENTITY_HEAD_ROTATION);
StructureModifier<Object> mods = spawnPackets[1].getModifier(); StructureModifier<Object> mods = spawnPackets[1].getModifier();
mods.write(0, disguisedEntity.getEntityId()); mods.write(0, disguisedEntity.getEntityId());
mods.write(1, (byte) (int) Math.floor(loc.getYaw() * 256.0F / 360.0F)); mods.write(1, yaw);
} }
return spawnPackets; return spawnPackets;
} }
@ -624,15 +628,35 @@ public class PacketsManager {
if (fakeId > 0) { if (fakeId > 0) {
// Here I grab the packets to convert them to, So I can display them as if the disguise sent them. // Here I grab the packets to convert them to, So I can display them as if the disguise sent them.
PacketContainer[] packets = transformPacket(event.getPacket(), event.getPlayer()); PacketContainer[] packets = transformPacket(event.getPacket(), event.getPlayer());
try { final PacketContainer[] delayedPackets = new PacketContainer[packets.length - 1];
for (PacketContainer packet : packets) { final Player observer = event.getPlayer();
for (int i = 0; i < packets.length; i++) {
PacketContainer packet = packets[i];
if (packet.equals(event.getPacket())) if (packet.equals(event.getPacket()))
packet = packet.deepClone(); packet = packet.deepClone();
packet.getModifier().write(0, fakeId); packet.getModifier().write(0, fakeId);
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, false); if (i == 0) {
try {
ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, false);
} catch (InvocationTargetException e) {
e.printStackTrace();
} }
} catch (Exception ex) { } else {
ex.printStackTrace(); delayedPackets[i - 1] = packets[i];
}
}
if (delayedPackets.length > 0) {
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
public void run() {
try {
for (PacketContainer packet : delayedPackets) {
ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, false);
}
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
});
} }
if (event.getPacketID() == Packets.Server.ENTITY_METADATA) { if (event.getPacketID() == Packets.Server.ENTITY_METADATA) {
@ -652,15 +676,6 @@ public class PacketsManager {
} else { } else {
switch (event.getPacketID()) { switch (event.getPacketID()) {
case Packets.Server.NAMED_ENTITY_SPAWN: case Packets.Server.NAMED_ENTITY_SPAWN:
case Packets.Server.ATTACH_ENTITY:
case Packets.Server.REL_ENTITY_MOVE:
case Packets.Server.REL_ENTITY_MOVE_LOOK:
case Packets.Server.ENTITY_LOOK:
case Packets.Server.ENTITY_TELEPORT:
case Packets.Server.ENTITY_HEAD_ROTATION:
case Packets.Server.MOB_EFFECT:
case Packets.Server.ENTITY_EQUIPMENT:
if (event.getPacketID() == Packets.Server.NAMED_ENTITY_SPAWN) {
PacketContainer packet = new PacketContainer(Packets.Server.ENTITY_METADATA); PacketContainer packet = new PacketContainer(Packets.Server.ENTITY_METADATA);
StructureModifier<Object> mods = packet.getModifier(); StructureModifier<Object> mods = packet.getModifier();
mods.write(0, entity.getEntityId()); mods.write(0, entity.getEntityId());
@ -675,7 +690,16 @@ public class PacketsManager {
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
} event.setCancelled(true);
break;
case Packets.Server.ATTACH_ENTITY:
case Packets.Server.REL_ENTITY_MOVE:
case Packets.Server.REL_ENTITY_MOVE_LOOK:
case Packets.Server.ENTITY_LOOK:
case Packets.Server.ENTITY_TELEPORT:
case Packets.Server.ENTITY_HEAD_ROTATION:
case Packets.Server.MOB_EFFECT:
case Packets.Server.ENTITY_EQUIPMENT:
event.setCancelled(true); event.setCancelled(true);
break; break;