Advertisement
BlackDereker

Answer #1

Jan 23rd, 2015
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.00 KB | None | 0 0
  1.         //The command
  2.         if(commandLabel.equalsIgnoreCase("rename")){
  3.            
  4.             //Only works if the player type the name
  5.             if(args.length == 1){
  6.                
  7.                 //Item at player's hand
  8.                 ItemStack item = player.getItemInHand();
  9.    
  10.                
  11.                
  12.                 //Cheking if he has a item at his hand
  13.                 if(item.getType() != Material.AIR){
  14.                    
  15.                 //Getting the name that he typed and add the color too 
  16.                 String name = ChatColor.translateAlternateColorCodes('&', args[0]);
  17.                    
  18.                 //Getting the itemdata from the item
  19.                 ItemMeta meta = item.getItemMeta();
  20.                
  21.                 //Setting the item's name to the name that the player typed
  22.                 meta.setDisplayName(name);
  23.                 //Setting the ItemData to the item
  24.                 item.setItemMeta(meta);
  25.                 //Update the player's inventory
  26.                 player.updateInventory();
  27.                
  28.                
  29.                 //Send a message if everything goes right (if you dont want taht just delete it)
  30.                 player.sendMessage(ChatColor.GREEN + "Item renamed to: " + ChatColor.YELLOW + name);
  31.                
  32.                
  33.                 //DONE
  34.                 }
  35.             }
  36.            
  37.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement