@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; }