From 5b7c996cff71330062a34103fa2f0212a6e0c872 Mon Sep 17 00:00:00 2001 From: Gibstick Date: Sun, 21 Jul 2013 11:36:37 -0400 Subject: [PATCH] added "-r dense" as argument for radius -r dense will tell the plugin to calculate the radius of the sheep using the forumla r = sqrt(sheep / pi), so that it party becomes a sheep moshpit. also renamed getSheep to getSheepList, and added getSheep to get the sheep number --- .../discosheep/BaaBaaBlockSheepEvents.java | 4 +-- src/ca/gibstick/discosheep/DiscoParty.java | 29 +++++++++++++++---- .../discosheep/DiscoSheepCommandExecutor.java | 25 +++++++++++----- 3 files changed, 43 insertions(+), 15 deletions(-) diff --git a/src/ca/gibstick/discosheep/BaaBaaBlockSheepEvents.java b/src/ca/gibstick/discosheep/BaaBaaBlockSheepEvents.java index c0f7c43..a9c29c5 100644 --- a/src/ca/gibstick/discosheep/BaaBaaBlockSheepEvents.java +++ b/src/ca/gibstick/discosheep/BaaBaaBlockSheepEvents.java @@ -32,7 +32,7 @@ public class BaaBaaBlockSheepEvents implements Listener { public void onPlayerShear(PlayerShearEntityEvent e) { if (e.getEntity() instanceof Sheep) { for (DiscoParty party : parent.getParties()) { - if (party.getSheep().contains((Sheep) e.getEntity())) { + if (party.getSheepList().contains((Sheep) e.getEntity())) { e.setCancelled(true); } } @@ -44,7 +44,7 @@ public class BaaBaaBlockSheepEvents implements Listener { public void onEntityDamageEvent(EntityDamageEvent e) { if (e.getEntity() instanceof Sheep) { for (DiscoParty party : parent.getParties()) { - if (party.getSheep().contains((Sheep) e.getEntity())) { + if (party.getSheepList().contains((Sheep) e.getEntity())) { { party.jumpSheep((Sheep) e.getEntity()); // for kicks e.setCancelled(true); diff --git a/src/ca/gibstick/discosheep/DiscoParty.java b/src/ca/gibstick/discosheep/DiscoParty.java index fcae489..c97011d 100644 --- a/src/ca/gibstick/discosheep/DiscoParty.java +++ b/src/ca/gibstick/discosheep/DiscoParty.java @@ -26,7 +26,6 @@ public class DiscoParty { private DiscoSheep ds; private Player player; private ArrayList sheepList = new ArrayList(); - private int duration, period, radius, sheep; static int defaultDuration = 300; // ticks for entire party static int defaultPeriod = 10; // ticks per state change static int defaultRadius = 5; @@ -39,6 +38,7 @@ public class DiscoParty { static int maxPeriod = 40; // 2.0 seconds private boolean doFireworks = false; private boolean doJump = true; + private int duration, period, radius, sheep; private int state = 0; // basically our own tick system private DiscoUpdater updater; private static final DyeColor[] discoColours = { @@ -86,10 +86,14 @@ public class DiscoParty { return newParty; } - List getSheep() { + List getSheepList() { return sheepList; } + public int getSheep() { + return this.sheep; + } + public DiscoParty setPlayer(Player player) { if (player != null) { this.player = player; @@ -126,6 +130,19 @@ public class DiscoParty { } } + public DiscoParty setDenseRadius(int sheepNo) throws IllegalArgumentException { + Integer r = (int) Math.floor(Math.sqrt(sheep / Math.PI)); + if (r > DiscoParty.maxRadius) { + r = DiscoParty.maxRadius; + } + if (r < 1) { + r = 1; + } + + this.setRadius(r); + return this; + } + public DiscoParty setSheep(int sheep) throws IllegalArgumentException { if (sheep <= DiscoParty.maxSheep && sheep > 0) { this.sheep = sheep; @@ -171,16 +188,16 @@ public class DiscoParty { newSheep.setColor(discoColours[(int) (Math.random() * (discoColours.length - 1))]); newSheep.setBreed(false); // this prevents breeding - no event listener required newSheep.teleport(loc); // teleport is needed to set orientation - getSheep().add(newSheep); + getSheepList().add(newSheep); } // Mark all sheep in the sheep array for removal, then clear the array void removeAllSheep() { - for (Sheep sheeple : getSheep()) { + for (Sheep sheeple : getSheepList()) { //sheeple.setHealth(0); // removed to make it more resilient to updates sheeple.remove(); } - getSheep().clear(); + getSheepList().clear(); } // Set a random colour for all sheep in array @@ -254,7 +271,7 @@ public class DiscoParty { } void updateAllSheep() { - for (Sheep sheeple : getSheep()) { + for (Sheep sheeple : getSheepList()) { randomizeSheepColour(sheeple); if (doFireworks && state % 8 == 0) { diff --git a/src/ca/gibstick/discosheep/DiscoSheepCommandExecutor.java b/src/ca/gibstick/discosheep/DiscoSheepCommandExecutor.java index a24b672..33594fa 100644 --- a/src/ca/gibstick/discosheep/DiscoSheepCommandExecutor.java +++ b/src/ca/gibstick/discosheep/DiscoSheepCommandExecutor.java @@ -59,6 +59,8 @@ public class DiscoSheepCommandExecutor implements CommandExecutor { Player player = null; boolean isPlayer = false; + boolean specialRadius = false; + // flag to determine if we calculate a radius so that the sheep spawn densely in an area if (sender instanceof Player) { player = (Player) sender; @@ -89,15 +91,20 @@ public class DiscoSheepCommandExecutor implements CommandExecutor { if (sender.hasPermission(DiscoSheep.PERMISSION_FIREWORKS)) { mainParty.setDoFireworks(true); } else { - return parent.noPermsMessage(sender,DiscoSheep.PERMISSION_FIREWORKS); + return parent.noPermsMessage(sender, DiscoSheep.PERMISSION_FIREWORKS); } } else if (args[i].equalsIgnoreCase("-r")) { - try { - mainParty.setRadius(parseNextIntArg(args, i)); - } catch (IllegalArgumentException e) { - sender.sendMessage("Radius must be an integer within the range [1, " - + DiscoParty.maxRadius + "]"); - return false; + if (parseNextArg(args, i, "dense")) { + specialRadius = true; + } + if (!specialRadius) { + try { + mainParty.setRadius(parseNextIntArg(args, i)); + } catch (IllegalArgumentException e) { + sender.sendMessage("Radius must be an integer within the range [1, " + + DiscoParty.maxRadius + "]"); + return false; + } } } else if (args[i].equalsIgnoreCase("-n")) { try { @@ -131,6 +138,10 @@ public class DiscoSheepCommandExecutor implements CommandExecutor { } } + if (specialRadius) { + mainParty.setDenseRadius(mainParty.getSheep()); + } + if (args.length > 0) { if (args[0].equalsIgnoreCase("all")) { return parent.partyAllCommand(sender, mainParty, this);