sounds are now global, added dance floor flag

This commit is contained in:
Charlie 2014-08-01 23:49:29 -04:00
parent f64a5f85b7
commit 1d1d6d9868
4 changed files with 69 additions and 71 deletions

View File

@ -4,7 +4,7 @@ annotation.processing.processors.list=
annotation.processing.run.all.processors=true annotation.processing.run.all.processors=true
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
application.title=DiscoSheep application.title=DiscoSheep
application.vendor=Charlie application.vendor=
auxiliary.org-netbeans-modules-editor-indent.CodeStyle.project.expand-tabs=true auxiliary.org-netbeans-modules-editor-indent.CodeStyle.project.expand-tabs=true
auxiliary.org-netbeans-modules-editor-indent.CodeStyle.project.indent-shift-width=4 auxiliary.org-netbeans-modules-editor-indent.CodeStyle.project.indent-shift-width=4
auxiliary.org-netbeans-modules-editor-indent.CodeStyle.project.spaces-per-tab=4 auxiliary.org-netbeans-modules-editor-indent.CodeStyle.project.spaces-per-tab=4

View File

@ -30,9 +30,9 @@ public class DiscoCommands {
static final String PERMISSION_SPAWNGUESTS = "discosheep.party.spawnguests"; static final String PERMISSION_SPAWNGUESTS = "discosheep.party.spawnguests";
static final String PERMISSION_TOGGLEPARTYONJOIN = "discosheep.admin.toggleonjoin"; static final String PERMISSION_TOGGLEPARTYONJOIN = "discosheep.admin.toggleonjoin";
static final String PERMISSION_LIGHTNING = "discosheep.party.lightning"; static final String PERMISSION_LIGHTNING = "discosheep.party.lightning";
static final String PERMISSION_SHARED = "discosheep.party.shared"; static final String PERMISSION_DANCEFLOOR = "discosheep.party.dancefloor";
static final String FLAGS = "n:t:p:r:lfg"; static final String FLAGS = "n:t:p:r:lfgd";
private static final DiscoSheep plugin = DiscoSheep.getInstance(); private static final DiscoSheep plugin = DiscoSheep.getInstance();
@ -84,6 +84,10 @@ public class DiscoCommands {
party.setPeriod(args.getFlagInteger('p', DiscoParty.defaultPeriod)); party.setPeriod(args.getFlagInteger('p', DiscoParty.defaultPeriod));
party.setSheep(args.getFlagInteger('n', DiscoParty.defaultSheep)); party.setSheep(args.getFlagInteger('n', DiscoParty.defaultSheep));
if (sender.hasPermission(PERMISSION_DANCEFLOOR)) {
party.setDoFloor(args.hasFlag('d'));
}
// handle special case of duration conversion ugh // handle special case of duration conversion ugh
if (args.hasFlag('t')) { if (args.hasFlag('t')) {
int duration = args.getFlagInteger('t'); int duration = args.getFlagInteger('t');
@ -141,7 +145,6 @@ public class DiscoCommands {
} }
} }
} }
/*-- Actual commands begin here --*/ /*-- Actual commands begin here --*/
@ -206,32 +209,6 @@ public class DiscoCommands {
} }
} }
@Command(
aliases = {"shared"},
desc = "Start your own shared DiscoParty (other players can see the party)",
usage = "[optional flags]",
min = 0,
max = -1,
flags = FLAGS
)
@CommandPermissions(value = PERMISSION_SHARED)
public static void partySharedCommand(final CommandContext args, CommandSender sender) {
if (!(sender instanceof Player)) {
sender.sendMessage("You must be a player to have a party");
return;
}
Player player = (Player) sender;
if (!plugin.hasParty(player.getName())) {
DiscoParty party = new DiscoParty();
party.setMainPlayer(player);
parsePartyFlags(party, args, sender);
party.getPlayers().addAll(plugin.getPlayersWithin(player, party.getRadius()));
party.startDisco();
} else {
player.sendMessage(ChatColor.RED + "You already have a party.");
}
}
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
// UUIDs not necessary since DiscoSheep only lasts for one session at most // UUIDs not necessary since DiscoSheep only lasts for one session at most
// and permissions will handle onJoin DiscoSheep // and permissions will handle onJoin DiscoSheep

View File

@ -9,7 +9,6 @@ import java.util.Random;
import java.util.Set; import java.util.Set;
import org.bukkit.Color; import org.bukkit.Color;
import org.bukkit.DyeColor; import org.bukkit.DyeColor;
import org.bukkit.Material;
import static org.bukkit.EntityEffect.*; import static org.bukkit.EntityEffect.*;
import org.bukkit.FireworkEffect; import org.bukkit.FireworkEffect;
import org.bukkit.FireworkEffect.Builder; import org.bukkit.FireworkEffect.Builder;
@ -23,6 +22,7 @@ import org.bukkit.block.BlockState;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.Firework; import org.bukkit.entity.Firework;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.Sheep; import org.bukkit.entity.Sheep;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
@ -86,27 +86,29 @@ public class DiscoParty {
// Instance properties // Instance properties
private Random r = new Random(); private Random r = new Random();
private PartyEvents partyEvents; private PartyEvents partyEvents;
private final DiscoSheep parent = DiscoSheep.getInstance(); private final DiscoSheep plugin = DiscoSheep.getInstance();
private ArrayList<Player> players = new ArrayList<Player>(); private Player player;
private Player mainPlayer; private final ArrayList<Sheep> sheepList = new ArrayList<Sheep>();
private ArrayList<Sheep> sheepList = new ArrayList<Sheep>(); private final HashSet<Sheep> sheepSet = new HashSet<Sheep>();
private HashSet<Sheep> sheepSet = new HashSet<Sheep>(); private final ArrayList<Entity> guestList = new ArrayList<Entity>();
private ArrayList<Entity> guestList = new ArrayList<Entity>(); private final HashSet<Entity> guestSet = new HashSet<Entity>();
private HashSet<Entity> guestSet = new HashSet<Entity>(); private final ArrayList<BlockState> floorBlockCache = new ArrayList<BlockState>();
private ArrayList<BlockState> floorBlockCache = new ArrayList<BlockState>(); private final ArrayList<Block> floorBlocks = new ArrayList<Block>();
private ArrayList<Block> floorBlocks = new ArrayList<Block>();
private HashMap<String, Integer> guestNumbers = new HashMap<String, Integer>(); private HashMap<String, Integer> guestNumbers = new HashMap<String, Integer>();
private boolean doFireworks = false; private boolean doFireworks = false;
private boolean doJump = true; private final boolean doJump = true;
private boolean doLightning = false; private boolean doLightning = false;
private boolean doFloor = false;
private int duration, period, radius, sheep; private int duration, period, radius, sheep;
private int state = 0; // basically our own tick system private int state = 0; // basically our own tick system
private float volumeMultiplier;
private Location partyLocation;
private DiscoUpdater updater; private DiscoUpdater updater;
public DiscoParty(Player player) { public DiscoParty(Player player) {
this(); this();
this.mainPlayer = player; this.player = player;
this.players.add(player); this.partyLocation = player.getLocation();
} }
public DiscoParty() { public DiscoParty() {
@ -177,15 +179,12 @@ public class DiscoParty {
return this.sheep; return this.sheep;
} }
public DiscoParty setMainPlayer(Player player) { public DiscoParty setPlayer(Player player) {
this.mainPlayer = player; this.player = player;
this.partyLocation = player.getLocation();
return this; return this;
} }
public ArrayList<Player> getPlayers() {
return players;
}
public DiscoParty setDuration(int duration) throws IllegalArgumentException { public DiscoParty setDuration(int duration) throws IllegalArgumentException {
if (duration <= DiscoParty.maxDuration && duration > 0) { if (duration <= DiscoParty.maxDuration && duration > 0) {
this.duration = duration; this.duration = duration;
@ -245,6 +244,10 @@ public class DiscoParty {
return this; return this;
} }
public void setDoFloor(boolean doFloor) {
this.doFloor = doFloor;
}
public DiscoParty setGuestNumber(String key, int n) throws IllegalArgumentException { public DiscoParty setGuestNumber(String key, int n) throws IllegalArgumentException {
if (getMaxGuestNumbers().containsKey(key.toUpperCase())) { if (getMaxGuestNumbers().containsKey(key.toUpperCase())) {
if (n <= getMaxGuestNumbers().get(key.toUpperCase()) && n >= 0) { // so that /ds defaults can take 0 as arg if (n <= getMaxGuestNumbers().get(key.toUpperCase()) && n >= 0) { // so that /ds defaults can take 0 as arg
@ -278,7 +281,7 @@ public class DiscoParty {
double azimuth = r.nextDouble() * 2 * Math.PI; // radians double azimuth = r.nextDouble() * 2 * Math.PI; // radians
x += rand * Math.cos(azimuth); x += rand * Math.cos(azimuth);
z += rand * Math.sin(azimuth); z += rand * Math.sin(azimuth);
y = this.mainPlayer.getLocation().getY(); y = partyLocation.getY();
loc = new Location(world, x, y, z); loc = new Location(world, x, y, z);
loc.setPitch(r.nextFloat() * 360 - 180); loc.setPitch(r.nextFloat() * 360 - 180);
@ -290,10 +293,10 @@ public class DiscoParty {
// Spawn some number of guests next to given player // Spawn some number of guests next to given player
void spawnAll(int sheep, int spawnRadius) { void spawnAll(int sheep, int spawnRadius) {
Location loc; Location loc;
World world = mainPlayer.getWorld(); World world = player.getWorld();
double x = mainPlayer.getLocation().getX(); double x = partyLocation.getX();
double z = mainPlayer.getLocation().getZ(); double z = partyLocation.getZ();
for (int i = 0; i < sheep; i++) { for (int i = 0; i < sheep; i++) {
loc = getRandomSpawnLocation(x, z, world, spawnRadius); loc = getRandomSpawnLocation(x, z, world, spawnRadius);
spawnSheep(world, loc); spawnSheep(world, loc);
@ -310,8 +313,9 @@ public class DiscoParty {
} }
} }
loc = mainPlayer.getLocation(); if (doFloor) {
this.spawnFloor(world, new Location(world, loc.getBlockX(), loc.getBlockY() - 1, loc.getBlockZ())); this.spawnFloor(world, new Location(world, partyLocation.getBlockX(), partyLocation.getBlockY() - 1, partyLocation.getBlockZ()));
}
} }
void spawnSheep(World world, Location loc) { void spawnSheep(World world, Location loc) {
@ -319,7 +323,6 @@ public class DiscoParty {
//newSheep.setColor(discoColours[(r.nextInt(discoColours.length))]); //newSheep.setColor(discoColours[(r.nextInt(discoColours.length))]);
newSheep.setBreed(false); // this prevents breeding - no event listener required newSheep.setBreed(false); // this prevents breeding - no event listener required
newSheep.teleport(loc); // teleport is needed to set orientation newSheep.teleport(loc); // teleport is needed to set orientation
newSheep.setTarget(this.mainPlayer);
getSheepList().add(newSheep); getSheepList().add(newSheep);
getSheepSet().add(newSheep); getSheepSet().add(newSheep);
if (doLightning) { if (doLightning) {
@ -331,7 +334,8 @@ public class DiscoParty {
} }
void spawnGuest(World world, Location loc, EntityType type) { void spawnGuest(World world, Location loc, EntityType type) {
Entity newGuest = loc.getWorld().spawnEntity(loc, type); LivingEntity newGuest = (LivingEntity) loc.getWorld().spawnEntity(loc, type);
newGuest.setRemoveWhenFarAway(false);
getGuestList().add(newGuest); getGuestList().add(newGuest);
getGuestSet().add(newGuest); getGuestSet().add(newGuest);
if (doLightning) { if (doLightning) {
@ -485,16 +489,28 @@ public class DiscoParty {
} }
void playSounds() { void playSounds() {
for (Player p : players) {
p.playSound(p.getLocation(), Sound.NOTE_BASS_DRUM, 0.75f, 1.0f); /*for (Sheep sheep : this.getSheepList()) {
sheep.getWorld().playSound(sheep.getLocation(), Sound.NOTE_BASS_DRUM, 0.75f, 1.0f);
if (this.state % 2 == 0) { if (this.state % 2 == 0) {
p.playSound(p.getLocation(), Sound.NOTE_SNARE_DRUM, 0.8f, 1.0f); sheep.getWorld().playSound(sheep.getLocation(), Sound.NOTE_SNARE_DRUM, 0.8f, 1.0f);
} }
if ((this.state + 1) % 8 == 0) { if ((this.state + 1) % 8 == 0) {
p.playSound(p.getLocation(), Sound.NOTE_STICKS, 1.0f, 1.0f); sheep.getWorld().playSound(sheep.getLocation(), Sound.NOTE_STICKS, 1.0f, 1.0f);
} }
}*/
partyLocation.getWorld().playSound(partyLocation, Sound.NOTE_BASS_DRUM, volumeMultiplier * 0.75f, 1.0f);
if (this.state % 2 == 0) {
partyLocation.getWorld().playSound(partyLocation, Sound.NOTE_SNARE_DRUM, volumeMultiplier * 0.8f, 1.0f);
} }
if ((this.state + 1) % 8 == 0) {
partyLocation.getWorld().playSound(partyLocation, Sound.NOTE_STICKS, volumeMultiplier * 1.0f, 1.0f);
}
} }
void randomizeFirework(Firework firework) { void randomizeFirework(Firework firework) {
@ -541,16 +557,17 @@ public class DiscoParty {
void scheduleUpdate() { void scheduleUpdate() {
updater = new DiscoUpdater(); updater = new DiscoUpdater();
updater.runTaskLater(parent, this.period); updater.runTaskLater(plugin, this.period);
} }
void startDisco() { void startDisco() {
this.volumeMultiplier = Math.max(this.radius / 10, 1.0f);
this.spawnAll(sheep, radius); this.spawnAll(sheep, radius);
this.scheduleUpdate(); this.scheduleUpdate();
parent.getPartyMap().put(this.mainPlayer.getName(), this); plugin.getPartyMap().put(this.player.getName(), this);
// start listening // start listening
this.partyEvents = new PartyEvents(this); this.partyEvents = new PartyEvents(this);
parent.getServer().getPluginManager().registerEvents(this.partyEvents, this.parent); plugin.getServer().getPluginManager().registerEvents(this.partyEvents, this.plugin);
} }
void stopDisco() { void stopDisco() {
@ -560,7 +577,7 @@ public class DiscoParty {
updater.cancel(); updater.cancel();
} }
updater = null; updater = null;
parent.getPartyMap().remove(this.mainPlayer.getName()); plugin.getPartyMap().remove(this.player.getName());
// stop listening // stop listening
HandlerList.unregisterAll(this.partyEvents); HandlerList.unregisterAll(this.partyEvents);
} }

View File

@ -1,7 +1,7 @@
name: DiscoSheep name: DiscoSheep
main: ca.gibstick.discosheep.DiscoSheep main: ca.gibstick.discosheep.DiscoSheep
authors: [Gibstick, RangerMauve] authors: [Gibstick, RangerMauve]
version: 1.1.2 version: 1.2
commands: commands:
#ds: #ds:
#description: "Main DiscoSheep command" #description: "Main DiscoSheep command"
@ -28,6 +28,7 @@ permissions:
discosheep.party.changeperiod: true discosheep.party.changeperiod: true
discosheep.party.spawnguests: true discosheep.party.spawnguests: true
discosheep.party.lightning: true discosheep.party.lightning: true
discosheep.party.dancefloor: true
discosheep.admin.*: discosheep.admin.*:
description: Suggested permissions for administrators description: Suggested permissions for administrators
default: op default: op
@ -78,6 +79,9 @@ permissions:
discosheep.party.lightning: discosheep.party.lightning:
description: Allow a player to use lightning for parties description: Allow a player to use lightning for parties
default: op default: op
discosheep.party.dancefloor:
description: Allow a player to spawn a dance floor
default: op
# FOR BACKWARDS COMPAT FROM 1.1 TO 1.1.1 # FOR BACKWARDS COMPAT FROM 1.1 TO 1.1.1
discosheep.party: discosheep.party:
children: children: