From b00eb288340088218182a52f48391faa94a21ec3 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Fri, 1 Mar 2013 13:10:56 +0100 Subject: [PATCH] Adding debug output to the protocol lib useage location to get more data. --- .../EntityPotionColorPacketAdapter.java | 56 +++++++++++-------- 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/src/com/massivecraft/mcore/integration/protocollib/EntityPotionColorPacketAdapter.java b/src/com/massivecraft/mcore/integration/protocollib/EntityPotionColorPacketAdapter.java index 90697036..9c711c08 100644 --- a/src/com/massivecraft/mcore/integration/protocollib/EntityPotionColorPacketAdapter.java +++ b/src/com/massivecraft/mcore/integration/protocollib/EntityPotionColorPacketAdapter.java @@ -41,32 +41,42 @@ public class EntityPotionColorPacketAdapter extends PacketAdapter @Override public void onPacketSending(PacketEvent event) { - // If the server is sending a meta-data packet to a sendee player... - // NOTE: That must be the case. We are listening to no other situation. - final PacketContainer packet = event.getPacket(); - final Player sendee = event.getPlayer(); - - // ... fetch the entity ... - // NOTE: MetaData packets are only sent to players in the same world. - final Entity entity = packet.getEntityModifier(sendee.getWorld()).read(0); - - // ... fetch the metadata ... - final List metadata = packet.getWatchableCollectionModifier().read(0); - - // ... for each watchable in the metadata ... - for (WrappedWatchableObject watchable : metadata) + try { - // If the watchable is about potion effect color ... - if (watchable.getIndex() != 8) continue; + // If the server is sending a meta-data packet to a sendee player... + // NOTE: That must be the case. We are listening to no other situation. + final PacketContainer packet = event.getPacket(); + final Player sendee = event.getPlayer(); - // ... run our custom async event to allow changing it ... - int oldColor = (Integer) watchable.getValue(); - MCoreEntityPotionColorEvent colorEvent = new MCoreEntityPotionColorEvent(sendee, entity, oldColor); - colorEvent.run(); - int newColor = colorEvent.getColor(); + // ... fetch the entity ... + // NOTE: MetaData packets are only sent to players in the same world. + final Entity entity = packet.getEntityModifier(sendee.getWorld()).read(0); - // ... alter if changed. - if (newColor != oldColor) watchable.setValue(newColor, false); + // ... fetch the metadata ... + final List metadata = packet.getWatchableCollectionModifier().read(0); + + // ... for each watchable in the metadata ... + for (WrappedWatchableObject watchable : metadata) + { + // If the watchable is about potion effect color ... + if (watchable.getIndex() != 8) continue; + + // ... run our custom async event to allow changing it ... + int oldColor = (Integer) watchable.getValue(); + MCoreEntityPotionColorEvent colorEvent = new MCoreEntityPotionColorEvent(sendee, entity, oldColor); + colorEvent.run(); + int newColor = colorEvent.getColor(); + + // ... alter if changed. + if (newColor != oldColor) watchable.setValue(newColor, false); + } + } + catch (Exception e) + { + System.out.println("Caught "+e.getClass().getName()+" exception in EntityPotionColorPacketAdapter#onPacketSending"); + System.out.println("Message: "+e.getMessage()); + System.out.println("Stack Trace:"); + e.printStackTrace(); } } }