Sets the MaterialData for this stack of items @param data New MaterialData for this item
(@Nullable MaterialData data)
| 184 | * @param data New MaterialData for this item |
| 185 | */ |
| 186 | public void setData(@Nullable MaterialData data) { |
| 187 | if (data == null) { |
| 188 | this.data = data; |
| 189 | } else { |
| 190 | Material mat = Bukkit.getUnsafe().toLegacy(getType()); |
| 191 | |
| 192 | if ((data.getClass() == mat.getData()) || (data.getClass() == MaterialData.class)) { |
| 193 | this.data = data; |
| 194 | } else { |
| 195 | throw new IllegalArgumentException("Provided data is not of type " + mat.getData().getName() + ", found " + data.getClass().getName()); |
| 196 | } |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | /** |
| 201 | * Sets the durability of this item |