Spawnmob Plugin Help

Discussion in 'Spigot Plugin Development' started by NDGAM3R, Apr 2, 2014.

  1. Hello,

    Today I wanted to finish the 'Spawnmob' plugin I have been working on, but I have ran into a problem. When I made the "You do not have access to that command." message, it would send that message even when the player had permission. It would be great if you could look at the small portion of code I took, and would also be great if you could help me as soon as possible.

    Code:

    Code (Text):
    public boolean onCommand(CommandSender sender, Command cmd, String CommandLabel, String[] args) {
        Player p = (Player)sender;
        Block b = p.getTargetBlock(null, 5);
        b.getLocation();
        b.getTypeId();
        if ((cmd.getName().equalsIgnoreCase("spawnmob")) &&
          (p.hasPermission("spawnmob")) &&
          (args.length == 0)) {
          p.sendMessage(ChatColor.GOLD + "Correct Usage" + ChatColor.WHITE + ": /spawnmob (mob) (amount)");
         
        } else {
            p.sendMessage(ChatColor.DARK_RED + "You do not have access to that command.");
        }
       
        if ((args.length == 1) &&
          (args[0].equalsIgnoreCase("help")) &&
          (p.hasPermission("spawnmob.help"))) {
          p.sendMessage(ChatColor.GOLD + "SpawnMob Commands:");
          p.sendMessage(ChatColor.GOLD + "/spawnmob" + ChatColor.WHITE + ": Spawns mobs.");
          p.sendMessage(ChatColor.GOLD + "/spawnmob list" + ChatColor.WHITE + ": Lists mobs.");
        }
    Thank you!
     
  2. That's because your doing:

    Code (Text):
    if ((cmd.getName().equalsIgnoreCase("spawnmob")) &&
          (p.hasPermission("spawnmob")) &&
          (args.length == 0)) {
    Which checks if there are no arguments... Your doing args.length == 0 I'm guessing that you want to check if there is 1 argument, in that case you should do: args.length == 1 so:

    Code (Text):
    if ((cmd.getName().equalsIgnoreCase("spawnmob")) &&
          (p.hasPermission("spawnmob")) &&
          (args.length == 1)) {
    That should fix your error.
     
  3. I never have permission to do the /spawnmob command now...
     
  4. This might be a mistake, I'm still learning java

    if ((cmd.getName().equalsIgnoreCase("spawnmob"))

    if (equalsIgnoreCase("spawnmob" cmd.getName())

    I didn't test, so forgive if that's a misguided usage.

    But either way, you have 3 conditions to reach success. Break it down into 1 at a time to see which are failing.

    ((cmd.getName().equalsIgnoreCase("spawnmob")) &&
    (p.hasPermission("spawnmob")) &&
    (args.length == 1))

    So just make debug comments that echo the value of each of the conditions by itself.