added number sheep number and radius switches

This commit is contained in:
Charlie Wang 2013-07-11 21:15:54 -04:00
parent 291a39ccc0
commit ff9e992460
3 changed files with 75 additions and 55 deletions

View File

@ -26,10 +26,10 @@ public class DiscoParty {
private Player player;
private ArrayList<Sheep> sheepList = new ArrayList<Sheep>();
private int duration, frequency = 20, numSheep = 5;
private final int defaultDuration = 300; // ticks for entire party
private final int defaultFrequency = 10; // ticks per state change
private final int defaultSheepSpawnRadius = 5;
private final int defaultSheepAmount = 10;
static final int defaultDuration = 300; // ticks for entire party
static final int defaultFrequency = 10; // ticks per state change
static final int defaultSheepSpawnRadius = 5;
static final int defaultSheepAmount = 10;
private boolean doFireworks = false;
private int state = 0;
private DiscoUpdater updater;
@ -230,15 +230,11 @@ public class DiscoParty {
this.doFireworks = fireworks;
this.spawnSheep(sheepAmount, radius);
this.frequency = this.defaultFrequency;
this.duration = this.defaultDuration;
this.duration = duration;
this.scheduleUpdate();
ds.getPartyMap().put(this.player.getName(), this);
}
void startDisco(boolean fireworks) {
this.startDisco(this.defaultDuration, this.defaultSheepAmount, this.defaultSheepSpawnRadius, fireworks);
}
void stopDisco() {
removeAllSheep();
this.duration = 0;

View File

@ -57,9 +57,9 @@ public final class DiscoSheep extends JavaPlugin {
}
}
public void startParty(Player player, boolean fireworksEnabled) {
public void startParty(Player player, int duration, int sheepAmount, int radius, boolean fireworksEnabled) {
if (!hasParty(player.getName())) {
new DiscoParty(this, player).startDisco(fireworksEnabled);
new DiscoParty(this, player).startDisco(duration, sheepAmount, radius, fireworksEnabled);
}
}
}

View File

@ -14,22 +14,32 @@ public class DiscoSheepCommandExecutor implements CommandExecutor {
public DiscoSheepCommandExecutor(DiscoSheep parent) {
this.parent = parent;
}
private CommandSender curSender;
private static final String PERMISSION_PARTY = "discosheep.party";
private static final String PERMISSION_ALL = "discosheep.partyall";
private static final String PERMISSION_FIREWORKS = "discosheep.fireworks";
private static final String PERMISSION_STOP = "discosheep.stop";
private static final String PERMISSION_SUPER = "disosheep.*";
private boolean senderHasPerm(String permission) {
return curSender.hasPermission(permission) || curSender.hasPermission(PERMISSION_SUPER);
private boolean senderHasPerm(CommandSender sender, String permission) {
return sender.hasPermission(permission) || sender.hasPermission(PERMISSION_SUPER);
}
private void noPermsMessage(String permission) {
curSender.sendMessage(ChatColor.RED + "You do not have the permission node " + ChatColor.GRAY + permission);
private void noPermsMessage(CommandSender sender, String permission) {
sender.sendMessage(ChatColor.RED + "You do not have the permission node " + ChatColor.GRAY + permission);
}
private boolean parseNextArg(String[] args, int i, String compare) {
if (i < args.length - 1) {
return args[i + 1].equalsIgnoreCase(compare);
}
return false;
}
private int parseNextIntArg(String[] args, int i) {
if (i < args.length - 1) {
return Integer.parseInt(args[i + 1]);
}
return -1;
}
@Override
@ -37,58 +47,72 @@ public class DiscoSheepCommandExecutor implements CommandExecutor {
Player player = null;
boolean isPlayer = false;
boolean fireworks = false;
int sheepNumber = 0;
int radius = 0;
this.curSender = sender;
int sheepNumber = DiscoParty.defaultSheepAmount;
int radius = DiscoParty.defaultSheepSpawnRadius;
int duration = DiscoParty.defaultDuration;
if (sender instanceof Player) {
player = (Player) sender;
isPlayer = true;
}
if (!senderHasPerm(PERMISSION_PARTY)) {
noPermsMessage(PERMISSION_PARTY);
if (!senderHasPerm(sender, PERMISSION_PARTY)) {
noPermsMessage(sender, PERMISSION_PARTY);
return true;
}
for (int i = 1; i < args.length; i++) {
switch (args[i]) {
case "-fw":
if (senderHasPerm(PERMISSION_FIREWORKS)) {
if (args[i].equalsIgnoreCase("-fw")) {
if (senderHasPerm(sender, PERMISSION_FIREWORKS)) {
fireworks = !fireworks;
} else {
noPermsMessage(PERMISSION_FIREWORKS);
noPermsMessage(sender, PERMISSION_FIREWORKS);
}
} else if (args[i].equalsIgnoreCase("-r")) {
radius = parseNextIntArg(args, i);
if (radius < 1 || radius > 100) {
sender.sendMessage("Radius must be an integer within the range [1, 100]");
return true;
}
} else if (args[i].equalsIgnoreCase("-n")) {
sheepNumber = parseNextIntArg(args, i);
if (sheepNumber < 1 || sheepNumber > 100) {
sender.sendMessage("The number of sheep must be an integer within the range [1, 100]");
}
}
}
if (args.length > 0) {
switch (args[0]) {
case "all":
if (senderHasPerm(PERMISSION_ALL))
if (args[0].equalsIgnoreCase("all")) {
if (senderHasPerm(sender, PERMISSION_ALL)) {
for (Player p : Bukkit.getServer().getOnlinePlayers()) {
parent.startParty(p, fireworks);
parent.startParty(player, duration, sheepNumber, radius, fireworks);
p.sendMessage(ChatColor.RED + "LET'S DISCO!");
}
} else {
noPermsMessage(PERMISSION_ALL);
noPermsMessage(sender, PERMISSION_ALL);
}
return true;
case "stop":
if (senderHasPerm(PERMISSION_STOP)) {
} else if (args[0].equalsIgnoreCase("stop")) {
if (senderHasPerm(sender, PERMISSION_STOP)) {
parent.stopAllParties();
} else {
noPermsMessage(PERMISSION_STOP);
noPermsMessage(sender, PERMISSION_STOP);
}
return true;
case "me":
} else if (args[0].equalsIgnoreCase("me")) {
if (isPlayer) {
parent.startParty(player, fireworks);
parent.startParty(player, duration, sheepNumber, radius, fireworks);
return true;
}
default:
} else {
sender.sendMessage(ChatColor.RED + "Invalid argument.");
return true;
}
}
return false;