add fireworks, fix pentatonicParty volume

This commit is contained in:
Charlie Wang 2015-08-17 13:32:39 -04:00
parent 5abaffeee7
commit 2bcbbe1878
8 changed files with 85 additions and 38 deletions

View File

@ -68,6 +68,8 @@ public abstract class AbstractParty {
protected abstract int getState(); protected abstract int getState();
protected abstract float getVolumeMultiplier();
protected abstract Location getLocation(); protected abstract Location getLocation();
protected abstract Sheep spawnSheep(); protected abstract Sheep spawnSheep();

View File

@ -3,7 +3,6 @@ package me.cwang.discosheep;
import org.bukkit.*; import org.bukkit.*;
import org.bukkit.entity.*; import org.bukkit.entity.*;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
import org.bukkit.inventory.meta.FireworkMeta;
import org.bukkit.metadata.FixedMetadataValue; import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
@ -121,6 +120,11 @@ public class BasicDiscoParty extends AbstractParty {
return state; return state;
} }
@Override
protected float getVolumeMultiplier() {
return volumeMultiplier;
}
@Override @Override
protected Location getLocation() { protected Location getLocation() {
return partyLocation; return partyLocation;
@ -152,37 +156,6 @@ public class BasicDiscoParty extends AbstractParty {
return newGuest; 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 * Setter for the static default settings. Takes the values from the current instance
* and sets them as the defaults for all parties. * and sets them as the defaults for all parties.

View File

@ -101,6 +101,9 @@ public class DiscoCommands implements CommandExecutor {
} }
} }
break; break;
case 'w':
builder.fireworks();
break;
case 'l': case 'l':
if (sender.hasPermission(DiscoSheep.PERMISSION_LIGHTNING)) if (sender.hasPermission(DiscoSheep.PERMISSION_LIGHTNING))
builder.lightning(); builder.lightning();
@ -113,6 +116,7 @@ public class DiscoCommands implements CommandExecutor {
break; break;
case 'b': case 'b':
builder.baby(Integer.parseInt(g.getOptarg())); builder.baby(Integer.parseInt(g.getOptarg()));
break;
} }
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
sender.sendMessage("Bad command: " + e.getMessage()); sender.sendMessage("Bad command: " + e.getMessage());

View File

@ -53,6 +53,9 @@ public class DiscoDecorator extends AbstractParty {
@Override @Override
protected int getState() { return decoratedParty.getState(); } protected int getState() { return decoratedParty.getState(); }
@Override
protected float getVolumeMultiplier() { return decoratedParty.getVolumeMultiplier(); }
@Override @Override
protected Location getLocation() { protected Location getLocation() {
return decoratedParty.getLocation(); return decoratedParty.getLocation();

View File

@ -206,7 +206,9 @@ public final class DiscoSheep extends JavaPlugin {
+ "-g <mob:integer, mob:integer...>: set spawns for other mobs, eg. -g cow:5,pig:2\n" + "-g <mob:integer, mob:integer...>: set spawns for other mobs, eg. -g cow:5,pig:2\n"
+ "-l: enables lightning\n" + "-l: enables lightning\n"
+ "-w: enables fireworks\n" + "-w: enables fireworks\n"
+ "-j: enables alternative method for setting sheep colours\n"); + "-j: enables alternative method for setting sheep colours\n"
+ "-b <integer>: spawns a percentage of mobs as babies, if possible\n"
+ "-P: enables pentatonic backing track\n");
return true; return true;
} }

View File

@ -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);
}
}
}

View File

@ -87,6 +87,11 @@ public class PartyBuilder {
return this; return this;
} }
public PartyBuilder fireworks() {
fireworks = true;
return this;
}
public PartyBuilder jeb() { public PartyBuilder jeb() {
jeb = true; jeb = true;
return this; return this;
@ -109,10 +114,7 @@ public class PartyBuilder {
radius = denseRadius; radius = denseRadius;
} }
AbstractParty party = new BasicDiscoParty(player, duration, radius, period, sheep, guests); AbstractParty party = new BasicDiscoParty(player, duration, radius, period, sheep, guests);
if (fireworks) { if (fireworks) party = new FireworkParty(party);
// do stuff
}
if (lightning) party = new LightningParty(party); if (lightning) party = new LightningParty(party);
if (jeb) party = new JebParty(party); if (jeb) party = new JebParty(party);
if (pentatonic) party = new PentatonicParty(party); if (pentatonic) party = new PentatonicParty(party);

View File

@ -31,6 +31,6 @@ public class PentatonicParty extends DiscoDecorator {
@Override @Override
protected void playSounds() { protected void playSounds() {
super.playSounds(); super.playSounds();
getLocation().getWorld().playSound(getLocation(), Sound.NOTE_PIANO, 1.0f, getPentatonicNote()); getLocation().getWorld().playSound(getLocation(), Sound.NOTE_PIANO, getVolumeMultiplier() * 1.0f, getPentatonicNote());
} }
} }