Use constants for common strings

This commit is contained in:
tastybento 2022-03-19 14:43:52 +00:00
parent bda56763a8
commit 0b3ef8df6d
5 changed files with 38 additions and 30 deletions

View File

@ -20,7 +20,8 @@ import world.bentobox.bentobox.util.Util;
*/
public class IslandTeamInviteAcceptCommand extends ConfirmableCommand {
private final IslandTeamCommand itc;
private static final String INVALID_INVITE = "commands.island.team.invite.errors.invalid-invite";
private final IslandTeamCommand itc;
private UUID playerUUID;
private UUID prospectiveOwnerUUID;
@ -47,7 +48,7 @@ public class IslandTeamInviteAcceptCommand extends ConfirmableCommand {
// Get the island owner
prospectiveOwnerUUID = itc.getInviter(playerUUID);
if (prospectiveOwnerUUID == null) {
user.sendMessage("commands.island.team.invite.errors.invalid-invite");
user.sendMessage(INVALID_INVITE);
return false;
}
Invite invite = itc.getInvite(playerUUID);
@ -56,7 +57,7 @@ public class IslandTeamInviteAcceptCommand extends ConfirmableCommand {
Island island = getIslands().getIsland(getWorld(), prospectiveOwnerUUID);
String inviteUsage = getParent().getSubCommand("invite").map(CompositeCommand::getUsage).orElse("");
if (island == null || island.getRank(prospectiveOwnerUUID) < island.getRankCommand(inviteUsage)) {
user.sendMessage("commands.island.team.invite.errors.invalid-invite");
user.sendMessage(INVALID_INVITE);
itc.removeInvite(playerUUID);
return false;
}
@ -149,7 +150,7 @@ public class IslandTeamInviteAcceptCommand extends ConfirmableCommand {
// Get the team's island
Island teamIsland = getIslands().getIsland(getWorld(), prospectiveOwnerUUID);
if (teamIsland == null) {
user.sendMessage("commands.island.team.invite.errors.invalid-invite");
user.sendMessage(INVALID_INVITE);
return;
}
if (teamIsland.getMemberSet(RanksManager.MEMBER_RANK, true).size() > getIslands().getMaxMembers(teamIsland, RanksManager.MEMBER_RANK)) {

View File

@ -41,6 +41,10 @@ public class TemplateReader
private static final String BORDER = "border";
private static final String FORCE_SHOWN = "force-shown";
private static final String FALLBACK = "fallback";
private static final String YML = ".yml";
private static final String ACTIONS = "actions";
private static final String TOOLTIP = "tooltip";
private static final String CLICK_TYPE = "click-type";
/**
@ -73,7 +77,7 @@ public class TemplateReader
return null;
}
File file = new File(panelLocation, templateName.endsWith(".yml") ? templateName : templateName + ".yml");
File file = new File(panelLocation, templateName.endsWith(YML) ? templateName : templateName + YML);
if (!file.exists())
{
@ -337,9 +341,9 @@ public class TemplateReader
}
// Read Click data
if (section.isConfigurationSection("actions"))
if (section.isConfigurationSection(ACTIONS))
{
ConfigurationSection actionSection = section.getConfigurationSection("actions");
ConfigurationSection actionSection = section.getConfigurationSection(ACTIONS);
if (actionSection != null)
{
@ -356,7 +360,7 @@ public class TemplateReader
new ItemTemplateRecord.ActionRecords(clickType,
actionDataSection.getString("type"),
actionDataSection.getString("content"),
actionDataSection.getString("tooltip"));
actionDataSection.getString(TOOLTIP));
itemRecord.addAction(actionData);
}
}
@ -364,34 +368,34 @@ public class TemplateReader
{
ConfigurationSection actionDataSection = actionSection.getConfigurationSection(actionKey);
if (actionDataSection != null && actionDataSection.contains("click-type"))
if (actionDataSection != null && actionDataSection.contains(CLICK_TYPE))
{
clickType = Enums.getIfPresent(ClickType.class,
actionDataSection.getString("click-type", "UNKNOWN").toUpperCase()).
actionDataSection.getString(CLICK_TYPE, "UNKNOWN").toUpperCase()).
or(ClickType.UNKNOWN);
ItemTemplateRecord.ActionRecords actionData =
new ItemTemplateRecord.ActionRecords(clickType,
actionKey,
actionDataSection.getString("content"),
actionDataSection.getString("tooltip"));
actionDataSection.getString(TOOLTIP));
itemRecord.addAction(actionData);
}
}
});
}
}
else if (section.isList("actions"))
else if (section.isList(ACTIONS))
{
// Read Click data as list which allows to have duplicate click types.
List<Map<?, ?>> actionList = section.getMapList("actions");
List<Map<?, ?>> actionList = section.getMapList(ACTIONS);
if (!actionList.isEmpty())
{
actionList.forEach(valueMap -> {
ClickType clickType = Enums.getIfPresent(ClickType.class,
String.valueOf(valueMap.get("click-type")).toUpperCase()).orNull();
String.valueOf(valueMap.get(CLICK_TYPE)).toUpperCase()).orNull();
if (clickType != null)
{
@ -399,7 +403,7 @@ public class TemplateReader
new ItemTemplateRecord.ActionRecords(clickType,
valueMap.containsKey("type") ? String.valueOf(valueMap.get("type")) : null,
valueMap.containsKey("content") ? String.valueOf(valueMap.get("content")) : null,
valueMap.containsKey("tooltip") ? String.valueOf(valueMap.get("tooltip")) : null);
valueMap.containsKey(TOOLTIP) ? String.valueOf(valueMap.get(TOOLTIP)) : null);
itemRecord.addAction(actionData);
}
});

View File

@ -289,7 +289,7 @@ public class YamlDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
// Convert any serialized dots back to dots
// In YAML dots . cause a lot of problems, so I serialize them as :dot:
// There may be a better way to do this.
key = key.replaceAll(":dot:", ".");
key = key.replace(":dot:", ".");
Object mapKey = deserialize(key,Class.forName(keyType.getTypeName()));
if (mapKey == null) {
continue;

View File

@ -17,6 +17,7 @@ import world.bentobox.bentobox.api.user.User;
public class VaultHook extends Hook {
private static final String AMOUNT_MUST_BE_POSITIVE = "Amount must be positive.";
private static final String PLAYER_OR_OFFLINEPLAYER_REQUIRED = "User must be a Player or an OfflinePlayer";
private Economy economy;
public VaultHook() {
@ -109,7 +110,7 @@ public class VaultHook extends Hook {
*/
public EconomyResponse withdraw(User user, double amount, World world) {
if (!user.isOfflinePlayer()) {
throw new IllegalArgumentException("User must be a Player or an OfflinePlayer");
throw new IllegalArgumentException(PLAYER_OR_OFFLINEPLAYER_REQUIRED);
}
if (amount < 0.0D) {
throw new IllegalArgumentException(AMOUNT_MUST_BE_POSITIVE);
@ -149,7 +150,7 @@ public class VaultHook extends Hook {
*/
public EconomyResponse deposit(User user, double amount, World world) {
if (!user.isOfflinePlayer()) {
throw new IllegalArgumentException("User must be a Player or an OfflinePlayer");
throw new IllegalArgumentException(PLAYER_OR_OFFLINEPLAYER_REQUIRED);
}
if (amount < 0.0D) {
throw new IllegalArgumentException(AMOUNT_MUST_BE_POSITIVE);
@ -198,7 +199,7 @@ public class VaultHook extends Hook {
}
if (!user.isOfflinePlayer()) {
throw new IllegalArgumentException("User must be a Player or an OfflinePlayer");
throw new IllegalArgumentException(PLAYER_OR_OFFLINEPLAYER_REQUIRED);
}
if (world == null)

View File

@ -21,7 +21,9 @@ import world.bentobox.bentobox.managers.RanksManager;
*/
public class IslandInfo {
private final BentoBox plugin;
private static final String XZ1 = "[xz1]";
private static final String RANGE = "[range]";
private final BentoBox plugin;
private final Island island;
private final @Nullable UUID owner;
private final World world;
@ -62,18 +64,18 @@ public class IslandInfo {
}
user.sendMessage("commands.admin.info.last-login","[date]", formattedDate);
user.sendMessage("commands.admin.info.deaths", "[number]", String.valueOf(plugin.getPlayers().getDeaths(world, owner)));
user.sendMessage("commands.admin.info.deaths", TextVariables.NUMBER, String.valueOf(plugin.getPlayers().getDeaths(world, owner)));
String resets = String.valueOf(plugin.getPlayers().getResets(world, owner));
String total = plugin.getIWM().getResetLimit(world) < 0 ? "Unlimited" : String.valueOf(plugin.getIWM().getResetLimit(world));
user.sendMessage("commands.admin.info.resets-left", "[number]", resets, "[total]", total);
user.sendMessage("commands.admin.info.resets-left", TextVariables.NUMBER, resets, "[total]", total);
// Show team members
showMembers(user);
}
Vector location = island.getProtectionCenter().toVector();
user.sendMessage("commands.admin.info.island-protection-center", TextVariables.XYZ, Util.xyz(location));
user.sendMessage("commands.admin.info.island-center", TextVariables.XYZ, Util.xyz(island.getCenter().toVector()));
user.sendMessage("commands.admin.info.island-coords", "[xz1]", Util.xyz(new Vector(island.getMinX(), 0, island.getMinZ())), "[xz2]", Util.xyz(new Vector(island.getMaxX(), 0, island.getMaxZ())));
user.sendMessage("commands.admin.info.protection-range", "[range]", String.valueOf(island.getProtectionRange()));
user.sendMessage("commands.admin.info.island-coords", XZ1, Util.xyz(new Vector(island.getMinX(), 0, island.getMinZ())), "[xz2]", Util.xyz(new Vector(island.getMaxX(), 0, island.getMaxZ())));
user.sendMessage("commands.admin.info.protection-range", RANGE, String.valueOf(island.getProtectionRange()));
if (!island.getBonusRanges().isEmpty()) {
user.sendMessage("commands.admin.info.protection-range-bonus-title");
}
@ -84,8 +86,8 @@ public class IslandInfo {
user.sendMessage(brb.getMessage(), TextVariables.NUMBER, String.valueOf(brb.getRange()));
}
});
user.sendMessage("commands.admin.info.max-protection-range", "[range]", String.valueOf(island.getMaxEverProtectionRange()));
user.sendMessage("commands.admin.info.protection-coords", "[xz1]", Util.xyz(new Vector(island.getMinProtectedX(), 0, island.getMinProtectedZ())), "[xz2]", Util.xyz(new Vector(island.getMaxProtectedX() - 1, 0, island.getMaxProtectedZ() - 1)));
user.sendMessage("commands.admin.info.max-protection-range", RANGE, String.valueOf(island.getMaxEverProtectionRange()));
user.sendMessage("commands.admin.info.protection-coords", XZ1, Util.xyz(new Vector(island.getMinProtectedX(), 0, island.getMinProtectedZ())), "[xz2]", Util.xyz(new Vector(island.getMaxProtectedX() - 1, 0, island.getMaxProtectedZ() - 1)));
if (island.isSpawn()) {
user.sendMessage("commands.admin.info.is-spawn");
}
@ -110,17 +112,17 @@ public class IslandInfo {
user.sendMessage("commands.admin.info.unowned");
} else {
user.sendMessage("commands.admin.info.owner", "[owner]", plugin.getPlayers().getName(owner), TextVariables.UUID, owner.toString());
user.sendMessage("commands.admin.info.deaths", "[number]", String.valueOf(plugin.getPlayers().getDeaths(world, owner)));
user.sendMessage("commands.admin.info.deaths", TextVariables.NUMBER, String.valueOf(plugin.getPlayers().getDeaths(world, owner)));
String resets = String.valueOf(plugin.getPlayers().getResets(world, owner));
String total = plugin.getIWM().getResetLimit(world) < 0 ? "Unlimited" : String.valueOf(plugin.getIWM().getResetLimit(world));
user.sendMessage("commands.admin.info.resets-left", "[number]", resets, "[total]", total);
user.sendMessage("commands.admin.info.resets-left", TextVariables.NUMBER, resets, "[total]", total);
// Show team members
showMembers(user);
}
Vector location = island.getProtectionCenter().toVector();
user.sendMessage("commands.admin.info.island-center", TextVariables.XYZ, Util.xyz(location));
user.sendMessage("commands.admin.info.protection-range", "[range]", String.valueOf(island.getProtectionRange()));
user.sendMessage("commands.admin.info.protection-coords", "[xz1]", Util.xyz(new Vector(island.getMinProtectedX(), 0, island.getMinProtectedZ())), "[xz2]", Util.xyz(new Vector(island.getMaxProtectedX() - 1, 0, island.getMaxProtectedZ() - 1)));
user.sendMessage("commands.admin.info.protection-range", RANGE, String.valueOf(island.getProtectionRange()));
user.sendMessage("commands.admin.info.protection-coords", XZ1, Util.xyz(new Vector(island.getMinProtectedX(), 0, island.getMinProtectedZ())), "[xz2]", Util.xyz(new Vector(island.getMaxProtectedX() - 1, 0, island.getMaxProtectedZ() - 1)));
if (island.isSpawn()) {
user.sendMessage("commands.admin.info.is-spawn");
}