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:
parent
28a27c9c29
commit
5b7c996cff
@ -32,7 +32,7 @@ public class BaaBaaBlockSheepEvents implements Listener {
|
|||||||
public void onPlayerShear(PlayerShearEntityEvent e) {
|
public void onPlayerShear(PlayerShearEntityEvent e) {
|
||||||
if (e.getEntity() instanceof Sheep) {
|
if (e.getEntity() instanceof Sheep) {
|
||||||
for (DiscoParty party : parent.getParties()) {
|
for (DiscoParty party : parent.getParties()) {
|
||||||
if (party.getSheep().contains((Sheep) e.getEntity())) {
|
if (party.getSheepList().contains((Sheep) e.getEntity())) {
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -44,7 +44,7 @@ public class BaaBaaBlockSheepEvents implements Listener {
|
|||||||
public void onEntityDamageEvent(EntityDamageEvent e) {
|
public void onEntityDamageEvent(EntityDamageEvent e) {
|
||||||
if (e.getEntity() instanceof Sheep) {
|
if (e.getEntity() instanceof Sheep) {
|
||||||
for (DiscoParty party : parent.getParties()) {
|
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
|
party.jumpSheep((Sheep) e.getEntity()); // for kicks
|
||||||
e.setCancelled(true);
|
e.setCancelled(true);
|
||||||
|
@ -26,7 +26,6 @@ public class DiscoParty {
|
|||||||
private DiscoSheep ds;
|
private DiscoSheep ds;
|
||||||
private Player player;
|
private Player player;
|
||||||
private ArrayList<Sheep> sheepList = new ArrayList<Sheep>();
|
private ArrayList<Sheep> sheepList = new ArrayList<Sheep>();
|
||||||
private int duration, period, radius, sheep;
|
|
||||||
static int defaultDuration = 300; // ticks for entire party
|
static int defaultDuration = 300; // ticks for entire party
|
||||||
static int defaultPeriod = 10; // ticks per state change
|
static int defaultPeriod = 10; // ticks per state change
|
||||||
static int defaultRadius = 5;
|
static int defaultRadius = 5;
|
||||||
@ -39,6 +38,7 @@ public class DiscoParty {
|
|||||||
static int maxPeriod = 40; // 2.0 seconds
|
static int maxPeriod = 40; // 2.0 seconds
|
||||||
private boolean doFireworks = false;
|
private boolean doFireworks = false;
|
||||||
private boolean doJump = true;
|
private boolean doJump = true;
|
||||||
|
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 DiscoUpdater updater;
|
private DiscoUpdater updater;
|
||||||
private static final DyeColor[] discoColours = {
|
private static final DyeColor[] discoColours = {
|
||||||
@ -86,10 +86,14 @@ public class DiscoParty {
|
|||||||
return newParty;
|
return newParty;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Sheep> getSheep() {
|
List<Sheep> getSheepList() {
|
||||||
return sheepList;
|
return sheepList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getSheep() {
|
||||||
|
return this.sheep;
|
||||||
|
}
|
||||||
|
|
||||||
public DiscoParty setPlayer(Player player) {
|
public DiscoParty setPlayer(Player player) {
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
this.player = player;
|
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 {
|
public DiscoParty setSheep(int sheep) throws IllegalArgumentException {
|
||||||
if (sheep <= DiscoParty.maxSheep && sheep > 0) {
|
if (sheep <= DiscoParty.maxSheep && sheep > 0) {
|
||||||
this.sheep = sheep;
|
this.sheep = sheep;
|
||||||
@ -171,16 +188,16 @@ public class DiscoParty {
|
|||||||
newSheep.setColor(discoColours[(int) (Math.random() * (discoColours.length - 1))]);
|
newSheep.setColor(discoColours[(int) (Math.random() * (discoColours.length - 1))]);
|
||||||
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
|
||||||
getSheep().add(newSheep);
|
getSheepList().add(newSheep);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mark all sheep in the sheep array for removal, then clear the array
|
// Mark all sheep in the sheep array for removal, then clear the array
|
||||||
void removeAllSheep() {
|
void removeAllSheep() {
|
||||||
for (Sheep sheeple : getSheep()) {
|
for (Sheep sheeple : getSheepList()) {
|
||||||
//sheeple.setHealth(0); // removed to make it more resilient to updates
|
//sheeple.setHealth(0); // removed to make it more resilient to updates
|
||||||
sheeple.remove();
|
sheeple.remove();
|
||||||
}
|
}
|
||||||
getSheep().clear();
|
getSheepList().clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set a random colour for all sheep in array
|
// Set a random colour for all sheep in array
|
||||||
@ -254,7 +271,7 @@ public class DiscoParty {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void updateAllSheep() {
|
void updateAllSheep() {
|
||||||
for (Sheep sheeple : getSheep()) {
|
for (Sheep sheeple : getSheepList()) {
|
||||||
randomizeSheepColour(sheeple);
|
randomizeSheepColour(sheeple);
|
||||||
|
|
||||||
if (doFireworks && state % 8 == 0) {
|
if (doFireworks && state % 8 == 0) {
|
||||||
|
@ -59,6 +59,8 @@ public class DiscoSheepCommandExecutor implements CommandExecutor {
|
|||||||
|
|
||||||
Player player = null;
|
Player player = null;
|
||||||
boolean isPlayer = false;
|
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) {
|
if (sender instanceof Player) {
|
||||||
player = (Player) sender;
|
player = (Player) sender;
|
||||||
@ -92,6 +94,10 @@ public class DiscoSheepCommandExecutor implements CommandExecutor {
|
|||||||
return parent.noPermsMessage(sender, DiscoSheep.PERMISSION_FIREWORKS);
|
return parent.noPermsMessage(sender, DiscoSheep.PERMISSION_FIREWORKS);
|
||||||
}
|
}
|
||||||
} else if (args[i].equalsIgnoreCase("-r")) {
|
} else if (args[i].equalsIgnoreCase("-r")) {
|
||||||
|
if (parseNextArg(args, i, "dense")) {
|
||||||
|
specialRadius = true;
|
||||||
|
}
|
||||||
|
if (!specialRadius) {
|
||||||
try {
|
try {
|
||||||
mainParty.setRadius(parseNextIntArg(args, i));
|
mainParty.setRadius(parseNextIntArg(args, i));
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
@ -99,6 +105,7 @@ public class DiscoSheepCommandExecutor implements CommandExecutor {
|
|||||||
+ DiscoParty.maxRadius + "]");
|
+ DiscoParty.maxRadius + "]");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else if (args[i].equalsIgnoreCase("-n")) {
|
} else if (args[i].equalsIgnoreCase("-n")) {
|
||||||
try {
|
try {
|
||||||
mainParty.setSheep(parseNextIntArg(args, i));
|
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.length > 0) {
|
||||||
if (args[0].equalsIgnoreCase("all")) {
|
if (args[0].equalsIgnoreCase("all")) {
|
||||||
return parent.partyAllCommand(sender, mainParty, this);
|
return parent.partyAllCommand(sender, mainParty, this);
|
||||||
|
Loading…
Reference in New Issue
Block a user