Something wrong with my plugins or minecraft?

Discussion in 'Plugin Development' started by xXMaTTHDXx, Nov 4, 2013.

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

    xXMaTTHDXx

    Well, I made a minigame plugin and when I do my commands no aliases are show as supposed to, the server seems to eat them up forsay. Even a simple /hi command isn't working!
     
  2. Offline

    JPG2000

    xXMaTTHDXx You mean every command not working?

    If thats the case, then its bukkit. Get a new version of bukkit + mc etc.
     
  3. Offline

    xXMaTTHDXx

    Ok I am going to try that now.
     
  4. Offline

    milesmcc

    Please elaborate. Is every plugin on the server's commands not working or is it just the one you made? Try installing Essentials and do /fly or /broadcast, see if it works.
     
  5. Offline

    xXMaTTHDXx

    JPG2000 it seems that did not fix the problem...

    EDIT: milesmcc it is just the plugin, but for some reason it isnt working, while it should.
     
  6. Offline

    sgavster

    xXMaTTHDXx Are they in the plugin.yml? Are there any errors?
     
  7. Offline

    xXMaTTHDXx

    sgavster No, no errors, and it doesnt say unknown command it just does nothing....
     
  8. Offline

    sgavster

  9. Have you registered your plugin's event listeners? If so, is your onCommand method set up correctly?

    It should look like this:

    Code:java
    1. @Override
    2. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
     
  10. Offline

    sgavster

    Someguyfromcrowd There is no need for an @Override, you need a {, and you don't need to register a listener for a command.
     
  11. Offline

    xXMaTTHDXx

    Code:java
    1. package me.xXMaTTHDXx.TSRun;
    2.  
    3. import java.util.ArrayList;
    4. import java.util.Arrays;
    5. import java.util.TreeSet;
    6.  
    7. import me.xXMaTTHDXx.TSRun.MessageManager.MessageType;
    8. import me.xXMaTTHDXx.TSRun.cmds.Create;
    9. import me.xXMaTTHDXx.TSRun.cmds.Delete;
    10. import me.xXMaTTHDXx.TSRun.cmds.Join;
    11. import me.xXMaTTHDXx.TSRun.cmds.Leave;
    12. import me.xXMaTTHDXx.TSRun.cmds.Lobby;
    13. import me.xXMaTTHDXx.TSRun.cmds.Reload;
    14. import me.xXMaTTHDXx.TSRun.cmds.SetLocation;
    15. import me.xXMaTTHDXx.TSRun.cmds.Start;
    16. import me.xXMaTTHDXx.TSRun.cmds.Stop;
    17. import me.xXMaTTHDXx.TSRun.cmds.TSRunCommand;
    18.  
    19. import org.bukkit.command.Command;
    20. import org.bukkit.command.CommandExecutor;
    21. import org.bukkit.command.CommandSender;
    22. import org.bukkit.entity.Player;
    23.  
    24.  
    25. public class CommandManager implements CommandExecutor {
    26.  
    27. private TreeSet<TSRunCommand> cmds = new TreeSet<TSRunCommand>();
    28.  
    29. public void setup() {
    30. cmds.add(new Create());
    31. cmds.add(new Delete());
    32. cmds.add(new Start());
    33. cmds.add(new Stop());
    34. cmds.add(new Join());
    35. cmds.add(new Leave());
    36. cmds.add(new Reload());
    37. cmds.add(new SetLocation());
    38. cmds.add(new Lobby());
    39. }
    40.  
    41. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    42. if (!(sender instanceof Player)) {
    43. MessageManager.getInstance().msg(sender, MessageType.BAD, "Only players can use TSRun!");
    44. return true;
    45. }
    46.  
    47. Player p = (Player) sender;
    48.  
    49. if (cmd.getName().equalsIgnoreCase("tsrun")) {
    50. if (args.length == 0) {
    51. for (TSRunCommand mc : cmds) MessageManager.getInstance().msg(p, MessageType.INFO, "/tsrun " + aliases(mc) + " " + mc.getUsage() + " - " + mc.getMessage());
    52. return true;
    53. }
    54.  
    55. TSRunCommand c = getCommand(args[0]);
    56.  
    57. if (c == null) {
    58. MessageManager.getInstance().msg(sender, MessageType.BAD, "That command doesn't exist!");
    59. return true;
    60. }
    61.  
    62. TreeSet<String> a = new TreeSet<String>(Arrays.asList(args));
    63. a.remove(0);
    64. args = a.toArray(new String[a.size()]);
    65.  
    66. c.onCommand(p, args);
    67.  
    68. return true;
    69. }
    70. return true;
    71. }
    72.  
    73. private String aliases(TSRunCommand cmd) {
    74. String fin = "";
    75.  
    76. for (String a : cmd.getAliases()) {
    77. fin += a + " | ";
    78. }
    79.  
    80. return fin.substring(0, fin.lastIndexOf(" | "));
    81. }
    82.  
    83. private TSRunCommand getCommand(String name) {
    84. for (TSRunCommand cmd : cmds) if (cmd.getClass().getSimpleName().equalsIgnoreCase(name)) return cmd;
    85. return null;
    86. }
    87. }


    sgavster
     

  12. Ah, I forgot that @Override is more of an optional tag (I use relatively strict JavaDoc rules).

    I excluded the braces because I was referring solely to the method declaration. As for the listener, it was registered earlier in the onEnable method.
     
  13. Offline

    blablubbabc

    xXMaTTHDXx

    Have you set the CommandExecutor for your commands in onEnable?
     
  14. Offline

    xXMaTTHDXx

    blablubbabc Yes:
    Code:
    CommandManager cm = new CommandManager();
            cm.setup();
            getCommand("tsrun").setExecutor(cm);
           
            PluginManager pm = Bukkit.getServer().getPluginManager();
            pm.registerEvents(new BlockBreak(), this);
            pm.registerEvents(new PlayerDeath(), this);
            pm.registerEvents(new PlayerLeave(), this);
            pm.registerEvents(new PlayerLoseHunger(), this);
        }
     
        public void onDisable(){
            getLogger().info("TSRun is disabled!");
        }
     
  15. Offline

    blablubbabc

    You will have to debug, step by step.
    Maybe a plugin is cancelling the PlayerCommandPreprocessEvent? You could set up a listener to listen for that event at monitor priority to check for that.
    Also make sure that the command "tsrun" is setup in your plugin.yml.

    Maybe add print a message via System.out.println(..) to see, if it even reaches the onCommand method. If it does, verify that your MessageManager.getInstance().msg(..) methods are working.
     

  16. This is definitely a good idea- I do this all the time to debug code. Just put a print statement at key points your plugin should be reaching, then focus your debugging on the point where they fail to output.
     
  17. Offline

    xXMaTTHDXx

    I cant find it, this is really enoying!
     
  18. Offline

    Blah1

    When this happens it's usually:
    - Error in the plugin.yml
    - Didn't register events/commands
    - An error in the beginning of onEnable that stops the code.
    - or Wrong imports
    Those are the main ones. Check for those.
    (I didn't read all the posts so sorry if someone already mentioned these)
     
Thread Status:
Not open for further replies.

Share This Page