Development Assistance Code not running properly

Discussion in 'Plugin Help/Development/Requests' started by BizarrePlatinum, May 19, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    BizarrePlatinum

    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
            if(!(sender instanceof Player)) {
                sender.sendMessage(ChatColor.RED + "Could not send command :(.");
                return true;
            }
         
            Player p = (Player) sender;
            if(cmd.getName().equalsIgnoreCase("bounty")) { 
                if(args.length > 0 && args[0].equalsIgnoreCase("test")) {
                    dropHead(p.getLocation(), p);
                    return true;
                }
                if(!(args.length < 2)) {
                    if(args[0].equalsIgnoreCase("set")) {
                        if(args[1].equalsIgnoreCase("contractor")) {
                            if(p.hasPermission("hb.spawn")) {
                                spawnContractor(p.getWorld().toString(), p.getLocation());
                                p.sendMessage(ChatColor.GREEN + "Successfully spawned contractor.");
                                return true;
                            }
                            p.sendMessage(ChatColor.RED + "Could not send command :(.");
                            return true;
                        }
                        p.sendMessage(ChatColor.RED + "Not enough arguments specified.");
                        return true;
                    }
                    [B]String target = args[0];
                    Double amnt = Double.parseDouble(args[1]);
                    if(Bukkit.getServer().getOnlinePlayers().contains(target)) {
                        bounties.put(Bukkit.getPlayer(target), amnt);
                        return true;
                    }
                    p.sendMessage(ChatColor.RED + "Could not find specified player.");
                    return true;
                }[/B]
                p.sendMessage(ChatColor.RED + "Not enough arguments specified.");
                return true;
            }
            return true;
        }
    
    I have bolded my issue. What I want to happen here is if a player sends /bounty <player> <amount>, to add the target to a hashmap, if the player is online. For some reason however, that code is being ignored, and it appears to just be sending the "Could not find specified player." message. If anyone could provide some insight here, it would be appreciated. Ignore my mess please :p.
     
    Last edited: May 23, 2015
  2. Offline

    pie_flavor

    @BizarrePlatinum
    mm.
    Also, if it's not adding them to the hashmap, then obviously trying to get them from the hashmap will return null.
     
  3. Offline

    BizarrePlatinum

    @pie_flavor I do not understand why I did post that bit, I have already figured out that it was because the other command wasn't running (bounty (p) (amount)). The reason I'm using .toString() was because it needed a string for the world name.
     
  4. Offline

    BizarrePlatinum

  5. Offline

    MCMatters

    if(Bukkit.getServer().getOnlinePlayers().contains(target)) {
    bounties.put(Bukkit.getPlayer(target), amnt);
    return true;
    }
    Replace that to
    if(Bukkit.getPlayer(target) != null){
    //CODE
    }

    @BizarrePlatinum

    EDIT by Timtower: merged posts
     
    Last edited by a moderator: May 23, 2015
Thread Status:
Not open for further replies.

Share This Page