Unknown Command

Discussion in 'Plugin Development' started by SkyStatus, Jul 9, 2014.

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

    SkyStatus

    Hello,

    I've been coding a "Custom Join Sign" plugin, and I've tried many things, but they don't seem to work:


    Code:java
    1. public class Main extends JavaPlugin implements Listener {
    2.  
    3. public final HashMap<Location, String> signs = new HashMap<Location, String>();
    4.  
    5. public static Main plugin;
    6.  
    7. public void onEnable(){
    8. plugin = this;
    9. this.getLogger().info("{Custom Join Signs} has been enabled!");
    10. this.getConfig().options().copyDefaults(true);
    11. this.saveConfig();
    12. this.getServer().getPluginManager().registerEvents(this, this);
    13. }
    14.  
    15. public void onDisable() {
    16. plugin = null;
    17. getLogger().info("{Custom Join Signs} has been disabled!");
    18. }
    19. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
    20. if(sender instanceof Player);
    21. Player player = (Player) sender;
    22. if(player.isOp()) {
    23. if(commandLabel.equalsIgnoreCase("cjs create")){
    24. player.sendMessage(ChatColor.BLUE + "Please type in the minigame name:");
    25. player.sendMessage(ChatColor.GOLD + " 1)" + ChatColor.RED + "Do " + ChatColor.YELLOW + "/cjs setminigame [Minigame]" + ChatColor.RED + "to create a minigame.");
    26. if(commandLabel.equalsIgnoreCase("cjs setminigame" + minvar));
    27. player.sendMessage("Test Successful");
    28. }
    29. }
    30. return false;
    31. }
    32.  
    33. @EventHandler
    34. public void onBlockBreak(BlockBreakEvent event){
    35. Player player = event.getPlayer();
    36. if(event.equals(Blocks.SIGN_POST)) {
    37. if(signs.containsKey(event.getBlock().getLocation()) && !signs.containsValue(event.getPlayer().getName()) || !player.isOp()) {
    38. event.setCancelled(true);
    39. } else {
    40. signs.remove(event.getBlock().getLocation());
    41. event.getBlock().breakNaturally();
    42. }
    43. }
    44. }
    45.  
    46. @EventHandler
    47. public void onPlayerInteract(PlayerInteractEvent event){
    48. Player player = event.getPlayer();
    49. if(signs.containsKey(event.getClickedBlock().getLocation())) {
    50. player.teleport(player.getWorld().getSpawnLocation());
    51. } else {
    52.  
    53. }
    54. }


    When I apply the command: /cjs create; it simply doesn't work. Any help?
     
  2. Offline

    endoml

    What about them does not work? Are you getting errors?
     
  3. Offline

    SkyStatus


    There are no errors in the console, but is simply says on the server (When I type in the command): "Unknown Command. Type '/help' for help."
     
  4. Offline

    endoml

    Ah. Are you registering the commands in the plugin.yml?
     
  5. That's not how you do sub commands.
     
  6. Offline

    brbtus

    Im not sure if this would work but try to use this code. Tell me if it works:
    Code:java
    1. if (args[0].equalsIgnoreCase("cjs")) {
    2. //When typed /cjs
    3. if (args[1].equalsIgnoreCase("create")) {
    4. //when typed /cjs create
    5. return true;
    6. }
    7. if (args[1].equalsIgnoreCase("setminigame")){
    8. //when typed /cjs setminigame
    9. }
    10. }
    11.  

    You probably know where to put this... I don't want to explain right now.
    If it doesen't work try to work your way around it. If it still doesn't work then tag me and il help!
     
  7. Offline

    SkyStatus


    I did exactly what you did, but it's not working. Do I need to register the commands in the plugin.yml? If so, how?
     
  8. Offline

    Necrodoom

    brbtus um, no, that's wrong, it goes /cmd args[0] args[1] etc, not /args[0] args[1] args[2].
    SkyStatus don't copy-paste above code, register the command cjs in the plugin.yml, then check the args.
     
  9. Offline

    brbtus

    ...
    idk why I did that mistake.
    :mad:
     
  10. Offline

    SkyStatus

    Alright, thanks Necrodoom, but now I've got another problem which I need help.

    I want a variable to be an input from the player (For example):

    Code:java
    1. if (args[0].equalsIgnoreCase("setminigame" + minvar)); //Variable minvar is the variable I want to get from the player.


    How would I do that? Using "String minvar;", "float minvar;", or something like that?

    Thanks for your help!

    Note: System.out.print("I'm still learning, I'm much a noob. -- SkyStatus");
     
  11. Offline

    Necrodoom

    What is the example command you want a player to execute? Also where you are getting minvar from? Because you don't seem to get it from the command.
     
  12. Offline

    SkyStatus

    I want the player to execute anything, and I'm getting minvar from the player. The point is that I want them to do this: Whenever they do /cjs setminigame <Anything>, It gets the the "Anything" (Which is the variable minvar), it gets the variable minvar and sends it back to the player using "player.sendMessage('You typed in: " + minvar')".
     
  13. Offline

    Necrodoom

    SkyStatus so you are looking for the next arg?
     
  14. Offline

    SkyStatus


    I already got this problem resolved. (Thanks for your help though):

    Look at the code below (I thought it would work and it worked):

    Code:java
    1. if (args[1].length() > 0) {
    2. String minvar = args[1];
    3. player.sendMessage(ChatColor.BLUE
    4. + "Success! You have added the minigame "
    5. + ChatColor.YELLOW + minvar
    6. + ChatColor.BLUE
    7. + " to the configuration file!");
    8. this.getConfig().createSection(minvar);
    9. this.getConfig().set(minvar, "Arena Number []:" + "Arena Name: []" + "Max Players: []" + "Arena Location: [] [] []");
    10. this.saveConfig();
    11. return true;
    12. }


    However, I have another problem:

    Look at this code first:

    Code:java
    1. if (args[1].length() > 0) {
    2. String minvard = args[1];
    3. if (this.getConfig().getString(minvard).isEmpty()) { // I had absolutely no idea what to write, so I played around with the code for a bit.
    4. player.sendMessage(ChatColor.RED + "Error: The minigame " + ChatColor.YELLOW + minvard + ChatColor.RED + "does not exist!");
    5. return true;
    6. }
    7. this.getConfig().set(minvard, null);
    8. this.saveConfig();
    9. player.sendMessage(ChatColor.BLUE
    10. + "Success! You have deleted the minigame "
    11. + ChatColor.YELLOW + minvard
    12. + ChatColor.BLUE
    13. + " to the configuration file!");
    14. return true;
    15. }


    I want it to send the player a message if the variable "minvar" they type in doesn't exist in the configuration file. How would I do that though?
     
  15. Offline

    Necrodoom

    SkyStatus your length check shows me you need to learn how to use arrays before continuing, or you will simply get errors if the command is written wrong.
     
  16. Offline

    SkyStatus


    Um..

    How would Arrays relate to this? Arent' they when coders get frustrated with many variables they use something like "String names[] = new String[8]"?
     
  17. Offline

    Necrodoom

  18. Offline

    SkyStatus

    Well, the fact is that the commands are working, so I'm not sure what I'm doing wrong.
     
Thread Status:
Not open for further replies.

Share This Page