Added updater code
This commit is contained in:
parent
f2d1cbde35
commit
337a491dc6
@ -11,6 +11,7 @@ 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() {
|
||||
@ -53,5 +54,34 @@ public final class DiscoSheep extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
35
src/gibstick/bukkit/discosheep/DiscoUpdater.java
Normal file
35
src/gibstick/bukkit/discosheep/DiscoUpdater.java
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user