Plugin.yml help

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

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

    kmccmk9

    Hello, I am developing a plugin that has an argument. How do I format the plugin.yml file to allow for that? I believe this is why I get an error in game that the command is unknown but the plugin itself still works. Any help is appreciated!
     
  2. Offline

    Jayjay110

    no need for any format, if you want to allow a plugin to have args its all coded into the plugin, no yml needed, post the output of your error btw, example plugin.yml for args:
    Code:
    name: Example
    main: com.blah.Example.Example
    version: 1.00
    commands:
      example:
        description: Create examples by typing /Example Example.
        usage: |
                /example
     
  3. Offline

    cjc343

    You should check out ScrapBukkit, HomeBukkit, and ChatBukkit for some advanced yml features.
     
  4. Offline

    kmccmk9

    In game I get an unknown command error, yet the plugin still works
     
  5. Offline

    Jayjay110

    paste error
     
  6. Offline

    kmccmk9

    This is all the server says,
    Code:
    01:55:03 [INFO] kmccmk9 issued server command: serverreload 5
    
    In game I receive an unknown console command error
     
  7. Offline

    Jayjay110

    Oh thats an easy fix i had that error before, paste ur plugin.yml ill fix it 4 u
     
  8. Offline

    kmccmk9

    Thanks!

    Code:
    name: ServerRestarter
    main: com.kmccmk9.ServerRestarter.ServerRestarter
    version: 0.01
    commands:
      serverrestart:
        description: A plugin that allows for in game server restarts with timer!
        usage: |
                /serverrestart
                
     
  9. Offline

    1337

    try this
    Code:
    name: ServerRestarter
    main: com.kmccmk9.ServerRestarter.ServerRestarter
    version: 0.01
    commands:
      serverrestart:
        description: A plugin that allows for in game server restarts with timer!
        usage: |
                /<command>
                
     
  10. Offline

    Jayjay110

    Old Code:
    Code:
    name: ServerRestarter
    main: com.kmccmk9.ServerRestarter.ServerRestarter
    version: 0.01
    commands:
      serverrestart:
        description: A plugin that allows for in game server restarts with timer!
        usage: |
                /serverrestart
    New Code:
    Code:
    name: ServerRestarter
    main: com.kmccmk9.ServerRestarter.ServerRestarter
    version: 0.01
    commands:
      serverreload:
        description: A plugin that allows for in game server restarts with timer!
        usage: |
                /serverreload
    Basically what you did wrong was typed in serverrestart as the command name, when bukkit checks to see if the command was correct it checks ur plugin.yml not ur command arguments in the java code :)

    if u want it to be serverrestart instead of serverreload type that in the plugin.yml and change ur code too :)

    soz i didnt reply fast i was at tennis b4 :)


    That wont work because his command is still serverreload btw :) it doesnt matter if u type /<command> or the actual command, it just makes it easier when copy and pasting

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

    kmccmk9

    Great, thanks. Boy do I feel stupid lol :p

    EDIT: But wait, my code does look for the command /serverrestart
     
  12. Offline

    Jayjay110

    lol dont, thats how I felt when I did that too :p


    P.S, how did u get plugin developer in your member thingy, Ive been looking for it lol
     
  13. Offline

    1337

    Make a few good plugins :D
     
  14. Offline

    Jayjay110

    lol ok :p
     
  15. Offline

    kmccmk9

    You mean the purple developer logo under my name?

    But I'm confused with the plugin.yml, if my code is waiting for the command /serverrestart, why do I have to change it to serverreload in the plugin.yml?

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

    Jayjay110

    oh sorry I thought that ur plugin was waiting for serverreload because thats what you typed when you error popped up, what is your java code looking for in the command?

    and yes the purple thing lol
     
  17. Offline

    kmccmk9

    Lol ok my code is waiting for the command, /serverrestart <time>.

    Maybe I did issue the wrong command repeatedly. I'm gonna give it another shot tomorrow. Thank you for all your help, I will post results.

    Btw, I got it from designing one plugin, it was automatically given.
     
  18. Offline

    Jayjay110

    ah ok thats kool :), well then revert your plugin.yml to what you had before I told you what to do and type /serverrestart <time> instead of reload :p
     
  19. Offline

    kmccmk9

    Ok now I'm confused, here is my plugin code


    Code:
    package com.kmccmk9.ServerRestarter;
    
    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 ServerRestarter extends JavaPlugin {
        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("ServerRestart has been disabled.");
        }
    
        public void onEnable() {
            // TODO Auto-generated method stub
            server = this.getServer();
            log.info("ServerRestart 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;
                            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>");
                        }
                    }
                }
            }
            return true;
        }
    }
    
    And this is my plugin.yml

    Code:
    name: ServerRestarter
    main: com.kmccmk9.ServerRestarter.ServerRestarter
    version: 0.01
    commands:
      serverreload:
        description: A plugin that allows for in game server restarts with timer!
        usage: |
                /serverreload
                
    Now why am I still getting an unknown command error?
     
  20. Offline

    iPhysX

    under server restarter put..

    Code:
    public static ServerRestarter plugin;
    and in onEnable() put...

    Code:
    plugin = this;
    and

    Code:
    name: ServerRestarter
    main: com.kmccmk9.ServerRestarter.ServerRestarter
    version: 0.01
    commands:
      serverreload:
        description: A plugin that allows for in game server restarts with timer!
        usage: /serverreload
     
  21. Offline

    kmccmk9

    Thanks for the reply but for some reason I get this error int he console when executing the command

    Code:
    23:20:05 [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: 0
            at com.kmccmk9.ServerReloader.ServerReloader.onCommand(ServerReloader.java:59)
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:35)
            ... 12 more
    
     
  22. Offline

    iPhysX

    yes what Exactly did you type, because the ZERO you typed in is causing it..
    line 59 of your plugin.. should be in your onCommand!

    try

    Code:
    if (args.length >= 0)
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jul 16, 2016
  23. Offline

    kmccmk9

    That's strange everything is inside the onCommand except for return true; I typed in /serverreload help

    I believe your second post fixed it thanks!
     
  24. Offline

    iPhysX

    yeah no problem!
    Good luck :D
     
  25. Offline

    kmccmk9

    Ok this is my code and I can't figure out why its not working.

    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;
                            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>");
                        }
                    }
                }
            }
            return true;
        }
    }
    
     
  26. Offline

    iPhysX

    i think

    Code:
    enteredtime = args[1];
    and
    Code:
    if (args[1] == "help")
    not 100% sure though!
     
  27. Offline

    kmccmk9

    That didn't seem to change anything :(
     
  28. Offline

    iPhysX

    hmm. im not going to be good at this.
    i dont really know. Ill keep looking!
     
  29. Offline

    kmccmk9

    Lol ok thanks. Would it help if I copied the error message in console?
     
  30. Offline

    iPhysX

    yes that would help :D
     
Thread Status:
Not open for further replies.

Share This Page