Java Code Examples for org.bukkit.Material#getData()

The following examples show how to use org.bukkit.Material#getData() . 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: MaterialEncoder.java    From PGM with GNU Affero General Public License v3.0 5 votes vote down vote up
static MaterialData decodeMaterial(int encoded) {
  if (encoded == ENCODED_NULL_MATERIAL) return null;
  Material material = decodeType(encoded);
  if (material.getData() == MaterialData.class) {
    return new MaterialData(material, decodeMetadata(encoded));
  } else {
    return material.getNewData(decodeMetadata(encoded));
  }
}
 
Example 2
Source File: ItemStack.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Gets the MaterialData for this stack of items
 *
 * @return MaterialData for this item
 */
public MaterialData getData() {
    Material mat = getType();
    if (data == null && mat != null && mat.getData() != null) {
        data = mat.getNewData((byte) this.getDurability());
    }

    return data;
}
 
Example 3
Source File: ItemStack.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Sets the MaterialData for this stack of items
 *
 * @param data New MaterialData for this item
 */
public void setData(MaterialData data) {
    Material mat = getType();

    if (data == null || mat == null || mat.getData() == null) {
        this.data = data;
    } else {
        if ((data.getClass() == mat.getData()) || (data.getClass() == MaterialData.class)) {
            this.data = data;
        } else {
            throw new IllegalArgumentException("Provided data is not of type " + mat.getData().getName() + ", found " + data.getClass().getName());
        }
    }
}
 
Example 4
Source File: CraftBlockState.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
public void setData(final MaterialData data) {
    Material mat = getType();

    if ((mat == null) || (mat.getData() == null)) {
        this.data = data;
    } else {
        if ((data.getClass() == mat.getData()) || (data.getClass() == MaterialData.class)) {
            this.data = data;
        } else {
            throw new IllegalArgumentException("Provided data is not of type "
                    + mat.getData().getName() + ", found " + data.getClass().getName());
        }
    }
}
 
Example 5
Source File: CraftBlockState.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
private void createData(final byte data) {
    Material mat = getType();
    if (mat == null || mat.getData() == null) {
        this.data = new MaterialData(type, data);
    } else {
        this.data = mat.getNewData(data);
    }
}
 
Example 6
Source File: MaterialUtils.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
public static MaterialData decodeMaterial(int encoded) {
    if(encoded == ENCODED_NULL_MATERIAL) return null;
    Material material = decodeType(encoded);
    if(material.getData() == MaterialData.class) {
        return new MaterialData(material, decodeMetadata(encoded));
    } else {
        return material.getNewData(decodeMetadata(encoded));
    }
}
 
Example 7
Source File: ItemStackImpl.java    From Civs with GNU General Public License v3.0 5 votes vote down vote up
public MaterialData getData() {
    Material mat = Bukkit.getUnsafe().toLegacy(this.getType());
    if (this.data == null && mat != null && mat.getData() != null) {
        this.data = mat.getNewData((byte)this.getDurability());
    }

    return this.data;
}
 
Example 8
Source File: ItemStackImpl.java    From Civs with GNU General Public License v3.0 5 votes vote down vote up
public void setData(MaterialData data) {
    Material mat = Bukkit.getUnsafe().toLegacy(this.getType());
    if (data != null && mat != null && mat.getData() != null) {
        if (data.getClass() != mat.getData() && data.getClass() != MaterialData.class) {
            throw new IllegalArgumentException("Provided data is not of type " + mat.getData().getName() + ", found " + data.getClass().getName());
        }

        this.data = data;
    } else {
        this.data = data;
    }

}
 
Example 9
Source File: CraftBlockState.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
public void setData(final MaterialData data) {
    Material mat = getType();

    if ((mat == null) || (mat.getData() == null)) {
        this.data = data;
    } else {
        if ((data.getClass() == mat.getData()) || (data.getClass() == MaterialData.class)) {
            this.data = data;
        } else {
            throw new IllegalArgumentException("Provided data is not of type "
                    + mat.getData().getName() + ", found " + data.getClass().getName());
        }
    }
}
 
Example 10
Source File: CraftBlockState.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
private void createData(final byte data) {
    Material mat = getType();
    if (mat == null || mat.getData() == null) {
        this.data = new MaterialData(type, data);
    } else {
        this.data = mat.getNewData(data);
    }
}