Skip to content

Commit

Permalink
Clean up Constants a bit.
Browse files Browse the repository at this point in the history
  • Loading branch information
BONNe committed Sep 19, 2021
1 parent 89c5121 commit 2bc71b5
Show file tree
Hide file tree
Showing 21 changed files with 781 additions and 225 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import world.bentobox.bentobox.util.Util;
import world.bentobox.challenges.ChallengesAddon;
import world.bentobox.challenges.database.object.Challenge;
import world.bentobox.challenges.utils.Constants;
import world.bentobox.challenges.utils.Utils;


Expand Down Expand Up @@ -109,8 +110,8 @@ else if (!args.get(1).isEmpty())
if (user.isPlayer())
{
Utils.sendMessage(user, user.getTranslation("challenges.messages.admin.completed",
"[name]", challenge.getFriendlyName(),
"[player]", User.getInstance(targetUUID).getName()));
Constants.PARAMETER_NAME, challenge.getFriendlyName(),
Constants.PARAMETER_PLAYER, User.getInstance(targetUUID).getName()));
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import world.bentobox.bentobox.util.Util;
import world.bentobox.challenges.ChallengesAddon;
import world.bentobox.challenges.database.object.Challenge;
import world.bentobox.challenges.utils.Constants;
import world.bentobox.challenges.utils.Utils;


Expand Down Expand Up @@ -103,7 +104,7 @@ else if (!args.get(1).isEmpty())
if (user.isPlayer())
{
Utils.sendMessage(user, user.getTranslation("challenges.messages.admin.reset-all",
"[player]", User.getInstance(targetUUID).getName()));
Constants.PARAMETER_PLAYER, User.getInstance(targetUUID).getName()));
}
else
{
Expand All @@ -127,8 +128,8 @@ else if (!args.get(1).isEmpty())
if (user.isPlayer())
{
Utils.sendMessage(user, user.getTranslation("challenges.messages.admin.reset",
"[name]", challenge.getFriendlyName(),
"[player]", User.getInstance(targetUUID).getName()));
Constants.PARAMETER_NAME, challenge.getFriendlyName(),
Constants.PARAMETER_PLAYER, User.getInstance(targetUUID).getName()));
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void importFile(@Nullable User user, World world, String file)
{
if (user != null)
{
Utils.sendMessage(user, user.getTranslation(Constants.ERRORS + "no-file", Constants.FILE, file));
Utils.sendMessage(user, user.getTranslation(Constants.ERRORS + "no-file", Constants.PARAMETER_FILE, file));
}

return;
Expand All @@ -99,7 +99,7 @@ public void importFile(@Nullable User user, World world, String file)
if (user != null)
{
Utils.sendMessage(user, user.getTranslation(Constants.ERRORS + "no-load",
Constants.FILE, file, TextVariables.DESCRIPTION, e.getMessage()));
Constants.PARAMETER_FILE, file, TextVariables.DESCRIPTION, e.getMessage()));
}
else
{
Expand All @@ -117,7 +117,7 @@ public void importFile(@Nullable User user, World world, String file)
{
Utils.sendMessage(user,
user.getTranslation(Constants.ERRORS + "not-a-gamemode-world",
Constants.WORLD, world.getName()));
Constants.PARAMETER_WORLD, world.getName()));
}
else
{
Expand Down Expand Up @@ -805,7 +805,7 @@ public void generateDatabaseFile(User user, World world, String fileName)
{
Utils.sendMessage(user,
user.getTranslation(Constants.ERRORS + "file-exist",
Constants.FILE, fileName));
Constants.PARAMETER_FILE, fileName));
}
else
{
Expand Down Expand Up @@ -872,7 +872,7 @@ public void generateDatabaseFile(User user, World world, String fileName)
{
Utils.sendMessage(user,
user.getTranslation(Constants.ERRORS + "no-load",
Constants.FILE, fileName,
Constants.PARAMETER_FILE, fileName,
TextVariables.DESCRIPTION, e.getMessage()));
}

Expand All @@ -884,8 +884,8 @@ public void generateDatabaseFile(User user, World world, String fileName)
{
Utils.sendMessage(user,
user.getTranslation(Constants.CONVERSATIONS + "database-export-completed",
Constants.WORLD, world.getName(),
Constants.FILE, fileName));
Constants.PARAMETER_WORLD, world.getName(),
Constants.PARAMETER_FILE, fileName));
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ protected PanelItem getButton(CommonButtons button)
if (button == CommonButtons.NEXT)
{
description.add(this.user.getTranslation(reference + "description",
Constants.NUMBER, String.valueOf(this.pageIndex + 2)));
Constants.PARAMETER_NUMBER, String.valueOf(this.pageIndex + 2)));

icon = new ItemStack(Material.OAK_SIGN, this.pageIndex + 2);
clickHandler = (panel, user, clickType, slot) ->
Expand All @@ -141,7 +141,7 @@ protected PanelItem getButton(CommonButtons button)
else if (button == CommonButtons.PREVIOUS)
{
description.add(this.user.getTranslation(reference + "description",
Constants.NUMBER, String.valueOf(this.pageIndex)));
Constants.PARAMETER_NUMBER, String.valueOf(this.pageIndex)));

icon = new ItemStack(Material.OAK_SIGN, Math.max(1, this.pageIndex));
clickHandler = (panel, user, clickType, slot) ->
Expand Down
54 changes: 27 additions & 27 deletions src/main/java/world/bentobox/challenges/panel/CommonPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ protected List<String> generateChallengeDescription(Challenge challenge, @Nullab
if (!description.replaceAll("(?m)^[ \\t]*\\r?\\n", "").isEmpty())
{
String returnString = this.user.getTranslationOrNothing(reference + "lore",
Constants.REQUIREMENTS, requirements,
Constants.REWARDS, rewards,
Constants.STATUS, status);
"[requirements]", requirements,
"[rewards]", rewards,
"[status]", status);

// remove empty lines from the generated text.
List<String> collect =
Expand All @@ -170,9 +170,9 @@ protected List<String> generateChallengeDescription(Challenge challenge, @Nullab

for (int i = 0; i < collect.size(); i++)
{
if (collect.get(i).contains(Constants.DESCRIPTION))
if (collect.get(i).contains(Constants.PARAMETER_DESCRIPTION))
{
collect.set(i, collect.get(i).replace(Constants.DESCRIPTION, description));
collect.set(i, collect.get(i).replace(Constants.PARAMETER_DESCRIPTION, description));
}
}

Expand All @@ -181,10 +181,10 @@ protected List<String> generateChallengeDescription(Challenge challenge, @Nullab
else
{
String returnString = this.user.getTranslationOrNothing(reference + "lore",
Constants.DESCRIPTION, description,
Constants.REQUIREMENTS, requirements,
Constants.REWARDS, rewards,
Constants.STATUS, status);
Constants.PARAMETER_DESCRIPTION, description,
"[requirements]", requirements,
"[rewards]", rewards,
"[status]", status);

// Remove empty lines and returns as a list.

Expand Down Expand Up @@ -214,7 +214,7 @@ private String generateRequirements(Challenge challenge, @Nullable User target)
else if (challenge.getEnvironment().size() == 1)
{
environment = this.user.getTranslationOrNothing(reference + "environment-single",
Constants.ENVIRONMENT,
Constants.PARAMETER_ENVIRONMENT,
Utils.prettifyObject(challenge.getEnvironment().iterator().next(), this.user));
}
else
Expand All @@ -225,7 +225,7 @@ else if (challenge.getEnvironment().size() == 1)
{
builder.append("\n");
builder.append(this.user.getTranslationOrNothing(reference + "environment-single",
Constants.ENVIRONMENT,
Constants.PARAMETER_ENVIRONMENT,
Utils.prettifyObject(en, this.user)));
});

Expand All @@ -247,7 +247,7 @@ else if (challenge.getEnvironment().size() == 1)
if (missingPermissions.size() == 1)
{
permissionBuilder.append(this.user.getTranslationOrNothing(reference + "permission-single",
Constants.PERMISSION, missingPermissions.get(0)));
Constants.PARAMETER_PERMISSION, missingPermissions.get(0)));
}
else if (!missingPermissions.isEmpty())
{
Expand All @@ -256,7 +256,7 @@ else if (!missingPermissions.isEmpty())
{
permissionBuilder.append("\n");
permissionBuilder.append(this.user.getTranslationOrNothing(reference + "permissions-list",
Constants.PERMISSION, permission));
Constants.PARAMETER_PERMISSION, permission));
});
}

Expand All @@ -275,9 +275,9 @@ else if (!missingPermissions.isEmpty())
};

return this.user.getTranslationOrNothing(reference + "lore",
Constants.ENVIRONMENT, environment,
Constants.TYPE_REQUIREMENT, typeRequirement,
Constants.PERMISSIONS, permissions);
Constants.PARAMETER_ENVIRONMENT, environment,
"[type-requirement]", typeRequirement,
"[permissions]", permissions);
}


Expand Down Expand Up @@ -305,13 +305,13 @@ private String generateIslandChallenge(IslandRequirements requirement)
if (entry.getValue() > 1)
{
builder.append(this.user.getTranslationOrNothing(reference + "blocks-value",
Constants.NUMBER, String.valueOf(entry.getValue()),
Constants.MATERIAL, Utils.prettifyObject(entry.getKey(), this.user)));
Constants.PARAMETER_NUMBER, String.valueOf(entry.getValue()),
Constants.PARAMETER_MATERIAL, Utils.prettifyObject(entry.getKey(), this.user)));
}
else
{
builder.append(this.user.getTranslationOrNothing(reference + "block-value",
Constants.MATERIAL, Utils.prettifyObject(entry.getKey(), this.user)));
Constants.PARAMETER_MATERIAL, Utils.prettifyObject(entry.getKey(), this.user)));
}
});

Expand All @@ -337,13 +337,13 @@ private String generateIslandChallenge(IslandRequirements requirement)
if (entry.getValue() > 1)
{
builder.append(this.user.getTranslationOrNothing(reference + "entities-value",
Constants.NUMBER, String.valueOf(entry.getValue()),
Constants.ENTITY, Utils.prettifyObject(entry.getKey(), this.user)));
Constants.PARAMETER_NUMBER, String.valueOf(entry.getValue()),
Constants.PARAMETER_ENTITY, Utils.prettifyObject(entry.getKey(), this.user)));
}
else
{
builder.append(this.user.getTranslationOrNothing(reference + "entity-value",
Constants.ENTITY, Utils.prettifyObject(entry.getKey(), this.user)));
Constants.PARAMETER_ENTITY, Utils.prettifyObject(entry.getKey(), this.user)));
}
});

Expand All @@ -355,7 +355,7 @@ private String generateIslandChallenge(IslandRequirements requirement)
}

String searchRadius = this.user.getTranslationOrNothing(reference + "search-radius",
Constants.NUMBER, String.valueOf(requirement.getSearchRadius()));
Constants.PARAMETER_NUMBER, String.valueOf(requirement.getSearchRadius()));

String warningBlocks = requirement.isRemoveBlocks() ?
this.user.getTranslationOrNothing(reference + "warning-block") : "";
Expand Down Expand Up @@ -547,7 +547,7 @@ private String generateChallengeStatus(boolean completedOnce,
if (maxCompletions > 1)
{
return this.user.getTranslationOrNothing(reference + "completed-times-reached",
Constants.MAX, String.valueOf(maxCompletions));
Constants.PARAMETER_MAX, String.valueOf(maxCompletions));
}
else
{
Expand All @@ -559,13 +559,13 @@ else if (completedOnce)
if (maxCompletions > 0)
{
return this.user.getTranslationOrNothing(reference + "completed-times-of",
Constants.MAX, String.valueOf(maxCompletions),
Constants.NUMBER, String.valueOf(completionCount));
Constants.PARAMETER_MAX, String.valueOf(maxCompletions),
Constants.PARAMETER_NUMBER, String.valueOf(completionCount));
}
else
{
return this.user.getTranslationOrNothing(reference + "completed-times",
Constants.NUMBER, String.valueOf(completionCount));
Constants.PARAMETER_NUMBER, String.valueOf(completionCount));
}
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ protected String getFailedValidationText(ConversationContext context,
String invalidInput)
{
return user.getTranslation(failTranslationLocation,
Constants.ID,
Constants.PARAMETER_ID,
Utils.sanitizeInput(invalidInput));
}

Expand Down Expand Up @@ -303,7 +303,7 @@ protected boolean isNumberValid(ConversationContext context, Number input)
@Override
protected String getInputNotNumericText(ConversationContext context, String invalidInput)
{
return user.getTranslation(Constants.CONVERSATIONS + "numeric-only", Constants.VALUE, invalidInput);
return user.getTranslation(Constants.CONVERSATIONS + "numeric-only", Constants.PARAMETER_VALUE, invalidInput);
}


Expand All @@ -319,9 +319,9 @@ protected String getInputNotNumericText(ConversationContext context, String inva
protected String getFailedValidationText(ConversationContext context, Number invalidInput)
{
return user.getTranslation(Constants.CONVERSATIONS + "not-valid-value",
Constants.VALUE, invalidInput.toString(),
Constants.MIN, Double.toString(minValue.doubleValue()),
Constants.MAX, Double.toString(maxValue.doubleValue()));
Constants.PARAMETER_VALUE, invalidInput.toString(),
Constants.PARAMETER_MIN, Double.toString(minValue.doubleValue()),
Constants.PARAMETER_MAX, Double.toString(maxValue.doubleValue()));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ private PanelItem createButton(Button button)
this.user,
this.user.getTranslation(Constants.CONVERSATIONS + "write-name"),
this.user.getTranslation(Constants.CONVERSATIONS + "new-object-created",
Constants.WORLD, this.world.getName()),
Constants.PARAMETER_WORLD, this.world.getName()),
Constants.CONVERSATIONS + "object-already-exists");

return true;
Expand Down Expand Up @@ -262,7 +262,7 @@ private PanelItem createButton(Button button)
this.user,
this.user.getTranslation(Constants.CONVERSATIONS + "write-name"),
this.user.getTranslation(Constants.CONVERSATIONS + "new-object-created",
Constants.GAMEMODE, Utils.getGameMode(this.world)),
Constants.PARAMETER_GAMEMODE, Utils.getGameMode(this.world)),
Constants.CONVERSATIONS + "object-already-exists");

return true;
Expand Down Expand Up @@ -379,7 +379,7 @@ private PanelItem createButton(Button button)
this.user,
this.user.getTranslation(Constants.CONVERSATIONS + "exported-file-name"),
this.user.getTranslation(Constants.CONVERSATIONS + "database-export-completed",
Constants.WORLD, world.getName()),
Constants.PARAMETER_WORLD, world.getName()),
Constants.CONVERSATIONS + "file-name-exist");

return true;
Expand Down Expand Up @@ -438,9 +438,9 @@ private PanelItem createButton(Button button)
consumer,
this.user,
this.user.getTranslation(Constants.CONVERSATIONS + "confirm-all-data-deletion",
Constants.GAMEMODE, Utils.getGameMode(this.world)),
Constants.PARAMETER_GAMEMODE, Utils.getGameMode(this.world)),
this.user.getTranslation(Constants.CONVERSATIONS + "all-data-removed",
Constants.GAMEMODE, Utils.getGameMode(this.world)));
Constants.PARAMETER_GAMEMODE, Utils.getGameMode(this.world)));
}

return true;
Expand Down Expand Up @@ -477,9 +477,9 @@ private PanelItem createButton(Button button)
consumer,
this.user,
this.user.getTranslation(Constants.CONVERSATIONS + "confirm-challenge-data-deletion",
Constants.GAMEMODE, Utils.getGameMode(this.world)),
Constants.PARAMETER_GAMEMODE, Utils.getGameMode(this.world)),
this.user.getTranslation(Constants.CONVERSATIONS + "challenge-data-removed",
Constants.GAMEMODE, Utils.getGameMode(this.world)));
Constants.PARAMETER_GAMEMODE, Utils.getGameMode(this.world)));
}

return true;
Expand Down Expand Up @@ -508,9 +508,9 @@ private PanelItem createButton(Button button)
consumer,
this.user,
this.user.getTranslation(Constants.CONVERSATIONS + "confirm-user-data-deletion",
Constants.GAMEMODE, Utils.getGameMode(this.world)),
Constants.PARAMETER_GAMEMODE, Utils.getGameMode(this.world)),
this.user.getTranslation(Constants.CONVERSATIONS + "user-data-removed",
Constants.GAMEMODE, Utils.getGameMode(this.world)));
Constants.PARAMETER_GAMEMODE, Utils.getGameMode(this.world)));

return true;
};
Expand Down

0 comments on commit 2bc71b5

Please sign in to comment.