diff --git a/src/gibstick/bukkit/discosheep/BaaBaaBlockSheepEvents.java b/src/gibstick/bukkit/discosheep/BaaBaaBlockSheepEvents.java index 9898bcb..2b9876a 100644 --- a/src/gibstick/bukkit/discosheep/BaaBaaBlockSheepEvents.java +++ b/src/gibstick/bukkit/discosheep/BaaBaaBlockSheepEvents.java @@ -7,7 +7,6 @@ package gibstick.bukkit.discosheep; import org.bukkit.entity.Sheep; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; -import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.player.PlayerShearEntityEvent; /** diff --git a/src/gibstick/bukkit/discosheep/DiscoParty.java b/src/gibstick/bukkit/discosheep/DiscoParty.java index 335243f..ccf5d1c 100644 --- a/src/gibstick/bukkit/discosheep/DiscoParty.java +++ b/src/gibstick/bukkit/discosheep/DiscoParty.java @@ -2,13 +2,19 @@ package gibstick.bukkit.discosheep; import java.util.ArrayList; import java.util.List; +import java.util.Random; +import org.bukkit.Color; import org.bukkit.DyeColor; import org.bukkit.Location; import org.bukkit.Sound; import org.bukkit.World; import org.bukkit.entity.EntityType; +import org.bukkit.entity.Firework; import org.bukkit.entity.Player; import org.bukkit.entity.Sheep; +import org.bukkit.FireworkEffect; +import org.bukkit.FireworkEffect.Builder; +import org.bukkit.inventory.meta.FireworkMeta; /** * @@ -18,7 +24,7 @@ public class DiscoParty { private DiscoSheep ds; private Player player; - private ArrayList sheepList= new ArrayList(); + private ArrayList sheepList = new ArrayList(); private int duration, frequency = 20, numSheep = 5; private final int defaultDuration = 300; // ticks for entire party private final int defaultFrequency = 10; // ticks per state change @@ -88,26 +94,117 @@ public class DiscoParty { // Set a random colour for all sheep in array void randomizeSheepColour(Sheep sheep) { - sheep.setColor(discoColours[(int) Math.round(Math.random() * (discoColours.length - 1))]); + sheep.setColor(discoColours[(int) Math.round(Math.random() * (discoColours.length - 1))]); } - + + private Color getColor(int i) { + Color c = null; + if (i == 1) { + c = Color.AQUA; + } + if (i == 2) { + c = Color.BLACK; + } + if (i == 3) { + c = Color.BLUE; + } + if (i == 4) { + c = Color.FUCHSIA; + } + if (i == 5) { + c = Color.GRAY; + } + if (i == 6) { + c = Color.GREEN; + } + if (i == 7) { + c = Color.LIME; + } + if (i == 8) { + c = Color.MAROON; + } + if (i == 9) { + c = Color.NAVY; + } + if (i == 10) { + c = Color.OLIVE; + } + if (i == 11) { + c = Color.ORANGE; + } + if (i == 12) { + c = Color.PURPLE; + } + if (i == 13) { + c = Color.RED; + } + if (i == 14) { + c = Color.SILVER; + } + if (i == 15) { + c = Color.TEAL; + } + if (i == 16) { + c = Color.WHITE; + } + if (i == 17) { + c = Color.YELLOW; + } + + return c; + } + void updateAllSheep() { - for (Sheep sheep: getSheep()) { + for (Sheep sheep : getSheep()) { randomizeSheepColour(sheep); + if (state % 8 == 0) { + spawnRandomFireworkAtSheep(sheep); + } } } void playSounds() { player.playSound(player.getLocation(), Sound.NOTE_BASS_DRUM, 1.0f, 1.0f); - if(this.state%2 == 0){ + if (this.state % 2 == 0) { player.playSound(player.getLocation(), Sound.NOTE_SNARE_DRUM, 1.0f, 1.0f); } - if(this.state%3 == 0){ + if (this.state % 4 == 0) { player.playSound(player.getLocation(), Sound.NOTE_STICKS, 1.0f, 1.0f); } player.playSound(player.getLocation(), Sound.BURP, 0.5f, (float) Math.random() + 1); } + void randomizeFirework(Firework firework) { + Random r = new Random(); + Builder effect = FireworkEffect.builder(); + FireworkMeta meta = firework.getFireworkMeta(); + + // construct [1, 3] random colours + int numColours = r.nextInt(3) + 1; + Color[] colourArray = new Color[numColours]; + for (int i = 0; i < numColours; i++) { + colourArray[i] = getColor(r.nextInt(17) + 1); + } + + // randomize effects + effect.withColor(colourArray); + effect.flicker(r.nextDouble() < 0.5); + effect.trail(r.nextDouble() < 0.5); + effect.with(FireworkEffect.Type.values()[r.nextInt(FireworkEffect.Type.values().length)]); + + // set random effect and randomize power + meta.addEffect(effect.build()); + meta.setPower(r.nextInt(2)); + + // apply it to the given firework + firework.setFireworkMeta(meta); + } + + void spawnRandomFireworkAtSheep(Sheep sheep) { + Firework firework = (Firework) sheep.getWorld().spawnEntity(sheep.getEyeLocation(), EntityType.FIREWORK); + randomizeFirework(firework); + } + void update() { if (duration > 0) { updateAllSheep();