mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2024-11-28 05:35:28 +01:00
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.
This commit is contained in:
parent
5f54b95998
commit
d70f102655
@ -33,6 +33,7 @@ import java.util.Collection;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.ConcurrentMap;
|
import java.util.concurrent.ConcurrentMap;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import org.bukkit.World;
|
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.WrappedWatchableObject;
|
||||||
import com.comphenix.protocol.wrappers.nbt.NbtBase;
|
import com.comphenix.protocol.wrappers.nbt.NbtBase;
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
|
import com.google.common.base.Preconditions;
|
||||||
import com.google.common.collect.Maps;
|
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
|
* MAY return null or invalid entities for certain fields. Using the correct index
|
||||||
* is essential.
|
* is essential.
|
||||||
*
|
*
|
||||||
|
* @param world - the world each entity is currently occupying.
|
||||||
* @return A modifier entity types.
|
* @return A modifier entity types.
|
||||||
*/
|
*/
|
||||||
public StructureModifier<Entity> getEntityModifier(World world) {
|
public StructureModifier<Entity> getEntityModifier(@Nonnull World world) {
|
||||||
|
Preconditions.checkNotNull(world, "world cannot be NULL.");
|
||||||
// Convert to and from the Bukkit wrapper
|
// Convert to and from the Bukkit wrapper
|
||||||
return structureModifier.<Entity>withType(
|
return structureModifier.<Entity>withType(
|
||||||
int.class, BukkitConverters.getEntityConverter(world));
|
int.class, BukkitConverters.getEntityConverter(world));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves a read/write structure for entity objects.
|
||||||
|
* <p>
|
||||||
|
* 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<Entity> getEntityModifier(@Nonnull PacketEvent event) {
|
||||||
|
Preconditions.checkNotNull(event, "event cannot be NULL.");
|
||||||
|
return getEntityModifier(event.getPlayer().getWorld());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves a read/write structure for chunk positions.
|
* Retrieves a read/write structure for chunk positions.
|
||||||
* @return A modifier for a ChunkPosition.
|
* @return A modifier for a ChunkPosition.
|
||||||
|
Loading…
Reference in New Issue
Block a user