com.comphenix.protocol.wrappers.WrappedWatchableObject Java Examples

The following examples show how to use com.comphenix.protocol.wrappers.WrappedWatchableObject. 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: MetadataHelper.java    From HolographicDisplays with GNU General Public License v3.0 6 votes vote down vote up
public Object getCustomNameNMSObject(WrappedWatchableObject customNameWatchableObject) {
	Object customNameNMSObject = customNameWatchableObject.getRawValue();
	if (customNameNMSObject == null) {
		return null;
	}
	
	if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_13_R1)) {
		if (!(customNameNMSObject instanceof Optional)) {
			throw new IllegalArgumentException("Expected custom name of type " + Optional.class);
		}
		
		return ((Optional<?>) customNameNMSObject).orElse(null);
		
	} else {			
		if (!(customNameNMSObject instanceof String)) {
			throw new IllegalArgumentException("Expected custom name of type " + String.class);
		}
		
		return (String) customNameNMSObject;
	}
}
 
Example #2
Source File: ProtocolLibHookImpl.java    From HolographicDisplays with GNU General Public License v3.0 6 votes vote down vote up
private boolean replaceRelativePlaceholders(WrappedWatchableObject customNameWatchableObject, Player player, Collection<RelativePlaceholder> relativePlaceholders) {
	if (customNameWatchableObject == null) {
		return false;
	}
	
	final Object originalCustomNameNMSObject = metadataHelper.getCustomNameNMSObject(customNameWatchableObject);
	if (originalCustomNameNMSObject == null) {
		return false;
	}
	
	Object replacedCustomNameNMSObject = originalCustomNameNMSObject;
	for (RelativePlaceholder relativePlaceholder : relativePlaceholders) {
		replacedCustomNameNMSObject = nmsManager.replaceCustomNameText(replacedCustomNameNMSObject, relativePlaceholder.getTextPlaceholder(), relativePlaceholder.getReplacement(player));
	}
	
	if (replacedCustomNameNMSObject == originalCustomNameNMSObject) {
		// It means nothing has been replaced, since original custom name has been returned.
		return false;
	}
	
	metadataHelper.setCustomNameNMSObject(customNameWatchableObject, replacedCustomNameNMSObject);
	return true;
}
 
Example #3
Source File: SpigotProtocolHackPacketListener.java    From EchoPet with GNU General Public License v3.0 5 votes vote down vote up
private void removeKey(int key, List<WrappedWatchableObject> wrappedWatchableObjectList) {
    for (Iterator<WrappedWatchableObject> wrappedWatchableObjectIterator = wrappedWatchableObjectList.iterator(); wrappedWatchableObjectIterator.hasNext(); ) {
        WrappedWatchableObject next = wrappedWatchableObjectIterator.next();
        if (next.getIndex() == key) {
            wrappedWatchableObjectIterator.remove();
            break;
        }
    }
}
 
Example #4
Source File: SpigotProtocolHackPacketListener.java    From EchoPet with GNU General Public License v3.0 5 votes vote down vote up
private Object getKeyValue(int key, List<WrappedWatchableObject> wrappedWatchableObjectList) {
    for (Iterator<WrappedWatchableObject> wrappedWatchableObjectIterator = wrappedWatchableObjectList.iterator(); wrappedWatchableObjectIterator.hasNext(); ) {
        WrappedWatchableObject next = wrappedWatchableObjectIterator.next();
        if (next.getIndex() == key) {
            return next.getValue();
        }
    }
    return null;
}
 
Example #5
Source File: SpigotProtocolHackPacketListener.java    From EchoPet with GNU General Public License v3.0 5 votes vote down vote up
private boolean hasKey(int key, List<WrappedWatchableObject> wrappedWatchableObjectList) {
    for (Iterator<WrappedWatchableObject> wrappedWatchableObjectIterator = wrappedWatchableObjectList.iterator(); wrappedWatchableObjectIterator.hasNext(); ) {
        WrappedWatchableObject next = wrappedWatchableObjectIterator.next();
        if (next.getIndex() == key) {
            return true;
        }
    }
    return false;
}
 
Example #6
Source File: MetadataHelper.java    From HolographicDisplays with GNU General Public License v3.0 5 votes vote down vote up
public void setCustomNameNMSObject(WrappedWatchableObject customNameWatchableObject, Object customNameNMSObject) {
	if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_13_R1)) {
		customNameWatchableObject.setValue(Optional.ofNullable(customNameNMSObject));
	} else {
		customNameWatchableObject.setValue(customNameNMSObject);
	}
}
 
Example #7
Source File: MetadataHelper.java    From HolographicDisplays with GNU General Public License v3.0 5 votes vote down vote up
public WrappedWatchableObject getCustomNameWatchableObject(List<WrappedWatchableObject> dataWatcherValues) {
	for (int i = 0; i < dataWatcherValues.size(); i++) {
		WrappedWatchableObject watchableObject = dataWatcherValues.get(i);
		
		if (watchableObject.getIndex() == customNameIndex) {
			return watchableObject;
		}
	}
	
	return null;
}
 
Example #8
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 #9
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 List} of {@link WrappedWatchableObject}s.
 */
public List<WrappedWatchableObject> asList()
{
    return this.dataWatcher.getWatchableObjects();
}
 
Example #10
Source File: PacketIndividualHologramFactory.java    From helper with MIT License 4 votes vote down vote up
@Override
public void addViewer(@Nonnull Player player) {
    if (!this.viewers.add(player)) {
        return;
    }

    boolean modern = MinecraftVersion.getRuntimeVersion().isAfterOrEq(MinecraftVersions.v1_9);

    // handle resending
    for (HologramEntity entity : this.spawnedEntities) {
        PacketContainer spawnPacket = new PacketContainer(PacketType.Play.Server.SPAWN_ENTITY);
        spawnPacket.getModifier().writeDefaults();

        // write entity id
        spawnPacket.getIntegers().write(0, entity.getId());

        // write unique id
        if (modern) {
            spawnPacket.getUUIDs().write(0, entity.getArmorStand().getUniqueId());
        }

        // write coordinates
        Location loc = entity.getArmorStand().getLocation();

        if (modern) {
            spawnPacket.getDoubles().write(0, loc.getX());
            spawnPacket.getDoubles().write(1, loc.getY());
            spawnPacket.getDoubles().write(2, loc.getZ());
        } else {
            spawnPacket.getIntegers().write(1, (int) Math.floor(loc.getX() * 32));
            spawnPacket.getIntegers().write(2, (int) Math.floor(loc.getY() * 32));
            spawnPacket.getIntegers().write(3, (int) Math.floor(loc.getZ() * 32));
        }
        spawnPacket.getIntegers().write(modern ? 4 : 7, (int) ((loc.getPitch()) * 256.0F / 360.0F));
        spawnPacket.getIntegers().write(modern ? 5 : 8, (int) ((loc.getYaw()) * 256.0F / 360.0F));

        // write type
        spawnPacket.getIntegers().write(modern ? 6 : 9, 78);

        // write object data
        spawnPacket.getIntegers().write(modern ? 7 : 10, 0);

        // send it
        Protocol.sendPacket(player, spawnPacket);


        // send missed metadata
        PacketContainer metadataPacket = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);

        // write entity id
        metadataPacket.getIntegers().write(0, entity.getId());

        // write metadata
        List<WrappedWatchableObject> watchableObjects = new ArrayList<>();
        // set custom name
        watchableObjects.add(new WrappedWatchableObject(2, Text.colorize(entity.getLine().resolve(player))));
        // set custom name visible
        if (modern) {
            watchableObjects.add(new WrappedWatchableObject(3, true));
        } else {
            watchableObjects.add(new WrappedWatchableObject(3, (byte) 1));
        }

        // re-add all other cached metadata
        for (Map.Entry<Integer, WrappedWatchableObject> ent : entity.getCachedMetadata().entrySet()) {
            if (ent.getKey() != 2 && ent.getKey() != 3) {
                watchableObjects.add(ent.getValue());
            }
        }

        metadataPacket.getWatchableCollectionModifier().write(0, watchableObjects);

        // send it
        Protocol.sendPacket(player, metadataPacket);
    }
}
 
Example #11
Source File: PacketIndividualHologramFactory.java    From helper with MIT License 4 votes vote down vote up
public Map<Integer, WrappedWatchableObject> getCachedMetadata() {
    return this.cachedMetadata;
}
 
Example #12
Source File: WrapperPlayServerEntityMetadata.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(List<WrappedWatchableObject> value)
{
    handle.getWatchableCollectionModifier().write(0, value);
}
 
Example #13
Source File: WrapperPlayServerEntityMetadata.java    From AACAdditionPro with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Retrieve Metadata.
 *
 * @return The current Metadata
 */
public List<WrappedWatchableObject> getMetadata()
{
    return handle.getWatchableCollectionModifier().read(0);
}
 
Example #14
Source File: WrapperPlayServerEntityMetadata.java    From HolographicDisplays with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Retrieve a list of all the watchable objects.
 * <p>
 * This can be converted to a data watcher using {@link WrappedDataWatcher#WrappedDataWatcher(List) WrappedDataWatcher(List)}
 * @return The current metadata
*/
public List<WrappedWatchableObject> getEntityMetadata() {
    return handle.getWatchableCollectionModifier().read(0);
}
 
Example #15
Source File: WrapperPlayServerEntityMetadata.java    From HolographicDisplays with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Set the list of the watchable objects (meta data).
 * @param value - new value.
*/
public void setEntityMetadata(List<WrappedWatchableObject> value) {
    handle.getWatchableCollectionModifier().write(0, value);
}
 
Example #16
Source File: WrapperPlayServerEntityMetadata.java    From PacketWrapper with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Retrieve a list of all the watchable objects.
 * <p>
 * This can be converted to a data watcher using {@link WrappedDataWatcher#WrappedDataWatcher(List) WrappedDataWatcher(List)}
 * @return The current metadata
*/
public List<WrappedWatchableObject> getEntityMetadata() {
    return handle.getWatchableCollectionModifier().read(0);
}
 
Example #17
Source File: WrapperPlayServerEntityMetadata.java    From PacketWrapper with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Set the list of the watchable objects (meta data).
 * @param value - new value.
*/
public void setEntityMetadata(List<WrappedWatchableObject> value) {
    handle.getWatchableCollectionModifier().write(0, value);
}