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,18 +80,22 @@ 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];
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { }
public void run() { if (delayedPackets.length > 0) {
try { Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
for (PacketContainer packet : delayedPackets) public void run() {
ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet); try {
} catch (InvocationTargetException e) { for (PacketContainer packet : delayedPackets) {
e.printStackTrace(); ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, false);
}
} catch (InvocationTargetException e) {
e.printStackTrace();
}
} }
} });
}); }
} }
} }
}); });
@ -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();
if (packet.equals(event.getPacket())) for (int i = 0; i < packets.length; i++) {
packet = packet.deepClone(); PacketContainer packet = packets[i];
packet.getModifier().write(0, fakeId); if (packet.equals(event.getPacket()))
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, false); packet = packet.deepClone();
packet.getModifier().write(0, fakeId);
if (i == 0) {
try {
ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, false);
} catch (InvocationTargetException e) {
e.printStackTrace();
}
} else {
delayedPackets[i - 1] = packets[i];
} }
} catch (Exception ex) { }
ex.printStackTrace(); 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,6 +676,22 @@ public class PacketsManager {
} else { } else {
switch (event.getPacketID()) { switch (event.getPacketID()) {
case Packets.Server.NAMED_ENTITY_SPAWN: case Packets.Server.NAMED_ENTITY_SPAWN:
PacketContainer packet = new PacketContainer(Packets.Server.ENTITY_METADATA);
StructureModifier<Object> mods = packet.getModifier();
mods.write(0, entity.getEntityId());
List<WrappedWatchableObject> watchableList = new ArrayList<WrappedWatchableObject>();
byte b = (byte) (0 | 1 << 5);
if (event.getPlayer().isSprinting())
b = (byte) (b | 1 << 3);
watchableList.add(new WrappedWatchableObject(0, b));
packet.getWatchableCollectionModifier().write(0, watchableList);
try {
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, false);
} catch (Exception ex) {
ex.printStackTrace();
}
event.setCancelled(true);
break;
case Packets.Server.ATTACH_ENTITY: case Packets.Server.ATTACH_ENTITY:
case Packets.Server.REL_ENTITY_MOVE: case Packets.Server.REL_ENTITY_MOVE:
case Packets.Server.REL_ENTITY_MOVE_LOOK: case Packets.Server.REL_ENTITY_MOVE_LOOK:
@ -660,22 +700,6 @@ public class PacketsManager {
case Packets.Server.ENTITY_HEAD_ROTATION: case Packets.Server.ENTITY_HEAD_ROTATION:
case Packets.Server.MOB_EFFECT: case Packets.Server.MOB_EFFECT:
case Packets.Server.ENTITY_EQUIPMENT: case Packets.Server.ENTITY_EQUIPMENT:
if (event.getPacketID() == Packets.Server.NAMED_ENTITY_SPAWN) {
PacketContainer packet = new PacketContainer(Packets.Server.ENTITY_METADATA);
StructureModifier<Object> mods = packet.getModifier();
mods.write(0, entity.getEntityId());
List<WrappedWatchableObject> watchableList = new ArrayList<WrappedWatchableObject>();
byte b = (byte) (0 | 1 << 5);
if (event.getPlayer().isSprinting())
b = (byte) (b | 1 << 3);
watchableList.add(new WrappedWatchableObject(0, b));
packet.getWatchableCollectionModifier().write(0, watchableList);
try {
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, false);
} catch (Exception ex) {
ex.printStackTrace();
}
}
event.setCancelled(true); event.setCancelled(true);
break; break;