SHARE
TWEET

Aditional /head command for craftbook

Darker666 Sep 21st, 2013 36 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.         @Command(aliases = {"head", "gethead"},
  2.                         usage = "[player]", desc = "Get a player's head",
  3.                         flags = "c", min = 0, max = 64)
  4.         @CommandPermissions({"commandbook.head"})
  5.         public void head(CommandContext args,CommandSender sender) throws CommandException {    
  6.             Iterable<Player> targets = null;
  7.             CommandBook.inst().checkPermission(sender, "commandbook.head");
  8.            
  9.             if (args.argsLength() == 0) {
  10.                 //Use current player
  11.                 targets = PlayerUtil.matchPlayers(PlayerUtil.checkPlayer(sender));
  12.             } else if (args.argsLength() == 1) {
  13.                 try {
  14.                   //Use matched players
  15.                   targets = PlayerUtil.matchPlayers(sender, args.getString(0));
  16.                 }  
  17.                 catch (CommandException e) {
  18.                   //use exact string if no players matched
  19.                   String name = args.getString(0);
  20.                   String displayName = "";
  21.                   //Only allow valid minecraft usernames
  22.                   if(!name.matches("^[a-zA-Z0-9_]{3,16}$")) {
  23.                     throw new CommandException("Invalid username. Head cannot be created.");
  24.                   }
  25.                   ItemStack head = new ItemStack(Material.SKULL_ITEM, 1, (short) 3);
  26.                   SkullMeta meta = (SkullMeta)head.getItemMeta();
  27.                   meta.setOwner(name);
  28.                  
  29.                   //Special coloring for known mob-heads
  30.                   if(name.equals("MHF_Pig"))
  31.                     displayName = ChatColor.RESET.toString()+ChatColor.LIGHT_PURPLE.toString() + "Pig's"+ChatColor.RESET.toString();
  32.                   else if(name.equals("MHF_PigZombie"))
  33.                     displayName = (ChatColor.RESET.toString()+ChatColor.GREEN.toString() + "Zombie pig's"+ChatColor.RESET.toString());
  34.                   else if(name.equals("MHF_Sheep"))
  35.                     displayName = (ChatColor.RESET.toString() + "Sheep's");
  36.                   else if(name.equals("MHF_Villager"))
  37.                     displayName = (ChatColor.RESET.toString()+ChatColor.DARK_RED.toString() + "Villager's"+ChatColor.RESET.toString());
  38.                   else if(name.equals("MHF_Blaze"))
  39.                     displayName = (ChatColor.RESET.toString()+ChatColor.GOLD.toString() + "Blaze's"+ChatColor.RESET.toString());
  40.                   else if(name.equals("MHF_Herobrine"))
  41.                     displayName = (ChatColor.RESET.toString()+ChatColor.YELLOW.toString()+ChatColor.BOLD.toString() + "Herobrine's"+ChatColor.RESET.toString());
  42.                   else
  43.                     displayName = (ChatColor.RESET.toString() + name);
  44.                   //Set display name
  45.                   meta.setDisplayName(displayName+" head");
  46.                   head.setItemMeta(meta);
  47.                   PlayerUtil.checkPlayer(sender).getInventory().addItem(head);
  48.                   sender.sendMessage(ChatColor.YELLOW.toString() + "Giving you "+displayName+ChatColor.YELLOW+" head.");
  49.                   return;
  50.                 }
  51.             }
  52.  
  53.            
  54.            
  55.            
  56.             ItemStack head = null;
  57.             int count = 0;
  58.             //Is it fine to add items in loop?
  59.            
  60.             for (Player player : targets) {
  61.               //head = ItemStack.makeHead(player.getName());//(Material.SKULL_ITEM, 1, (short) 3);
  62.               head = new ItemStack(Material.SKULL_ITEM, 1, (short) 3);
  63.               SkullMeta meta = (SkullMeta)head.getItemMeta();
  64.               meta.setOwner(player.getName());
  65.               meta.setDisplayName(ChatColor.RESET + player.getDisplayName() + "'s Head");
  66.               head.setItemMeta(meta);
  67.               //head.makeHead(player.getName());  
  68.               PlayerUtil.checkPlayer(sender).getInventory().addItem(head);
  69.               count++;
  70.               //CommandBookUtil.giveItem(sender, head, 1, sender, PlayerComponent.this);
  71.             }  
  72.             sender.sendMessage(ChatColor.YELLOW.toString() + Integer.toString(count)+" heads given.");
  73.         }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top