Refactored to make DiscoUpdater only call the update method on DiscoSheep and moved all the update logic to DiscoSheep.
This commit is contained in:
parent
a087e07052
commit
1c350e844d
@ -35,7 +35,7 @@ public final class DiscoSheep extends JavaPlugin {
|
||||
private final int defaultSheepAmount = 10;
|
||||
private final int defaultDuration = 1000;// ticks
|
||||
private final int defaultFrequency = 20;// ticks per state change
|
||||
|
||||
private int frequency = 0, duration = 0;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
@ -52,7 +52,7 @@ public final class DiscoSheep extends JavaPlugin {
|
||||
return sheepArray;
|
||||
}
|
||||
|
||||
ArrayList<Player> getPlayers(){
|
||||
ArrayList<Player> getPlayers() {
|
||||
return this.playerArray;
|
||||
}
|
||||
|
||||
@ -105,22 +105,32 @@ public final class DiscoSheep extends JavaPlugin {
|
||||
//TODO: Add sound playing here
|
||||
}
|
||||
|
||||
// Called after discosheep is stopped
|
||||
void cleanUp() {
|
||||
removeAllSheep();
|
||||
this.playerArray.clear();
|
||||
void update() {
|
||||
if (duration > 0) {
|
||||
randomizeSheepColours();
|
||||
playSounds();
|
||||
duration -= frequency;
|
||||
this.scheduleUpdate();
|
||||
} else {
|
||||
this.stopDisco();
|
||||
}
|
||||
}
|
||||
|
||||
void scheduleUpdate() {
|
||||
updater.runTaskLater(this, updater.frequency);
|
||||
new DiscoUpdater(this).runTaskLater(this, this.frequency);
|
||||
}
|
||||
|
||||
void startDisco(int duration, List<Player> players) {
|
||||
if(this.duration > 0){
|
||||
stopDisco();
|
||||
}
|
||||
this.playerArray.addAll(players);
|
||||
for(Player player : players){
|
||||
this.spawnSheep(player, this.defaultSheepAmount);
|
||||
}
|
||||
updater.start(duration,this.defaultFrequency);
|
||||
this.frequency = this.defaultFrequency;
|
||||
this.duration = this.defaultDuration;
|
||||
this.scheduleUpdate();
|
||||
}
|
||||
|
||||
void startDisco(List<Player> players) {
|
||||
@ -128,6 +138,8 @@ public final class DiscoSheep extends JavaPlugin {
|
||||
}
|
||||
|
||||
void stopDisco() {
|
||||
updater.stop();
|
||||
removeAllSheep();
|
||||
this.playerArray.clear();
|
||||
this.duration = 0;
|
||||
}
|
||||
}
|
||||
|
@ -4,33 +4,14 @@ import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class DiscoUpdater extends BukkitRunnable {
|
||||
|
||||
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 = frequency;
|
||||
this.duration = duration;
|
||||
parent.scheduleUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (duration > 0) {
|
||||
parent.randomizeSheepColours();
|
||||
parent.playSounds();
|
||||
duration -= frequency;
|
||||
parent.scheduleUpdate();
|
||||
} else {
|
||||
this.stop();
|
||||
}
|
||||
parent.update();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user