refactorizations, fixed /ds other, added permission for -p switch
This commit is contained in:
parent
dbbe9d5dba
commit
886d7f4192
BIN
dist/DiscoSheep.jar
vendored
BIN
dist/DiscoSheep.jar
vendored
Binary file not shown.
@ -58,10 +58,18 @@ public class DiscoParty {
|
|||||||
public DiscoParty(DiscoSheep parent, Player player) {
|
public DiscoParty(DiscoSheep parent, Player player) {
|
||||||
this.ds = parent;
|
this.ds = parent;
|
||||||
this.player = player;
|
this.player = player;
|
||||||
|
this.duration = DiscoParty.defaultDuration;
|
||||||
|
this.period = DiscoParty.defaultPeriod;
|
||||||
|
this.radius = DiscoParty.defaultRadius;
|
||||||
|
this.sheep = DiscoParty.defaultSheep;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DiscoParty(DiscoSheep parent) {
|
public DiscoParty(DiscoSheep parent) {
|
||||||
this.ds = parent;
|
this.ds = parent;
|
||||||
|
this.duration = DiscoParty.defaultDuration;
|
||||||
|
this.period = DiscoParty.defaultPeriod;
|
||||||
|
this.radius = DiscoParty.defaultRadius;
|
||||||
|
this.sheep = DiscoParty.defaultSheep;
|
||||||
}
|
}
|
||||||
|
|
||||||
// copy but with new player
|
// copy but with new player
|
||||||
@ -77,7 +85,7 @@ public class DiscoParty {
|
|||||||
newParty.setPeriod(this.period);
|
newParty.setPeriod(this.period);
|
||||||
newParty.setRadius(this.radius);
|
newParty.setRadius(this.radius);
|
||||||
newParty.setSheep(this.sheep);
|
newParty.setSheep(this.sheep);
|
||||||
return newParty;
|
return newParty;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Sheep> getSheep() {
|
List<Sheep> getSheep() {
|
||||||
|
@ -108,15 +108,15 @@ public final class DiscoSheep extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startParty(Player player, int duration, int sheepAmount, int radius, int period, boolean fireworksEnabled) {
|
/*public void startParty(Player player, int duration, int sheepAmount, int radius, int period, boolean fireworksEnabled) {
|
||||||
if (!hasParty(player.getName())) {
|
* if (!hasParty(player.getName())) {
|
||||||
DiscoParty ds = new DiscoParty(this, player);
|
* DiscoParty ds = new DiscoParty(this, player);
|
||||||
ds.setDuration(duration);
|
* ds.setDuration(duration);
|
||||||
ds.setSheep(sheepAmount);
|
* ds.setSheep(sheepAmount);
|
||||||
ds.setRadius(radius);
|
* ds.setRadius(radius);
|
||||||
ds.setPeriod(period);
|
* ds.setPeriod(period);
|
||||||
ds.setDoFireworks(fireworksEnabled);
|
* ds.setDoFireworks(fireworksEnabled);
|
||||||
ds.startDisco();
|
* ds.startDisco();
|
||||||
}
|
* }
|
||||||
}
|
* }*/
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@ public class DiscoSheepCommandExecutor implements CommandExecutor {
|
|||||||
private static final String PERMISSION_STOPALL = "discosheep.stopall";
|
private static final String PERMISSION_STOPALL = "discosheep.stopall";
|
||||||
private static final String PERMISSION_RELOAD = "discosheep.reload";
|
private static final String PERMISSION_RELOAD = "discosheep.reload";
|
||||||
private static final String PERMISSION_OTHER = "discosheep.partyother";
|
private static final String PERMISSION_OTHER = "discosheep.partyother";
|
||||||
|
private static final String PERMISSION_CHANGEPERIOD = "discosheep.changeperiod";
|
||||||
|
|
||||||
//private static final String DELIM = "[ ]+";
|
//private static final String DELIM = "[ ]+";
|
||||||
private boolean senderHasPerm(CommandSender sender, String permission) {
|
private boolean senderHasPerm(CommandSender sender, String permission) {
|
||||||
@ -60,8 +61,8 @@ public class DiscoSheepCommandExecutor implements CommandExecutor {
|
|||||||
// extract a list of players from a list of arguments
|
// extract a list of players from a list of arguments
|
||||||
private String[] parsePlayerList(String[] args, int i) {
|
private String[] parsePlayerList(String[] args, int i) {
|
||||||
int j = i;
|
int j = i;
|
||||||
while (j < args.length && !args[i].startsWith("-")) {
|
while (j < args.length && !args[j].startsWith("-")) {
|
||||||
++j;
|
j++;
|
||||||
}
|
}
|
||||||
return Arrays.copyOfRange(args, i, j);
|
return Arrays.copyOfRange(args, i, j);
|
||||||
}
|
}
|
||||||
@ -94,20 +95,28 @@ public class DiscoSheepCommandExecutor implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean partyCommand(CommandSender sender, int _duration, int _sheepNumber, int _radius, int _period, boolean _fireworks) {
|
private boolean partyCommand(Player player, DiscoParty party) {
|
||||||
if (senderHasPerm(sender, PERMISSION_PARTY)) {
|
if (senderHasPerm(player, PERMISSION_PARTY)) {
|
||||||
parent.startParty((Player) sender, _duration, _sheepNumber, _radius, _period, _fireworks);
|
if (!parent.hasParty(player.getName())) {
|
||||||
|
party.setPlayer(player);
|
||||||
|
party.startDisco();
|
||||||
|
} else {
|
||||||
|
player.sendMessage("You already have a party. Are you underground?");
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return noPermsMessage(sender, PERMISSION_PARTY);
|
return noPermsMessage(player, PERMISSION_PARTY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean partyAllCommand(CommandSender sender, int _duration, int _sheepNumber, int _radius, int _period, boolean _fireworks) {
|
private boolean partyAllCommand(CommandSender sender, DiscoParty party) {
|
||||||
if (senderHasPerm(sender, PERMISSION_ALL)) {
|
if (senderHasPerm(sender, PERMISSION_ALL)) {
|
||||||
for (Player p : Bukkit.getServer().getOnlinePlayers()) {
|
for (Player p : Bukkit.getServer().getOnlinePlayers()) {
|
||||||
parent.startParty(p, _duration, _sheepNumber, _radius, _period, _fireworks);
|
if (!parent.hasParty(p.getName())) {
|
||||||
p.sendMessage(ChatColor.RED + "LET'S DISCO!");
|
DiscoParty individualParty = party.DiscoParty(p);
|
||||||
|
individualParty.startDisco();
|
||||||
|
p.sendMessage(ChatColor.RED + "LET'S DISCO!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
@ -129,13 +138,16 @@ public class DiscoSheepCommandExecutor implements CommandExecutor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean partySelectCommand(String[] players, CommandSender sender, int _duration, int _sheepNumber, int _radius, int _period, boolean _fireworks) {
|
private boolean partyOtherCommand(String[] players, CommandSender sender, DiscoParty party) {
|
||||||
if (senderHasPerm(sender, PERMISSION_OTHER)) {
|
if (senderHasPerm(sender, PERMISSION_OTHER)) {
|
||||||
Player p;
|
Player p;
|
||||||
for (String playerName : players) {
|
for (String playerName : players) {
|
||||||
p = Bukkit.getServer().getPlayer(playerName);
|
p = Bukkit.getServer().getPlayer(playerName);
|
||||||
if (p != null) {
|
if (p != null) {
|
||||||
parent.startParty(p, _duration, _sheepNumber, _radius, _period, _fireworks);
|
if (!parent.hasParty(p.getName())) {
|
||||||
|
DiscoParty individualParty = party.DiscoParty(p);
|
||||||
|
individualParty.startDisco();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage("Invalid player: " + playerName);
|
sender.sendMessage("Invalid player: " + playerName);
|
||||||
}
|
}
|
||||||
@ -151,11 +163,6 @@ public class DiscoSheepCommandExecutor implements CommandExecutor {
|
|||||||
|
|
||||||
Player player = null;
|
Player player = null;
|
||||||
boolean isPlayer = false;
|
boolean isPlayer = false;
|
||||||
boolean fireworks = false;
|
|
||||||
int sheepNumber = DiscoParty.defaultSheep;
|
|
||||||
int radius = DiscoParty.defaultRadius;
|
|
||||||
int duration = DiscoParty.defaultDuration;
|
|
||||||
int period = DiscoParty.defaultPeriod;
|
|
||||||
|
|
||||||
if (sender instanceof Player) {
|
if (sender instanceof Player) {
|
||||||
player = (Player) sender;
|
player = (Player) sender;
|
||||||
@ -175,19 +182,19 @@ public class DiscoSheepCommandExecutor implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DiscoParty mainParty = new DiscoParty(parent);
|
DiscoParty parentParty = new DiscoParty(parent);
|
||||||
|
|
||||||
for (int i = 1; i < args.length; i++) {
|
for (int i = 1; i < args.length; i++) {
|
||||||
if (args[i].equalsIgnoreCase("-fw")) {
|
if (args[i].equalsIgnoreCase("-fw")) {
|
||||||
if (senderHasPerm(sender, PERMISSION_FIREWORKS)) {
|
if (senderHasPerm(sender, PERMISSION_FIREWORKS)) {
|
||||||
mainParty.setDoFireworks(true);
|
parentParty.setDoFireworks(true);
|
||||||
} else {
|
} else {
|
||||||
return noPermsMessage(sender, PERMISSION_FIREWORKS);
|
return noPermsMessage(sender, PERMISSION_FIREWORKS);
|
||||||
}
|
}
|
||||||
} else if (args[i].equalsIgnoreCase("-r")) {
|
} else if (args[i].equalsIgnoreCase("-r")) {
|
||||||
try {
|
try {
|
||||||
mainParty.setRadius(parseNextIntArg(args, i));
|
parentParty.setRadius(parseNextIntArg(args, i));
|
||||||
sender.sendMessage("RADIUS OK");
|
//sender.sendMessage("RADIUS OK");
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
sender.sendMessage("Radius must be an integer within the range [1, "
|
sender.sendMessage("Radius must be an integer within the range [1, "
|
||||||
+ DiscoParty.maxRadius + "]");
|
+ DiscoParty.maxRadius + "]");
|
||||||
@ -195,8 +202,8 @@ public class DiscoSheepCommandExecutor implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
} else if (args[i].equalsIgnoreCase("-n")) {
|
} else if (args[i].equalsIgnoreCase("-n")) {
|
||||||
try {
|
try {
|
||||||
mainParty.setSheep(parseNextIntArg(args, i));
|
parentParty.setSheep(parseNextIntArg(args, i));
|
||||||
sender.sendMessage("SHEEP OK");
|
//sender.sendMessage("SHEEP OK");
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
sender.sendMessage("The number of sheep must be an integer within the range [1, "
|
sender.sendMessage("The number of sheep must be an integer within the range [1, "
|
||||||
+ DiscoParty.maxSheep + "]");
|
+ DiscoParty.maxSheep + "]");
|
||||||
@ -204,17 +211,20 @@ public class DiscoSheepCommandExecutor implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
} else if (args[i].equalsIgnoreCase("-t")) {
|
} else if (args[i].equalsIgnoreCase("-t")) {
|
||||||
try {
|
try {
|
||||||
mainParty.setDuration(parent.toTicks(parseNextIntArg(args, i)));
|
parentParty.setDuration(parent.toTicks(parseNextIntArg(args, i)));
|
||||||
sender.sendMessage("DURATION OK");
|
//sender.sendMessage("DURATION OK");
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
sender.sendMessage("The duration in seconds must be an integer within the range [1, "
|
sender.sendMessage("The duration in seconds must be an integer within the range [1, "
|
||||||
+ parent.toSeconds(DiscoParty.maxDuration) + "]");
|
+ parent.toSeconds(DiscoParty.maxDuration) + "]");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else if (args[i].equalsIgnoreCase("-p")) {
|
} else if (args[i].equalsIgnoreCase("-p")) {
|
||||||
|
if (!senderHasPerm(sender, PERMISSION_CHANGEPERIOD)) {
|
||||||
|
return noPermsMessage(sender, PERMISSION_CHANGEPERIOD);
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
mainParty.setPeriod(parseNextIntArg(args, i));
|
parentParty.setPeriod(parseNextIntArg(args, i));
|
||||||
sender.sendMessage("PERIOD OK");
|
//sender.sendMessage("PERIOD OK");
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
sender.sendMessage(
|
sender.sendMessage(
|
||||||
"The period in ticks must be within the range ["
|
"The period in ticks must be within the range ["
|
||||||
@ -227,11 +237,11 @@ public class DiscoSheepCommandExecutor implements CommandExecutor {
|
|||||||
|
|
||||||
if (args.length > 0) {
|
if (args.length > 0) {
|
||||||
if (args[0].equalsIgnoreCase("all")) {
|
if (args[0].equalsIgnoreCase("all")) {
|
||||||
return partyAllCommand(sender, duration, sheepNumber, radius, period, fireworks);
|
return partyAllCommand(sender, parentParty);
|
||||||
} else if (args[0].equalsIgnoreCase("me") && isPlayer) {
|
} else if (args[0].equalsIgnoreCase("me") && isPlayer) {
|
||||||
return partyCommand(player, duration, sheepNumber, radius, period, fireworks);
|
return partyCommand(player, parentParty);
|
||||||
} else if (args[0].equalsIgnoreCase("other")) {
|
} else if (args[0].equalsIgnoreCase("other")) {
|
||||||
return partySelectCommand(parsePlayerList(args, 1), sender, duration, sheepNumber, radius, period, fireworks);
|
return partyOtherCommand(parsePlayerList(args, 1), sender, parentParty);
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage(ChatColor.RED + "Invalid argument (certain commands do not work from console).");
|
sender.sendMessage(ChatColor.RED + "Invalid argument (certain commands do not work from console).");
|
||||||
return false;
|
return false;
|
||||||
|
@ -19,6 +19,8 @@ permissions:
|
|||||||
discosheep.fireworks: true
|
discosheep.fireworks: true
|
||||||
discosheep.stopall: true
|
discosheep.stopall: true
|
||||||
discosheep.reload: true
|
discosheep.reload: true
|
||||||
|
discosheep.other: true
|
||||||
|
discosheep.period: true
|
||||||
discosheep.party:
|
discosheep.party:
|
||||||
description: Allows a player to have a party of one
|
description: Allows a player to have a party of one
|
||||||
default: op
|
default: op
|
||||||
@ -39,3 +41,6 @@ permissions:
|
|||||||
default: op
|
default: op
|
||||||
children:
|
children:
|
||||||
discosheep.party: true
|
discosheep.party: true
|
||||||
|
discosheep.changeperiod:
|
||||||
|
description: Allows a player to use the -p switch
|
||||||
|
default: op
|
Loading…
Reference in New Issue
Block a user