From d70f1026559fd6dab0c197d54fef019371531248 Mon Sep 17 00:00:00 2001 From: "Kristian S. Stangeland" Date: Sun, 21 Jul 2013 03:23:29 +0200 Subject: [PATCH] Add a getEntityModifier() overload that makes it easier to use. Most people use it to retrieve the entity referenced in a certain packet, which will always be in the world of the receiving player. This method makes the same assumption. --- .../protocol/events/PacketContainer.java | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/events/PacketContainer.java b/ProtocolLib/src/main/java/com/comphenix/protocol/events/PacketContainer.java index b234d379..e0ec72a9 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/events/PacketContainer.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/events/PacketContainer.java @@ -33,6 +33,7 @@ import java.util.Collection; import java.util.List; import java.util.concurrent.ConcurrentMap; +import javax.annotation.Nonnull; import javax.annotation.Nullable; import org.bukkit.World; @@ -65,6 +66,7 @@ import com.comphenix.protocol.wrappers.WrappedDataWatcher; import com.comphenix.protocol.wrappers.WrappedWatchableObject; import com.comphenix.protocol.wrappers.nbt.NbtBase; import com.google.common.base.Function; +import com.google.common.base.Preconditions; import com.google.common.collect.Maps; /** @@ -336,14 +338,32 @@ public class PacketContainer implements Serializable { * MAY return null or invalid entities for certain fields. Using the correct index * is essential. * + * @param world - the world each entity is currently occupying. * @return A modifier entity types. */ - public StructureModifier getEntityModifier(World world) { + public StructureModifier getEntityModifier(@Nonnull World world) { + Preconditions.checkNotNull(world, "world cannot be NULL."); // Convert to and from the Bukkit wrapper return structureModifier.withType( int.class, BukkitConverters.getEntityConverter(world)); } + /** + * Retrieves a read/write structure for entity objects. + *

+ * Note that entities are transmitted by integer ID, and the type may not be enough + * to distinguish between entities and other values. Thus, this structure modifier + * MAY return null or invalid entities for certain fields. Using the correct index + * is essential. + * + * @param event - the original packet event. + * @return A modifier entity types. + */ + public StructureModifier getEntityModifier(@Nonnull PacketEvent event) { + Preconditions.checkNotNull(event, "event cannot be NULL."); + return getEntityModifier(event.getPlayer().getWorld()); + } + /** * Retrieves a read/write structure for chunk positions. * @return A modifier for a ChunkPosition.