added number sheep number and radius switches
This commit is contained in:
parent
291a39ccc0
commit
ff9e992460
@ -26,10 +26,10 @@ public class DiscoParty {
|
|||||||
private Player player;
|
private Player player;
|
||||||
private ArrayList<Sheep> sheepList = new ArrayList<Sheep>();
|
private ArrayList<Sheep> sheepList = new ArrayList<Sheep>();
|
||||||
private int duration, frequency = 20, numSheep = 5;
|
private int duration, frequency = 20, numSheep = 5;
|
||||||
private final int defaultDuration = 300; // ticks for entire party
|
static final int defaultDuration = 300; // ticks for entire party
|
||||||
private final int defaultFrequency = 10; // ticks per state change
|
static final int defaultFrequency = 10; // ticks per state change
|
||||||
private final int defaultSheepSpawnRadius = 5;
|
static final int defaultSheepSpawnRadius = 5;
|
||||||
private final int defaultSheepAmount = 10;
|
static final int defaultSheepAmount = 10;
|
||||||
private boolean doFireworks = false;
|
private boolean doFireworks = false;
|
||||||
private int state = 0;
|
private int state = 0;
|
||||||
private DiscoUpdater updater;
|
private DiscoUpdater updater;
|
||||||
@ -230,15 +230,11 @@ public class DiscoParty {
|
|||||||
this.doFireworks = fireworks;
|
this.doFireworks = fireworks;
|
||||||
this.spawnSheep(sheepAmount, radius);
|
this.spawnSheep(sheepAmount, radius);
|
||||||
this.frequency = this.defaultFrequency;
|
this.frequency = this.defaultFrequency;
|
||||||
this.duration = this.defaultDuration;
|
this.duration = duration;
|
||||||
this.scheduleUpdate();
|
this.scheduleUpdate();
|
||||||
ds.getPartyMap().put(this.player.getName(), this);
|
ds.getPartyMap().put(this.player.getName(), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void startDisco(boolean fireworks) {
|
|
||||||
this.startDisco(this.defaultDuration, this.defaultSheepAmount, this.defaultSheepSpawnRadius, fireworks);
|
|
||||||
}
|
|
||||||
|
|
||||||
void stopDisco() {
|
void stopDisco() {
|
||||||
removeAllSheep();
|
removeAllSheep();
|
||||||
this.duration = 0;
|
this.duration = 0;
|
||||||
|
@ -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())) {
|
if (!hasParty(player.getName())) {
|
||||||
new DiscoParty(this, player).startDisco(fireworksEnabled);
|
new DiscoParty(this, player).startDisco(duration, sheepAmount, radius, fireworksEnabled);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,22 +14,32 @@ public class DiscoSheepCommandExecutor implements CommandExecutor {
|
|||||||
public DiscoSheepCommandExecutor(DiscoSheep parent) {
|
public DiscoSheepCommandExecutor(DiscoSheep parent) {
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
private CommandSender curSender;
|
|
||||||
|
|
||||||
private static final String PERMISSION_PARTY = "discosheep.party";
|
private static final String PERMISSION_PARTY = "discosheep.party";
|
||||||
private static final String PERMISSION_ALL = "discosheep.partyall";
|
private static final String PERMISSION_ALL = "discosheep.partyall";
|
||||||
private static final String PERMISSION_FIREWORKS = "discosheep.fireworks";
|
private static final String PERMISSION_FIREWORKS = "discosheep.fireworks";
|
||||||
private static final String PERMISSION_STOP = "discosheep.stop";
|
private static final String PERMISSION_STOP = "discosheep.stop";
|
||||||
private static final String PERMISSION_SUPER= "disosheep.*";
|
private static final String PERMISSION_SUPER = "disosheep.*";
|
||||||
|
|
||||||
|
private boolean senderHasPerm(CommandSender sender, String permission) {
|
||||||
private boolean senderHasPerm(String permission) {
|
return sender.hasPermission(permission) || sender.hasPermission(PERMISSION_SUPER);
|
||||||
return curSender.hasPermission(permission) || curSender.hasPermission(PERMISSION_SUPER);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void noPermsMessage(String permission) {
|
private void noPermsMessage(CommandSender sender, String permission) {
|
||||||
curSender.sendMessage(ChatColor.RED + "You do not have the permission node " + ChatColor.GRAY + 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
|
@Override
|
||||||
@ -37,58 +47,72 @@ public class DiscoSheepCommandExecutor implements CommandExecutor {
|
|||||||
Player player = null;
|
Player player = null;
|
||||||
boolean isPlayer = false;
|
boolean isPlayer = false;
|
||||||
boolean fireworks = false;
|
boolean fireworks = false;
|
||||||
int sheepNumber = 0;
|
int sheepNumber = DiscoParty.defaultSheepAmount;
|
||||||
int radius = 0;
|
int radius = DiscoParty.defaultSheepSpawnRadius;
|
||||||
this.curSender = sender;
|
int duration = DiscoParty.defaultDuration;
|
||||||
|
|
||||||
if (sender instanceof Player) {
|
if (sender instanceof Player) {
|
||||||
player = (Player) sender;
|
player = (Player) sender;
|
||||||
isPlayer = true;
|
isPlayer = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!senderHasPerm(PERMISSION_PARTY)) {
|
if (!senderHasPerm(sender, PERMISSION_PARTY)) {
|
||||||
noPermsMessage(PERMISSION_PARTY);
|
noPermsMessage(sender, PERMISSION_PARTY);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 1; i < args.length; i++) {
|
for (int i = 1; i < args.length; i++) {
|
||||||
switch (args[i]) {
|
if (args[i].equalsIgnoreCase("-fw")) {
|
||||||
case "-fw":
|
if (senderHasPerm(sender, PERMISSION_FIREWORKS)) {
|
||||||
if (senderHasPerm(PERMISSION_FIREWORKS)) {
|
|
||||||
fireworks = !fireworks;
|
fireworks = !fireworks;
|
||||||
} else {
|
} 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) {
|
if (args.length > 0) {
|
||||||
switch (args[0]) {
|
|
||||||
case "all":
|
if (args[0].equalsIgnoreCase("all")) {
|
||||||
if (senderHasPerm(PERMISSION_ALL))
|
if (senderHasPerm(sender, PERMISSION_ALL)) {
|
||||||
for (Player p : Bukkit.getServer().getOnlinePlayers()) {
|
for (Player p : Bukkit.getServer().getOnlinePlayers()) {
|
||||||
parent.startParty(p, fireworks);
|
parent.startParty(player, duration, sheepNumber, radius, fireworks);
|
||||||
p.sendMessage(ChatColor.RED + "LET'S DISCO!");
|
p.sendMessage(ChatColor.RED + "LET'S DISCO!");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
noPermsMessage(PERMISSION_ALL);
|
noPermsMessage(sender, PERMISSION_ALL);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
case "stop":
|
} else if (args[0].equalsIgnoreCase("stop")) {
|
||||||
if (senderHasPerm(PERMISSION_STOP)) {
|
if (senderHasPerm(sender, PERMISSION_STOP)) {
|
||||||
parent.stopAllParties();
|
parent.stopAllParties();
|
||||||
} else {
|
} else {
|
||||||
noPermsMessage(PERMISSION_STOP);
|
noPermsMessage(sender, PERMISSION_STOP);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
case "me":
|
} else if (args[0].equalsIgnoreCase("me")) {
|
||||||
if (isPlayer) {
|
if (isPlayer) {
|
||||||
parent.startParty(player, fireworks);
|
parent.startParty(player, duration, sheepNumber, radius, fireworks);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
default:
|
} else {
|
||||||
sender.sendMessage(ChatColor.RED + "Invalid argument.");
|
sender.sendMessage(ChatColor.RED + "Invalid argument.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
Reference in New Issue
Block a user