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 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, frequency = 20;
|
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;
|
||||||
@ -64,6 +64,56 @@ public class DiscoParty {
|
|||||||
return sheepList;
|
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) {
|
void spawnSheep(World world, Location loc) {
|
||||||
Sheep newSheep = (Sheep) world.spawnEntity(loc, EntityType.SHEEP);
|
Sheep newSheep = (Sheep) world.spawnEntity(loc, EntityType.SHEEP);
|
||||||
newSheep.setColor(discoColours[(int) (Math.random() * (discoColours.length - 1))]);
|
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
|
// Mark all sheep in the sheep array for removal, then clear the array
|
||||||
void removeAllSheep() {
|
void removeAllSheep() {
|
||||||
for (Sheep sheep : getSheep()) {
|
for (Sheep sheeple : getSheep()) {
|
||||||
sheep.setHealth(0);
|
sheeple.setHealth(0);
|
||||||
sheep.remove();
|
sheeple.remove();
|
||||||
}
|
}
|
||||||
getSheep().clear();
|
getSheep().clear();
|
||||||
}
|
}
|
||||||
@ -175,16 +225,16 @@ public class DiscoParty {
|
|||||||
|
|
||||||
void updateAllSheep() {
|
void updateAllSheep() {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (Sheep sheep : getSheep()) {
|
for (Sheep sheeple : getSheep()) {
|
||||||
randomizeSheepColour(sheep);
|
randomizeSheepColour(sheeple);
|
||||||
if (doFireworks && state % 8 == 0) {
|
if (doFireworks && state % 8 == 0) {
|
||||||
spawnRandomFireworkAtSheep(sheep);
|
spawnRandomFireworkAtSheep(sheeple);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (doJump) {
|
if (doJump) {
|
||||||
if (state % 2 == 0) {
|
if (state % 2 == 0) {
|
||||||
if (Math.random() < 0.5) {
|
if (Math.random() < 0.5) {
|
||||||
jumpSheep(sheep);
|
jumpSheep(sheeple);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -238,7 +288,7 @@ public class DiscoParty {
|
|||||||
if (duration > 0) {
|
if (duration > 0) {
|
||||||
updateAllSheep();
|
updateAllSheep();
|
||||||
playSounds();
|
playSounds();
|
||||||
duration -= frequency;
|
duration -= period;
|
||||||
this.scheduleUpdate();
|
this.scheduleUpdate();
|
||||||
this.state++;
|
this.state++;
|
||||||
} else {
|
} else {
|
||||||
@ -248,16 +298,16 @@ public class DiscoParty {
|
|||||||
|
|
||||||
void scheduleUpdate() {
|
void scheduleUpdate() {
|
||||||
updater = new DiscoUpdater(this);
|
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) {
|
if (this.duration > 0) {
|
||||||
stopDisco();
|
stopDisco();
|
||||||
}
|
}
|
||||||
this.doFireworks = fireworks;
|
|
||||||
this.spawnSheep(sheepAmount, radius);
|
this.spawnSheep(sheepAmount, radius);
|
||||||
this.frequency = frequency;
|
this.doFireworks = fireworks;
|
||||||
|
this.period = period;
|
||||||
this.duration = duration;
|
this.duration = duration;
|
||||||
this.scheduleUpdate();
|
this.scheduleUpdate();
|
||||||
ds.getPartyMap().put(this.player.getName(), this);
|
ds.getPartyMap().put(this.player.getName(), this);
|
||||||
|
@ -4,7 +4,6 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import org.bukkit.configuration.Configuration;
|
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
@ -51,7 +50,7 @@ public final class DiscoSheep extends JavaPlugin {
|
|||||||
DiscoParty.defaultDuration = toTicks(getConfig().getInt("default.duration"));
|
DiscoParty.defaultDuration = toTicks(getConfig().getInt("default.duration"));
|
||||||
DiscoParty.defaultPeriod = getConfig().getInt("default.period-ticks");
|
DiscoParty.defaultPeriod = getConfig().getInt("default.period-ticks");
|
||||||
}
|
}
|
||||||
|
|
||||||
void reloadConfigFromDisk() {
|
void reloadConfigFromDisk() {
|
||||||
reloadConfig();
|
reloadConfig();
|
||||||
loadConfigFromDisk();
|
loadConfigFromDisk();
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package gibstick.bukkit.discosheep;
|
package gibstick.bukkit.discosheep;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.command.CommandExecutor;
|
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_FIREWORKS = "discosheep.fireworks";
|
||||||
private static final String PERMISSION_STOP = "discosheep.stop";
|
private static final String PERMISSION_STOP = "discosheep.stop";
|
||||||
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 DELIM = "[ ]+";
|
||||||
private boolean senderHasPerm(CommandSender sender, String permission) {
|
private boolean senderHasPerm(CommandSender sender, String permission) {
|
||||||
return sender.hasPermission(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);
|
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) {
|
private boolean parseNextArg(String[] args, int i, String compare) {
|
||||||
@ -50,8 +53,92 @@ public class DiscoSheepCommandExecutor implements CommandExecutor {
|
|||||||
return -1.0d;
|
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
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||||
|
|
||||||
Player player = null;
|
Player player = null;
|
||||||
boolean isPlayer = false;
|
boolean isPlayer = false;
|
||||||
boolean fireworks = false;
|
boolean fireworks = false;
|
||||||
@ -112,50 +199,17 @@ public class DiscoSheepCommandExecutor implements CommandExecutor {
|
|||||||
if (args.length > 0) {
|
if (args.length > 0) {
|
||||||
|
|
||||||
if (args[0].equalsIgnoreCase("all")) {
|
if (args[0].equalsIgnoreCase("all")) {
|
||||||
if (senderHasPerm(sender, PERMISSION_ALL)) {
|
return partyAllCommand(player, duration, sheepNumber, radius, period, fireworks);
|
||||||
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;
|
|
||||||
} else if (args[0].equalsIgnoreCase("stop")) {
|
} else if (args[0].equalsIgnoreCase("stop")) {
|
||||||
if (senderHasPerm(sender, PERMISSION_STOP)) {
|
return stopCommand(sender);
|
||||||
parent.stopAllParties();
|
|
||||||
} else {
|
|
||||||
noPermsMessage(sender, PERMISSION_STOP);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
} else if (args[0].equalsIgnoreCase("me") && isPlayer) {
|
} else if (args[0].equalsIgnoreCase("me") && isPlayer) {
|
||||||
if (senderHasPerm(sender, PERMISSION_PARTY)) {
|
return partyCommand(player, duration, sheepNumber, radius, period, fireworks);
|
||||||
parent.startParty(player, duration, sheepNumber, radius, period, fireworks);
|
} else if (args[0].equalsIgnoreCase("other")) {
|
||||||
return true;
|
return partySelectCommand(parsePlayerList(args, 1), sender, duration, sheepNumber, radius, period, fireworks);
|
||||||
} else {
|
|
||||||
noPermsMessage(sender, PERMISSION_PARTY);
|
|
||||||
}
|
|
||||||
} else if (args[0].equalsIgnoreCase("help")) {
|
} else if (args[0].equalsIgnoreCase("help")) {
|
||||||
sender.sendMessage(ChatColor.YELLOW + "DiscoSheep Help\n"
|
return helpCommand(sender);
|
||||||
+ 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;
|
|
||||||
} else if (args[0].equalsIgnoreCase("reload")) {
|
} else if (args[0].equalsIgnoreCase("reload")) {
|
||||||
if (senderHasPerm(sender, PERMISSION_RELOAD)) {
|
return reloadCommand(sender);
|
||||||
parent.reloadConfigFromDisk();
|
|
||||||
sender.sendMessage(ChatColor.GREEN + "DiscoSheep config reloaded from disk");
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
noPermsMessage(sender, PERMISSION_RELOAD);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage(ChatColor.RED + "Invalid argument.");
|
sender.sendMessage(ChatColor.RED + "Invalid argument.");
|
||||||
return false;
|
return false;
|
||||||
|
@ -32,4 +32,9 @@ permissions:
|
|||||||
default: op
|
default: op
|
||||||
discosheep.reload:
|
discosheep.reload:
|
||||||
description: Allows a player to reload settings from config.yml
|
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