Java Code Examples for com.comphenix.protocol.wrappers.WrappedDataWatcher#setObject()

The following examples show how to use com.comphenix.protocol.wrappers.WrappedDataWatcher#setObject() . 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: 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 3
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 4
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 5
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 6
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 7
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 8
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);
}