rewrote command handling and added fireworks toggle switch

This commit is contained in:
Charlie Wang 2013-07-11 11:28:20 -04:00
parent a41da1fd45
commit 43fd8815f5
4 changed files with 81 additions and 25 deletions

View File

@ -30,6 +30,7 @@ public class DiscoParty {
private final int defaultFrequency = 10; // ticks per state change
private final int sheepSpawnRadius = 5;
private final int defaultSheepAmount = 10;
private boolean doFireworks = false;
private int state = 0;
private DiscoUpdater updater;
private static final DyeColor[] discoColours = {
@ -157,7 +158,7 @@ public class DiscoParty {
void updateAllSheep() {
for (Sheep sheep : getSheep()) {
randomizeSheepColour(sheep);
if (state % 8 == 0) {
if (doFireworks && state % 8 == 0) {
spawnRandomFireworkAtSheep(sheep);
}
}
@ -222,10 +223,11 @@ public class DiscoParty {
updater.runTaskLater(ds, this.frequency);
}
void startDisco(int duration) {
void startDisco(int duration, boolean fireworks) {
if (this.duration > 0) {
stopDisco();
}
this.doFireworks = fireworks;
this.spawnSheep(this.defaultSheepAmount);
this.frequency = this.defaultFrequency;
this.duration = this.defaultDuration;
@ -233,8 +235,8 @@ public class DiscoParty {
ds.getPartyMap().put(this.player.getName(), this);
}
void startDisco() {
this.startDisco(this.defaultDuration);
void startDisco(boolean fireworks) {
this.startDisco(this.defaultDuration, fireworks);
}
void stopDisco() {

View File

@ -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())) {
new DiscoParty(this, player).startDisco();
new DiscoParty(this, player).startDisco(fireworksEnabled);
}
}
}

View File

@ -1,6 +1,7 @@
package gibstick.bukkit.discosheep;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.CommandExecutor;
@ -14,25 +15,80 @@ public class DiscoSheepCommandExecutor implements CommandExecutor {
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
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (args.length == 1) {
if ("all".equals(args[0])) {
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
parent.startParty(player);
}
}
else if ("stop".equals(args[0])) {
parent.stopAllParties();
} else {
sender.sendMessage("Invalid argument.");
return true;
}
} else {
if (sender instanceof Player) {
parent.startParty((Player) sender);
Player player = null;
boolean isPlayer = false;
boolean fireworks = false;
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);
}
}
}
return true;
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();
} else {
noPermsMessage(PERMISSION_STOP);
}
return true;
case "me":
if (isPlayer) {
parent.startParty(player, fireworks);
return true;
}
default:
sender.sendMessage(ChatColor.RED + "Invalid argument.");
return true;
}
}
return false;
}
}

View File

@ -4,6 +4,4 @@ version: 0.9
commands:
ds:
description: "Main DiscoSheep command"
usage: /ds
permission: discosheep.party
permission-message: You don't have permission
usage: /ds [arguments]