[?] Plugin giving no messages or stack traces.

Discussion in 'Plugin Development' started by caldabeast, Mar 25, 2012.

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

    caldabeast

    I am currently coding a plugin, and two of the commands are not only not sending the player any messages as they are supposed to, but there are also absolutely no stack traces. Help would be very appreciated!

    Command 1 : TakeBadges, give no stacktrace and no messages, and I can't find my logic flaw.
    Code:java
    1. public boolean onCommand(CommandSender s, Command cc, String cl, String[] args) {
    2. Player p = (Player) s;
    3. if (cl.equalsIgnoreCase("takebagdes")){
    4.  
    5. if (args[0].equals(null)){p.sendMessage(Badges + "You cannot take away " + ChatColor.DARK_PURPLE + "null" + ChatColor.LIGHT_PURPLE + "'s badges!");}
    6. List<Player> playerList = p.getWorld().getPlayers();
    7. Player[] players = p.getWorld().getPlayers().toArray(new Player[playerList.size()]);
    8. boolean playerNameIsGood = false;
    9. Player takeBadgesFrom = null;
    10.  
    11. for (int i = 0; i > players.length; i++){
    12. if (args[0].equalsIgnoreCase(players[i].getName())){
    13. playerNameIsGood = true;
    14. takeBadgesFrom = players[i];
    15. break;
    16. }
    17. }
    18.  
    19. if (p.hasPermission("badges.kanto.elitefour")){
    20.  
    21. if (playerNameIsGood){
    22. int total = 0;
    23. List<String> a = this.getConfig().getStringList("DATA.BADGEDATA.KANTO.PEWTER");
    24. List<String> b = this.getConfig().getStringList("DATA.BADGEDATA.KANTO.CERULEAN");
    25. List<String> c = this.getConfig().getStringList("DATA.BADGEDATA.KANTO.VERMILION");
    26. List<String> d = this.getConfig().getStringList("DATA.BADGEDATA.KANTO.CELADON");
    27. List<String> e = this.getConfig().getStringList("DATA.BADGEDATA.KANTO.FUSHCIA");
    28. List<String> f = this.getConfig().getStringList("DATA.BADGEDATA.KANTO.SAFFRON");
    29. List<String> g = this.getConfig().getStringList("DATA.BADGEDATA.KANTO.CINNABAR");
    30. List<String> h = this.getConfig().getStringList("DATA.BADGEDATA.KANTO.VIRIDIAN");
    31. if (a.contains(takeBadgesFrom.getName())){total++;}
    32. if (c.contains(takeBadgesFrom.getName())){total++;}
    33. if (c.contains(takeBadgesFrom.getName())){total++;}
    34. if (d.contains(takeBadgesFrom.getName())){total++;}
    35. if (e.contains(takeBadgesFrom.getName())){total++;}
    36. if (f.contains(takeBadgesFrom.getName())){total++;}
    37. if (g.contains(takeBadgesFrom.getName())){total++;}
    38. if (h.contains(takeBadgesFrom.getName())){total++;}
    39. if (total != 8){
    40. p.sendMessage(Badges + "The player doesn't have all eight badges! Why are you trying to take them?");
    41. } else {
    42. a.remove(takeBadgesFrom.getName());
    43. b.remove(takeBadgesFrom.getName());
    44. c.remove(takeBadgesFrom.getName());
    45. d.remove(takeBadgesFrom.getName());
    46. e.remove(takeBadgesFrom.getName());
    47. f.remove(takeBadgesFrom.getName());
    48. g.remove(takeBadgesFrom.getName());
    49. h.remove(takeBadgesFrom.getName());
    50. this.getConfig().set("DATA.BADGEDATA.KANTO.PEWTER", a);
    51. this.getConfig().set("DATA.BADGEDATA.KANTO.CERULEAN", b);
    52. this.getConfig().set("DATA.BADGEDATA.KANTO.VERMILION", c);
    53. this.getConfig().set("DATA.BADGEDATA.KANTO.CELADON", d);
    54. this.getConfig().set("DATA.BADGEDATA.KANTO.FUCHSIA", e);
    55. this.getConfig().set("DATA.BADGEDATA.KANTO.SAFFRON", f);
    56. this.getConfig().set("DATA.BADGEDATA.KANTO.CINNABAR", g);
    57. this.getConfig().set("DATA.BADGEDATA.KANTO.VIRIDIAN", h);
    58. this.saveConfig();
    59. p.sendMessage(Badges + "You took away " + ChatColor.DARK_PURPLE + p.getName() + ChatColor.LIGHT_PURPLE + "'s eight Kanto badges. Let the match begin!");
    60. takeBadgesFrom.sendMessage(Badges + "Elite Four " + ChatColor.DARK_PURPLE + p.getName() + ChatColor.LIGHT_PURPLE + " took away your eight Kanto badges. Let the match begin!");
    61. }
    62. } else {
    63. p.sendMessage(Badges + "The player " + ChatColor.DARK_PURPLE + args[0] + ChatColor.LIGHT_PURPLE + " is not on the server.");
    64. }
    65. }[/i][/i]


    <Skipping duplicate of the above code for Johto and the code for the command that works>

    Command 3: givebadge, gives no stacktraces or messages, can't find my logic flaw
    Code:java
    1. else if (cl.equalsIgnoreCase("givebadge")){
    2.  
    3. //Checking if the player to give a badge to is actually on the server
    4. if (args[0].equals(null)){
    5. p.sendMessage(Badges + "You cannot give a badge to " + ChatColor.DARK_PURPLE + "null");
    6. } List<Player> playerList = p.getWorld().getPlayers();
    7. Player[] players = p.getWorld().getPlayers().toArray(new Player[playerList.size()]);
    8. boolean playerNameIsGood = false;
    9. Player giveBadgeTo = null;
    10. for (int i = 0; i > players.length; i++){
    11. if (args[0].equalsIgnoreCase(players[i].getName())){
    12. playerNameIsGood = true;
    13. giveBadgeTo = players[i];
    14. break;
    15. }
    16. }
    17.  
    18. if (playerNameIsGood){
    19. if (p.hasPermission("badges.kanto.pewter")){
    20. p.sendMessage(Badges + "You gave the " + ChatColor.GRAY + "Boulder Badge" + "to" + ChatColor.DARK_PURPLE + giveBadgeTo.getName());
    21. giveBadgeTo.sendMessage(Badges + "You were given the " + ChatColor.GRAY + "Boulder Badge" + "by" + ChatColor.DARK_PURPLE + "Gym Leader " + p.getName());
    22. List<String> badgeList = this.getConfig().getStringList("DATA.BADGEDATA.KANTO.PEWTER");
    23. if (badgeList.contains(giveBadgeTo.getName())){
    24. giveBadgeTo.sendMessage(Badges + "But wait! You already have that badge!");
    25. giveBadgeTo.sendMessage(Badges + "You return the badge to the gym leader.");
    26. p.sendMessage(Badges + "But wait! That player already has that badge!");
    27. p.sendMessage(Badges + "The player returns the badge to you.");
    28. } else {
    29. badgeList.add(giveBadgeTo.getName());
    30. this.getConfig().set("DATA.BADGEDATA.KANTO.PEWTER", badgeList);
    31. this.saveConfig();
    32. }
    33. } else if (p.hasPermission("badges.kanto.cerulean")){
    34. p.sendMessage(Badges + "You gave the " + ChatColor.BLUE + "Cascade Badge" + "to" + ChatColor.DARK_PURPLE + giveBadgeTo.getName());
    35. giveBadgeTo.sendMessage(Badges + "You were given the " + ChatColor.BLUE + "Cascade Badge" + "by" + ChatColor.DARK_PURPLE + "Gym Leader " + p.getName());
    36. List<String> badgeList = this.getConfig().getStringList("DATA.BADGEDATA.KANTO.CERULEAN");
    37. if (badgeList.contains(giveBadgeTo.getName())){
    38. giveBadgeTo.sendMessage(Badges + "But wait! You already have that badge!");
    39. giveBadgeTo.sendMessage(Badges + "You return the badge to the gym leader.");
    40. p.sendMessage(Badges + "But wait! That player already has that badge!");
    41. p.sendMessage(Badges + "The player returns the badge to you.");
    42. } else {
    43. badgeList.add(giveBadgeTo.getName());
    44. this.getConfig().set("DATA.BADGEDATA.KANTO.CERULEAN", badgeList);
    45. this.saveConfig();
    46. }
    47. }
    48. [/i][/i]

    <more duplicate code of the above>

    Any help would be very appreciated!
     
  2. Offline

    Njol

    I guess you didn't register the commands with plugin.getCommand("givebadge").setExecutor(yourExecutor);

    Also I found some other problems:

    > Player p = (Player) s;
    Will throw an error if the command is run from the console. Check s instanceof Player first.

    > if (args[0].equals(null)){
    Will throw an error if no arguments are given, and will never evaluate to true. Check args.length >= 1 first (or == 1 if you only expect one argument)

    Also you can replace this whole chunk of code:
    Code:java
    1. List<Player> playerList = p.getWorld().getPlayers();
    2. Player[] players = p.getWorld().getPlayers().toArray(new Player[playerList.size()]);
    3. boolean playerNameIsGood = false;
    4. Player takeBadgesFrom = null;
    5.  
    6. for (int i = 0; i > players.length; i++){
    7. if (args[0].equalsIgnoreCase(players[i].getName())){
    8. playerNameIsGood = true;
    9. takeBadgesFrom = players[i];
    10. break;
    11. }
    12. }[/i][/i]

    with this line:
    Code:java
    1. Player takeBadgesFrom = Bukkit.getPlayerExact(args[0]);

    and instead of playerNameIsGood use takeBadgesFrom != null.
     
  3. Offline

    caldabeast

    Njol what is "plugin.getCommand("givebadge").setExecutor(yourExecutor);" and how do I use it?

    THANK YOU!! Because of your helps up top, I got the plugin working :D
     
Thread Status:
Not open for further replies.

Share This Page