-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Support for Custom Item definitions for JSON Advancements and the…
… showtoast command Custom Item Definitions define the Custom Model Data of an Item. The Custom Definition can then be used in JSON Advancements and the showtoast command
- Loading branch information
1 parent
8e5ad50
commit fb2ea25
Showing
3 changed files
with
164 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/eu/endercentral/crazy_advancements/item/CustomItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package eu.endercentral.crazy_advancements.item; | ||
|
||
import org.bukkit.Material; | ||
|
||
import eu.endercentral.crazy_advancements.NameKey; | ||
|
||
public class CustomItem { | ||
|
||
private final NameKey name; | ||
private final Material type; | ||
private final int customModelData; | ||
|
||
public CustomItem(NameKey name, Material type, int customModelData) { | ||
if(name == null) { | ||
throw new RuntimeException("Custom Item Name may not be null"); | ||
} | ||
if(type == null) { | ||
throw new RuntimeException("Custom Item Type may not be null"); | ||
} | ||
if(!type.isItem()) { | ||
throw new RuntimeException("Can't create Custom Item from non-item Type '" + type.name().toLowerCase() + "'"); | ||
} | ||
this.name = name; | ||
this.type = type; | ||
this.customModelData = customModelData; | ||
} | ||
|
||
public NameKey getName() { | ||
return name; | ||
} | ||
|
||
public Material getType() { | ||
return type; | ||
} | ||
|
||
public int getCustomModelData() { | ||
return customModelData; | ||
} | ||
|
||
public SerializedCustomItem serialize() { | ||
return new SerializedCustomItem(type.name().toLowerCase(), customModelData); | ||
} | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
src/eu/endercentral/crazy_advancements/item/SerializedCustomItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package eu.endercentral.crazy_advancements.item; | ||
|
||
import org.bukkit.Material; | ||
|
||
import eu.endercentral.crazy_advancements.NameKey; | ||
|
||
public class SerializedCustomItem { | ||
|
||
private final String item; | ||
private final int customModelData; | ||
|
||
public SerializedCustomItem(String item, int customModelData) { | ||
this.item = item; | ||
this.customModelData = customModelData; | ||
} | ||
|
||
public String getItem() { | ||
return item; | ||
} | ||
|
||
public int getCustomModelData() { | ||
return customModelData; | ||
} | ||
|
||
public CustomItem deserialize(NameKey name) { | ||
Material type = Material.matchMaterial(getItem()); | ||
return new CustomItem(name, type, customModelData); | ||
} | ||
|
||
} |