Solved Unknown Command

Discussion in 'Plugin Development' started by Ozeir, Jul 18, 2014.

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

    Ozeir

  2. Offline

    Necrodoom

    Paste edited code, then.
     
  3. Offline

    ZodiacTheories

  4. Offline

    Ozeir

    Code:java
    1. package me.braedenh.conquest;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.command.Command;
    6. import org.bukkit.command.CommandSender;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.plugin.java.JavaPlugin;
    9. import org.bukkit.scoreboard.Scoreboard;
    10. import org.bukkit.scoreboard.ScoreboardManager;
    11. import org.bukkit.scoreboard.Team;
    12.  
    13. public class Main extends JavaPlugin{
    14.  
    15. private ScoreboardManager manager = null;
    16. private Scoreboard board = null;
    17. private Team Asaerith = null;
    18. private Team Acendath = null;{
    19.  
    20. }
    21.  
    22. @Override
    23. public void onEnable() {
    24.  
    25. manager = Bukkit.getScoreboardManager();
    26. board = manager.getNewScoreboard();
    27.  
    28. Asaerith = board.registerNewTeam("Asaerith");
    29. Acendath = board.registerNewTeam("Acendath");
    30.  
    31. Asaerith.setPrefix(ChatColor.RED + "[" + ChatColor.BLUE + "Asaerith" + ChatColor.RED + "]");
    32. Asaerith.setAllowFriendlyFire(false);
    33. Asaerith.setCanSeeFriendlyInvisibles(true);
    34. Acendath.setAllowFriendlyFire(false);
    35. Acendath.setPrefix(ChatColor.RED + "[" + ChatColor.BLUE + "Acendath" + ChatColor.RED + "]");
    36. Acendath.setCanSeeFriendlyInvisibles(true);
    37.  
    38. }
    39.  
    40. public void onDisable(){
    41.  
    42.  
    43. }
    44.  
    45.  
    46.  
    47. public boolean OnCommand(CommandSender sender, Command cmd, String Lable, String[] args) {
    48. Player player = (Player) sender;
    49. if(sender instanceof Player)
    50. if ( cmd.getName().equalsIgnoreCase("conquest") )
    51. if(args.length ==1 || args.length <= 1) {
    52. if(args[0].equalsIgnoreCase("acendath"))
    53. Acendath.addPlayer(player);
    54.  
    55.  
    56.  
    57.  
    58. }
    59. return true;
    60.  
    61. }
    62.  
    63. }
    64.  
    65.  
    66.  
    67.  
    68.  
    69.  
    70.  
     
  5. Offline

    Necrodoom

    Good enough, now put your sender to player cast after you check if its a player, not before.
     
  6. Offline

    Ozeir

    Like this?
    Code:java
    1. public boolean OnCommand(CommandSender sender, Command cmd, String Lable, String[] args) {
    2. if(sender instanceof Player)
    3. Player player = (Player) sender;
    4. if ( cmd.getName().equalsIgnoreCase("conquest") )
    5. if(args.length ==1 || args.length <= 1) {
    6. if(args[0].equalsIgnoreCase("acendath"))
    7. Acendath.addPlayer(player);


    It gives player red:
    http://gyazo.com/3cabe1b1b5180716dc29739cf91efa0b
     
  7. Offline

    Necrodoom

    Now fix the brackets of the if checks.
     
  8. Offline

    Ozeir

    Ok did it i'm gonna try it
    Code:java
    1. public boolean OnCommand(CommandSender sender, Command cmd, String Lable, String[] args) {
    2. if(sender instanceof Player) {
    3. Player player = (Player) sender;
    4. if ( cmd.getName().equalsIgnoreCase("conquest") )
    5. if(args.length ==1 || args.length <= 1) {
    6. if(args[0].equalsIgnoreCase("acendath"))
    7. Acendath.addPlayer(player);
    8.  
    9.  
    10.  
    11.  
    12. }
    13.  
    14.  
    15. }
    16. return true;
    17.  
    18. }
    19.  
    20. }
    21.  
    22.  
    23.  
    24.  


    EDIT:
    Weird, Still giving me the same.
    when i type /conquest acendath it gives me
    /conquest [Nation]
     
  9. Offline

    Flamedek

    Ozeir having == 1 and <= 1 is unnececary, as <= means 'less then or equal to' so that would match equal too.
    besides that you are still missing 2 brackets ( { ) after the top and bottom if statements, and they'd need to be closed at the bottom
     
  10. Offline

    Ozeir

    Okay, I'm gonna try it.
    I think I'll recode it if it doesn't work
    Code:java
    1. package me.braedenh.conquest;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.command.Command;
    6. import org.bukkit.command.CommandSender;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.plugin.java.JavaPlugin;
    9. import org.bukkit.scoreboard.Scoreboard;
    10. import org.bukkit.scoreboard.ScoreboardManager;
    11. import org.bukkit.scoreboard.Team;
    12.  
    13. public class Main extends JavaPlugin{
    14.  
    15. private ScoreboardManager manager = null;
    16. private Scoreboard board = null;
    17. private Team Asaerith = null;
    18. private Team Acendath = null;{
    19.  
    20. }
    21.  
    22. @Override
    23. public void onEnable() {
    24.  
    25. manager = Bukkit.getScoreboardManager();
    26. board = manager.getNewScoreboard();
    27.  
    28. Asaerith = board.registerNewTeam("Asaerith");
    29. Acendath = board.registerNewTeam("Acendath");
    30.  
    31. Asaerith.setPrefix(ChatColor.RED + "[" + ChatColor.BLUE + "Asaerith" + ChatColor.RED + "]");
    32. Asaerith.setAllowFriendlyFire(false);
    33. Asaerith.setCanSeeFriendlyInvisibles(true);
    34. Acendath.setAllowFriendlyFire(false);
    35. Acendath.setPrefix(ChatColor.RED + "[" + ChatColor.BLUE + "Acendath" + ChatColor.RED + "]");
    36. Acendath.setCanSeeFriendlyInvisibles(true);
    37.  
    38. }
    39.  
    40. public void onDisable(){
    41.  
    42.  
    43. }
    44.  
    45.  
    46.  
    47. public boolean OnCommand(CommandSender sender, Command cmd, String Lable, String[] args) {
    48. if(sender instanceof Player) {
    49.  
    50. }
    51. Player player = (Player) sender;
    52. if ( cmd.getName().equalsIgnoreCase("conquest") ) {
    53. if(args.length ==1 || args.length > 1) {
    54. if(args[0].equalsIgnoreCase("acendath")) {
    55.  
    56. Acendath.addPlayer(player);
    57.  
    58.  
    59.  
    60.  
    61. }
    62.  
    63.  
    64. }
    65.  
    66. }
    67. return true;
    68.  
    69. }
    70. }
    71.  
    72.  
    73.  
    74.  
    75.  
    76.  


    It didn't work.
     
  11. Offline

    AoH_Ruthless

    Ozeir
    Everything wrong with your code from post #34.
    1. Lines 18-20; why are there brackets ...?
    2. Lines 17 and 18; you don't follow Java naming conventions.
    3. You have an empty onDisable ...
    4. You have a capital o in onCommand, this was already pointed out to you..
    5. Your string parameter variable is 'Lable'. This fails to follow Java naming conventions.
    6. Put brackets on all if checks so you can see what you are doing (and follow Java conventions). (courtesy of Flamedek )
    7. You are checking if args is both 1 and less than or equal to one. Makes no sense. Just check if it equals one (courtesy of Flamedek )
    8. You never set your command executor, because you incorrectly used the onCommand method (see #4).
    In conclusion, this whole thread could be avoided if you had basic understanding of Java. Everyone else is nice and did not really point it out, but I will. All 8 errors I pointed out were Java errors. Not Bukkit Errors. If you would take the time to actually learn the language, you would have some sort of insight into what you are doing. You are basically trying to run, before learning to walk. It comes off to me as very ignorant. Don't refuse this, you need Java. You have 0 clue what you are doing. Every time we tell you what you are doing, you have no idea what we are saying because you have no OOP understanding.

    Edit: In post 40, you messed up your sender instance check because again, you have no clue what you are doing.
     
    Asgernohns likes this.
  12. Offline

    Asgernohns


    I'm sorry Ozeir but i have to agree with all this above ^^
     
  13. Offline

    Ozeir

    Lol it worked but he doesn't put the player in the team acendath
    Code:java
    1. package me.braedenh.conquest;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.command.Command;
    6. import org.bukkit.command.CommandSender;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.plugin.java.JavaPlugin;
    9. import org.bukkit.scoreboard.Scoreboard;
    10. import org.bukkit.scoreboard.ScoreboardManager;
    11. import org.bukkit.scoreboard.Team;
    12.  
    13. public class Main extends JavaPlugin{
    14.  
    15. private ScoreboardManager manager = null;
    16. private Scoreboard board = null;
    17. private Team Asaerith = null;
    18. private Team Acendath = null;
    19.  
    20.  
    21. @Override
    22. public void onEnable() {
    23.  
    24. manager = Bukkit.getScoreboardManager();
    25. board = manager.getNewScoreboard();
    26.  
    27. Asaerith = board.registerNewTeam("Asaerith");
    28. Acendath = board.registerNewTeam("Acendath");
    29.  
    30. Asaerith.setPrefix(ChatColor.RED + "[" + ChatColor.BLUE + "Asaerith" + ChatColor.RED + "]");
    31. Asaerith.setAllowFriendlyFire(false);
    32. Asaerith.setCanSeeFriendlyInvisibles(true);
    33. Acendath.setAllowFriendlyFire(false);
    34. Acendath.setPrefix(ChatColor.RED + "[" + ChatColor.BLUE + "Acendath" + ChatColor.RED + "]");
    35. Acendath.setCanSeeFriendlyInvisibles(true);
    36.  
    37. }
    38.  
    39. public void onDisable(){
    40.  
    41.  
    42. }
    43.  
    44.  
    45.  
    46. public boolean onCommand(CommandSender sender, Command cmd, String Lable, String[] args) {
    47. if(sender instanceof Player) {
    48. Player player = (Player) sender;
    49. if ( cmd.getName().equalsIgnoreCase("conquest") ) {
    50. if(args.length ==1 || args.length > 1) {
    51. if(args[0].equalsIgnoreCase("acendath")) {
    52. player.sendMessage("You are now in Acendath");
    53. Acendath.addPlayer(player);
    54.  
    55.  
    56.  
    57.  
    58. }
    59.  
    60.  
    61. }
    62.  
    63. }
    64.  
    65.  
    66. }
    67. return true;
    68.  
    69. }
    70. }
    71.  
    72.  
    73.  
    74.  
    75.  
    76.  
    77.  
    78.  
    79.  
    80.  
    81.  
    82.  
    83.  


    http://gyazo.com/9d83097c08b3362ccb55ad6322f4a286
    Or is the prefix not working?
     
  14. Offline

    AoH_Ruthless

    Ozeir
    The prefix is a prefix on the tab list, not in chat. You have to add the prefix to their chat using AsyncPlayerChatEvent. Obviously after you learn Java, though.
     
  15. Offline

    Ozeir

    Not even at tab list m8
     
  16. Offline

    jimuskin

    Ozeir m8 lrn jva plz
     
Thread Status:
Not open for further replies.

Share This Page