Solved How to makea Exp Countdown???

Discussion in 'Plugin Development' started by FisheyLP, Feb 23, 2014.

Thread Status:
Not open for further replies.
  1. I know how to set xp levels and how to use for-loops and schedulers, but how can i combine them all the get a xp-countdown? pls help me :)
     
  2. Offline

    badboystee

    Do you have any code for this? If so share it so people can help :)
     
  3. Offline

    L33m4n123

    set their level to the remaining seconds

    want to display the total time left in the exp bar?

    then think about that the max time equals 100% which equals setExp(1F)
    then get the seconds left.. get the ammount of % and set the exp accordingly
     
  4. solved it myself ^^
    Code:JAVA
    1.  
    2. if(commandLabel.equalsIgnoreCase("countdown")){
    3. Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable(){
    4. public int xpscheduler;
    5. int number = 15;
    6. public void run(){
    7. if(number !=0){
    8. if(number <= 5){
    9. p.playSound(p.getLocation(), Sound.ORB_PICKUP, 1, 1);
    10. }
    11. p.setLevel(number);
    12. number--;
    13. }else{
    14. p.setLevel(0);
    15. Bukkit.getScheduler().cancelTask(xpscheduler);
    16. p.playSound(p.getLocation(), Sound.LEVEL_UP, 1, 1);
    17. }
    18. }
    19. }, 0L, 1*20L);
    20. return true;
    21. }
    22.  

    anyone of you know how to cancel just this one scheduling task instead of cancelAllTasks()? or how to make multiple schedulers? :)
     
  5. Offline

    TopTobster5

    FisheyLP Give the schedualr a name when you declare it.
    Code:java
    1. public static int scheduler; // Don't ask my why this line is how it is, I'm not sure, it's just something I have always done.
    2.  
    3. scheduler = Bukkit.getScheduler().scheduleSyncRepeatingTask//blah blah blah
    4.  
    5.  
    6.  


    Then cancel it using:
    Code:java
    1. Bukkit.getScheduler().cancelTask(scheduler);


    (I haven't tested this code, but I'm pretty sure this is how it works)

    Bukkit will generate a task ID for the task you have, and there are functions to get hold of it (I think it's getTaskID() or something like that) but this must be ran from inside of the task, so my method works if you wish to cancel the task from outside.
     
  6. TopTobster5
    that didnt work on public static int scheduler; scheduler gets red underlined with this error: Illegal modifier for the variable scheduler; only final is permitted, and i tried something like public final int scheduler; but it didnt work too

    TopTobster5
    i think i got it now, i put the static away and wrote the same between Bukkit.getServer.getScheduler().balblabla and public void run(){ but didnt tested it out, it doesnt show any errors :)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  7. badboystee
    if you share please give me credits :D
     
  8. Offline

    badboystee


    I didn't share :p
     
  9. badboystee
    And whats that? ^^
     
Thread Status:
Not open for further replies.

Share This Page