Plugin.yml help

Discussion in 'Plugin Development' started by kmccmk9, May 15, 2011.

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

    kmccmk9

    Code:
    23:38:24 [SEVERE] null
    org.bukkit.command.CommandException: Unhandled exception executing command 'serverreload' in plugin ServerReloader v0.01
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:37)
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:85)
            at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:278)
            at net.minecraft.server.NetServerHandler.handleCommand(NetServerHandler.java:682)
            at net.minecraft.server.NetServerHandler.chat(NetServerHandler.java:645)
            at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:639)
            at net.minecraft.server.Packet3Chat.a(Packet3Chat.java:32)
            at net.minecraft.server.NetworkManager.a(NetworkManager.java:196)
            at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:75)
            at net.minecraft.server.NetworkListenThread.a(SourceFile:100)
            at net.minecraft.server.MinecraftServer.h(MinecraftServer.java:372)
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:287)
            at net.minecraft.server.ThreadServerApplication.run(SourceFile:394)
    Caused by: java.lang.ArrayIndexOutOfBoundsException: 1
            at com.kmccmk9.ServerReloader.ServerReloader.onCommand(ServerReloader.java:41)
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:35)
            ... 12 more
    
     
  2. Offline

    cjc343

     
    iPhysX likes this.
  3. Offline

    kmccmk9

    Ok so what does that mean?
     
  4. Offline

    iPhysX

    he changed the code inside it!
     
  5. Offline

    kmccmk9

    Oh didn't see that
     
  6. Offline

    iPhysX

    :O
    Hope it works out!
    it should do cjc is great
     
  7. Offline

    kmccmk9

    Ok but I'm confused on what I'm supposed to change.
     
  8. Offline

    iPhysX

    wait!
    he has added notes in the code!
     
  9. Offline

    kmccmk9

    No he didn't...he just commented it telling me that this part won't work ect. Otherwise its exactly what I already have
     
  10. Offline

    iPhysX

    i wasnt concentrating, its 5am!
     
  11. Offline

    kmccmk9

    Oh ouch lol
     
  12. Offline

    cjc343

    Do you need help understanding why it won't work or how to fix it? Or do you understand now?
     
  13. Offline

    iPhysX

    i think he needs both :)
     
  14. Offline

    cjc343

    Your first if:

    if (args.length >= 0) // This is always true.

    is always true because args.length will always be 0 or greater. Since you access args[0], this actually needs to be at least 1 in order to not cause a NPE.

    So, if you change that to "if (args.length > 0)" then you know that you at least have more than 0 arguments.


    Since you have two cases which may have one argument, the specific case should come first, followed by the generic case.

    This means that once you know that the length is 1 or greater, you should check to see if the argument was "help" and attempt to use the command only if it wasn't help.


    In the end, the code will probably be structured similarly to the following:

    Code:
    if (args.length > 0) {
      if (args[0].equals("help") {
        //your help message here
      } else {
        //your command's code here
      }
    } else {
      //error/not enough arguments
    }
     
    Jayjay110 and kmccmk9 like this.
  15. Code:
    public boolean onCommand(final CommandSender sender, Command command, String commandLabel, String[] args)
        {
            if (sender instanceof Player) {
                player = (Player) sender;
                if(commandLabel.equalsIgnoreCase("serverreload")) {
                    {
                        if (args.length >= 1)
                        {
                            if (args[0].matches("[0-9]+") {
                                enteredtime = args[0];
                                time = Integer.parseInt(enteredtime);
                                time = time * 60;
                                time2 = time / 2;
                                time3 = time - 10;
                                server.dispatchCommand(sender, "The server will reload in " + time/60 + " minutes");
                                server.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
                                    public void run() {
                                        server.dispatchCommand(sender, "say Server Reloading in " + time2/60 + " minutes");
                                    }
                                }, time2 * 20L);
                                server.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
                                    public void run() {
                                        server.dispatchCommand(sender, "say Server Reloading");
                                        server.dispatchCommand(sender, "reload");
                                    }
                                }, time * 20L);
                            }
                            else if (args[0] == "help")
                            {
                                player.sendMessage("The correct format is /serverreload <time in minutes>");
                                player.sendMessage("using /serverreload help - Will list the help file");
                            } else {
                                player.sendMessage("The correct format is /serverreload <time in minutes>");
                            }
                        } else {
                            player.sendMessage("Wrong arguments.");
                            return false;
                        }
                    }
                }
            return true;
        }
    
    This will check with regular expressions if args[0] is an number.
    if it is, it will execute your time script, else it will check for help or say its a wrong format
     
  16. Offline

    kmccmk9

    Ok, now using this code...I'm getting an unknown console command. But, the plugin then seems to continue and work as normal. I can't figure out why its telling me that it is unknown even though it is and it works.

    Code:
    package com.kmccmk9.ServerReloader;
    
    import java.util.logging.Logger;
    
    import org.bukkit.Server;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class ServerReloader extends JavaPlugin {
        public static ServerReloader plugin;
        Server server;
        Logger log = Logger.getLogger("Minecraft");
        Player player;
        String enteredtime;
        int time;
        int time2;
        int time3;
        public void onDisable() {
            // TODO Auto-generated method stub
            log.info("ServerReloader has been disabled.");
        }
    
        public void onEnable() {
            // TODO Auto-generated method stub
            server = this.getServer();
            plugin = this;
            log.info("ServerReloader has been enabled.");
    
        }
    
        public boolean onCommand(final CommandSender sender, Command command, String commandLabel, String[] args)
        {
            if (sender instanceof Player) {
                player = (Player) sender;
                if(commandLabel.equalsIgnoreCase("serverreload")) {
                    {
                        if (args.length >= 0)
                        {
                            enteredtime = args[0];
                            time = Integer.parseInt(enteredtime);
                            time = time * 60;
                            time2 = time / 2;
                            time3 = time - 10;
                            if (args[0] == "help")
                            {
                                player.sendMessage("The correct format is /serverreload <time in minutes>");
                                player.sendMessage("using /serverreload help - Will list the help file");
                            }
                            else if (args[0] == null)
                            {
                                player.sendMessage("The correct format is /serverreload <time in minutes>");
                            }
                            else
                            {
                            server.dispatchCommand(sender, "The server will reload in " + time/60 + " minutes");
                            server.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
                                public void run() {
                                    server.dispatchCommand(sender, "say Server Reloading in " + time2/60 + " minutes");
                                }
                            }, time2 * 20L);
                            server.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
                                public void run() {
                                    server.dispatchCommand(sender, "say Server Reloading");
                                    server.dispatchCommand(sender, "reload");
                                }
                            }, time * 20L);
                            }
                        }
                    }
                }
            }
            return true;
        }
    }
    
     
  17. Offline

    Jayjay110

    Ok... Go into your plugin.yml and make sure:

    command:
    serverreload

    Is there
     
  18. Offline

    kmccmk9

    This is my plugin.yml

    The only thing is commands should be command?

    Code:
    name: ServerReloader
    main: com.kmccmk9.ServerReloader.ServerReloader
    version: 0.01
    commands:
      serverreload:
        description: A plugin that allows for in game server restarts with timer!
        usage: /serverreload <time in minutes>
     
  19. Offline

    Jayjay110

    Nope, sorry I was wrong, just say this, when you get the error what command are you entering?
     
  20. Offline

    kmccmk9

    /serverreload 10
     
  21. Offline

    Jayjay110

    any other errors? and is your plugin.yml correctly parsed
     
  22. Offline

    kmccmk9

    No other errors, and what do you mean by parsed?
     
  23. Offline

    Jayjay110

    Correctly formatted
     
  24. Offline

    kmccmk9

    I have no idea lol. How would I know. I believe I based this off of a tutorial/my previous plugin but let me give that a shot...
     
  25. Offline

    Jayjay110

    well if you dont know, upload ur yml file Ill check for you :) (dont copy paste, actually upload :))
     
  26. Offline

    kmccmk9

    Ok attached is my plugin.yml in txt format.
     

    Attached Files:

  27. Offline

    Jayjay110

    :3 Really, why would u upload it in text format that doesnt make sense lol :p

    EDIT:

    OH right I cee why u uploaded it in text format :3
    I fixed it btw :) found the error I couldnt notice it before but it was were u placed /serverreload
     

    Attached Files:

  28. Offline

    kmccmk9

    I know but .yml is not an accepted extension
     
  29. Offline

    Jayjay110

    Last edited by a moderator: Jul 16, 2016
    kmccmk9 likes this.
  30. Offline

    iPhysX

Thread Status:
Not open for further replies.

Share This Page