diff --git a/nbproject/project.properties b/nbproject/project.properties index 39cbd0d..012bc1b 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -4,7 +4,7 @@ annotation.processing.processors.list= annotation.processing.run.all.processors=true annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output 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.indent-shift-width=4 auxiliary.org-netbeans-modules-editor-indent.CodeStyle.project.spaces-per-tab=4 diff --git a/src/ca/gibstick/discosheep/DiscoCommands.java b/src/ca/gibstick/discosheep/DiscoCommands.java index 7bfa252..fbc9b4e 100644 --- a/src/ca/gibstick/discosheep/DiscoCommands.java +++ b/src/ca/gibstick/discosheep/DiscoCommands.java @@ -30,9 +30,9 @@ public class DiscoCommands { static final String PERMISSION_SPAWNGUESTS = "discosheep.party.spawnguests"; static final String PERMISSION_TOGGLEPARTYONJOIN = "discosheep.admin.toggleonjoin"; 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(); @@ -84,6 +84,10 @@ public class DiscoCommands { party.setPeriod(args.getFlagInteger('p', DiscoParty.defaultPeriod)); party.setSheep(args.getFlagInteger('n', DiscoParty.defaultSheep)); + if (sender.hasPermission(PERMISSION_DANCEFLOOR)) { + party.setDoFloor(args.hasFlag('d')); + } + // handle special case of duration conversion ugh if (args.hasFlag('t')) { int duration = args.getFlagInteger('t'); @@ -141,7 +145,6 @@ public class DiscoCommands { } } - } /*-- 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") // UUIDs not necessary since DiscoSheep only lasts for one session at most // and permissions will handle onJoin DiscoSheep diff --git a/src/ca/gibstick/discosheep/DiscoParty.java b/src/ca/gibstick/discosheep/DiscoParty.java index 9b0353c..946fb35 100644 --- a/src/ca/gibstick/discosheep/DiscoParty.java +++ b/src/ca/gibstick/discosheep/DiscoParty.java @@ -9,7 +9,6 @@ import java.util.Random; import java.util.Set; import org.bukkit.Color; import org.bukkit.DyeColor; -import org.bukkit.Material; import static org.bukkit.EntityEffect.*; import org.bukkit.FireworkEffect; import org.bukkit.FireworkEffect.Builder; @@ -23,6 +22,7 @@ import org.bukkit.block.BlockState; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.Firework; +import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.entity.Sheep; import org.bukkit.event.HandlerList; @@ -86,27 +86,29 @@ public class DiscoParty { // Instance properties private Random r = new Random(); private PartyEvents partyEvents; - private final DiscoSheep parent = DiscoSheep.getInstance(); - private ArrayList players = new ArrayList(); - private Player mainPlayer; - private ArrayList sheepList = new ArrayList(); - private HashSet sheepSet = new HashSet(); - private ArrayList guestList = new ArrayList(); - private HashSet guestSet = new HashSet(); - private ArrayList floorBlockCache = new ArrayList(); - private ArrayList floorBlocks = new ArrayList(); + private final DiscoSheep plugin = DiscoSheep.getInstance(); + private Player player; + private final ArrayList sheepList = new ArrayList(); + private final HashSet sheepSet = new HashSet(); + private final ArrayList guestList = new ArrayList(); + private final HashSet guestSet = new HashSet(); + private final ArrayList floorBlockCache = new ArrayList(); + private final ArrayList floorBlocks = new ArrayList(); private HashMap guestNumbers = new HashMap(); private boolean doFireworks = false; - private boolean doJump = true; + private final boolean doJump = true; private boolean doLightning = false; + private boolean doFloor = false; private int duration, period, radius, sheep; private int state = 0; // basically our own tick system + private float volumeMultiplier; + private Location partyLocation; private DiscoUpdater updater; public DiscoParty(Player player) { this(); - this.mainPlayer = player; - this.players.add(player); + this.player = player; + this.partyLocation = player.getLocation(); } public DiscoParty() { @@ -177,15 +179,12 @@ public class DiscoParty { return this.sheep; } - public DiscoParty setMainPlayer(Player player) { - this.mainPlayer = player; + public DiscoParty setPlayer(Player player) { + this.player = player; + this.partyLocation = player.getLocation(); return this; } - public ArrayList getPlayers() { - return players; - } - public DiscoParty setDuration(int duration) throws IllegalArgumentException { if (duration <= DiscoParty.maxDuration && duration > 0) { this.duration = duration; @@ -245,6 +244,10 @@ public class DiscoParty { return this; } + public void setDoFloor(boolean doFloor) { + this.doFloor = doFloor; + } + public DiscoParty setGuestNumber(String key, int n) throws IllegalArgumentException { if (getMaxGuestNumbers().containsKey(key.toUpperCase())) { 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 x += rand * Math.cos(azimuth); z += rand * Math.sin(azimuth); - y = this.mainPlayer.getLocation().getY(); + y = partyLocation.getY(); loc = new Location(world, x, y, z); loc.setPitch(r.nextFloat() * 360 - 180); @@ -290,10 +293,10 @@ public class DiscoParty { // Spawn some number of guests next to given player void spawnAll(int sheep, int spawnRadius) { Location loc; - World world = mainPlayer.getWorld(); + World world = player.getWorld(); - double x = mainPlayer.getLocation().getX(); - double z = mainPlayer.getLocation().getZ(); + double x = partyLocation.getX(); + double z = partyLocation.getZ(); for (int i = 0; i < sheep; i++) { loc = getRandomSpawnLocation(x, z, world, spawnRadius); spawnSheep(world, loc); @@ -310,16 +313,16 @@ public class DiscoParty { } } - loc = mainPlayer.getLocation(); - this.spawnFloor(world, new Location(world, loc.getBlockX(), loc.getBlockY() - 1, loc.getBlockZ())); + if (doFloor) { + this.spawnFloor(world, new Location(world, partyLocation.getBlockX(), partyLocation.getBlockY() - 1, partyLocation.getBlockZ())); + } } void spawnSheep(World world, Location loc) { Sheep newSheep = (Sheep) world.spawnEntity(loc, EntityType.SHEEP); //newSheep.setColor(discoColours[(r.nextInt(discoColours.length))]); newSheep.setBreed(false); // this prevents breeding - no event listener required - newSheep.teleport(loc); // teleport is needed to set orientation - newSheep.setTarget(this.mainPlayer); + newSheep.teleport(loc); // teleport is needed to set orientation getSheepList().add(newSheep); getSheepSet().add(newSheep); if (doLightning) { @@ -331,7 +334,8 @@ public class DiscoParty { } 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); getGuestSet().add(newGuest); if (doLightning) { @@ -485,16 +489,28 @@ public class DiscoParty { } void playSounds() { - for (Player p : players) { - p.playSound(p.getLocation(), Sound.NOTE_BASS_DRUM, 0.75f, 1.0f); - if (this.state % 2 == 0) { - p.playSound(p.getLocation(), Sound.NOTE_SNARE_DRUM, 0.8f, 1.0f); - } - if ((this.state + 1) % 8 == 0) { - p.playSound(p.getLocation(), Sound.NOTE_STICKS, 1.0f, 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) { + sheep.getWorld().playSound(sheep.getLocation(), Sound.NOTE_SNARE_DRUM, 0.8f, 1.0f); + } + + if ((this.state + 1) % 8 == 0) { + 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) { @@ -541,16 +557,17 @@ public class DiscoParty { void scheduleUpdate() { updater = new DiscoUpdater(); - updater.runTaskLater(parent, this.period); + updater.runTaskLater(plugin, this.period); } void startDisco() { + this.volumeMultiplier = Math.max(this.radius / 10, 1.0f); this.spawnAll(sheep, radius); this.scheduleUpdate(); - parent.getPartyMap().put(this.mainPlayer.getName(), this); + plugin.getPartyMap().put(this.player.getName(), this); // start listening this.partyEvents = new PartyEvents(this); - parent.getServer().getPluginManager().registerEvents(this.partyEvents, this.parent); + plugin.getServer().getPluginManager().registerEvents(this.partyEvents, this.plugin); } void stopDisco() { @@ -560,7 +577,7 @@ public class DiscoParty { updater.cancel(); } updater = null; - parent.getPartyMap().remove(this.mainPlayer.getName()); + plugin.getPartyMap().remove(this.player.getName()); // stop listening HandlerList.unregisterAll(this.partyEvents); } diff --git a/src/plugin.yml b/src/plugin.yml index 59a2f36..7d080fb 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,7 +1,7 @@ name: DiscoSheep main: ca.gibstick.discosheep.DiscoSheep authors: [Gibstick, RangerMauve] -version: 1.1.2 +version: 1.2 commands: #ds: #description: "Main DiscoSheep command" @@ -28,6 +28,7 @@ permissions: discosheep.party.changeperiod: true discosheep.party.spawnguests: true discosheep.party.lightning: true + discosheep.party.dancefloor: true discosheep.admin.*: description: Suggested permissions for administrators default: op @@ -78,6 +79,9 @@ permissions: discosheep.party.lightning: description: Allow a player to use lightning for parties 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 discosheep.party: children: