Created
October 11, 2014 16:05
-
-
Save keepoff07/09286b116bfee015514d to your computer and use it in GitHub Desktop.
[Bukkit] TimerSample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.github.keepoff07.hiyaserver.blockparty.timer; | |
import org.bukkit.Bukkit; | |
import org.bukkit.Sound; | |
import org.bukkit.entity.Player; | |
public class ExpManager { | |
private JavaPlugin main; | |
public static void setMain(JavaPlugin plugin){ | |
main = plugin; | |
} | |
public static void setAllExp(int level, float xp, Sound sound){ | |
for(Player p : Bukkit.getOnlinePlayers()){ | |
p.setLevel(level); | |
p.setExp(xp); | |
if(sound != null) p.playSound(p.getLocation(), sound, 1F, 1F); | |
} | |
} | |
public static void setTimer(int time){ | |
new ExpTask(time).runTaskLater(main, 20); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.github.keepoff07.hiyaserver.blockparty.timer; | |
import org.bukkit.Sound; | |
import org.bukkit.scheduler.BukkitRunnable; | |
public class ExpTask extends BukkitRunnable { | |
private int n; | |
public ExpTask(int time){ | |
n = time; | |
} | |
@Override | |
public void run() { | |
if(n >= 10){ | |
ExpManager.setAllExp(n, 1F, null); | |
n--; | |
ExpManager.setTimer(n, d); | |
}else if(n == 0){ | |
ExpManager.setAllExp(n, 0F, Sound.EXPLODE); | |
}else{ | |
float a = ((float)n)/10F; | |
ExpManager.setAllExp(n, a, Sound.CLICK); | |
n--; | |
ExpManager.setTimer(n, d); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.bukkit.plugin.java.JavaPlugin; | |
public class Main extends JavaPlugin{ | |
public void onEnable(){ | |
ExpManager.setMain(this); | |
} | |
public void onDisable() { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment