From 813661877d0bb73cabe56f748c72ad6e7e72df0f Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Thu, 5 Dec 2013 13:27:55 +0100 Subject: [PATCH] An attempt to use the latest version protocol lib. Warning it seems protocol lib for 1.7.2 still has bugs. --- .../EntityPotionColorPacketAdapter.java | 15 ++++++++++----- .../MCoreEntityPotionColorEvent.java | 1 + .../mcore/store/accessor/AccessorUtil.java | 17 ++++++++--------- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/com/massivecraft/mcore/integration/protocollib/EntityPotionColorPacketAdapter.java b/src/com/massivecraft/mcore/integration/protocollib/EntityPotionColorPacketAdapter.java index d3272460..a94c5d71 100644 --- a/src/com/massivecraft/mcore/integration/protocollib/EntityPotionColorPacketAdapter.java +++ b/src/com/massivecraft/mcore/integration/protocollib/EntityPotionColorPacketAdapter.java @@ -3,12 +3,11 @@ package com.massivecraft.mcore.integration.protocollib; import java.util.List; import org.bukkit.entity.Entity; -import org.bukkit.entity.Firework; +import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; -import com.comphenix.protocol.Packets; +import com.comphenix.protocol.PacketType; import com.comphenix.protocol.ProtocolLibrary; -import com.comphenix.protocol.events.ConnectionSide; import com.comphenix.protocol.events.ListenerPriority; import com.comphenix.protocol.events.PacketAdapter; import com.comphenix.protocol.events.PacketContainer; @@ -22,7 +21,11 @@ public class EntityPotionColorPacketAdapter extends PacketAdapter // INSTANCE & CONSTRUCT // -------------------------------------------- // - private EntityPotionColorPacketAdapter() { super(MCore.get(), ConnectionSide.SERVER_SIDE, ListenerPriority.NORMAL, Packets.Server.ENTITY_METADATA); } + //private EntityPotionColorPacketAdapter() { super(MCore.get(), ConnectionSide.SERVER_SIDE, ListenerPriority.NORMAL, Packets.Server.ENTITY_METADATA); } + private EntityPotionColorPacketAdapter() + { + super(PacketAdapter.params().plugin(MCore.get()).serverSide().listenerPriority(ListenerPriority.NORMAL).types(PacketType.Play.Server.ENTITY_METADATA)); + } private static EntityPotionColorPacketAdapter i = new EntityPotionColorPacketAdapter(); public static EntityPotionColorPacketAdapter get() { return i; } @@ -55,7 +58,9 @@ public class EntityPotionColorPacketAdapter extends PacketAdapter // Fireworks cannot have potion effects! They also reuse index 8 // for sending their item stack, causing a crash if we don't bail out now. - if (entity instanceof Firework) return; + // We could have done: if (entity instanceof Firework) return; + // But it's actually more safe to use a whitelist than a blacklist. + if (!(entity instanceof LivingEntity)) return; // ... fetch the metadata ... final List metadata = packet.getWatchableCollectionModifier().read(0); diff --git a/src/com/massivecraft/mcore/integration/protocollib/MCoreEntityPotionColorEvent.java b/src/com/massivecraft/mcore/integration/protocollib/MCoreEntityPotionColorEvent.java index e6515e22..efaca502 100644 --- a/src/com/massivecraft/mcore/integration/protocollib/MCoreEntityPotionColorEvent.java +++ b/src/com/massivecraft/mcore/integration/protocollib/MCoreEntityPotionColorEvent.java @@ -23,6 +23,7 @@ public class MCoreEntityPotionColorEvent extends Event implements Runnable private final Player sendee; public Player getSendee() { return this.sendee; } + // TODO: Should probably be made a LivingEntity instead? private final Entity entity; public Entity getEntity() { return this.entity; } diff --git a/src/com/massivecraft/mcore/store/accessor/AccessorUtil.java b/src/com/massivecraft/mcore/store/accessor/AccessorUtil.java index 73a86ce1..00108cf8 100644 --- a/src/com/massivecraft/mcore/store/accessor/AccessorUtil.java +++ b/src/com/massivecraft/mcore/store/accessor/AccessorUtil.java @@ -11,10 +11,9 @@ import java.util.Map; public class AccessorUtil { - - //----------------------------------------------// + // -------------------------------------------- // // MAKE ACCESSIBLE - //----------------------------------------------// + // -------------------------------------------- // public static void makeAccessible(Field field) { @@ -32,9 +31,9 @@ public class AccessorUtil } } - //----------------------------------------------// + // -------------------------------------------- // // FIND - //----------------------------------------------// + // -------------------------------------------- // public static List findMethod(Class clazz, String name) { @@ -93,9 +92,9 @@ public class AccessorUtil return ret; } - //----------------------------------------------// + // -------------------------------------------- // // FIND GETTERS AND SETTERS - //----------------------------------------------// + // -------------------------------------------- // public static String ucfirst(String str) { @@ -134,9 +133,9 @@ public class AccessorUtil return null; } - //----------------------------------------------// + // -------------------------------------------- // // CREATE PROPERTY ACCESS - //----------------------------------------------// + // -------------------------------------------- // public static PropertyGetter createPropertyGetter(Class clazz, String name) {