Skip to content

Instantly share code, notes, and snippets.

@TheFlash787
Created September 14, 2018 21:51
Show Gist options
  • Save TheFlash787/3fac7fdd8ffcf902cb48168d23c0dec6 to your computer and use it in GitHub Desktop.
Save TheFlash787/3fac7fdd8ffcf902cb48168d23c0dec6 to your computer and use it in GitHub Desktop.
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