com.comphenix.protocol.wrappers.WrappedDataWatcher Java Examples

The following examples show how to use com.comphenix.protocol.wrappers.WrappedDataWatcher. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ProtocolLibHook.java    From StackMob-3 with GNU General Public License v3.0 6 votes vote down vote up
public void sendPacket(Player player, Entity entity, boolean visible){
    PacketContainer packet = protocolManager.createPacket(PacketType.Play.Server.ENTITY_METADATA);
    // Cloning the packet and getting the entity involved.
    WrappedDataWatcher watcher = new WrappedDataWatcher(entity);
    WrappedDataWatcher.Serializer booleanSerializer = WrappedDataWatcher.Registry.get(Boolean.class);
    // Set if the tag is visible or not.
    watcher.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(3, booleanSerializer), visible);
    // Writing the stuff to the packet.
    packet.getEntityModifier(entity.getWorld()).write(0, entity);
    packet.getWatchableCollectionModifier().write(0, watcher.getWatchableObjects());

    // Send the new packet.
    try{
        protocolManager.sendServerPacket(player, packet);
    }catch (InvocationTargetException e){
        e.printStackTrace();
    }
}
 
Example #2
Source File: MetadataPacket.java    From AACAdditionPro with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Sets a metadata.
 */
public MetadataBuilder setMetadata(final int index, final Class classOfValue, final Object value)
{
    switch (ServerVersion.getActiveServerVersion()) {
        case MC188:
            dataWatcher.setObject(index, value);
            break;
        case MC112:
        case MC113:
        case MC114:
        case MC115:
            dataWatcher.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(index, WrappedDataWatcher.Registry.get(classOfValue)), value);
            break;
        default:
            throw new UnknownMinecraftVersion();
    }

    return this;
}
 
Example #3
Source File: PacketHelper.java    From HolographicDisplays with GNU General Public License v3.0 6 votes vote down vote up
public void sendSpawnSlimePacket(Player receiver, NMSSlime slime) {
	AbstractPacket spawnPacket = new WrapperPlayServerSpawnEntityLiving(slime.getBukkitEntityNMS());
	spawnPacket.sendPacket(receiver);
	
	if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_15_R1)) {
		WrapperPlayServerEntityMetadata dataPacket = new WrapperPlayServerEntityMetadata();
		WrappedDataWatcher dataWatcher = new WrappedDataWatcher();
		
		metadataHelper.setEntityStatus(dataWatcher, (byte) 0x20); // Invisible
		metadataHelper.setSlimeSize(dataWatcher, 1); // Size 1 = small
		
		dataPacket.setEntityMetadata(dataWatcher.getWatchableObjects());
		dataPacket.setEntityID(slime.getIdNMS());
		dataPacket.sendPacket(receiver);
	}
}
 
Example #4
Source File: PacketHelper.java    From HolographicDisplays with GNU General Public License v3.0 5 votes vote down vote up
public void sendItemMetadataPacket(Player receiver, NMSItem item) {
	WrapperPlayServerEntityMetadata packet = new WrapperPlayServerEntityMetadata();
	
	WrappedDataWatcher dataWatcher = new WrappedDataWatcher();
	metadataHelper.setItemMetadata(dataWatcher, item.getRawItemStack());
	packet.setEntityMetadata(dataWatcher.getWatchableObjects());
	
	packet.setEntityID(item.getIdNMS());
	packet.sendPacket(receiver);
}
 
Example #5
Source File: MetadataHelper.java    From HolographicDisplays with GNU General Public License v3.0 5 votes vote down vote up
public void setItemMetadata(WrappedDataWatcher dataWatcher, Object nmsItemStack) {
	if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_9_R1)) {
		if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_11_R1)) {
			dataWatcher.setObject(new WrappedDataWatcherObject(itemSlotIndex, itemSerializer), nmsItemStack);
		} else {
			dataWatcher.setObject(new WrappedDataWatcherObject(itemSlotIndex, itemSerializer), com.google.common.base.Optional.of(nmsItemStack));
		}
		dataWatcher.setObject(new WrappedDataWatcherObject(airLevelWatcherIndex, intSerializer), 300);
		dataWatcher.setObject(new WrappedDataWatcherObject(entityStatusIndex, byteSerializer), (byte) 0);
	} else {
		dataWatcher.setObject(itemSlotIndex, nmsItemStack);
		dataWatcher.setObject(airLevelWatcherIndex, 300);
		dataWatcher.setObject(entityStatusIndex, (byte) 0);
	}
}
 
Example #6
Source File: ProtocolService.java    From Transport-Pipes with MIT License 5 votes vote down vote up
@Inject
public ProtocolService(TransportPipes plugin) {
    INT_SERIALIZER = WrappedDataWatcher.Registry.get(Integer.class);
    BYTE_SERIALIZER = WrappedDataWatcher.Registry.get(Byte.class);
    VECTOR_SERIALIZER = WrappedDataWatcher.Registry.get(NMSUtils.getVector3fClass());
    BOOLEAN_SERIALIZER = WrappedDataWatcher.Registry.get(Boolean.class);

    this.plugin = plugin;
}
 
Example #7
Source File: MetadataHelper.java    From HolographicDisplays with GNU General Public License v3.0 5 votes vote down vote up
public void setCustomNameNMSObject(WrappedDataWatcher dataWatcher, Object customNameNMSObject) {
	requireMinimumVersion(NMSVersion.v1_9_R1);
	
	if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_13_R1)) {
		dataWatcher.setObject(new WrappedDataWatcherObject(customNameIndex, chatComponentSerializer), Optional.ofNullable(customNameNMSObject));
	} else {
		dataWatcher.setObject(new WrappedDataWatcherObject(customNameIndex, stringSerializer), customNameNMSObject);
	}
}
 
Example #8
Source File: MetadataHelper.java    From HolographicDisplays with GNU General Public License v3.0 4 votes vote down vote up
public void setArmorStandStatus(WrappedDataWatcher dataWatcher, byte statusBitmask) {
	requireMinimumVersion(NMSVersion.v1_9_R1);
	dataWatcher.setObject(new WrappedDataWatcherObject(armorStandStatusIndex, byteSerializer), statusBitmask);
}
 
Example #9
Source File: MetadataHelper.java    From HolographicDisplays with GNU General Public License v3.0 4 votes vote down vote up
public void setSlimeSize(WrappedDataWatcher dataWatcher, int size) {
	requireMinimumVersion(NMSVersion.v1_15_R1);
	dataWatcher.setObject(new WrappedDataWatcherObject(slimeSizeIndex, intSerializer), size);
}
 
Example #10
Source File: MetadataHelper.java    From HolographicDisplays with GNU General Public License v3.0 4 votes vote down vote up
public void setNoGravity(WrappedDataWatcher dataWatcher, boolean noGravity) {
	requireMinimumVersion(NMSVersion.v1_9_R1);
	dataWatcher.setObject(new WrappedDataWatcherObject(noGravityIndex, booleanSerializer), noGravity);
}
 
Example #11
Source File: MetadataHelper.java    From HolographicDisplays with GNU General Public License v3.0 4 votes vote down vote up
public void setCustomNameVisible(WrappedDataWatcher dataWatcher, boolean customNameVisible) {
	requireMinimumVersion(NMSVersion.v1_9_R1);
	dataWatcher.setObject(new WrappedDataWatcherObject(customNameVisibleIndex, booleanSerializer), customNameVisible);
}
 
Example #12
Source File: MetadataHelper.java    From HolographicDisplays with GNU General Public License v3.0 4 votes vote down vote up
public WrappedWatchableObject getCustomNameWacthableObject(WrappedDataWatcher metadata) {
	return metadata.getWatchableObject(customNameIndex);
}
 
Example #13
Source File: MetadataHelper.java    From HolographicDisplays with GNU General Public License v3.0 4 votes vote down vote up
public void setEntityStatus(WrappedDataWatcher dataWatcher, byte statusBitmask) {
	requireMinimumVersion(NMSVersion.v1_9_R1);
	dataWatcher.setObject(new WrappedDataWatcherObject(entityStatusIndex, byteSerializer), statusBitmask);
}
 
Example #14
Source File: MetadataPacket.java    From AACAdditionPro with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Get the metadata in form of a {@link WrappedDataWatcher}
 */
public WrappedDataWatcher asWatcher()
{
    return this.dataWatcher;
}
 
Example #15
Source File: WrapperPlayServerNamedEntitySpawn.java    From AACAdditionPro with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Set Metadata.
 *
 * @param value - new value.
 */
public void setMetadata(WrappedDataWatcher value)
{
    handle.getDataWatcherModifier().write(0, value);
}
 
Example #16
Source File: WrapperPlayServerSpawnEntityLiving.java    From HolographicDisplays with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Retrieve the data watcher.
 * <p>
 * Content varies by mob, see Entities.
 * @return The current Metadata
*/
public WrappedDataWatcher getMetadata() {
    return handle.getDataWatcherModifier().read(0);
}
 
Example #17
Source File: WrapperPlayServerSpawnEntityLiving.java    From HolographicDisplays with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Set the data watcher.
 * @param value - new value.
*/
public void setMetadata(WrappedDataWatcher value) {
    handle.getDataWatcherModifier().write(0, value);
}
 
Example #18
Source File: WrapperPlayServerNamedEntitySpawn.java    From AACAdditionPro with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Retrieve Metadata.
 * <p>
 * Notes: the client will crash if no metadata is sent
 *
 * @return The current Metadata
 */
public WrappedDataWatcher getMetadata()
{
    return handle.getDataWatcherModifier().read(0);
}
 
Example #19
Source File: WrapperPlayServerSpawnEntityLiving.java    From PacketWrapper with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Retrieve the data watcher. 
 * <p>
 * Content varies by mob, see Entities.
 * @return The current Metadata
*/
public WrappedDataWatcher getMetadata() {
    return handle.getDataWatcherModifier().read(0);
}
 
Example #20
Source File: WrapperPlayServerSpawnEntityLiving.java    From PacketWrapper with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Set the data watcher.
 * @param value - new value.
*/
public void setMetadata(WrappedDataWatcher value) {
    handle.getDataWatcherModifier().write(0, value);
}
 
Example #21
Source File: WrapperPlayServerNamedEntitySpawn.java    From PacketWrapper with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Retrieve the associated metadata object.
 * <p>
 * Note that the 1.3 client crashes on packets with no metadata, but the server can send any metadata 
 * key of 0, 1 or 8 and the client is fine.
 * @return The current metadata.
*/
public WrappedDataWatcher getMetadata() {
    return handle.getDataWatcherModifier().read(0);
}
 
Example #22
Source File: WrapperPlayServerNamedEntitySpawn.java    From PacketWrapper with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Set the associated metadata object. 
 * <p>
 * Note that the 1.3 client crashes on packets with no metadata, but the server can send any metadata 
 * key of 0, 1 or 8 and the client is fine..
 * @param value - new value.
*/
public void setMetadata(WrappedDataWatcher value) {
    handle.getDataWatcherModifier().write(0, value);
}