From c3008d9608a460d1933c6ab8ea316596b0bbde8a Mon Sep 17 00:00:00 2001 From: Charlie Wang Date: Sun, 30 Jun 2013 15:46:52 -0400 Subject: [PATCH] Renamed cycleSheepColours to randomizeSheepColours, and implemented it using a lookup table of accetable disco colours --- .../bukkit/discosheep/DiscoSheep.java | 21 ++++++++++++++++--- .../bukkit/discosheep/DiscoUpdater.java | 2 +- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/gibstick/bukkit/discosheep/DiscoSheep.java b/src/gibstick/bukkit/discosheep/DiscoSheep.java index 4e54979..7a7c45d 100644 --- a/src/gibstick/bukkit/discosheep/DiscoSheep.java +++ b/src/gibstick/bukkit/discosheep/DiscoSheep.java @@ -1,6 +1,8 @@ package gibstick.bukkit.discosheep; import java.util.ArrayList; +import java.util.Random; +import org.bukkit.DyeColor; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.entity.EntityType; @@ -12,6 +14,19 @@ import org.bukkit.plugin.java.JavaPlugin; public final class DiscoSheep extends JavaPlugin { private ArrayList sheepArray = new ArrayList(); + private static final DyeColor[] discoColours = { + DyeColor.RED, + DyeColor.ORANGE, + DyeColor.YELLOW, + DyeColor.GREEN, + DyeColor.BLUE, + DyeColor.LIGHT_BLUE, + DyeColor.PINK, + DyeColor.MAGENTA, + DyeColor.LIME, + DyeColor.CYAN, + DyeColor.PURPLE + }; // array of accetable disco colours (order not important) private DiscoUpdater updater = new DiscoUpdater(this); // radius for random sheep spawns around player private static int sheepSpawnRadius = 5; @@ -59,10 +74,10 @@ public final class DiscoSheep extends JavaPlugin { sheepArray.clear(); } - // Cycle colours of all sheep in the array - void cycleSheepColours() { + // Set a random colour for all sheep in array + void randomizeSheepColours() { for (int i = 0; i < sheepArray.size(); i++) { - //sheepArray.get(i) something something + sheepArray.get(i).setColor(discoColours[(int)Math.random() * discoColours.length]); } } diff --git a/src/gibstick/bukkit/discosheep/DiscoUpdater.java b/src/gibstick/bukkit/discosheep/DiscoUpdater.java index cf6ff55..d383c84 100644 --- a/src/gibstick/bukkit/discosheep/DiscoUpdater.java +++ b/src/gibstick/bukkit/discosheep/DiscoUpdater.java @@ -27,7 +27,7 @@ public class DiscoUpdater extends BukkitRunnable { @Override public void run() { if (duration > 0) { - parent.cycleSheepColours(); + parent.randomizeSheepColours(); parent.playSounds(); duration -= frequency; parent.scheduleUpdate();