Added ability to disable arenas.

This commit is contained in:
2022-06-04 11:56:50 -04:00
parent b8c3bbf263
commit 08f689debf
6 changed files with 78 additions and 2 deletions

View File

@@ -139,6 +139,44 @@ public final class CommandHandler {
sender.sendMessage(successMessage("Successfully deleted arena " + arena.getName() + ".")); 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. * Creates a new arena with a given name in a specific world.
* *

View File

@@ -83,6 +83,7 @@ public final class Snowbrawl extends JavaPlugin {
for (int id = 0; id < this.arenaManager.getArenas().size(); id++){ for (int id = 0; id < this.arenaManager.getArenas().size(); id++){
Arena arena = this.arenaManager.getArenas().get(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 + ".name", arena.getName());
newConfig.set("arenas." + id + ".refill", arena.getRefill()); newConfig.set("arenas." + id + ".refill", arena.getRefill());
newConfig.set("arenas." + id + ".playerLimit", arena.getPlayerLimit()); newConfig.set("arenas." + id + ".playerLimit", arena.getPlayerLimit());
@@ -154,6 +155,7 @@ public final class Snowbrawl extends JavaPlugin {
// Finally, we populate all the configuration variables. // 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. // 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.setRefill(config.getInt("arenas." + id + ".refill", Arena.DEFAULT_REFILL));
arena.setPlayerLimit(config.getInt("arenas." + id + ".playerLimit", Arena.DEFAULT_PLAYER_LIMIT)); arena.setPlayerLimit(config.getInt("arenas." + id + ".playerLimit", Arena.DEFAULT_PLAYER_LIMIT));
arena.setGraceTime(config.getInt("arenas." + id + ".graceTime", Arena.DEFAULT_GRACE_TIME)); arena.setGraceTime(config.getInt("arenas." + id + ".graceTime", Arena.DEFAULT_GRACE_TIME));

View File

@@ -896,6 +896,7 @@ public class ArenaManager implements Listener {
private void logArenaInfo(Arena arena){ private void logArenaInfo(Arena arena){
Logger logger = this.snowbrawl.getLogger(); Logger logger = this.snowbrawl.getLogger();
logger.info(" - Name: " + arena.getName()); logger.info(" - Name: " + arena.getName());
logger.info(" - Enabled: " + arena.isEnabled());
logger.info(" - Refill: " + arena.getRefill() + " snowballs"); logger.info(" - Refill: " + arena.getRefill() + " snowballs");
logger.info(" - Player Limit: " + arena.getPlayerLimit() + " players"); logger.info(" - Player Limit: " + arena.getPlayerLimit() + " players");
logger.info(" - Grace Time: " + arena.getGraceTime() + "s"); logger.info(" - Grace Time: " + arena.getGraceTime() + "s");

View File

@@ -122,10 +122,10 @@ public class MatchManager implements Listener, Runnable {
* @return A list of available arenas. * @return A list of available arenas.
*/ */
public List<Arena> getAvailableArenas(){ public List<Arena> getAvailableArenas(){
ArrayList<Arena> availableArenas = new ArrayList<>(); final List<Arena> availableArenas = new ArrayList<>();
for (Arena arena : this.snowbrawl.getArenaManager().getArenas()){ for (Arena arena : this.snowbrawl.getArenaManager().getArenas()){
if (this.getMatchFromArena(arena) == null){ if (arena.isEnabled() && this.getMatchFromArena(arena) == null){
availableArenas.add(arena); availableArenas.add(arena);
} }
} }

View File

@@ -20,6 +20,7 @@ import java.util.Random;
*/ */
public class Arena { public class Arena {
// Default config variables // Default config variables
public static final boolean DEFAULT_ENABLED = false;
public static final int DEFAULT_REFILL = 16; public static final int DEFAULT_REFILL = 16;
public static final int DEFAULT_PLAYER_LIMIT = 8; public static final int DEFAULT_PLAYER_LIMIT = 8;
public static final int DEFAULT_GRACE_TIME = 15 * 20; public static final int DEFAULT_GRACE_TIME = 15 * 20;
@@ -32,6 +33,7 @@ public class Arena {
// Runtime variables // Runtime variables
private final Random rng = new Random(); private final Random rng = new Random();
// Config variables // 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 String name; // A friendly name for this arena
private int refill; // Amount of snowballs to give players per snow block right click. 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. 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: * Creates a new arena with a given name in a given world and sets all other attributes to the below defaults:
* <ul> * <ul>
* <li>enabled = Arena.DEFAULT_ENABLED</li>
* <li>refill = Arena.DEFAULT_REFILL</li> * <li>refill = Arena.DEFAULT_REFILL</li>
* <li>playerLimit = Arena.DEFAULT_PLAYER_LIMIT</li> * <li>playerLimit = Arena.DEFAULT_PLAYER_LIMIT</li>
* <li>graceTime = Arena.DEFAULT_GRACE_TIME</li> * <li>graceTime = Arena.DEFAULT_GRACE_TIME</li>
@@ -68,6 +71,24 @@ public class Arena {
this.setPos2(new Location(this.getWorld(), 0, 0, 0)); 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. * Gets the friendly name for this arena.
* *

View File

@@ -35,6 +35,20 @@ command snowbrawl {
help Deletes an arena.; 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 { arena [string:name] config {
run get_arena_config name; run get_arena_config name;
type all; type all;