Added updater code

This commit is contained in:
RangerMauve 2013-06-30 13:53:07 -04:00
parent f2d1cbde35
commit 337a491dc6
2 changed files with 68 additions and 3 deletions

View File

@ -11,7 +11,8 @@ import org.bukkit.entity.Player;
public final class DiscoSheep extends JavaPlugin {
private ArrayList<Sheep> sheepArray = new ArrayList<>();
private DiscoUpdater updater = new DiscoUpdater();
@Override
public void onEnable() {
getCommand("ds").setExecutor(new DiscoSheepCommandExecutor(this));
@ -52,6 +53,35 @@ public final class DiscoSheep extends JavaPlugin {
//sheepArray.get(i) something something
}
}
public void playSounds(){
// TODO: generate list of players to send sounds to
}
public void playSounds(Player player){
//TODO: Add sound playing here
}
/*
Called after discosheep is stopped
*/
public void cleanUp(){
removeAllSheep();
}
void scheduleUpdate(){
updater.runTaskLater(updater,frequency);
}
public void startDisco(int frequency, int duration){
updater.start(frequency, duration);
}
public void startDisco(){
this.startDisco();
}
public void stopDisco(){
updater.stop();
}
}

View File

@ -0,0 +1,35 @@
public class DiscoUpdater extends BukkitRunnable{
private final int defaultDuration = 1000;// ticks
private final int defaultFrequency = 20;// ticks per state change
int frequency=0,duration=0;
private DiscoSheep parent;
public DiscoUpdater(DiscoSheep parent){
this.parent = parent;
}
public void stop(){
this.duration = 0;
parent.cleanUp();
}
public void start(int duration, int frequency){
this.frequency = this.defaultFrequency;
this.durtion = this.defaultDuration;
parent.scheduleUpdate();
}
public void run(){
if(duration > 0){
cycleSheepColours();
playSounds();
duration -= frequency;
parent.scheduleUpdate(this);
} else {
this.stop();
}
}
}