Bukkit need timer

Discussion in 'Plugin Development' started by kevin3220, Aug 1, 2013.

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

    kevin3220

    Hello,


    Is it possibel to make timer, but not in mainclass. I need to start timer for 10 seconds if player writes /t


    Thank you
     
  2. Offline

    savagesun

  3. Offline

    JPG2000

    kevin3220 To awnser your question, absolutey. People use countdowns all the time (Join a server with a minigame). Use the bukkit scheduler. There are plent of tutorials on youtube, I find that the best is from pogostick29dev
     
  4. Offline

    kevin3220

    Dosent work ;(

    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    2. play=(Player) sender;
    3. if(label.equalsIgnoreCase("test")){
    4. Location loc=new Location(Bukkit.getWorld("world"), -104, 67, 307);
    5. int minuoma=-104+67+307-1;
    6. Location pl=play.getLocation();
    7. int summa=pl.getBlockX()+pl.getBlockY()+pl.getBlockZ();
    8. if(minuoma==summa){
    9. juhus=ra.nextInt(10);
    10. if(juhus<=6){
    11. Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
    12. @Override
    13. public void run() {
    14. Bukkit.broadcastMessage("TESTUNG");
    15.  
    16.  
    17. }
    18. },0L,100L);
    19.  
    20.  
    21. return true;
    22. }else{
    23. play.sendMessage("FAIL");
    24. return true;
    25. }
    26. }else{
    27. play.sendMessage("You are not @ test location!");
    28.  
    29. return true;
    30. }
    31.  
    32.  
    33.  
    34.  
    35. }
    36. return false;}}
    37.  
    38.  
    39.  
     
  5. Offline

    stonar96

    Befor you post this code you should look for a tutorial how to format your source code, that i can read it without searching for the if, witch belongs to the else.

    Example:
    Code:java
    1. if (boolean1) {
    2. System.out.println("boolean1 is true");
    3. }
    4.  
    5. if (boolean2) {
    6. System.out.println("boolean2 is true");
    7. } else {
    8. System.out.println("boolean2 is false");
    9.  
    10. if (boolean3) {
    11. System.out.println("boolean3 is true");
    12. } else {
    13. System.out.println("boolean3 is false");
    14. }
    15. }


    It would be also nice, if you tell us what this should do.

    Now about your code:
    Why do you add your locations, and compare the sum? You can also compare your locations, or the single coordinates.
    I see you use a repeating task. I thought you need a delay. If you only need a delay of 10 seconds, you should use a delayed task. For 10 seconds you have to write 200L instead of 100L, because 1 second = 20 ticks. Your code will write TESTUNG every 5 seconds.

    I don´t know what you want to do, but in my opinion this code is waste!

    (Sry for my bad english!)
     
  6. Offline

    xTrollxDudex

    kevin3220
    You really need to learn more java
     
  7. Offline

    kevin3220

    it was Alpha code xD

    Yeah, i know Java. I am new with tasks. In Java i use Thread.sleep(). I tried that once in Bukkit... It went wrong;(

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

    stonar96

    Thread.sleep() in the main thread will freeze the whole server! xD
     
Thread Status:
Not open for further replies.

Share This Page