private boolean feedCmd(CommandSender sender, String args[], boolean any) {
   if ((sender instanceof Player)) {
     sender.sendMessage("Must use ppfeed at the console");
     return true;
   }
   sender.sendMessage("Feeding all pearls: " + pearls.getPearlCount());
   sender.sendMessage(pearls.feedPearls(pearlman));
   return true;
 }
 private boolean restoreCmd(CommandSender sender, String args[], boolean any) {
   if ((sender instanceof Player)) {
     sender.sendMessage("Must use [[restore at the console");
     return true;
   }
   if (!args[0].isEmpty()) {
     sender.sendMessage("Restoring from " + args[0]);
     sender.sendMessage(pearls.restorePearls(pearlman, args[0]));
   } else {
     sender.sendMessage("Restoring from most recent record...");
     sender.sendMessage(pearls.restorePearls(pearlman, null));
   }
   return true;
 }
 private boolean broadcastCmd(CommandSender sender, String args[]) {
   if (args.length != 1) return false;
   if (!(sender instanceof Player)) {
     sender.sendMessage("Command cannot be used at console");
     return true;
   }
   Player player = (Player) sender;
   Player receiver = Bukkit.getPlayerExact(args[0]);
   if (receiver == null) {
     sender.sendMessage("No such player " + args[0]);
     return true;
   } else if (receiver == player) {
     sender.sendMessage("You cannot broadcast to yourself!");
     return true;
   } else if (!pearls.isImprisoned(player)) {
     sender.sendMessage("You are not imprisoned!");
     return true;
   }
   if (broadcastman.addBroadcast(player, receiver)) {
     sender.sendMessage("You will broadcast pplocate information to " + receiver.getDisplayName());
     receiver.sendMessage(
         "Type /ppconfirm to receive pplocate broadcasts from " + player.getDisplayName());
   } else {
     sender.sendMessage("You are already broadcasting to " + receiver.getDisplayName());
   }
   return true;
 }
 private boolean locateCmd(CommandSender sender, String args[], boolean any) {
   String name_is;
   String name_possesive;
   PrisonPearl pp;
   if (!any) {
     if (args.length != 0) return false;
     if (!(sender instanceof Player)) {
       sender.sendMessage("Must use pplocateany at the console");
       return true;
     }
     name_is = "You are";
     name_possesive = "Your";
     pp = pearls.getByImprisoned((Player) sender);
   } else {
     if (args.length != 1) return false;
     name_is = args[0] + " is";
     name_possesive = args[0] + "'s";
     pp = pearls.getByImprisoned(args[0]);
   }
   if (pp != null) {
     if (!pp.verifyLocation()) {
       System.err.println(
           "PrisonPearl for " + pp.getImprisonedName() + " didn't validate, so is now set free");
       pearlman.freePearl(pp);
       plugin
           .getLogger()
           .info(
               pp.getImprisonedName()
                   + " is being freed. Reason: Locate command returned a invalid pearl.");
     } else {
       sender.sendMessage(
           ChatColor.GREEN + name_possesive + " prison pearl is " + pp.describeLocation());
       if (sender instanceof Player && !any)
         broadcastman.broadcast(
             (Player) sender,
             ChatColor.GREEN + pp.getImprisonedName() + ": " + pp.describeLocation());
     }
   } else {
     sender.sendMessage(name_is + " not imprisoned");
   }
   return true;
 }
 private int getCommandPearlSlot(Player player, String args[], int pos) {
   if (args.length <= pos) {
     ItemStack item = player.getItemInHand();
     if (item.getType() != Material.ENDER_PEARL) {
       player.sendMessage("You must hold a pearl or supply the player's name to use this command");
       return -1;
     }
     if (pearls.getByItemStack(item) == null) {
       player.sendMessage("This is an ordinary ender pearl");
       return -1;
     }
     return player.getInventory().getHeldItemSlot();
   } else {
     PrisonPearl pp = pearls.getByImprisoned(args[pos]);
     if (pp != null) {
       Inventory inv = player.getInventory();
       for (Entry<Integer, ? extends ItemStack> entry : inv.all(Material.ENDER_PEARL).entrySet()) {
         if (entry.getValue().getDurability() == pp.getID()) return entry.getKey();
       }
     }
     player.sendMessage("You don't possess " + args[0] + "'s prison pearl");
     return -1;
   }
 }
 private boolean freeCmd(CommandSender sender, String args[], boolean any) {
   PrisonPearl pp;
   if (!any) {
     if (args.length > 1) return false;
     if (!(sender instanceof Player)) {
       sender.sendMessage("Must use freeany at console");
       return true;
     }
     Player player = (Player) sender;
     int slot = getCommandPearlSlot(player, args, 0);
     if (slot == -1) return true;
     pp = pearls.getByItemStack(player.getInventory().getItem(slot));
     player.getInventory().setItem(slot, null);
   } else {
     if (args.length != 1) return false;
     pp = pearls.getByImprisoned(args[0]);
     if (pp == null) {
       sender.sendMessage(args[0] + " is not imprisoned");
       return true;
     }
   }
   if (pearlman.freePearl(pp)) {
     plugin
         .getLogger()
         .info(
             pp.getImprisonedName()
                 + " is being freed. Reason: Freed via command by "
                 + sender.getName());
     if (pp.getImprisonedPlayer()
         != sender) // when freeing yourself, you're already going to get a message
     sender.sendMessage("You've freed " + pp.getImprisonedName());
   } else {
     sender.sendMessage("You failed to free " + pp.getImprisonedName());
   }
   return true;
 }
 private PrisonPearl getCommandPearl(Player player, String args[], int pos) {
   int slot = getCommandPearlSlot(player, args, pos);
   if (slot != -1) return pearls.getByItemStack(player.getInventory().getItem(slot));
   else return null;
 }