Added code for making sheep jump. Can be toggled with DiscoParty.doJump. Default Y velocity applied can be set with defaultSheepJump. Sheep jump at same time as they would launch fireworks. TODO: tune jump velocity to make it look natural.
This commit is contained in:
parent
3fc5d4ae2b
commit
3e06213fc5
@ -1,253 +1,268 @@
|
|||||||
package gibstick.bukkit.discosheep;
|
package gibstick.bukkit.discosheep;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import org.bukkit.Color;
|
import org.bukkit.Color;
|
||||||
import org.bukkit.DyeColor;
|
import org.bukkit.DyeColor;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.Firework;
|
import org.bukkit.entity.Firework;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.entity.Sheep;
|
import org.bukkit.entity.Sheep;
|
||||||
import org.bukkit.FireworkEffect;
|
import org.bukkit.FireworkEffect;
|
||||||
import org.bukkit.FireworkEffect.Builder;
|
import org.bukkit.FireworkEffect.Builder;
|
||||||
import org.bukkit.inventory.meta.FireworkMeta;
|
import org.bukkit.inventory.meta.FireworkMeta;
|
||||||
|
import org.bukkit.util.Vector;
|
||||||
/**
|
|
||||||
*
|
/**
|
||||||
* @author Georgiy
|
*
|
||||||
*/
|
* @author Georgiy
|
||||||
public class DiscoParty {
|
*/
|
||||||
|
public class DiscoParty {
|
||||||
private DiscoSheep ds;
|
|
||||||
private Player player;
|
private DiscoSheep ds;
|
||||||
private ArrayList<Sheep> sheepList = new ArrayList<Sheep>();
|
private Player player;
|
||||||
private int duration, frequency = 20;
|
private ArrayList<Sheep> sheepList = new ArrayList<Sheep>();
|
||||||
private int numSheep = 5;
|
private int duration, frequency = 20;
|
||||||
static int defaultDuration = 300; // ticks for entire party
|
private int numSheep = 5;
|
||||||
static int defaultPeriod = 10; // ticks per state change
|
static int defaultDuration = 300; // ticks for entire party
|
||||||
static int defaultRadius = 5;
|
static int defaultPeriod = 10; // ticks per state change
|
||||||
static int defaultSheep = 10;
|
static int defaultRadius = 5;
|
||||||
static int maxDuration = 2400; // 120 seconds
|
static int defaultSheep = 10;
|
||||||
static int maxSheep = 100;
|
static float defaultSheepJump = 0.5f;
|
||||||
static int maxRadius = 100;
|
static int maxDuration = 2400; // 120 seconds
|
||||||
static int minPeriod = 5; // 0.25 seconds
|
static int maxSheep = 100;
|
||||||
static int maxPeriod = 40; // 2.0 seconds
|
static int maxRadius = 100;
|
||||||
private boolean doFireworks = false;
|
static int minPeriod = 5; // 0.25 seconds
|
||||||
private int state = 0;
|
static int maxPeriod = 40; // 2.0 seconds
|
||||||
private DiscoUpdater updater;
|
private boolean doFireworks = false;
|
||||||
private static final DyeColor[] discoColours = {
|
private boolean doJump = true;
|
||||||
DyeColor.RED,
|
private int state = 0;
|
||||||
DyeColor.ORANGE,
|
private DiscoUpdater updater;
|
||||||
DyeColor.YELLOW,
|
private static final DyeColor[] discoColours = {
|
||||||
DyeColor.GREEN,
|
DyeColor.RED,
|
||||||
DyeColor.BLUE,
|
DyeColor.ORANGE,
|
||||||
DyeColor.LIGHT_BLUE,
|
DyeColor.YELLOW,
|
||||||
DyeColor.PINK,
|
DyeColor.GREEN,
|
||||||
DyeColor.MAGENTA,
|
DyeColor.BLUE,
|
||||||
DyeColor.LIME,
|
DyeColor.LIGHT_BLUE,
|
||||||
DyeColor.CYAN,
|
DyeColor.PINK,
|
||||||
DyeColor.PURPLE
|
DyeColor.MAGENTA,
|
||||||
};
|
DyeColor.LIME,
|
||||||
|
DyeColor.CYAN,
|
||||||
public DiscoParty(DiscoSheep parent, Player player) {
|
DyeColor.PURPLE
|
||||||
this.ds = parent;
|
};
|
||||||
this.player = player;
|
|
||||||
}
|
public DiscoParty(DiscoSheep parent, Player player) {
|
||||||
|
this.ds = parent;
|
||||||
List<Sheep> getSheep() {
|
this.player = player;
|
||||||
return sheepList;
|
}
|
||||||
}
|
|
||||||
|
List<Sheep> getSheep() {
|
||||||
void spawnSheep(World world, Location loc) {
|
return sheepList;
|
||||||
Sheep newSheep = (Sheep) world.spawnEntity(loc, EntityType.SHEEP);
|
}
|
||||||
newSheep.setMaxHealth(10000);
|
|
||||||
newSheep.setHealth(10000);
|
void spawnSheep(World world, Location loc) {
|
||||||
newSheep.setColor(discoColours[(int) Math.round(Math.random() * (discoColours.length - 1))]);
|
Sheep newSheep = (Sheep) world.spawnEntity(loc, EntityType.SHEEP);
|
||||||
newSheep.setTarget(player);
|
newSheep.setMaxHealth(10000);
|
||||||
newSheep.setBreed(false);
|
newSheep.setHealth(10000);
|
||||||
getSheep().add(newSheep);
|
newSheep.setColor(discoColours[(int) Math.round(Math.random() * (discoColours.length - 1))]);
|
||||||
}
|
newSheep.setTarget(player);
|
||||||
|
newSheep.setBreed(false);
|
||||||
// Spawn some number of sheep next to given player
|
getSheep().add(newSheep);
|
||||||
void spawnSheep(int num, int sheepSpawnRadius) {
|
}
|
||||||
Location loc;
|
|
||||||
World world = player.getWorld();
|
// Spawn some number of sheep next to given player
|
||||||
|
void spawnSheep(int num, int sheepSpawnRadius) {
|
||||||
for (int i = 0; i < num; i++) {
|
Location loc;
|
||||||
double x, y, z;
|
World world = player.getWorld();
|
||||||
|
|
||||||
// random x and z coordinates within a 5 block radius
|
for (int i = 0; i < num; i++) {
|
||||||
// safe y-coordinate
|
double x, y, z;
|
||||||
x = -sheepSpawnRadius + (Math.random() * ((sheepSpawnRadius * 2) + 1)) + player.getLocation().getX();
|
|
||||||
z = -sheepSpawnRadius + (Math.random() * ((sheepSpawnRadius * 2) + 1)) + player.getLocation().getZ();
|
// random x and z coordinates within a 5 block radius
|
||||||
y = world.getHighestBlockYAt((int) x, (int) z);
|
// safe y-coordinate
|
||||||
loc = new Location(world, x, y, z);
|
x = -sheepSpawnRadius + (Math.random() * ((sheepSpawnRadius * 2) + 1)) + player.getLocation().getX();
|
||||||
spawnSheep(world, loc);
|
z = -sheepSpawnRadius + (Math.random() * ((sheepSpawnRadius * 2) + 1)) + player.getLocation().getZ();
|
||||||
}
|
y = world.getHighestBlockYAt((int) x, (int) z);
|
||||||
}
|
loc = new Location(world, x, y, z);
|
||||||
|
spawnSheep(world, loc);
|
||||||
// Mark all sheep in the sheep array for removal, then clear the array
|
}
|
||||||
void removeAllSheep() {
|
}
|
||||||
for (Sheep sheep : getSheep()) {
|
|
||||||
sheep.setHealth(0);
|
// Mark all sheep in the sheep array for removal, then clear the array
|
||||||
sheep.remove();
|
void removeAllSheep() {
|
||||||
}
|
for (Sheep sheep : getSheep()) {
|
||||||
getSheep().clear();
|
sheep.setHealth(0);
|
||||||
}
|
sheep.remove();
|
||||||
|
}
|
||||||
// Set a random colour for all sheep in array
|
getSheep().clear();
|
||||||
void randomizeSheepColour(Sheep sheep) {
|
}
|
||||||
sheep.setColor(discoColours[(int) Math.round(Math.random() * (discoColours.length - 1))]);
|
|
||||||
}
|
// Set a random colour for all sheep in array
|
||||||
|
void randomizeSheepColour(Sheep sheep) {
|
||||||
private Color getColor(int i) {
|
sheep.setColor(discoColours[(int) Math.round(Math.random() * (discoColours.length - 1))]);
|
||||||
Color c = null;
|
}
|
||||||
if (i == 1) {
|
|
||||||
c = Color.AQUA;
|
void jumpSheep(Sheep sheep) {
|
||||||
}
|
Vector orgVel = sheep.getVelocity();
|
||||||
if (i == 2) {
|
Vector newVel = (new Vector()).copy(orgVel);
|
||||||
c = Color.BLACK;
|
newVel.add(new Vector(0, defaultSheepJump, 0));
|
||||||
}
|
sheep.setVelocity(newVel);
|
||||||
if (i == 3) {
|
}
|
||||||
c = Color.BLUE;
|
|
||||||
}
|
private Color getColor(int i) {
|
||||||
if (i == 4) {
|
Color c = null;
|
||||||
c = Color.FUCHSIA;
|
if (i == 1) {
|
||||||
}
|
c = Color.AQUA;
|
||||||
if (i == 5) {
|
}
|
||||||
c = Color.GRAY;
|
if (i == 2) {
|
||||||
}
|
c = Color.BLACK;
|
||||||
if (i == 6) {
|
}
|
||||||
c = Color.GREEN;
|
if (i == 3) {
|
||||||
}
|
c = Color.BLUE;
|
||||||
if (i == 7) {
|
}
|
||||||
c = Color.LIME;
|
if (i == 4) {
|
||||||
}
|
c = Color.FUCHSIA;
|
||||||
if (i == 8) {
|
}
|
||||||
c = Color.MAROON;
|
if (i == 5) {
|
||||||
}
|
c = Color.GRAY;
|
||||||
if (i == 9) {
|
}
|
||||||
c = Color.NAVY;
|
if (i == 6) {
|
||||||
}
|
c = Color.GREEN;
|
||||||
if (i == 10) {
|
}
|
||||||
c = Color.OLIVE;
|
if (i == 7) {
|
||||||
}
|
c = Color.LIME;
|
||||||
if (i == 11) {
|
}
|
||||||
c = Color.ORANGE;
|
if (i == 8) {
|
||||||
}
|
c = Color.MAROON;
|
||||||
if (i == 12) {
|
}
|
||||||
c = Color.PURPLE;
|
if (i == 9) {
|
||||||
}
|
c = Color.NAVY;
|
||||||
if (i == 13) {
|
}
|
||||||
c = Color.RED;
|
if (i == 10) {
|
||||||
}
|
c = Color.OLIVE;
|
||||||
if (i == 14) {
|
}
|
||||||
c = Color.SILVER;
|
if (i == 11) {
|
||||||
}
|
c = Color.ORANGE;
|
||||||
if (i == 15) {
|
}
|
||||||
c = Color.TEAL;
|
if (i == 12) {
|
||||||
}
|
c = Color.PURPLE;
|
||||||
if (i == 16) {
|
}
|
||||||
c = Color.WHITE;
|
if (i == 13) {
|
||||||
}
|
c = Color.RED;
|
||||||
if (i == 17) {
|
}
|
||||||
c = Color.YELLOW;
|
if (i == 14) {
|
||||||
}
|
c = Color.SILVER;
|
||||||
|
}
|
||||||
return c;
|
if (i == 15) {
|
||||||
}
|
c = Color.TEAL;
|
||||||
|
}
|
||||||
void updateAllSheep() {
|
if (i == 16) {
|
||||||
for (Sheep sheep : getSheep()) {
|
c = Color.WHITE;
|
||||||
randomizeSheepColour(sheep);
|
}
|
||||||
if (doFireworks && state % 8 == 0) {
|
if (i == 17) {
|
||||||
spawnRandomFireworkAtSheep(sheep);
|
c = Color.YELLOW;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
return c;
|
||||||
|
}
|
||||||
void playSounds() {
|
|
||||||
player.playSound(player.getLocation(), Sound.NOTE_BASS_DRUM, 1.0f, 1.0f);
|
void updateAllSheep() {
|
||||||
if (this.state % 2 == 0) {
|
for (Sheep sheep : getSheep()) {
|
||||||
player.playSound(player.getLocation(), Sound.NOTE_SNARE_DRUM, 1.0f, 1.0f);
|
randomizeSheepColour(sheep);
|
||||||
}
|
if (state % 8 == 0) { // HA HA IT LOOKS LIKE A PENIS
|
||||||
if (this.state % 4 == 0) {
|
if (doFireworks) {
|
||||||
player.playSound(player.getLocation(), Sound.NOTE_STICKS, 1.0f, 1.0f);
|
spawnRandomFireworkAtSheep(sheep);
|
||||||
}
|
}
|
||||||
player.playSound(player.getLocation(), Sound.BURP, 0.5f, (float) Math.random() + 1);
|
if(doJump){
|
||||||
}
|
jumpSheep(sheep);
|
||||||
|
}
|
||||||
void randomizeFirework(Firework firework) {
|
}
|
||||||
Random r = new Random();
|
}
|
||||||
Builder effect = FireworkEffect.builder();
|
}
|
||||||
FireworkMeta meta = firework.getFireworkMeta();
|
|
||||||
|
void playSounds() {
|
||||||
// construct [1, 3] random colours
|
player.playSound(player.getLocation(), Sound.NOTE_BASS_DRUM, 1.0f, 1.0f);
|
||||||
int numColours = r.nextInt(3) + 1;
|
if (this.state % 2 == 0) {
|
||||||
Color[] colourArray = new Color[numColours];
|
player.playSound(player.getLocation(), Sound.NOTE_SNARE_DRUM, 1.0f, 1.0f);
|
||||||
for (int i = 0; i < numColours; i++) {
|
}
|
||||||
colourArray[i] = getColor(r.nextInt(17) + 1);
|
if (this.state % 4 == 0) {
|
||||||
}
|
player.playSound(player.getLocation(), Sound.NOTE_STICKS, 1.0f, 1.0f);
|
||||||
|
}
|
||||||
// randomize effects
|
player.playSound(player.getLocation(), Sound.BURP, 0.5f, (float) Math.random() + 1);
|
||||||
effect.withColor(colourArray);
|
}
|
||||||
effect.flicker(r.nextDouble() < 0.5);
|
|
||||||
effect.trail(r.nextDouble() < 0.5);
|
void randomizeFirework(Firework firework) {
|
||||||
effect.with(FireworkEffect.Type.values()[r.nextInt(FireworkEffect.Type.values().length)]);
|
Random r = new Random();
|
||||||
|
Builder effect = FireworkEffect.builder();
|
||||||
// set random effect and randomize power
|
FireworkMeta meta = firework.getFireworkMeta();
|
||||||
meta.addEffect(effect.build());
|
|
||||||
meta.setPower(r.nextInt(2));
|
// construct [1, 3] random colours
|
||||||
|
int numColours = r.nextInt(3) + 1;
|
||||||
// apply it to the given firework
|
Color[] colourArray = new Color[numColours];
|
||||||
firework.setFireworkMeta(meta);
|
for (int i = 0; i < numColours; i++) {
|
||||||
}
|
colourArray[i] = getColor(r.nextInt(17) + 1);
|
||||||
|
}
|
||||||
void spawnRandomFireworkAtSheep(Sheep sheep) {
|
|
||||||
Firework firework = (Firework) sheep.getWorld().spawnEntity(sheep.getEyeLocation(), EntityType.FIREWORK);
|
// randomize effects
|
||||||
randomizeFirework(firework);
|
effect.withColor(colourArray);
|
||||||
}
|
effect.flicker(r.nextDouble() < 0.5);
|
||||||
|
effect.trail(r.nextDouble() < 0.5);
|
||||||
void update() {
|
effect.with(FireworkEffect.Type.values()[r.nextInt(FireworkEffect.Type.values().length)]);
|
||||||
if (duration > 0) {
|
|
||||||
updateAllSheep();
|
// set random effect and randomize power
|
||||||
playSounds();
|
meta.addEffect(effect.build());
|
||||||
duration -= frequency;
|
meta.setPower(r.nextInt(2));
|
||||||
this.scheduleUpdate();
|
|
||||||
this.state++;
|
// apply it to the given firework
|
||||||
} else {
|
firework.setFireworkMeta(meta);
|
||||||
this.stopDisco();
|
}
|
||||||
}
|
|
||||||
}
|
void spawnRandomFireworkAtSheep(Sheep sheep) {
|
||||||
|
Firework firework = (Firework) sheep.getWorld().spawnEntity(sheep.getEyeLocation(), EntityType.FIREWORK);
|
||||||
void scheduleUpdate() {
|
randomizeFirework(firework);
|
||||||
updater = new DiscoUpdater(this);
|
}
|
||||||
updater.runTaskLater(ds, this.frequency);
|
|
||||||
}
|
void update() {
|
||||||
|
if (duration > 0) {
|
||||||
void startDisco(int duration, int sheepAmount, int radius, int frequency, boolean fireworks) {
|
updateAllSheep();
|
||||||
if (this.duration > 0) {
|
playSounds();
|
||||||
stopDisco();
|
duration -= frequency;
|
||||||
}
|
this.scheduleUpdate();
|
||||||
this.doFireworks = fireworks;
|
this.state++;
|
||||||
this.spawnSheep(sheepAmount, radius);
|
} else {
|
||||||
this.frequency = frequency;
|
this.stopDisco();
|
||||||
this.duration = duration;
|
}
|
||||||
this.scheduleUpdate();
|
}
|
||||||
ds.getPartyMap().put(this.player.getName(), this);
|
|
||||||
}
|
void scheduleUpdate() {
|
||||||
|
updater = new DiscoUpdater(this);
|
||||||
void stopDisco() {
|
updater.runTaskLater(ds, this.frequency);
|
||||||
removeAllSheep();
|
}
|
||||||
this.duration = 0;
|
|
||||||
if (updater != null) {
|
void startDisco(int duration, int sheepAmount, int radius, int frequency, boolean fireworks) {
|
||||||
updater.cancel();
|
if (this.duration > 0) {
|
||||||
}
|
stopDisco();
|
||||||
updater = null;
|
}
|
||||||
ds.getPartyMap().remove(this.player.getName());
|
this.doFireworks = fireworks;
|
||||||
}
|
this.spawnSheep(sheepAmount, radius);
|
||||||
}
|
this.frequency = frequency;
|
||||||
|
this.duration = duration;
|
||||||
|
this.scheduleUpdate();
|
||||||
|
ds.getPartyMap().put(this.player.getName(), this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void stopDisco() {
|
||||||
|
removeAllSheep();
|
||||||
|
this.duration = 0;
|
||||||
|
if (updater != null) {
|
||||||
|
updater.cancel();
|
||||||
|
}
|
||||||
|
updater = null;
|
||||||
|
ds.getPartyMap().remove(this.player.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user