Skip to content

Commit

Permalink
added config file, added config file reload command, and registered p…
Browse files Browse the repository at this point in the history
…ermissions in plugin.yml
  • Loading branch information
Gibstick committed Jul 12, 2013
1 parent 7f7694c commit 1fb36d2
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 15 deletions.
Binary file modified dist/DiscoSheep.jar
Binary file not shown.
19 changes: 16 additions & 3 deletions src/gibstick/bukkit/discosheep/DiscoSheep.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.bukkit.configuration.MemoryConfiguration;
import org.bukkit.configuration.Configuration;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
Expand All @@ -13,13 +13,16 @@ public final class DiscoSheep extends JavaPlugin {

Map<String, DiscoParty> parties = new HashMap<String, DiscoParty>();
private BaaBaaBlockSheepEvents blockEvents = new BaaBaaBlockSheepEvents(this);
FileConfiguration config;

@Override
public void onEnable() {
getCommand("ds").setExecutor(new DiscoSheepCommandExecutor(this));
getServer().getPluginManager().registerEvents(blockEvents, this);

FileConfiguration config = this.getConfig();
if (config == null) {
config = this.getConfig();
}

config.addDefault("max.sheep", DiscoParty.maxSheep);
config.addDefault("max.radius", DiscoParty.maxRadius);
Expand All @@ -30,8 +33,12 @@ public void onEnable() {
config.addDefault("default.radius", DiscoParty.defaultRadius);
config.addDefault("default.duration", toSeconds_i(DiscoParty.defaultDuration));
config.addDefault("default.period-ticks", DiscoParty.defaultPeriod);
config.options().copyDefaults(true);

loadConfigFromDisk();
}

void loadConfigFromDisk() {
getConfig().options().copyDefaults(true);
saveConfig();

DiscoParty.maxSheep = getConfig().getInt("max.sheep");
Expand All @@ -44,10 +51,16 @@ public void onEnable() {
DiscoParty.defaultDuration = toTicks(getConfig().getInt("default.duration"));
DiscoParty.defaultPeriod = getConfig().getInt("default.period-ticks");
}

void reloadConfigFromDisk() {
reloadConfig();
loadConfigFromDisk();
}

@Override
public void onDisable() {
this.stopAllParties();
this.config = null;
}

int toTicks(double seconds) {
Expand Down
38 changes: 28 additions & 10 deletions src/gibstick/bukkit/discosheep/DiscoSheepCommandExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ public DiscoSheepCommandExecutor(DiscoSheep parent) {
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 static final String PERMISSION_RELOAD = "discosheep.reload";

private boolean senderHasPerm(CommandSender sender, String permission) {
return sender.hasPermission(permission) || sender.hasPermission(PERMISSION_SUPER);
return sender.hasPermission(permission);
}

private void noPermsMessage(CommandSender sender, String permission) {
Expand Down Expand Up @@ -65,11 +65,6 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
isPlayer = true;
}

if (!senderHasPerm(sender, PERMISSION_PARTY)) {
noPermsMessage(sender, PERMISSION_PARTY);
return true;
}

for (int i = 1; i < args.length; i++) {
if (args[i].equalsIgnoreCase("-fw")) {
if (senderHasPerm(sender, PERMISSION_FIREWORKS)) {
Expand Down Expand Up @@ -133,14 +128,37 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
noPermsMessage(sender, PERMISSION_STOP);
}
return true;
} else if (args[0].equalsIgnoreCase("me")) {
if (isPlayer) {
} 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);
}
} 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;
} 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);
}
} else {
sender.sendMessage(ChatColor.RED + "Invalid argument.");
return true;
return false;
}

}
Expand Down
32 changes: 30 additions & 2 deletions src/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,35 @@
name: DiscoSheep
main: gibstick.bukkit.discosheep.DiscoSheep
version: 0.9
authors: [Gibstick, RangerMauve]
version: 1.0
commands:
ds:
description: "Main DiscoSheep command"
usage: /ds [arguments]
usage: |
<command> <subcommand> [arguments]
Use /ds help for more information
permissions:
discosheep.*:
description: Permission node for all DiscoSheep commands
default: op
children:
discosheep.party: true
discosheep.partyall: true
discosheep.fireworks: true
discosheep.stop: true
discosheep.reload: true
discosheep.party:
description: Allows a player to have a party of one
default: op
discosheep.partyall:
description: Allows a player to call a server-wide party
default: op
discosheep.stop:
description: Allows a player to stop all parties on the server
default: op
discosheep.fireworks:
description: Allows a player to enable have parties with fireworks
default: op
discosheep.reload:
description: Allows a player to reload settings from config.yml
default: op

0 comments on commit 1fb36d2

Please sign in to comment.