Trying to create a timer

Discussion in 'Spigot Plugin Development' started by ryu, Jun 12, 2016.

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

    ryu

    Hello I am trying to create a command where when you do /timer it sends the player a message with the time remaining. But for some reason I am getting an error when I start up the server and I don't know why.

    Code:
    http://hastebin.com/vocifoxamo.avrasm

    Error:
    Code (Text):
    [03:30:18] [Server thread/INFO]: [0;32;1mWithdraw Advanced [0;33;1mhas been enabled![m
    [03:30:18] [Server thread/ERROR]: Error occurred while enabling WithdrawAdvanced v1.0 (Is it up to date?)
    java.lang.IllegalArgumentException: Illegal pattern character 'r'
        at java.text.SimpleDateFormat.compile(Unknown Source) ~[?:1.8.0_91]
        at java.text.SimpleDateFormat.initialize(Unknown Source) ~[?:1.8.0_91]
        at java.text.SimpleDateFormat.<init>(Unknown Source) ~[?:1.8.0_91]
        at java.text.SimpleDateFormat.<init>(Unknown Source) ~[?:1.8.0_91]
        at dev.ryujix.withdraw.Commands.Timer.<init>(Timer.java:14) ~[?:?]
        at dev.ryujix.withdraw.WithdrawAdvanced.registerCommands(WithdrawAdvanced.java:56) ~[?:?]
        at dev.ryujix.withdraw.WithdrawAdvanced.onEnable(WithdrawAdvanced.java:34) ~[?:?]
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) ~[1.8.jar:git-Spigot-550ebac-7019900]
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:335) [1.8.jar:git-Spigot-550ebac-7019900]
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405) [1.8.jar:git-Spigot-550ebac-7019900]
        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.loadPlugin(CraftServer.java:356) [1.8.jar:git-Spigot-550ebac-7019900]
        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.enablePlugins(CraftServer.java:316) [1.8.jar:git-Spigot-550ebac-7019900]
        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.reload(CraftServer.java:746) [1.8.jar:git-Spigot-550ebac-7019900]
        at org.bukkit.Bukkit.reload(Bukkit.java:534) [1.8.jar:git-Spigot-550ebac-7019900]
        at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:25) [1.8.jar:git-Spigot-550ebac-7019900]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) [1.8.jar:git-Spigot-550ebac-7019900]
        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchCommand(CraftServer.java:646) [1.8.jar:git-Spigot-550ebac-7019900]
        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchServerCommand(CraftServer.java:632) [1.8.jar:git-Spigot-550ebac-7019900]
        at net.minecraft.server.v1_8_R1.DedicatedServer.aM(DedicatedServer.java:353) [1.8.jar:git-Spigot-550ebac-7019900]
        at net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:317) [1.8.jar:git-Spigot-550ebac-7019900]
        at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:634) [1.8.jar:git-Spigot-550ebac-7019900]
        at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:537) [1.8.jar:git-Spigot-550ebac-7019900]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_91]
     
     
  2. Code (Text):
    private SimpleDateFormat format = new SimpleDateFormat("hh hr mm min ss sec");
    That hR is giving the error. ;)
     
  3. ryu

    ryu

    Would you know how I would be able to label everything so like hours mins seconds?
    bc this is what I'm getting atm:
    [​IMG]
     
  4. Bruh.. Just use a for statement in a repeating task..

    Code (Text):
    //(You can use a int outside of the method for cancellation, so public static int a; then a = (code))
    //String is countdown
    final String string = "";
    Bukkit.getScheduler().scheduleSyncRepeatinTask(plugin, new Runnable(){
        public void run(){
            for(int i = 10; i <= 0;i--) {//By putting 10, it has a delay of 10 seconds
                string = ""+i;
                //restart
                if(i == 0){
                    i = 10;
                }
            }
        }
    }, 0L, 20L); //20 ticks = 1 second
     
    • Useful Useful x 1
    • Optimistic Optimistic x 1
  5. final String string = "";
    string = ""+i;

    Good luck with that ;)
     
    • Funny Funny x 1
Thread Status:
Not open for further replies.