Java Code Examples for us.myles.ViaVersion.api.type.Type#getTypeName()

The following examples show how to use us.myles.ViaVersion.api.type.Type#getTypeName() . 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: PacketWrapper.java    From ViaVersion with MIT License 5 votes vote down vote up
/**
 * Get a part from the output
 *
 * @param type  The type of the part you wish to get.
 * @param <T>   The return type of the type you wish to get.
 * @param index The index of the part (relative to the type)
 * @return The requested type or throws ArrayIndexOutOfBounds
 * @throws InformativeException If it fails to find it, an exception will be thrown.
 */
public <T> T get(Type<T> type, int index) throws Exception {
    int currentIndex = 0;
    for (Pair<Type, Object> packetValue : packetValues) {
        if (packetValue.getKey() == type) { // Ref check
            if (currentIndex == index) {
                return (T) packetValue.getValue();
            }
            currentIndex++;
        }
    }

    Exception e = new ArrayIndexOutOfBoundsException("Could not find type " + type.getTypeName() + " at " + index);
    throw new InformativeException(e).set("Type", type.getTypeName()).set("Index", index).set("Packet ID", getId()).set("Data", packetValues);
}
 
Example 2
Source File: PacketWrapper.java    From ViaVersion with MIT License 5 votes vote down vote up
/**
 * Set a currently existing part in the output
 *
 * @param type  The type of the part you wish to set.
 * @param <T>   The return type of the type you wish to set.
 * @param index The index of the part (relative to the type)
 * @param value The value of the part you wish to set it to.
 * @throws InformativeException If it fails to set it, an exception will be thrown.
 */
public <T> void set(Type<T> type, int index, T value) throws Exception {
    int currentIndex = 0;
    for (Pair<Type, Object> packetValue : packetValues) {
        if (packetValue.getKey() == type) { // Ref check
            if (currentIndex == index) {
                packetValue.setValue(value);
                return;
            }
            currentIndex++;
        }
    }
    Exception e = new ArrayIndexOutOfBoundsException("Could not find type " + type.getTypeName() + " at " + index);
    throw new InformativeException(e).set("Type", type.getTypeName()).set("Index", index).set("Packet ID", getId());
}
 
Example 3
Source File: ArrayType.java    From ViaVersion with MIT License 4 votes vote down vote up
public ArrayType(Type<T> type) {
    super(type.getTypeName() + " Array", (Class<T[]>) getArrayClass(type.getOutputClass()));
    this.elementType = type;
}