Esempio n. 1
0
 @Override
 public boolean execute(
     KarmicLives plugin, CommandSender sender, Command command, String label, String[] args) {
   String name = plugin.expandName(args[0]);
   if (name == null) {
     // Just use as is, as they might be an offline player
     name = args[0];
   }
   if (!plugin.hasPermissionNode(sender, PermissionNode.VIEW) && !sender.getName().equals(name)) {
     sender.sendMessage(
         ChatColor.GRAY
             + plugin.getTag()
             + ChatColor.RED
             + " Lack permission: "
             + PermissionNode.VIEW.getNode());
     return true;
   }
   if (!plugin.getLivesConfig().playerExists(name)) {
     sender.sendMessage(
         ChatColor.GRAY
             + plugin.getTag()
             + ChatColor.RED
             + " Could not find player with name: "
             + name);
     return false;
   }
   final int lives = plugin.getLivesConfig().getLives(name);
   ChatColor status = ChatColor.GOLD;
   if (plugin.getCooldowns().containsKey(name)) {
     status = ChatColor.DARK_RED;
   }
   sender.sendMessage(
       ChatColor.GRAY
           + plugin.getTag()
           + " "
           + ChatColor.AQUA
           + name
           + ChatColor.WHITE
           + "'s lives: "
           + status
           + lives);
   return true;
 }
Esempio n. 2
0
 @Override
 public boolean execute(
     final KarmicLives plugin,
     CommandSender sender,
     Command command,
     String label,
     String[] args) {
   if (!(sender instanceof Player)) {
     sender.sendMessage(
         ChatColor.GRAY + plugin.getTag() + ChatColor.RED + " Cannot buy lives as a non-player.");
     return true;
   }
   // Check permissions
   if (!plugin.hasPermissionNode(sender, PermissionNode.USE)) {
     sender.sendMessage(
         ChatColor.GRAY
             + plugin.getTag()
             + ChatColor.RED
             + " Lack Permission: "
             + ChatColor.WHITE
             + PermissionNode.USE.getNode());
     return true;
   } else if (!plugin.hasPermissionNode(sender, PermissionNode.SELL)) {
     sender.sendMessage(
         ChatColor.GRAY
             + plugin.getTag()
             + ChatColor.RED
             + " Lack Permission: "
             + ChatColor.WHITE
             + PermissionNode.SELL.getNode());
     return true;
   }
   // determine amount to buy
   int amount = plugin.getRootConfig().getInt(RootConfigNode.LIVES_BUNDLE);
   if (args.length > 0) {
     try {
       amount = Integer.parseInt(args[0]);
     } catch (NumberFormatException e) {
       sender.sendMessage(
           ChatColor.GRAY
               + plugin.getTag()
               + ChatColor.RED
               + " Invalid number: "
               + ChatColor.WHITE
               + args[0]);
       return true;
     }
   }
   final int current = plugin.getLivesConfig().getLives(sender.getName());
   // Check if player has enough lives to sell
   if (current < amount) {
     sender.sendMessage(
         ChatColor.GRAY + plugin.getTag() + ChatColor.YELLOW + " Lack lives. Setting to max");
     amount = current;
   }
   if (amount <= 0) {
     // No lives to sell
     sender.sendMessage(ChatColor.GRAY + plugin.getTag() + ChatColor.RED + " No lives to sell.");
     return true;
   }
   // check if player ignores cost
   if (plugin.hasPermissionNode(sender, PermissionNode.IGNORE_COST)) {
     // skip to giving player amount
     plugin.getLivesConfig().set(sender.getName(), current - amount);
     return true;
   } else if (plugin.getEconomy() == null) {
     sender.sendMessage(
         ChatColor.GRAY
             + plugin.getTag()
             + ChatColor.DARK_RED
             + " Economy not found! Check your economy plugin or Vault.");
     return true;
   }
   // determine cost
   final double cost = plugin.getRootConfig().getDouble(RootConfigNode.LIVES_COST) * amount;
   // confirm sell lives
   final Map<Object, Object> map = new HashMap<Object, Object>();
   map.put("amount", amount);
   map.put("current", current);
   map.put("name", sender.getName());
   map.put("source", sender.getName());
   map.put("cost", cost);
   Conversation conv =
       plugin
           .getFactory()
           .withFirstPrompt(new SellConfirmConversation(plugin))
           .withPrefix(
               new ConversationPrefix() {
                 @Override
                 public String getPrefix(ConversationContext context) {
                   return ChatColor.GRAY + plugin.getTag();
                 }
               })
           .withInitialSessionData(map)
           .withLocalEcho(false)
           .buildConversation((Player) sender);
   conv.begin();
   return true;
 }