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
This commit is contained in:
Gibstick 2013-07-21 11:36:37 -04:00
parent 28a27c9c29
commit 5b7c996cff
3 changed files with 43 additions and 15 deletions

View File

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

View File

@ -26,7 +26,6 @@ public class DiscoParty {
private DiscoSheep ds;
private Player player;
private ArrayList<Sheep> sheepList = new ArrayList<Sheep>();
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<Sheep> getSheep() {
List<Sheep> 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) {

View File

@ -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;
@ -92,6 +94,10 @@ public class DiscoSheepCommandExecutor implements CommandExecutor {
return parent.noPermsMessage(sender, DiscoSheep.PERMISSION_FIREWORKS);
}
} else if (args[i].equalsIgnoreCase("-r")) {
if (parseNextArg(args, i, "dense")) {
specialRadius = true;
}
if (!specialRadius) {
try {
mainParty.setRadius(parseNextIntArg(args, i));
} catch (IllegalArgumentException e) {
@ -99,6 +105,7 @@ public class DiscoSheepCommandExecutor implements CommandExecutor {
+ DiscoParty.maxRadius + "]");
return false;
}
}
} else if (args[i].equalsIgnoreCase("-n")) {
try {
mainParty.setSheep(parseNextIntArg(args, i));
@ -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);