added /ds other command
This commit is contained in:
parent
1fb36d25e5
commit
d70eb38848
BIN
dist/DiscoSheep.jar
vendored
BIN
dist/DiscoSheep.jar
vendored
Binary file not shown.
@ -26,7 +26,7 @@ public class DiscoParty {
|
||||
private DiscoSheep ds;
|
||||
private Player player;
|
||||
private ArrayList<Sheep> sheepList = new ArrayList<Sheep>();
|
||||
private int duration, frequency = 20;
|
||||
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;
|
||||
@ -64,6 +64,56 @@ public class DiscoParty {
|
||||
return sheepList;
|
||||
}
|
||||
|
||||
public DiscoParty setPlayer(Player player) {
|
||||
if (player != null) {
|
||||
this.player = player;
|
||||
return this;
|
||||
} else {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
}
|
||||
|
||||
public DiscoParty setDuration(int duration) throws IllegalArgumentException {
|
||||
if (duration < DiscoParty.maxDuration) {
|
||||
this.duration = duration;
|
||||
return this;
|
||||
} else {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
public DiscoParty setPeriod(int period) throws IllegalArgumentException {
|
||||
if (period >= DiscoParty.minPeriod || period <= DiscoParty.maxPeriod) {
|
||||
this.period = period;
|
||||
return this;
|
||||
} else {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
public DiscoParty setRadius(int radius) throws IllegalArgumentException {
|
||||
if (radius < DiscoParty.maxRadius) {
|
||||
this.radius = radius;
|
||||
return this;
|
||||
} else {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
public DiscoParty setSheep(int sheep) throws IllegalArgumentException {
|
||||
if (sheep < DiscoParty.maxSheep) {
|
||||
this.sheep = sheep;
|
||||
return this;
|
||||
} else {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
public DiscoParty setDoFireworks(boolean doFireworks) {
|
||||
this.doFireworks = doFireworks;
|
||||
return this;
|
||||
}
|
||||
|
||||
void spawnSheep(World world, Location loc) {
|
||||
Sheep newSheep = (Sheep) world.spawnEntity(loc, EntityType.SHEEP);
|
||||
newSheep.setColor(discoColours[(int) (Math.random() * (discoColours.length - 1))]);
|
||||
@ -97,9 +147,9 @@ public class DiscoParty {
|
||||
|
||||
// Mark all sheep in the sheep array for removal, then clear the array
|
||||
void removeAllSheep() {
|
||||
for (Sheep sheep : getSheep()) {
|
||||
sheep.setHealth(0);
|
||||
sheep.remove();
|
||||
for (Sheep sheeple : getSheep()) {
|
||||
sheeple.setHealth(0);
|
||||
sheeple.remove();
|
||||
}
|
||||
getSheep().clear();
|
||||
}
|
||||
@ -175,16 +225,16 @@ public class DiscoParty {
|
||||
|
||||
void updateAllSheep() {
|
||||
int i = 0;
|
||||
for (Sheep sheep : getSheep()) {
|
||||
randomizeSheepColour(sheep);
|
||||
for (Sheep sheeple : getSheep()) {
|
||||
randomizeSheepColour(sheeple);
|
||||
if (doFireworks && state % 8 == 0) {
|
||||
spawnRandomFireworkAtSheep(sheep);
|
||||
spawnRandomFireworkAtSheep(sheeple);
|
||||
}
|
||||
|
||||
if (doJump) {
|
||||
if (state % 2 == 0) {
|
||||
if (Math.random() < 0.5) {
|
||||
jumpSheep(sheep);
|
||||
jumpSheep(sheeple);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -238,7 +288,7 @@ public class DiscoParty {
|
||||
if (duration > 0) {
|
||||
updateAllSheep();
|
||||
playSounds();
|
||||
duration -= frequency;
|
||||
duration -= period;
|
||||
this.scheduleUpdate();
|
||||
this.state++;
|
||||
} else {
|
||||
@ -248,16 +298,16 @@ public class DiscoParty {
|
||||
|
||||
void scheduleUpdate() {
|
||||
updater = new DiscoUpdater(this);
|
||||
updater.runTaskLater(ds, this.frequency);
|
||||
updater.runTaskLater(ds, this.period);
|
||||
}
|
||||
|
||||
void startDisco(int duration, int sheepAmount, int radius, int frequency, boolean fireworks) {
|
||||
void startDisco(int duration, int sheepAmount, int radius, int period, boolean fireworks) {
|
||||
if (this.duration > 0) {
|
||||
stopDisco();
|
||||
}
|
||||
this.doFireworks = fireworks;
|
||||
this.spawnSheep(sheepAmount, radius);
|
||||
this.frequency = frequency;
|
||||
this.doFireworks = fireworks;
|
||||
this.period = period;
|
||||
this.duration = duration;
|
||||
this.scheduleUpdate();
|
||||
ds.getPartyMap().put(this.player.getName(), this);
|
||||
|
@ -4,7 +4,6 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.bukkit.configuration.Configuration;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
@ -51,7 +50,7 @@ public final class DiscoSheep extends JavaPlugin {
|
||||
DiscoParty.defaultDuration = toTicks(getConfig().getInt("default.duration"));
|
||||
DiscoParty.defaultPeriod = getConfig().getInt("default.period-ticks");
|
||||
}
|
||||
|
||||
|
||||
void reloadConfigFromDisk() {
|
||||
reloadConfig();
|
||||
loadConfigFromDisk();
|
||||
|
@ -1,8 +1,8 @@
|
||||
package gibstick.bukkit.discosheep;
|
||||
|
||||
import java.util.Arrays;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
@ -20,13 +20,16 @@ public class DiscoSheepCommandExecutor implements CommandExecutor {
|
||||
private static final String PERMISSION_FIREWORKS = "discosheep.fireworks";
|
||||
private static final String PERMISSION_STOP = "discosheep.stop";
|
||||
private static final String PERMISSION_RELOAD = "discosheep.reload";
|
||||
private static final String PERMISSION_OTHER = "discosheep.partyother";
|
||||
|
||||
//private static final String DELIM = "[ ]+";
|
||||
private boolean senderHasPerm(CommandSender sender, String permission) {
|
||||
return sender.hasPermission(permission);
|
||||
}
|
||||
|
||||
private void noPermsMessage(CommandSender sender, String permission) {
|
||||
private boolean noPermsMessage(CommandSender sender, String permission) {
|
||||
sender.sendMessage(ChatColor.RED + "You do not have the permission node " + ChatColor.GRAY + permission);
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean parseNextArg(String[] args, int i, String compare) {
|
||||
@ -50,8 +53,92 @@ public class DiscoSheepCommandExecutor implements CommandExecutor {
|
||||
return -1.0d;
|
||||
}
|
||||
|
||||
// extract a list of players from a list of arguments
|
||||
private String[] parsePlayerList(String[] args, int i) {
|
||||
int j = i;
|
||||
while (j < args.length && !args[i].startsWith("-")) {
|
||||
++j;
|
||||
}
|
||||
return Arrays.copyOfRange(args, i, j);
|
||||
}
|
||||
|
||||
/*-- Actual commands begin here --*/
|
||||
private boolean helpCommand(CommandSender sender) {
|
||||
sender.sendMessage(ChatColor.YELLOW + "DiscoSheep Help\n"
|
||||
+ ChatColor.GRAY + " Subcommands\n" + ChatColor.WHITE
|
||||
+ "me: start a party for yourself\n"
|
||||
+ "all: start a party for all players on the server\n"
|
||||
+ "stop: stop all parties (takes no arguments)\n"
|
||||
+ "other <players>: start a party for the space-delimited list of players\n"
|
||||
+ ChatColor.GRAY + " Arguments\n" + ChatColor.WHITE
|
||||
+ "-n <integer>: set the number of sheep per player that spawn\n"
|
||||
+ "-t <integer>: set the party duration in seconds\n"
|
||||
+ "-p <ticks>: set the number of ticks between each disco beat\n"
|
||||
+ "-r <integer>: set radius of the area in which sheep can spawn\n"
|
||||
+ "-fw: enables fireworks");
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean reloadCommand(CommandSender sender) {
|
||||
if (senderHasPerm(sender, PERMISSION_RELOAD)) {
|
||||
parent.reloadConfigFromDisk();
|
||||
sender.sendMessage(ChatColor.GREEN + "DiscoSheep config reloaded from disk");
|
||||
return true;
|
||||
} else {
|
||||
return noPermsMessage(sender, PERMISSION_RELOAD);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean partyCommand(CommandSender sender, int _duration, int _sheepNumber, int _radius, int _period, boolean _fireworks) {
|
||||
if (senderHasPerm(sender, PERMISSION_PARTY)) {
|
||||
parent.startParty((Player) sender, _duration, _sheepNumber, _radius, _period, _fireworks);
|
||||
return true;
|
||||
} else {
|
||||
return noPermsMessage(sender, PERMISSION_PARTY);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean partyAllCommand(CommandSender sender, int _duration, int _sheepNumber, int _radius, int _period, boolean _fireworks) {
|
||||
if (senderHasPerm(sender, PERMISSION_ALL)) {
|
||||
for (Player p : Bukkit.getServer().getOnlinePlayers()) {
|
||||
parent.startParty(p, _duration, _sheepNumber, _radius, _period, _fireworks);
|
||||
p.sendMessage(ChatColor.RED + "LET'S DISCO!");
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return noPermsMessage(sender, PERMISSION_ALL);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean stopCommand(CommandSender sender) {
|
||||
if (senderHasPerm(sender, PERMISSION_STOP)) {
|
||||
parent.stopAllParties();
|
||||
return true;
|
||||
} else {
|
||||
return noPermsMessage(sender, PERMISSION_STOP);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean partySelectCommand(String[] players, CommandSender sender, int _duration, int _sheepNumber, int _radius, int _period, boolean _fireworks) {
|
||||
if (senderHasPerm(sender, PERMISSION_OTHER)) {
|
||||
Player p;
|
||||
for (String playerName : players) {
|
||||
p = Bukkit.getServer().getPlayer(playerName);
|
||||
if (p != null) {
|
||||
parent.startParty(p, _duration, _sheepNumber, _radius, _period, _fireworks);
|
||||
} else {
|
||||
sender.sendMessage("Invalid player: " + playerName);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return noPermsMessage(sender, PERMISSION_OTHER);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
|
||||
Player player = null;
|
||||
boolean isPlayer = false;
|
||||
boolean fireworks = false;
|
||||
@ -112,50 +199,17 @@ public class DiscoSheepCommandExecutor implements CommandExecutor {
|
||||
if (args.length > 0) {
|
||||
|
||||
if (args[0].equalsIgnoreCase("all")) {
|
||||
if (senderHasPerm(sender, PERMISSION_ALL)) {
|
||||
for (Player p : Bukkit.getServer().getOnlinePlayers()) {
|
||||
parent.startParty(p, duration, sheepNumber, radius, period, fireworks);
|
||||
p.sendMessage(ChatColor.RED + "LET'S DISCO!");
|
||||
}
|
||||
} else {
|
||||
noPermsMessage(sender, PERMISSION_ALL);
|
||||
}
|
||||
return true;
|
||||
return partyAllCommand(player, duration, sheepNumber, radius, period, fireworks);
|
||||
} else if (args[0].equalsIgnoreCase("stop")) {
|
||||
if (senderHasPerm(sender, PERMISSION_STOP)) {
|
||||
parent.stopAllParties();
|
||||
} else {
|
||||
noPermsMessage(sender, PERMISSION_STOP);
|
||||
}
|
||||
return true;
|
||||
return stopCommand(sender);
|
||||
} else if (args[0].equalsIgnoreCase("me") && isPlayer) {
|
||||
if (senderHasPerm(sender, PERMISSION_PARTY)) {
|
||||
parent.startParty(player, duration, sheepNumber, radius, period, fireworks);
|
||||
return true;
|
||||
} else {
|
||||
noPermsMessage(sender, PERMISSION_PARTY);
|
||||
}
|
||||
return partyCommand(player, duration, sheepNumber, radius, period, fireworks);
|
||||
} else if (args[0].equalsIgnoreCase("other")) {
|
||||
return partySelectCommand(parsePlayerList(args, 1), sender, duration, sheepNumber, radius, period, fireworks);
|
||||
} else if (args[0].equalsIgnoreCase("help")) {
|
||||
sender.sendMessage(ChatColor.YELLOW + "DiscoSheep Help\n"
|
||||
+ ChatColor.GRAY + " Subcommands\n" + ChatColor.WHITE
|
||||
+ "me: start a party for yourself\n"
|
||||
+ "all: start a party for all players on the server\n"
|
||||
+ "stop: stop all parties (takes no arguments)\n"
|
||||
+ ChatColor.GRAY + " Arguments\n" + ChatColor.WHITE
|
||||
+ "-n <integer>: set the number of sheep per player that spawn\n"
|
||||
+ "-t <integer>: set the party duration in seconds\n"
|
||||
+ "-p <ticks>: set the number of ticks between each disco beat\n"
|
||||
+ "-r <integer>: set radius of the area in which sheep can spawn\n"
|
||||
+ "-fw: enables fireworks");
|
||||
return true;
|
||||
return helpCommand(sender);
|
||||
} else if (args[0].equalsIgnoreCase("reload")) {
|
||||
if (senderHasPerm(sender, PERMISSION_RELOAD)) {
|
||||
parent.reloadConfigFromDisk();
|
||||
sender.sendMessage(ChatColor.GREEN + "DiscoSheep config reloaded from disk");
|
||||
return true;
|
||||
} else {
|
||||
noPermsMessage(sender, PERMISSION_RELOAD);
|
||||
}
|
||||
return reloadCommand(sender);
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "Invalid argument.");
|
||||
return false;
|
||||
|
@ -32,4 +32,9 @@ permissions:
|
||||
default: op
|
||||
discosheep.reload:
|
||||
description: Allows a player to reload settings from config.yml
|
||||
default: op
|
||||
default: op
|
||||
discosheep.other:
|
||||
description: Allows a player to call parties for other people, including themselves.
|
||||
default: op
|
||||
children:
|
||||
discosheep.party: true
|
Loading…
Reference in New Issue
Block a user