added config file, added config file reload command, and registered permissions in plugin.yml
This commit is contained in:
parent
7f7694c576
commit
1fb36d25e5
BIN
dist/DiscoSheep.jar
vendored
BIN
dist/DiscoSheep.jar
vendored
Binary file not shown.
@ -4,7 +4,7 @@ import java.util.ArrayList;
|
||||
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;
|
||||
@ -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);
|
||||
@ -30,8 +33,12 @@ public final class DiscoSheep extends JavaPlugin {
|
||||
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");
|
||||
@ -44,10 +51,16 @@ public final class DiscoSheep extends JavaPlugin {
|
||||
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) {
|
||||
|
@ -19,10 +19,10 @@ public class DiscoSheepCommandExecutor implements CommandExecutor {
|
||||
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) {
|
||||
@ -65,11 +65,6 @@ public class DiscoSheepCommandExecutor implements CommandExecutor {
|
||||
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)) {
|
||||
@ -133,14 +128,37 @@ public class DiscoSheepCommandExecutor implements CommandExecutor {
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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
|
Loading…
Reference in New Issue
Block a user