Last active
July 26, 2021 18:08
-
-
Save Yuhtin/d142fe4bac27c8ccfbbf25825c3a5397 to your computer and use it in GitHub Desktop.
Support materials from 1.8 to 1.17 with data (colors)
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
public final class MaterialUtils { | |
public static ItemStack convertFromLegacy(String materialName, int damage) { | |
try { | |
return new ItemStack(Material.getMaterial(materialName), 1, (short) damage); | |
} catch (Exception error) { | |
Material material = Material.valueOf("LEGACY_" + materialName); | |
return new ItemStack(Bukkit.getUnsafe().fromLegacy(new MaterialData(material, (byte) damage))); | |
} | |
} | |
} |
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
public final class UserDisconnectListener implements Listener { | |
@EventHandler | |
public void onJoin(PlayerJoinEvent event) { | |
PlayerInventory inventory = event.getPlayer().getInventory(); | |
inventory.addItem(MaterialUtils.convertFromLegacy("WOOL", 14)); | |
// add a red wool to player (1.8 & 1.17) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment