From 337a491dc646b11361e5a1f429b3b0407f977e73 Mon Sep 17 00:00:00 2001 From: RangerMauve Date: Sun, 30 Jun 2013 13:53:07 -0400 Subject: [PATCH] Added updater code --- .../bukkit/discosheep/DiscoSheep.java | 36 +++++++++++++++++-- .../bukkit/discosheep/DiscoUpdater.java | 35 ++++++++++++++++++ 2 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 src/gibstick/bukkit/discosheep/DiscoUpdater.java diff --git a/src/gibstick/bukkit/discosheep/DiscoSheep.java b/src/gibstick/bukkit/discosheep/DiscoSheep.java index 856c60b..93c15b3 100644 --- a/src/gibstick/bukkit/discosheep/DiscoSheep.java +++ b/src/gibstick/bukkit/discosheep/DiscoSheep.java @@ -11,7 +11,8 @@ import org.bukkit.entity.Player; public final class DiscoSheep extends JavaPlugin { private ArrayList 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(); + } } diff --git a/src/gibstick/bukkit/discosheep/DiscoUpdater.java b/src/gibstick/bukkit/discosheep/DiscoUpdater.java new file mode 100644 index 0000000..d152def --- /dev/null +++ b/src/gibstick/bukkit/discosheep/DiscoUpdater.java @@ -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(); + } + } +} \ No newline at end of file