Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //The command
- if(commandLabel.equalsIgnoreCase("rename")){
- //Only works if the player type the name
- if(args.length == 1){
- //Item at player's hand
- ItemStack item = player.getItemInHand();
- //Cheking if he has a item at his hand
- if(item.getType() != Material.AIR){
- //Getting the name that he typed and add the color too
- String name = ChatColor.translateAlternateColorCodes('&', args[0]);
- //Getting the itemdata from the item
- ItemMeta meta = item.getItemMeta();
- //Setting the item's name to the name that the player typed
- meta.setDisplayName(name);
- //Setting the ItemData to the item
- item.setItemMeta(meta);
- //Update the player's inventory
- player.updateInventory();
- //Send a message if everything goes right (if you dont want taht just delete it)
- player.sendMessage(ChatColor.GREEN + "Item renamed to: " + ChatColor.YELLOW + name);
- //DONE
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement