Skip to content

Instantly share code, notes, and snippets.

@keepoff07
Created October 11, 2014 16:05
Show Gist options
  • Save keepoff07/09286b116bfee015514d to your computer and use it in GitHub Desktop.
Save keepoff07/09286b116bfee015514d to your computer and use it in GitHub Desktop.
[Bukkit] TimerSample
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);
}
}
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);
}
}
}
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