From 2bcbbe187881f5a533cadc5d6b447b8a06558017 Mon Sep 17 00:00:00 2001 From: Charlie Wang Date: Mon, 17 Aug 2015 13:32:39 -0400 Subject: [PATCH] add fireworks, fix pentatonicParty volume --- src/me/cwang/discosheep/AbstractParty.java | 2 + src/me/cwang/discosheep/BasicDiscoParty.java | 37 ++---------- src/me/cwang/discosheep/DiscoCommands.java | 4 ++ src/me/cwang/discosheep/DiscoDecorator.java | 3 + src/me/cwang/discosheep/DiscoSheep.java | 4 +- src/me/cwang/discosheep/FireworkParty.java | 61 ++++++++++++++++++++ src/me/cwang/discosheep/PartyBuilder.java | 10 ++-- src/me/cwang/discosheep/PentatonicParty.java | 2 +- 8 files changed, 85 insertions(+), 38 deletions(-) create mode 100644 src/me/cwang/discosheep/FireworkParty.java diff --git a/src/me/cwang/discosheep/AbstractParty.java b/src/me/cwang/discosheep/AbstractParty.java index fb53836..05acf41 100644 --- a/src/me/cwang/discosheep/AbstractParty.java +++ b/src/me/cwang/discosheep/AbstractParty.java @@ -68,6 +68,8 @@ public abstract class AbstractParty { protected abstract int getState(); + protected abstract float getVolumeMultiplier(); + protected abstract Location getLocation(); protected abstract Sheep spawnSheep(); diff --git a/src/me/cwang/discosheep/BasicDiscoParty.java b/src/me/cwang/discosheep/BasicDiscoParty.java index 20651ee..fa3097f 100644 --- a/src/me/cwang/discosheep/BasicDiscoParty.java +++ b/src/me/cwang/discosheep/BasicDiscoParty.java @@ -3,7 +3,6 @@ package me.cwang.discosheep; import org.bukkit.*; import org.bukkit.entity.*; import org.bukkit.event.HandlerList; -import org.bukkit.inventory.meta.FireworkMeta; import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.util.Vector; @@ -121,6 +120,11 @@ public class BasicDiscoParty extends AbstractParty { return state; } + @Override + protected float getVolumeMultiplier() { + return volumeMultiplier; + } + @Override protected Location getLocation() { return partyLocation; @@ -152,37 +156,6 @@ public class BasicDiscoParty extends AbstractParty { return newGuest; } - - private void randomizeFirework(Firework firework) { - FireworkEffect.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) + 1); - - // 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); - } - /** * Setter for the static default settings. Takes the values from the current instance * and sets them as the defaults for all parties. diff --git a/src/me/cwang/discosheep/DiscoCommands.java b/src/me/cwang/discosheep/DiscoCommands.java index 994ac64..59f5afc 100644 --- a/src/me/cwang/discosheep/DiscoCommands.java +++ b/src/me/cwang/discosheep/DiscoCommands.java @@ -101,6 +101,9 @@ public class DiscoCommands implements CommandExecutor { } } break; + case 'w': + builder.fireworks(); + break; case 'l': if (sender.hasPermission(DiscoSheep.PERMISSION_LIGHTNING)) builder.lightning(); @@ -113,6 +116,7 @@ public class DiscoCommands implements CommandExecutor { break; case 'b': builder.baby(Integer.parseInt(g.getOptarg())); + break; } } catch (IllegalArgumentException e) { sender.sendMessage("Bad command: " + e.getMessage()); diff --git a/src/me/cwang/discosheep/DiscoDecorator.java b/src/me/cwang/discosheep/DiscoDecorator.java index 53d02c3..dc0edfb 100644 --- a/src/me/cwang/discosheep/DiscoDecorator.java +++ b/src/me/cwang/discosheep/DiscoDecorator.java @@ -53,6 +53,9 @@ public class DiscoDecorator extends AbstractParty { @Override protected int getState() { return decoratedParty.getState(); } + @Override + protected float getVolumeMultiplier() { return decoratedParty.getVolumeMultiplier(); } + @Override protected Location getLocation() { return decoratedParty.getLocation(); diff --git a/src/me/cwang/discosheep/DiscoSheep.java b/src/me/cwang/discosheep/DiscoSheep.java index c8edb2f..32ca98b 100644 --- a/src/me/cwang/discosheep/DiscoSheep.java +++ b/src/me/cwang/discosheep/DiscoSheep.java @@ -206,7 +206,9 @@ public final class DiscoSheep extends JavaPlugin { + "-g : set spawns for other mobs, eg. -g cow:5,pig:2\n" + "-l: enables lightning\n" + "-w: enables fireworks\n" - + "-j: enables alternative method for setting sheep colours\n"); + + "-j: enables alternative method for setting sheep colours\n" + + "-b : spawns a percentage of mobs as babies, if possible\n" + + "-P: enables pentatonic backing track\n"); return true; } diff --git a/src/me/cwang/discosheep/FireworkParty.java b/src/me/cwang/discosheep/FireworkParty.java new file mode 100644 index 0000000..db09cd4 --- /dev/null +++ b/src/me/cwang/discosheep/FireworkParty.java @@ -0,0 +1,61 @@ +package me.cwang.discosheep; + +import org.bukkit.Color; +import org.bukkit.FireworkEffect; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Firework; +import org.bukkit.entity.Sheep; +import org.bukkit.inventory.meta.FireworkMeta; + +import java.util.Random; + +/** + * Created by Charlie on 2015-08-17. + */ +public class FireworkParty extends DiscoDecorator { + Random r; + + public FireworkParty(AbstractParty p) { + super(p); + r = new Random(); + } + + + private void randomizeFirework(Firework firework) { + FireworkEffect.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) + 1); + + // apply it to the given firework + firework.setFireworkMeta(meta); + } + + private void spawnRandomFireworkAtSheep(Sheep sheep) { + Firework firework = (Firework) sheep.getWorld().spawnEntity(sheep.getEyeLocation(), EntityType.FIREWORK); + randomizeFirework(firework); + } + + @Override + protected void updateSheep(Sheep sheep) { + super.updateSheep(sheep); + if (getState() % 8 == 0 && r.nextDouble() < 0.5) { + spawnRandomFireworkAtSheep(sheep); + } + } +} diff --git a/src/me/cwang/discosheep/PartyBuilder.java b/src/me/cwang/discosheep/PartyBuilder.java index a004ff7..5613237 100644 --- a/src/me/cwang/discosheep/PartyBuilder.java +++ b/src/me/cwang/discosheep/PartyBuilder.java @@ -87,6 +87,11 @@ public class PartyBuilder { return this; } + public PartyBuilder fireworks() { + fireworks = true; + return this; + } + public PartyBuilder jeb() { jeb = true; return this; @@ -109,10 +114,7 @@ public class PartyBuilder { radius = denseRadius; } AbstractParty party = new BasicDiscoParty(player, duration, radius, period, sheep, guests); - if (fireworks) { - // do stuff - } - + if (fireworks) party = new FireworkParty(party); if (lightning) party = new LightningParty(party); if (jeb) party = new JebParty(party); if (pentatonic) party = new PentatonicParty(party); diff --git a/src/me/cwang/discosheep/PentatonicParty.java b/src/me/cwang/discosheep/PentatonicParty.java index e2ecb4c..d8ffc16 100644 --- a/src/me/cwang/discosheep/PentatonicParty.java +++ b/src/me/cwang/discosheep/PentatonicParty.java @@ -31,6 +31,6 @@ public class PentatonicParty extends DiscoDecorator { @Override protected void playSounds() { super.playSounds(); - getLocation().getWorld().playSound(getLocation(), Sound.NOTE_PIANO, 1.0f, getPentatonicNote()); + getLocation().getWorld().playSound(getLocation(), Sound.NOTE_PIANO, getVolumeMultiplier() * 1.0f, getPentatonicNote()); } }