added arguments for period, duration, number, and radius
This commit is contained in:
parent
1a5e5050dc
commit
0a7bd06579
@ -25,11 +25,17 @@ 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, numSheep = 5;
|
private int duration, frequency = 20;
|
||||||
static final int defaultDuration = 300; // ticks for entire party
|
private int numSheep = 5;
|
||||||
static final int defaultFrequency = 10; // ticks per state change
|
static int defaultDuration = 300; // ticks for entire party
|
||||||
static final int defaultSheepSpawnRadius = 5;
|
static int defaultPeriod = 10; // ticks per state change
|
||||||
static final int defaultSheepAmount = 10;
|
static int defaultRadius = 5;
|
||||||
|
static int defaultSheep = 10;
|
||||||
|
static int maxDuration = 2400; // 120 seconds
|
||||||
|
static int maxSheep = 100;
|
||||||
|
static int maxRadius = 100;
|
||||||
|
static int minPeriod = 5; // 0.25 seconds
|
||||||
|
static int maxPeriod = 40; // 2.0 seconds
|
||||||
private boolean doFireworks = false;
|
private boolean doFireworks = false;
|
||||||
private int state = 0;
|
private int state = 0;
|
||||||
private DiscoUpdater updater;
|
private DiscoUpdater updater;
|
||||||
@ -223,13 +229,13 @@ public class DiscoParty {
|
|||||||
updater.runTaskLater(ds, this.frequency);
|
updater.runTaskLater(ds, this.frequency);
|
||||||
}
|
}
|
||||||
|
|
||||||
void startDisco(int duration, int sheepAmount, int radius, boolean fireworks) {
|
void startDisco(int duration, int sheepAmount, int radius, int frequency, boolean fireworks) {
|
||||||
if (this.duration > 0) {
|
if (this.duration > 0) {
|
||||||
stopDisco();
|
stopDisco();
|
||||||
}
|
}
|
||||||
this.doFireworks = fireworks;
|
this.doFireworks = fireworks;
|
||||||
this.spawnSheep(sheepAmount, radius);
|
this.spawnSheep(sheepAmount, radius);
|
||||||
this.frequency = this.defaultFrequency;
|
this.frequency = frequency;
|
||||||
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,6 +4,8 @@ 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.MemoryConfiguration;
|
||||||
|
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;
|
||||||
|
|
||||||
@ -16,6 +18,31 @@ public final class DiscoSheep extends JavaPlugin {
|
|||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
getCommand("ds").setExecutor(new DiscoSheepCommandExecutor(this));
|
getCommand("ds").setExecutor(new DiscoSheepCommandExecutor(this));
|
||||||
getServer().getPluginManager().registerEvents(blockEvents, this);
|
getServer().getPluginManager().registerEvents(blockEvents, this);
|
||||||
|
|
||||||
|
FileConfiguration config = this.getConfig();
|
||||||
|
|
||||||
|
config.addDefault("max.sheep", DiscoParty.maxSheep);
|
||||||
|
config.addDefault("max.radius", DiscoParty.maxRadius);
|
||||||
|
config.addDefault("max.duration", DiscoParty.maxDuration);
|
||||||
|
config.addDefault("max.period", DiscoParty.maxPeriod);
|
||||||
|
config.addDefault("min.period", DiscoParty.minPeriod);
|
||||||
|
config.addDefault("default.sheep", DiscoParty.defaultSheep);
|
||||||
|
config.addDefault("default.radius", DiscoParty.defaultRadius);
|
||||||
|
config.addDefault("default.duration", DiscoParty.defaultDuration);
|
||||||
|
config.addDefault("default.period", DiscoParty.defaultPeriod);
|
||||||
|
config.options().copyDefaults(true);
|
||||||
|
|
||||||
|
saveConfig();
|
||||||
|
|
||||||
|
DiscoParty.maxSheep = getConfig().getInt("max.sheep");
|
||||||
|
DiscoParty.maxRadius = getConfig().getInt("max.radius");
|
||||||
|
DiscoParty.maxDuration = getConfig().getInt("max.duration");
|
||||||
|
DiscoParty.maxPeriod = getConfig().getInt("max.period");
|
||||||
|
DiscoParty.minPeriod = getConfig().getInt("min.period");
|
||||||
|
DiscoParty.defaultSheep = getConfig().getInt("default.sheep");
|
||||||
|
DiscoParty.defaultRadius = getConfig().getInt("default.radius");
|
||||||
|
DiscoParty.defaultDuration = getConfig().getInt("default.duration");
|
||||||
|
DiscoParty.defaultPeriod = getConfig().getInt("default.period");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -23,6 +50,14 @@ public final class DiscoSheep extends JavaPlugin {
|
|||||||
this.stopAllParties();
|
this.stopAllParties();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int toTicks(double seconds) {
|
||||||
|
return (int) Math.round(seconds * 20.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
double toSeconds(int ticks) {
|
||||||
|
return (double) Math.round(ticks / 20.0);
|
||||||
|
}
|
||||||
|
|
||||||
public synchronized Map<String, DiscoParty> getPartyMap() {
|
public synchronized Map<String, DiscoParty> getPartyMap() {
|
||||||
return this.parties;
|
return this.parties;
|
||||||
}
|
}
|
||||||
@ -37,8 +72,8 @@ public final class DiscoSheep extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stopAllParties(){
|
public void stopAllParties() {
|
||||||
for(DiscoParty party :this.getParties()){
|
for (DiscoParty party : this.getParties()) {
|
||||||
party.stopDisco();
|
party.stopDisco();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -57,12 +92,9 @@ public final class DiscoSheep extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startParty(Player player, int duration, int sheepAmount, int radius, 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())) {
|
||||||
new DiscoParty(this, player).startDisco(duration, sheepAmount, radius, fireworksEnabled);
|
new DiscoParty(this, player).startDisco(duration, sheepAmount, radius, period, fireworksEnabled);
|
||||||
} else {
|
|
||||||
player.sendMessage("You has party");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -42,14 +42,22 @@ public class DiscoSheepCommandExecutor implements CommandExecutor {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Double parseNextDoubleArg(String[] args, int i) {
|
||||||
|
if (i < args.length - 1) {
|
||||||
|
return Double.parseDouble(args[i + 1]);
|
||||||
|
}
|
||||||
|
return -1.0d;
|
||||||
|
}
|
||||||
|
|
||||||
@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;
|
||||||
int sheepNumber = DiscoParty.defaultSheepAmount;
|
int sheepNumber = DiscoParty.defaultSheep;
|
||||||
int radius = DiscoParty.defaultSheepSpawnRadius;
|
int radius = DiscoParty.defaultRadius;
|
||||||
int duration = DiscoParty.defaultDuration;
|
int duration = DiscoParty.defaultDuration;
|
||||||
|
int period = DiscoParty.defaultPeriod;
|
||||||
|
|
||||||
if (sender instanceof Player) {
|
if (sender instanceof Player) {
|
||||||
player = (Player) sender;
|
player = (Player) sender;
|
||||||
@ -71,15 +79,36 @@ public class DiscoSheepCommandExecutor implements CommandExecutor {
|
|||||||
} else if (args[i].equalsIgnoreCase("-r")) {
|
} else if (args[i].equalsIgnoreCase("-r")) {
|
||||||
radius = parseNextIntArg(args, i);
|
radius = parseNextIntArg(args, i);
|
||||||
|
|
||||||
if (radius < 1 || radius > 100) {
|
if (radius < 1 || radius > DiscoParty.maxRadius) {
|
||||||
sender.sendMessage("Radius must be an integer within the range [1, 100]");
|
sender.sendMessage("Radius must be an integer within the range [1, "
|
||||||
|
+ DiscoParty.maxRadius + "]");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else if (args[i].equalsIgnoreCase("-n")) {
|
} else if (args[i].equalsIgnoreCase("-n")) {
|
||||||
sheepNumber = parseNextIntArg(args, i);
|
sheepNumber = parseNextIntArg(args, i);
|
||||||
|
|
||||||
if (sheepNumber < 1 || sheepNumber > 100) {
|
if (sheepNumber < 1 || sheepNumber > DiscoParty.maxSheep) {
|
||||||
sender.sendMessage("The number of sheep must be an integer within the range [1, 100]");
|
sender.sendMessage("The number of sheep must be an integer within the range [1, "
|
||||||
|
+ DiscoParty.maxSheep + "]");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else if (args[i].equalsIgnoreCase("-t")) {
|
||||||
|
duration = parseNextIntArg(args, i);
|
||||||
|
|
||||||
|
if (duration < 1 || duration > parent.toSeconds(DiscoParty.maxDuration)) {
|
||||||
|
sender.sendMessage("The duration in ticks must be an integer within the range [1, "
|
||||||
|
+ parent.toSeconds(DiscoParty.maxDuration) + "]");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else if (args[i].equalsIgnoreCase("-p")) {
|
||||||
|
period = parseNextIntArg(args, i);
|
||||||
|
|
||||||
|
if (period < DiscoParty.minPeriod || period > DiscoParty.maxPeriod) {
|
||||||
|
sender.sendMessage(
|
||||||
|
"The period in ticks must be within the range ["
|
||||||
|
+ DiscoParty.minPeriod + ", "
|
||||||
|
+ DiscoParty.maxPeriod + "]");
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -89,7 +118,7 @@ public class DiscoSheepCommandExecutor implements CommandExecutor {
|
|||||||
if (args[0].equalsIgnoreCase("all")) {
|
if (args[0].equalsIgnoreCase("all")) {
|
||||||
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, fireworks);
|
parent.startParty(p, duration, sheepNumber, radius, period, fireworks);
|
||||||
p.sendMessage(ChatColor.RED + "LET'S DISCO!");
|
p.sendMessage(ChatColor.RED + "LET'S DISCO!");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -105,7 +134,7 @@ public class DiscoSheepCommandExecutor implements CommandExecutor {
|
|||||||
return true;
|
return true;
|
||||||
} else if (args[0].equalsIgnoreCase("me")) {
|
} else if (args[0].equalsIgnoreCase("me")) {
|
||||||
if (isPlayer) {
|
if (isPlayer) {
|
||||||
parent.startParty(player, duration, sheepNumber, radius, fireworks);
|
parent.startParty(player, duration, sheepNumber, radius, period, fireworks);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user