Multiple Commands, problems

Discussion in 'Plugin Development' started by chikenlitle99, May 21, 2014.

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

    chikenlitle99

    When you run a command in the console tells me "Only players can use this command" and that message only was in one command not in the 2 commands, if I explain?

    How i fix that?

    Sorry for my english, yo hablo español


    My Main class
    Code:java
    1. public class Main extends JavaPlugin implements Listener {
    2.  
    3. //Some Things
    4.  
    5. public void onEnable(){
    6.  
    7. this.getCommand("fwr").setExecutor(new FwrCommand(this));
    8. this.getCommand("fw").setExecutor(new FwCommand(this));
    9. //Some things
    10. }


    First Command class
    Code:java
    1. package com.choscar.jimdo.vipjoinplus;
    2.  
    3. import org.bukkit.command.Command;
    4. import org.bukkit.command.CommandExecutor;
    5. import org.bukkit.command.CommandSender;
    6. import org.bukkit.configuration.file.FileConfiguration;
    7.  
    8. public class FwrCommand implements CommandExecutor{
    9.  
    10. Main plugin;
    11.  
    12. public FwrCommand(Main plugin){
    13. this.plugin = plugin;
    14. }
    15.  
    16. String prefix = "§6§l[§e§lVipJoinPlus§6§l] ";
    17. String noperm = plugin.getConfig().getString("Messages.MessageLaunchNoPer").replaceAll("&", "§");
    18.  
    19. public void onEnable() {
    20.  
    21. FileConfiguration config = plugin.getConfig();
    22. config.options().copyDefaults(true);
    23. plugin.saveConfig();
    24. }
    25. @Override
    26. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] a) {
    27.  
    28. if(sender.hasPermission("fa.reload")){
    29. if(cmd.getName().equalsIgnoreCase("fwr") || (cmd.getName().equalsIgnoreCase("fwreload"))){
    30. plugin.reloadConfig();
    31. plugin.saveConfig();
    32. sender.sendMessage(prefix + "§2§lConfig Reloaded!!");
    33. }
    34. }else{sender.sendMessage(prefix + noperm);}
    35.  
    36. return true;
    37. }
    38.  
    39. }
    40.  


    Second command class
    Code:java
    1. package com.choscar.jimdo.vipjoinplus;
    2.  
    3. import org.bukkit.command.Command;
    4. import org.bukkit.command.CommandExecutor;
    5. import org.bukkit.command.CommandSender;
    6. import org.bukkit.configuration.file.FileConfiguration;
    7. import org.bukkit.entity.Player;
    8.  
    9. public class FwCommand implements CommandExecutor{
    10.  
    11. Main plugin;
    12.  
    13. public FwCommand(Main plugin){
    14. this.plugin = plugin;
    15. }
    16.  
    17. String prefix = "§6§l[§e§lVipJoinPlus§6§l] ";
    18. String noperm = plugin.getConfig().getString("Messages.MessageLaunchNoPer").replaceAll("&", "§");
    19.  
    20.  
    21. public void onEnable() {
    22.  
    23. FileConfiguration config = plugin.getConfig();
    24. config.options().copyDefaults(true);
    25. plugin.saveConfig();
    26. }
    27.  
    28.  
    29. @Override
    30. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] a) {
    31.  
    32. Player player = (Player)sender;
    33. if (sender.hasPermission("fa.launch")) {
    34.  
    35. if (sender instanceof Player) {
    36.  
    37. if (cmd.getName().equalsIgnoreCase("fw")){
    38. plugin.firework(player);
    39. sender.sendMessage(prefix + plugin.getConfig().getString("Messages.MessageLaunch").replaceAll("&", "§"));
    40. }
    41. }else{sender.sendMessage("Only players can use this command");}
    42.  
    43. }else{sender.sendMessage(prefix + noperm);}
    44.  
    45. return false;
    46. }
    47.  
    48. }
    49.  


    ?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
  2. Offline

    _feedDz

    ill help skype me mc-skull-craft my name on skype is kyler/javadeveloper
     
  3. Offline

    chikenlitle99

    ?
     
  4. Offline

    _feedDz

    add me on skype... my username is mc-skull-craft
    ill help you on there
     
  5. Offline

    chikenlitle99

    free?
     
  6. Offline

    _feedDz

    yea...
     
  7. Offline

    chikenlitle99

    Okey, ready!

    I'm chikengamer or chikenlitle99

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
  8. Offline

    CarPet

    _feedDz chikenlitle99
    Intended for plugin requests, but the same idea follows, keep the conversation here so people can learn.
     
    mrkirby153 likes this.
  9. Offline

    chikenlitle99

    sorry
     
  10. Offline

    CarPet

    It's fine, but you might get the answer here and it might keep someone from posting the exact same question in the future and having to wait for a response, have you found your answer?
     
  11. Offline

    chikenlitle99


    No, I no found the answer, any help?
     
  12. Offline

    TheHandfish

    Simple: one of the classes has an "if(sender instanceof Player)" statement and the other does not.
     
  13. Offline

    chikenlitle99

    @TheHandfish
    I have to put "if (sender instanceof Player)" in the two classes?
     
  14. Offline

    TheHandfish

    If you want to make it so it only works for Players, then yes.
     
  15. Offline

    chikenlitle99


    No, I want a command to work on the console and the another one in the game

    ?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
  16. Offline

    TheHandfish

    chikenlitle99: In that case, remove the if(sender instanceof Player) statement entirely.
     
  17. Offline

    chikenlitle99

  18. Offline

    TheHandfish

  19. Offline

    chikenlitle99

    ?
     
  20. Offline

    TheHandfish

    Since you marked this as "Solved", I assume you fixed the problem. :p
     
  21. Offline

    chikenlitle99

    @TheHandfish
    I did it because I had many post, I have a theory but not know if work
     
  22. Offline

    chikenlitle99

  23. Offline

    CarPet

    First of all, your English is harder to read than Spanish, to me at least, so would you please include a Spanish translation at the bottom of each message?

    What seems to be the problem, still the same thing as the original problem?
     
  24. Offline

    chikenlitle99

    Hablas español?, bueno, el problema es el mismo, no puedo ejecutar un comando en la consola el cual no tiene un "instanceof", la cosa es mas o menos asi, tengo 2 comandos y quiero que uno no se pueda ejecutar en la consola y el otro sí.
     
Thread Status:
Not open for further replies.

Share This Page