Created
September 14, 2018 21:51
-
-
Save TheFlash787/3fac7fdd8ffcf902cb48168d23c0dec6 to your computer and use it in GitHub Desktop.
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
Player player = (Player)src; | |
Optional<ItemStack> handItemOptional = player.getItemInHand(MAIN_HAND); | |
if(handItemOptional.isPresent()){ | |
ItemStack handItem = handItemOptional.get(); | |
int amount = handItem.getQuantity(); | |
boolean isBlock = false; | |
String soundName; | |
String itemId = handItem.createSnapshot().getType().getName(); | |
String itemName = handItem.get(Keys.DISPLAY_NAME).orElse(Text.of(handItem.getType().getName())).toPlain(); | |
if(handItem.createSnapshot().getType().getBlock().isPresent()){ | |
isBlock = true; | |
soundName = handItem.createSnapshot().getType().getBlock().get().getSoundGroup().getPlaceSound().getName(); | |
} | |
else{ | |
soundName = "N/A"; | |
} | |
player.sendMessage(Text.of("Item ID: ", itemId)); | |
player.sendMessage(Text.of("Item Name: ", itemName)); | |
player.sendMessage(Text.of("Is it a block? ", isBlock)); | |
player.sendMessage(Text.of("Amount: ", amount)); | |
player.sendMessage(Text.of("Sound name: ", soundName)); | |
} | |
else{ | |
player.sendMessage(Text.of("You have no items in your hand!")); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment