My Staff plugin just went all wrong HELP?

Discussion in 'Plugin Development' started by LeePMC, Aug 16, 2014.

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

    LeePMC

    hi,

    so i have recently been making my very first plugin, it was going great, everything was working perfectly... then i tried to add in

    Code:java
    1. if (args[2] == "?") {
    2. sender.sendMessage(ChatColor.RED + "/Staff Add <player>");
    3. }


    so that if you typed /staff <add/remove> ? it would show you how to use the command but instead it stoped the /modlist and the /staff remove from working so i removed them, went back in to test the plugin and now "/staff add" is removing staff and "/staff remove" doesnt do anything and also "/moidlist" now give me an error null even though i have put in the code that if it equalls null send a message but clearly it doesnt like me, here is all the code for my plugin it is in one file

    the only things that work are "/staff" send you a message on how to use the command and "/modlist <anything>" replys too many arguments!

    if someone could be so great to just tell me what i have done wrong, everything sems fine but i dont know how to fix it

    "/staff remove <player>" doesnt give me any error, it just does nothing i only get an error when i type "/modlist"

    Code:java
    1. package com.Cretincraft.staff;
    2.  
    3. import java.util.List;
    4.  
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.command.Command;
    7. import org.bukkit.command.CommandSender;
    8. import org.bukkit.plugin.java.JavaPlugin;
    9.  
    10. public class main extends JavaPlugin {
    11.  
    12. @Override
    13. public void onEnable() {
    14. getLogger().info("CretinStaff has been Successfully Enabled!");
    15.  
    16. this.saveDefaultConfig();
    17.  
    18. }
    19. @Override
    20. public void onDisable() {
    21. getLogger().info("CretinStaff has been Disabled!");
    22. }
    23. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    24.  
    25. if (cmd.getName().equalsIgnoreCase("Staff")) {
    26.  
    27. if(args.length == 0) {
    28. sender.sendMessage(ChatColor.RED + "Too few arguments!");
    29. sender.sendMessage(ChatColor.DARK_RED + "Usage: " + ChatColor.RED + "/staff <add/remove>");
    30. }
    31.  
    32.  
    33. else if (args[0].equalsIgnoreCase("remove")) {
    34. if (this.getConfig().getStringList("staff") == null) {
    35. sender.sendMessage(ChatColor.GRAY + "[" + ChatColor.DARK_PURPLE + "CRETIN" + ChatColor.GRAY + "]" + ChatColor.RED + " There are no staff added to remove!");
    36. sender.sendMessage(ChatColor.GRAY + "[" + ChatColor.DARK_PURPLE + "CRETIN" + ChatColor.GRAY + "]" + ChatColor.WHITE + " Staff names are case SeNsAtiVE!");
    37. }
    38. } else {
    39. List<String> staff = this.getConfig().getStringList("staff");
    40. staff.remove(args[1]);
    41. this.getConfig().set("staff", staff);
    42. this.saveConfig();
    43. sender.sendMessage(ChatColor.GRAY + "[" + ChatColor.DARK_PURPLE + "CRETIN" + ChatColor.GRAY + "]" + ChatColor.RED + " You successfully removed " + ChatColor.DARK_RED + args[1] + ChatColor.RED + " from the staff list!" );
    44. }
    45. }
    46.  
    47. else if (args[0].equalsIgnoreCase("add")) {
    48. List<String> add = getConfig().getStringList("staff");
    49. add.add(args[1]);
    50. getConfig().set("staff", add);
    51. this.saveConfig();
    52. sender.sendMessage(ChatColor.GRAY + "[" + ChatColor.DARK_PURPLE + "CRETIN" + ChatColor.GRAY + "]" + ChatColor.GREEN + " You successfully added " + ChatColor.DARK_GREEN + args[1] + ChatColor.GREEN + " to the staff list!" );
    53. return false;
    54. }
    55. else if(args.length > 2) {
    56. sender.sendMessage(ChatColor.RED + "Too many arguments!");
    57. }
    58.  
    59. if (cmd.getName().equalsIgnoreCase("modlist")) {
    60. if (args.length == 0) {
    61. this.reloadConfig();
    62. sender.sendMessage(ChatColor.GRAY + "[" + ChatColor.DARK_PURPLE + "CRETIN" + ChatColor.GRAY + "] " + ChatColor.GOLD + "Staff: " + ChatColor.GRAY + this.getConfig().getStringList("staff"));
    63. sender.sendMessage(ChatColor.GOLD + "You can use " + ChatColor.RED + "/mail send <player>" + ChatColor.GOLD + " to MSG an Admin at anytime!");
    64. }
    65. else {
    66. sender.sendMessage(ChatColor.RED + "Too many arguments!");
    67. sender.sendMessage(ChatColor.DARK_RED + "Usage: " + ChatColor.RED + "/Modlist");
    68. }
    69. }
    70. return true;
    71. }
    72. }


    this is my plugin.yml

    Code:
    name: CCMCStaff
    main: com.Cretincraft.staff.main
    version: 1.0
    description: List staff members of the server
    commands:
      staff:
          description: /Staff <add/Remove>
          usage: Usage - /<command> add/remove
          permission: CStaff.change
          permission-message: You don't have permission to change the staff list
      modlist:
          description: Shows all staff listed in the Config.yml
          usage: /<command>
          permission: CStaff.use
          permission-message: You don't have permission to list staff
    this is my config.yml

    Code:
    Staff:
     
  2. Offline

    blobic123


    This is how commands and arguments are structured

    /command args[0] args[1] args[2] ...

    with /staff <add/remove> ?, ? is the second argument and is args[1] not args[2]
     
  3. Offline

    mine-care

    Don't you Ned to check of what args is is a player because if I type /staff add thisisnotaplayerbutastring
    This will add it to the config but its useless
     
  4. Offline

    Necrodoom

    Error appears to be the extra } at line 37. Reindent your code and make sure all brakcets are proper.
     
    MarinD99 likes this.
  5. Offline

    TopTobster5

    mine-care If you wanted to add an offline player, you couldn't check that. Its fine how it is probably. No point in over complicating things for now.
     
  6. Offline

    mine-care

    TopTobster5 you can, the players folder of bukkit contains .dat files whith uuid's of players. There is a method too i am not sure about its name tho :/ but you always can check in the dir of the main world where players are held
     
  7. Offline

    Slikey

    A String is an object. If you check args[2] == "?", you check if args[2] and "?" is THE SAME. You have to do this.

    args[2].equals("?").
     
    ChipDev and Dragonphase like this.
  8. Slikey args[1].equals("?");
     
  9. Offline

    ChipDev

    Ninja'd 1-4 hours later >.>
    Psst. bwfcwalshy is right, args[1]
     
  10. Offline

    1Rogue


    He's talking about string comparisons. == compares memory values (or rather, their "reference value"), so unless those two string instances are the exact same instance (which you can not guarantee), then you need to compare by value. You can use:

    Code:java
    1. if ("?".equalsIgnoreCase(args[1])) {
    2. //second argument is '?'
    3. }


    http://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java
     
  11. 1Rogue I was just correcting him.
     
  12. Offline

    1Rogue

    Ahh, get an avatar ;)

    LeePMC My post was meant for you.
     
Thread Status:
Not open for further replies.

Share This Page