Added ability to disable arenas.
This commit is contained in:
@@ -139,6 +139,44 @@ public final class CommandHandler {
|
||||
sender.sendMessage(successMessage("Successfully deleted arena " + arena.getName() + "."));
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable an arena.
|
||||
*
|
||||
* @param sender The user who executed the command.
|
||||
* @param name The name of the arena.
|
||||
*/
|
||||
@Command(hook = "enable_arena")
|
||||
public void commandArenaEnable(CommandSender sender, String name){
|
||||
Arena arena = this.snowbrawl.getArenaManager().getArenaByName(name);
|
||||
if (arena == null){
|
||||
sender.sendMessage(failMessage("The specified arena does not exist."));
|
||||
return;
|
||||
}
|
||||
|
||||
arena.setEnabled(true);
|
||||
sender.sendMessage(successMessage("Arena " + arena.getName() + " has been enabled."));
|
||||
this.snowbrawl.saveConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables an arena.
|
||||
*
|
||||
* @param sender The user who executed the command.
|
||||
* @param name The name of the arena.
|
||||
*/
|
||||
@Command(hook = "disable_arena")
|
||||
public void commandArenaDisable(CommandSender sender, String name){
|
||||
Arena arena = this.snowbrawl.getArenaManager().getArenaByName(name);
|
||||
if (arena == null){
|
||||
sender.sendMessage(failMessage("The specified arena does not exist."));
|
||||
return;
|
||||
}
|
||||
|
||||
arena.setEnabled(false);
|
||||
sender.sendMessage(successMessage("Arena " + arena.getName() + " has been disabled."));
|
||||
this.snowbrawl.saveConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new arena with a given name in a specific world.
|
||||
*
|
||||
|
||||
@@ -83,6 +83,7 @@ public final class Snowbrawl extends JavaPlugin {
|
||||
for (int id = 0; id < this.arenaManager.getArenas().size(); id++){
|
||||
Arena arena = this.arenaManager.getArenas().get(id);
|
||||
|
||||
newConfig.set("arenas." + id + ".enabled", arena.isEnabled());
|
||||
newConfig.set("arenas." + id + ".name", arena.getName());
|
||||
newConfig.set("arenas." + id + ".refill", arena.getRefill());
|
||||
newConfig.set("arenas." + id + ".playerLimit", arena.getPlayerLimit());
|
||||
@@ -154,6 +155,7 @@ public final class Snowbrawl extends JavaPlugin {
|
||||
|
||||
// Finally, we populate all the configuration variables.
|
||||
// If any of these config options don't exist in the config file, then default to the defaults defined in Arena.
|
||||
arena.setEnabled(config.getBoolean("arenas." + id + ".enabled", Arena.DEFAULT_ENABLED));
|
||||
arena.setRefill(config.getInt("arenas." + id + ".refill", Arena.DEFAULT_REFILL));
|
||||
arena.setPlayerLimit(config.getInt("arenas." + id + ".playerLimit", Arena.DEFAULT_PLAYER_LIMIT));
|
||||
arena.setGraceTime(config.getInt("arenas." + id + ".graceTime", Arena.DEFAULT_GRACE_TIME));
|
||||
|
||||
@@ -896,6 +896,7 @@ public class ArenaManager implements Listener {
|
||||
private void logArenaInfo(Arena arena){
|
||||
Logger logger = this.snowbrawl.getLogger();
|
||||
logger.info(" - Name: " + arena.getName());
|
||||
logger.info(" - Enabled: " + arena.isEnabled());
|
||||
logger.info(" - Refill: " + arena.getRefill() + " snowballs");
|
||||
logger.info(" - Player Limit: " + arena.getPlayerLimit() + " players");
|
||||
logger.info(" - Grace Time: " + arena.getGraceTime() + "s");
|
||||
|
||||
@@ -122,10 +122,10 @@ public class MatchManager implements Listener, Runnable {
|
||||
* @return A list of available arenas.
|
||||
*/
|
||||
public List<Arena> getAvailableArenas(){
|
||||
ArrayList<Arena> availableArenas = new ArrayList<>();
|
||||
final List<Arena> availableArenas = new ArrayList<>();
|
||||
|
||||
for (Arena arena : this.snowbrawl.getArenaManager().getArenas()){
|
||||
if (this.getMatchFromArena(arena) == null){
|
||||
if (arena.isEnabled() && this.getMatchFromArena(arena) == null){
|
||||
availableArenas.add(arena);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import java.util.Random;
|
||||
*/
|
||||
public class Arena {
|
||||
// Default config variables
|
||||
public static final boolean DEFAULT_ENABLED = false;
|
||||
public static final int DEFAULT_REFILL = 16;
|
||||
public static final int DEFAULT_PLAYER_LIMIT = 8;
|
||||
public static final int DEFAULT_GRACE_TIME = 15 * 20;
|
||||
@@ -32,6 +33,7 @@ public class Arena {
|
||||
// Runtime variables
|
||||
private final Random rng = new Random();
|
||||
// Config variables
|
||||
private boolean enabled; // Flag for whether the arena can be used in matches.
|
||||
private String name; // A friendly name for this arena
|
||||
private int refill; // Amount of snowballs to give players per snow block right click.
|
||||
private int playerLimit; // Maximum amount of players allowed in this arena in a match.
|
||||
@@ -44,6 +46,7 @@ public class Arena {
|
||||
/**
|
||||
* Creates a new arena with a given name in a given world and sets all other attributes to the below defaults:
|
||||
* <ul>
|
||||
* <li>enabled = Arena.DEFAULT_ENABLED</li>
|
||||
* <li>refill = Arena.DEFAULT_REFILL</li>
|
||||
* <li>playerLimit = Arena.DEFAULT_PLAYER_LIMIT</li>
|
||||
* <li>graceTime = Arena.DEFAULT_GRACE_TIME</li>
|
||||
@@ -68,6 +71,24 @@ public class Arena {
|
||||
this.setPos2(new Location(this.getWorld(), 0, 0, 0));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether this arena can be used in matches. This value does not reflect if this arena is currently in use by a match. Instead, it only reflects an administrator's choice on if they want this arena to be used for matches.
|
||||
*
|
||||
* @return True if enabled, false otherwise.
|
||||
*/
|
||||
public boolean isEnabled(){
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether this arena can be used in matches. This value should not be updated to reflect if this arena is currently in use by a match. Instead, it should only reflect an administrators choice on if they want this arena to be used for matches.
|
||||
*
|
||||
* @param enabled The new enabled value.
|
||||
*/
|
||||
public void setEnabled(final boolean enabled){
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the friendly name for this arena.
|
||||
*
|
||||
|
||||
@@ -35,6 +35,20 @@ command snowbrawl {
|
||||
help Deletes an arena.;
|
||||
}
|
||||
|
||||
arena [string:name] enable {
|
||||
perm redstoner.snowbrawl.arena.enable;
|
||||
run enable_arena name;
|
||||
type all;
|
||||
help Enables an arena.;
|
||||
}
|
||||
|
||||
arena [string:name] disable {
|
||||
perm redstoner.snowbrawl.arena.disable;
|
||||
run disable_arena name;
|
||||
type all;
|
||||
help Disables an arena.;
|
||||
}
|
||||
|
||||
arena [string:name] config {
|
||||
run get_arena_config name;
|
||||
type all;
|
||||
|
||||
Reference in New Issue
Block a user