Solved You can DELETE THIS:)

Discussion in 'Plugin Development' started by vasil7112, Oct 28, 2012.

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

    vasil7112

    Hello, is it possible to make a countdown? I tried with sceduler but i failed.
     
  2. Offline

    ZeusAllMighty11 Retired Staff

    repeating task, -- on a variable int, use switch statement to check time
     
  3. Offline

    HamOmlet

    Perhaps something like this:

    Code:
    final int timer = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
      int count = 100 // Five seconds
      public void run() {
      switch(count--) {
      //code
      Bukkit.getScheduler().cancelTask(timer);
      }
    }, 0L, 20L);
     
  4. Offline

    vasil7112

    I thought to make a thread.sleep, will this work?
     
  5. Offline

    HamOmlet

    Sure.
     
  6. Offline

    vasil7112

    Alright thanks:)
     
  7. Offline

    Tzeentchful

    NEVER do thread.sleep in bukkit (unless using an async task) it will sleep the server thread so you will freeze the entire server.
     
    ZeusAllMighty11 and gomeow like this.
  8. Offline

    vasil7112

    So if i want to do something simple , countdown from 3 to 1. do i just not use the tread.sleep and use the above options? Or do you have an other code?
     
  9. Offline

    Squirtle771

    why not just do
    Code:
    int countfrom = 10
    while(countfrom > 0){
    getServer().broadcastMessage(countfrom);
    countfrom--
    }
    
    Replacing the value of countfrom with what you actually want to count from...
    Then if you want to do something when it is 0
    Code:
    int countfrom = 10
    while(countfrom > 0){
    getServer().broadcastMessage(countfrom);
    countfrom--
    if(countfrom == 0){
    //Do something
    }
    
     
  10. Offline

    vasil7112

    This needs to have a sceduler right? The problem is i get an error with the scheduler. Anyways , i g2g school. I will give you the error in 7-8 hours
     
  11. Offline

    Squirtle771

    This is stand alone code, designed to disregard the schedular, so no, it doesn't need one.
     
  12. Offline

    gomeow

    It would seem that he does not want a countdown that fast
     
  13. Offline

    vasil7112

    I need a countdown 3-1 for 1 sec each

    It goes to fast. How much is 3 seconds?

    Have a look on an error i get on my sceduler :)
    Code:
    2012-10-29 16:37:15 [SEVERE] Could not pass event InventoryClickEvent to PLUGIN
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:341)
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:477)
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:462)
        at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:1108)
        at net.minecraft.server.Packet102WindowClick.handle(SourceFile:29)
        at net.minecraft.server.NetworkManager.b(NetworkManager.java:282)
        at net.minecraft.server.NetServerHandler.d(NetServerHandler.java:109)
        at net.minecraft.server.ServerConnection.b(SourceFile:35)
        at net.minecraft.server.DedicatedServerConnection.b(SourceFile:30)
        at net.minecraft.server.MinecraftServer.q(MinecraftServer.java:577)
        at net.minecraft.server.DedicatedServer.q(DedicatedServer.java:213)
        at net.minecraft.server.MinecraftServer.p(MinecraftServer.java:473)
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:405)
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:539)
    Caused by: java.lang.IllegalArgumentException: Plugin cannot be null
        at org.apache.commons.lang.Validate.notNull(Validate.java:203)
        at org.bukkit.craftbukkit.scheduler.CraftScheduler.validate(CraftScheduler.java:367)
        at org.bukkit.craftbukkit.scheduler.CraftScheduler.scheduleSyncRepeatingTask(CraftScheduler.java:99)
        at me.vasil7112.PLUGIN.Events.JUSTACLASS.onInventoryClick(JUSTACLASS.java:42)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:339)
        ... 14 more
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 29, 2016
  14. Offline

    Infamous Jeezy

    You should learn how to read the stack-errors which can be found in one of the stickies.
    Here is your problem:
    Caused by: java.lang.IllegalArgumentException: Plugin cannot be null
    Although I cannot find out what exactly is causing this error without seeing your code, I believe the error is on line 42 of JUSTACLASS.java. You could either post that line or just paste the whole thing to find out your problem quicker.
     
  15. Offline

    vasil7112

    Man i know how to read the errors. The problem is i could not understand why i get this error
    line 42 final int timer = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {

    How do i declare that plugin
    public static Main plugin;
    public static void init(Main i)
    {
    plugin = i;
    }
     
  16. Offline

    Remi1115

    Could you post the line(s) in the plugin that uses this method please?
     
  17. Offline

    vasil7112

    final int timer = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
    int count = 60; // 3 seconds
    public void run() {
    if(count == 60){
    player.sendMessage(ChatColor.GOLD + "3...");
    }
    if(count == 40){
    player.sendMessage(ChatColor.GOLD + "2...");
    }
    if(count == 20){
    player.sendMessage(ChatColor.GOLD + "1...");
    }
    switch(count--) {
    }
    }

    }, 0L, 20L);
    Bukkit.getScheduler().cancelTask(timer);
    }

    Code taken by here


    Perhaps something like this:

    Code:
    final int timer = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
    int count = 100 // Five seconds
    public void run() {
    switch(count--) {
    //code
    Bukkit.getScheduler().cancelTask(timer);
    }
    }, 0L, 20L);


    Oh and it is here: public void onInventoryClick(InventoryClickEvent e)

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

    Remi1115

    Sorry, I mean where the 'init' method gets called.
    And could you please post your code between the '[ syntax=Java ] {CODE} [ /syntax]' (without the spaces)? It makes it easier to read for other people.
     
  19. Offline

    Infamous Jeezy

    Is your scheduler in your main class or a different one?
     
  20. Offline

    vasil7112

    Sorry i don't get what exactly you want, do you mind if i send you privatly the whole code? Or if it is easier for you, add me on skype and make you a sharescreen. (Skypename: vasil7112)

    Different one:)

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

    Remi1115

    That's probably the problem. Do you use 'this' for the argument when using 'init' method, or the instance of the Main class? (Sorry, I can't seem to be able to explain it any other way).
     
  22. Offline

    Infamous Jeezy

    Declaring the plugin should look like this:
    Code:java
    1.  
    2. CHANGEME plugin;
    3. METOO(CHANGEME p)
    4. {
    5. plugin = p;
    6. }
    7.  

    Where it says CHANGEME put the name of your main plugin. Where it says METOO put the name of the class where your scheduler is. Pretty sure class names are case-sensitive to make sure you type the names in correctly.
     
  23. Offline

    vasil7112

    Same error
     
  24. Offline

    Infamous Jeezy

    Post that class here and put it in code tags please.
     
  25. Offline

    vasil7112

    Fixed IT! I AM SO HAPPY! Thanks:)
     
Thread Status:
Not open for further replies.

Share This Page