Code clean up

This commit is contained in:
libraryaddict 2013-11-25 15:45:23 +13:00
parent 571c92ca7c
commit f9eedb7528
2 changed files with 39 additions and 47 deletions

View File

@ -59,7 +59,7 @@
<version>2.7.0</version> <version>2.7.0</version>
</dependency> </dependency>
</dependencies> </dependencies>
<version>7.7.2</version> <version>7.7.2-SNAPSHOT</version>
<distributionManagement> <distributionManagement>
<repository> <repository>

View File

@ -672,15 +672,13 @@ public class PacketsManager {
Packets.Server.ENTITY_VELOCITY, Packets.Server.UPDATE_ATTRIBUTES) { Packets.Server.ENTITY_VELOCITY, Packets.Server.UPDATE_ATTRIBUTES) {
@Override @Override
public void onPacketSending(PacketEvent event) { public void onPacketSending(PacketEvent event) {
StructureModifier<Entity> entityModifer = event.getPacket().getEntityModifier(event.getPlayer().getWorld()); final Player observer = event.getPlayer();
org.bukkit.entity.Entity entity = entityModifer.read(0); if (event.getPacket().getEntityModifier(observer.getWorld()).read(0) == observer) {
if (entity == event.getPlayer()) { int fakeId = DisguiseAPI.getFakeDisguise(observer.getEntityId());
int fakeId = DisguiseAPI.getFakeDisguise(entity.getEntityId());
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(), observer);
final PacketContainer[] delayedPackets = new PacketContainer[packets.length > 0 ? packets.length - 1 : 0]; final PacketContainer[] delayedPackets = new PacketContainer[packets.length > 0 ? packets.length - 1 : 0];
final Player observer = event.getPlayer();
for (int i = 0; i < packets.length; i++) { for (int i = 0; i < packets.length; i++) {
PacketContainer packet = packets[i]; PacketContainer packet = packets[i];
if (packet.equals(event.getPacket())) if (packet.equals(event.getPacket()))
@ -693,7 +691,7 @@ public class PacketsManager {
e.printStackTrace(); e.printStackTrace();
} }
} else { } else {
delayedPackets[i - 1] = packets[i]; delayedPackets[i - 1] = packet;
} }
} }
if (delayedPackets.length > 0) { if (delayedPackets.length > 0) {
@ -710,7 +708,8 @@ public class PacketsManager {
}); });
} }
if (event.getPacketID() == Packets.Server.ENTITY_METADATA) { switch (event.getPacketID()) {
case Packets.Server.ENTITY_METADATA:
event.setPacket(event.getPacket().deepClone()); event.setPacket(event.getPacket().deepClone());
Iterator<WrappedWatchableObject> itel = event.getPacket().getWatchableCollectionModifier().read(0) Iterator<WrappedWatchableObject> itel = event.getPacket().getWatchableCollectionModifier().read(0)
.iterator(); .iterator();
@ -724,24 +723,18 @@ public class PacketsManager {
watch.setValue(a); watch.setValue(a);
} }
} }
} else { break;
switch (event.getPacketID()) {
case Packets.Server.NAMED_ENTITY_SPAWN: case 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, observer.getEntityId());
List<WrappedWatchableObject> watchableList = new ArrayList<WrappedWatchableObject>(); List<WrappedWatchableObject> watchableList = new ArrayList<WrappedWatchableObject>();
byte b = (byte) (0 | 1 << 5); byte b = (byte) (0 | 1 << 5);
if (event.getPlayer().isSprinting()) if (observer.isSprinting())
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);
try { event.setPacket(packet);
ProtocolLibrary.getProtocolManager().sendServerPacket(event.getPlayer(), packet, false);
} catch (Exception ex) {
ex.printStackTrace();
}
event.setCancelled(true);
break; break;
case Packets.Server.ATTACH_ENTITY: case Packets.Server.ATTACH_ENTITY:
case Packets.Server.REL_ENTITY_MOVE: case Packets.Server.REL_ENTITY_MOVE:
@ -766,7 +759,6 @@ public class PacketsManager {
} }
} }
} }
}
}; };
// TODO Potentionally combine both listeners. // TODO Potentionally combine both listeners.
inventoryListenerServer = new PacketAdapter(libsDisguises, ConnectionSide.SERVER_SIDE, ListenerPriority.HIGHEST, inventoryListenerServer = new PacketAdapter(libsDisguises, ConnectionSide.SERVER_SIDE, ListenerPriority.HIGHEST,