rewrote command handling and added fireworks toggle switch
This commit is contained in:
parent
a41da1fd45
commit
43fd8815f5
@ -30,6 +30,7 @@ public class DiscoParty {
|
|||||||
private final int defaultFrequency = 10; // ticks per state change
|
private final int defaultFrequency = 10; // ticks per state change
|
||||||
private final int sheepSpawnRadius = 5;
|
private final int sheepSpawnRadius = 5;
|
||||||
private final int defaultSheepAmount = 10;
|
private final int defaultSheepAmount = 10;
|
||||||
|
private boolean doFireworks = false;
|
||||||
private int state = 0;
|
private int state = 0;
|
||||||
private DiscoUpdater updater;
|
private DiscoUpdater updater;
|
||||||
private static final DyeColor[] discoColours = {
|
private static final DyeColor[] discoColours = {
|
||||||
@ -157,7 +158,7 @@ public class DiscoParty {
|
|||||||
void updateAllSheep() {
|
void updateAllSheep() {
|
||||||
for (Sheep sheep : getSheep()) {
|
for (Sheep sheep : getSheep()) {
|
||||||
randomizeSheepColour(sheep);
|
randomizeSheepColour(sheep);
|
||||||
if (state % 8 == 0) {
|
if (doFireworks && state % 8 == 0) {
|
||||||
spawnRandomFireworkAtSheep(sheep);
|
spawnRandomFireworkAtSheep(sheep);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -222,10 +223,11 @@ public class DiscoParty {
|
|||||||
updater.runTaskLater(ds, this.frequency);
|
updater.runTaskLater(ds, this.frequency);
|
||||||
}
|
}
|
||||||
|
|
||||||
void startDisco(int duration) {
|
void startDisco(int duration, boolean fireworks) {
|
||||||
if (this.duration > 0) {
|
if (this.duration > 0) {
|
||||||
stopDisco();
|
stopDisco();
|
||||||
}
|
}
|
||||||
|
this.doFireworks = fireworks;
|
||||||
this.spawnSheep(this.defaultSheepAmount);
|
this.spawnSheep(this.defaultSheepAmount);
|
||||||
this.frequency = this.defaultFrequency;
|
this.frequency = this.defaultFrequency;
|
||||||
this.duration = this.defaultDuration;
|
this.duration = this.defaultDuration;
|
||||||
@ -233,8 +235,8 @@ public class DiscoParty {
|
|||||||
ds.getPartyMap().put(this.player.getName(), this);
|
ds.getPartyMap().put(this.player.getName(), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void startDisco() {
|
void startDisco(boolean fireworks) {
|
||||||
this.startDisco(this.defaultDuration);
|
this.startDisco(this.defaultDuration, fireworks);
|
||||||
}
|
}
|
||||||
|
|
||||||
void stopDisco() {
|
void stopDisco() {
|
||||||
|
@ -57,9 +57,9 @@ public final class DiscoSheep extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startParty(Player player) {
|
public void startParty(Player player, boolean fireworksEnabled) {
|
||||||
if (!hasParty(player.getName())) {
|
if (!hasParty(player.getName())) {
|
||||||
new DiscoParty(this, player).startDisco();
|
new DiscoParty(this, player).startDisco(fireworksEnabled);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package gibstick.bukkit.discosheep;
|
package gibstick.bukkit.discosheep;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
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;
|
||||||
@ -14,25 +15,80 @@ public class DiscoSheepCommandExecutor implements CommandExecutor {
|
|||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private CommandSender curSender;
|
||||||
|
|
||||||
|
private static final String PERMISSION_PARTY = "discosheep.party";
|
||||||
|
private static final String PERMISSION_ALL = "discosheep.partyall";
|
||||||
|
private static final String PERMISSION_FIREWORKS = "discosheep.fireworks";
|
||||||
|
private static final String PERMISSION_STOP = "discosheep.stop";
|
||||||
|
private static final String PERMISSION_SUPER= "disosheep.*";
|
||||||
|
|
||||||
|
|
||||||
|
private boolean senderHasPerm(String permission) {
|
||||||
|
return curSender.hasPermission(permission) || curSender.hasPermission(PERMISSION_SUPER);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void noPermsMessage(String permission) {
|
||||||
|
curSender.sendMessage(ChatColor.RED + "You do not have the permission node " + ChatColor.GRAY + permission);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||||
if (args.length == 1) {
|
Player player = null;
|
||||||
if ("all".equals(args[0])) {
|
boolean isPlayer = false;
|
||||||
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
|
boolean fireworks = false;
|
||||||
parent.startParty(player);
|
this.curSender = sender;
|
||||||
|
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
player = (Player) sender;
|
||||||
|
isPlayer = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!senderHasPerm(PERMISSION_PARTY)) {
|
||||||
|
noPermsMessage(PERMISSION_PARTY);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (String arg : args) {
|
||||||
|
switch (arg) {
|
||||||
|
case "-fw":
|
||||||
|
if (senderHasPerm(PERMISSION_FIREWORKS)) {
|
||||||
|
fireworks = !fireworks;
|
||||||
|
} else {
|
||||||
|
noPermsMessage(PERMISSION_FIREWORKS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ("stop".equals(args[0])) {
|
}
|
||||||
|
|
||||||
|
if (args.length > 0) {
|
||||||
|
switch (args[0]) {
|
||||||
|
case "all":
|
||||||
|
if (senderHasPerm(PERMISSION_ALL))
|
||||||
|
for (Player p : Bukkit.getServer().getOnlinePlayers()) {
|
||||||
|
parent.startParty(p, fireworks);
|
||||||
|
p.sendMessage(ChatColor.RED + "LET'S DISCO!");
|
||||||
|
} else {
|
||||||
|
noPermsMessage(PERMISSION_ALL);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
case "stop":
|
||||||
|
if (senderHasPerm(PERMISSION_STOP)) {
|
||||||
parent.stopAllParties();
|
parent.stopAllParties();
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage("Invalid argument.");
|
noPermsMessage(PERMISSION_STOP);
|
||||||
return true;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (sender instanceof Player) {
|
|
||||||
parent.startParty((Player) sender);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
case "me":
|
||||||
|
if (isPlayer) {
|
||||||
|
parent.startParty(player, fireworks);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
sender.sendMessage(ChatColor.RED + "Invalid argument.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,4 @@ version: 0.9
|
|||||||
commands:
|
commands:
|
||||||
ds:
|
ds:
|
||||||
description: "Main DiscoSheep command"
|
description: "Main DiscoSheep command"
|
||||||
usage: /ds
|
usage: /ds [arguments]
|
||||||
permission: discosheep.party
|
|
||||||
permission-message: You don't have permission
|
|
Loading…
Reference in New Issue
Block a user