Added ability to configure subtitles for arenas.

This commit is contained in:
2022-06-16 18:41:45 -04:00
parent d13abe5591
commit 7053e52646
5 changed files with 84 additions and 4 deletions

View File

@@ -226,6 +226,7 @@ public final class CommandHandler {
sender.sendMessage(successMessage("Configuration variables for arena " + arena.getName()) + ":"); sender.sendMessage(successMessage("Configuration variables for arena " + arena.getName()) + ":");
sender.sendMessage(successMessage(" - Enabled: " + arena.isEnabled())); sender.sendMessage(successMessage(" - Enabled: " + arena.isEnabled()));
sender.sendMessage(successMessage(" - Subtitle: " + arena.getSubtitle()));
sender.sendMessage(successMessage(" - Refill: " + arena.getRefill() + " snowballs")); sender.sendMessage(successMessage(" - Refill: " + arena.getRefill() + " snowballs"));
sender.sendMessage(successMessage(" - Player Limit: " + arena.getPlayerLimit() + " players")); sender.sendMessage(successMessage(" - Player Limit: " + arena.getPlayerLimit() + " players"));
sender.sendMessage(successMessage(" - Grace Time: " + (arena.getGraceTime() / 20) + "s")); sender.sendMessage(successMessage(" - Grace Time: " + (arena.getGraceTime() / 20) + "s"));
@@ -268,7 +269,48 @@ public final class CommandHandler {
return; return;
} }
sender.sendMessage(successMessage("The name for arena " + oldName + " has been changed to " + arena.getName())); sender.sendMessage(successMessage("The name for arena " + oldName + " has been changed to " + arena.getName()) + ".");
this.snowbrawl.saveConfig();
}
/**
* Clears the subtitle of an arena.
*
* @param sender The user who executed the command.
* @param name The name of the arena.
*/
@Command(hook = "clear_arena_subtitle")
public void commandArenaConfigSubtitleClear(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.setSubtitle("");
sender.sendMessage(successMessage("The subtitle for arena " + arena.getName() + " has been cleared."));
this.snowbrawl.saveConfig();
}
/**
* Changes the subtitle of an arena.
*
* @param sender The user who executed the command.
* @param name The name of the arena.
* @param newSubtitle The new name for the arena.
*/
@Command(hook = "set_arena_subtitle")
public void commandArenaConfigSubtitle(CommandSender sender, String name, String newSubtitle){
Arena arena = this.snowbrawl.getArenaManager().getArenaByName(name);
if (arena == null){
sender.sendMessage(failMessage("The specified arena does not exist."));
return;
}
arena.setSubtitle(newSubtitle);
sender.sendMessage(successMessage("The name for arena " + arena.getName() + " has been changed to '" + arena.getSubtitle()) + "'.");
this.snowbrawl.saveConfig(); this.snowbrawl.saveConfig();
} }

View File

@@ -85,6 +85,7 @@ public final class Snowbrawl extends JavaPlugin {
newConfig.set("arenas." + id + ".enabled", arena.isEnabled()); 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 + ".subtitle", arena.getSubtitle());
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());
newConfig.set("arenas." + id + ".graceTime", arena.getGraceTime()); newConfig.set("arenas." + id + ".graceTime", arena.getGraceTime());
@@ -158,6 +159,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.setEnabled(config.getBoolean("arenas." + id + ".enabled", Arena.DEFAULT_ENABLED));
arena.setSubtitle(config.getString("arenas." + id + ".subtitle", Arena.DEFAULT_SUBTITLE));
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

@@ -812,8 +812,7 @@ public class ArenaManager implements Listener {
if (arena != null){ // Did this player move into an arena's bounding box? if (arena != null){ // Did this player move into an arena's bounding box?
if (this.playersInArenas.get(player) != arena){ // Is the arena they entered different than the one they were last in? (Including not in an arena) if (this.playersInArenas.get(player) != arena){ // Is the arena they entered different than the one they were last in? (Including not in an arena)
// TODO: Add configurable arena subtitle (such as for giving credit to the arena's builders) player.sendTitle(ChatColor.AQUA + "" + arena.getName(), ChatColor.GOLD + "" + arena.getSubtitle(), 10, 70, 20); // Display a title screen with the arena's name.
player.sendTitle(ChatColor.AQUA + "" + arena.getName(), "", 10, 70, 20); // Display a title screen with the arena's name.
this.playersInArenas.put(player, arena); // Store which arena the player is in for future checks. this.playersInArenas.put(player, arena); // Store which arena the player is in for future checks.
} }
@@ -900,6 +899,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(" - Subtitle: " + arena.getSubtitle());
logger.info(" - Enabled: " + arena.isEnabled()); 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");

View File

@@ -13,6 +13,7 @@ import org.bukkit.World;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.Random; import java.util.Random;
/** /**
@@ -21,6 +22,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 boolean DEFAULT_ENABLED = false;
public static final String DEFAULT_SUBTITLE = "";
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;
@@ -36,7 +38,7 @@ public class Arena {
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 boolean enabled; // Flag for whether the arena can be used in matches.
private String name; // A friendly name for this arena private String name, subtitle; // A friendly name and subtitle 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.
private int graceTime, matchTime; private int graceTime, matchTime;
@@ -51,6 +53,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>enabled = Arena.DEFAULT_ENABLED</li>
* <li>subtitle = Arena.DEFAULT_SUBTITLE</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>
@@ -65,6 +68,7 @@ public class Arena {
this.setName(name); this.setName(name);
this.setEnabled(DEFAULT_ENABLED); this.setEnabled(DEFAULT_ENABLED);
this.setSubtitle(DEFAULT_SUBTITLE);
this.setRefill(DEFAULT_REFILL); this.setRefill(DEFAULT_REFILL);
this.setPlayerLimit(DEFAULT_PLAYER_LIMIT); this.setPlayerLimit(DEFAULT_PLAYER_LIMIT);
this.setGraceTime(DEFAULT_GRACE_TIME); this.setGraceTime(DEFAULT_GRACE_TIME);
@@ -117,6 +121,24 @@ public class Arena {
this.name = name.replaceAll(" ", "_"); this.name = name.replaceAll(" ", "_");
} }
/**
* Gets the subtitle for this arena.
*
* @return The subtitle.
*/
public String getSubtitle(){
return this.subtitle;
}
/**
* Changes the subtitle for this arena. Can be used to give credit to the author or something like that.
*
* @param subtitle The new subtitle.
*/
public void setSubtitle(final String subtitle){
this.subtitle = Objects.requireNonNullElse(subtitle, ""); // Convert null to empty string.
}
/** /**
* Gets the amount of snowballs given to players each time they click a snow block to refill their snowballs. * Gets the amount of snowballs given to players each time they click a snow block to refill their snowballs.
* *

View File

@@ -61,6 +61,20 @@ command snowbrawl {
help Changes the name of an arena.; help Changes the name of an arena.;
} }
subtitle {
perm redstoner.snowbrawl.arena.config.subtitle;
run clear_arena_subtitle name;
type all;
help Clears the subtitle of an arena.;
}
subtitle [string:new_subtitle...] {
perm redstoner.snowbrawl.arena.config.subtitle;
run set_arena_subtitle name new_subtitle;
type all;
help Changes the subtitle of an arena.;
}
refill [int:amount] { refill [int:amount] {
perm redstoner.snowbrawl.arena.config.refill; perm redstoner.snowbrawl.arena.config.refill;
run set_arena_refill name amount; run set_arena_refill name amount;