An attempt to use the latest version protocol lib. Warning it seems protocol lib for 1.7.2 still has bugs.

This commit is contained in:
Olof Larsson 2013-12-05 13:27:55 +01:00
parent e6d98e4e15
commit 813661877d
3 changed files with 19 additions and 14 deletions

View File

@ -3,12 +3,11 @@ package com.massivecraft.mcore.integration.protocollib;
import java.util.List; import java.util.List;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Firework; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.comphenix.protocol.Packets; import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.ConnectionSide;
import com.comphenix.protocol.events.ListenerPriority; import com.comphenix.protocol.events.ListenerPriority;
import com.comphenix.protocol.events.PacketAdapter; import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketContainer; import com.comphenix.protocol.events.PacketContainer;
@ -22,7 +21,11 @@ public class EntityPotionColorPacketAdapter extends PacketAdapter
// INSTANCE & CONSTRUCT // 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(); private static EntityPotionColorPacketAdapter i = new EntityPotionColorPacketAdapter();
public static EntityPotionColorPacketAdapter get() { return i; } 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 // 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. // 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 ... // ... fetch the metadata ...
final List<WrappedWatchableObject> metadata = packet.getWatchableCollectionModifier().read(0); final List<WrappedWatchableObject> metadata = packet.getWatchableCollectionModifier().read(0);

View File

@ -23,6 +23,7 @@ public class MCoreEntityPotionColorEvent extends Event implements Runnable
private final Player sendee; private final Player sendee;
public Player getSendee() { return this.sendee; } public Player getSendee() { return this.sendee; }
// TODO: Should probably be made a LivingEntity instead?
private final Entity entity; private final Entity entity;
public Entity getEntity() { return this.entity; } public Entity getEntity() { return this.entity; }

View File

@ -11,10 +11,9 @@ import java.util.Map;
public class AccessorUtil public class AccessorUtil
{ {
// -------------------------------------------- //
//----------------------------------------------//
// MAKE ACCESSIBLE // MAKE ACCESSIBLE
//----------------------------------------------// // -------------------------------------------- //
public static void makeAccessible(Field field) public static void makeAccessible(Field field)
{ {
@ -32,9 +31,9 @@ public class AccessorUtil
} }
} }
//----------------------------------------------// // -------------------------------------------- //
// FIND // FIND
//----------------------------------------------// // -------------------------------------------- //
public static List<Method> findMethod(Class<?> clazz, String name) public static List<Method> findMethod(Class<?> clazz, String name)
{ {
@ -93,9 +92,9 @@ public class AccessorUtil
return ret; return ret;
} }
//----------------------------------------------// // -------------------------------------------- //
// FIND GETTERS AND SETTERS // FIND GETTERS AND SETTERS
//----------------------------------------------// // -------------------------------------------- //
public static String ucfirst(String str) public static String ucfirst(String str)
{ {
@ -134,9 +133,9 @@ public class AccessorUtil
return null; return null;
} }
//----------------------------------------------// // -------------------------------------------- //
// CREATE PROPERTY ACCESS // CREATE PROPERTY ACCESS
//----------------------------------------------// // -------------------------------------------- //
public static PropertyGetter createPropertyGetter(Class<?> clazz, String name) public static PropertyGetter createPropertyGetter(Class<?> clazz, String name)
{ {