-
Notifications
You must be signed in to change notification settings - Fork 0
Writing plugins
Most Bukkit plugins already work with all new blocks and items in Fiddle!
You can get and use all custom blocks and items with the regular Bukkit API with matchMaterial
:
Material willowLog = Material.matchMaterial("willows:willow_log");
▻ Paper Javadoc for Material.matchMaterial(...)
(returns null if the Material doesn't exist)
✔️ Use material.getKey().toString()
Example return value: "willows:willow_log"
▻ Material.getKey()
❌ Do not use material.toString()
or material.name()
Doing this will usually work, but you should not rely on these.
Some of your pack's blocks or items may have been aliased.
Therefore, you must never compared namespaced keys of Material
instances, but instead compare the Material
instances directly.
✔️ Comparing Material
instances directly is good:
// Comparing two Materials is good! This example uses equals()
if (block.getType() == Material.matchMaterial("willows:willow_log")) {
...
}
❌ Do not do compare the strings or NamespacedKey
s:
// Comparing two Materials' namespaced keys as strings is bad:
if (block.getType().getKey().toString().equals("willows:willow_log")) {
...
}
// Comparing two Materials' namespaced keys as NamespacedKeys is bad:
if (block.getType().getKey().equals(new NamespacedKey("willows", "willow_log"))) {
...
}
In addition to the above, you must never use Material
namespaced keys as a key in maps, but instead use Material
directly.
✔️ Using Material
directly is good:
// Using Material as keys in a map is good!
Map<Material, Integer> countPerMaterial = new HashMap<>();
...
countPerMaterial.put(Material.matchMaterial("willows:willow_log"), 5);
countPerMaterial.put(block.getType(), 6);
❌ Do not do use the strings or NamespacedKey
s:
// Using Materials' namespaced keys (as strings) as keys in a map is bad:
Map<String, Integer> countPerMaterial = new HashMap<>();
...
countPerMaterial.put("willows:willow_log", 5);
countPerMaterial.put(block.getType().getKey().toString(), 6);
// Using Materials' namespaced keys (as NamespacedKeys) as keys in a map is bad:
Map<NamespacedKey, Integer> countPerMaterial = new HashMap<>();
...
countPerMaterial.put(new NamespacedKey("willows", "willow_log"), 5);
countPerMaterial.put(block.getType().getKey(), 6);