Skip to content

Commit

Permalink
Add support for gamemode-specific translations.
Browse files Browse the repository at this point in the history
This was a request from Floris
  • Loading branch information
BONNe committed Mar 31, 2023
1 parent e0377fd commit 9953459
Show file tree
Hide file tree
Showing 14 changed files with 254 additions and 151 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public boolean execute(User user, String label, List<String> args)

if (this.gameModeAddons.isEmpty())
{
Utils.sendMessage(user, user.getTranslation(Constants.ERRORS + "not-hooked"));
Utils.sendMessage(user, user.getWorld(), Constants.ERRORS + "not-hooked");
return false;
}
else if (this.gameModeAddons.size() == 1)
Expand All @@ -80,7 +80,7 @@ else if (this.<ChallengesAddon>getAddon().getChallengesSettings().getUserGuiMode
}
}

Utils.sendMessage(user, user.getTranslation("general.errors.wrong-world"));
Utils.sendMessage(user, user.getWorld(), "general.errors.wrong-world");
}
else if (this.<ChallengesAddon>getAddon().getChallengesSettings().getUserGuiMode() == GuiMode.GAMEMODE_LIST)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import world.bentobox.bentobox.util.Util;
import world.bentobox.challenges.ChallengesAddon;
import world.bentobox.challenges.panel.user.ChallengesPanel;
import world.bentobox.challenges.utils.Constants;
import world.bentobox.challenges.utils.Utils;


Expand All @@ -31,7 +32,7 @@ public boolean canExecute(User user, String label, List<String> args)
if (!this.getIWM().inWorld(user.getWorld()) ||
!Util.sameWorld(this.getWorld(), user.getWorld())) {
// Not a GameMode world.
Utils.sendMessage(user, user.getTranslation("general.errors.wrong-world"));
Utils.sendMessage(user, user.getWorld(), "general.errors.wrong-world");
return false;
}

Expand All @@ -47,13 +48,13 @@ public boolean canExecute(User user, String label, List<String> args)
map(GameModeAddon::getAdminCommand).
map(optionalAdminCommand -> optionalAdminCommand.map(CompositeCommand::getTopLabel).orElse(this.getTopLabel())).
orElse(this.getTopLabel());
Utils.sendMessage(user, user.getTranslation("challenges.errors.no-challenges-admin",
Utils.sendMessage(user, this.getWorld(), Constants.ERRORS + "no-challenges-admin",
"[command]",
topLabel + " " + this.<ChallengesAddon>getAddon().getChallengesSettings().getAdminMainCommand().split(" ")[0]));
topLabel + " " + this.<ChallengesAddon>getAddon().getChallengesSettings().getAdminMainCommand().split(" ")[0]);
}
else
{
Utils.sendMessage(user, user.getTranslation("challenges.errors.no-challenges"));
Utils.sendMessage(user, this.getWorld(), Constants.ERRORS + "no-challenges");
}

return false;
Expand All @@ -62,14 +63,14 @@ public boolean canExecute(User user, String label, List<String> args)
if (this.getIslands().getIsland(this.getWorld(), user) == null)
{
// Do not open gui if there is no island for this player.
Utils.sendMessage(user, user.getTranslation("general.errors.no-island"));
Utils.sendMessage(user, this.getWorld(), "general.errors.no-island");
return false;
} else if (ChallengesAddon.CHALLENGES_WORLD_PROTECTION.isSetForWorld(this.getWorld()) &&
!this.getIslands().locationIsOnIsland(user.getPlayer(), user.getLocation()))
{
// Do not open gui if player is not on the island, but challenges requires island for
// completion.
Utils.sendMessage(user, user.getTranslation("challenges.errors.not-on-island"));
Utils.sendMessage(user, this.getWorld(), Constants.ERRORS + "not-on-island");
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import world.bentobox.challenges.ChallengesAddon;
import world.bentobox.challenges.database.object.Challenge;
import world.bentobox.challenges.tasks.TryToComplete;
import world.bentobox.challenges.utils.Constants;
import world.bentobox.challenges.utils.Utils;


Expand Down Expand Up @@ -54,7 +55,7 @@ public boolean execute(User user, String label, List<String> args)
{
if (args.isEmpty())
{
Utils.sendMessage(user, user.getTranslation("challenges.errors.no-name"));
Utils.sendMessage(user, this.getWorld(), Constants.ERRORS + "no-name");
this.showHelp(this, user);
return false;
}
Expand All @@ -73,7 +74,7 @@ public boolean execute(User user, String label, List<String> args)

if (!canMultipleTimes && count > 1)
{
Utils.sendMessage(user, user.getTranslation("challenges.error.no-multiple-permission"));
Utils.sendMessage(user, this.getWorld(), Constants.ERRORS + "no-multiple-permission");
count = 1;
}

Expand All @@ -87,7 +88,7 @@ public boolean execute(User user, String label, List<String> args)
}
else
{
Utils.sendMessage(user, user.getTranslation("challenges.errors.unknown-challenge"));
Utils.sendMessage(user, this.getWorld(), Constants.ERRORS + "unknown-challenge");
this.showHelp(this, user);
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public boolean execute(User user, String label, List<String> args)

if (this.gameModeAddons.isEmpty())
{
Utils.sendMessage(user, user.getTranslation(Constants.ERRORS + "not-hooked"));
Utils.sendMessage(user, this.getWorld(), Constants.ERRORS + "not-hooked");
return false;
}
else if (this.gameModeAddons.size() == 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public boolean execute(User user, String label, List<String> args)
{
if (user.isPlayer())
{
Utils.sendMessage(user, user.getTranslation("challenges.errors.no-name"));
Utils.sendMessage(user, this.getWorld(), Constants.ERRORS + "no-name");
}
else
{
Expand All @@ -67,7 +67,7 @@ else if (args.size() < 2)
{
if (user.isPlayer())
{
Utils.sendMessage(user, user.getTranslation("challenges.errors.missing-arguments"));
Utils.sendMessage(user, this.getWorld(), Constants.ERRORS + "missing-arguments");
}
else
{
Expand All @@ -82,9 +82,11 @@ else if (!args.get(1).isEmpty())
{
if (user.isPlayer())
{
Utils.sendMessage(user, user.getTranslation("general.errors.unknown-player",
Utils.sendMessage(user,
this.getWorld(),
"general.errors.unknown-player",
TextVariables.NAME,
args.get(0)));
args.get(0));
}
else
{
Expand All @@ -109,9 +111,11 @@ else if (!args.get(1).isEmpty())

if (user.isPlayer())
{
Utils.sendMessage(user, user.getTranslation("challenges.messages.completed",
Utils.sendMessage(user,
this.getWorld(),
Constants.MESSAGES + "completed",
Constants.PARAMETER_NAME, challenge.getFriendlyName(),
Constants.PARAMETER_PLAYER, target.getName()));
Constants.PARAMETER_PLAYER, target.getName());
}
else
{
Expand All @@ -123,7 +127,9 @@ else if (!args.get(1).isEmpty())
{
if (user.isPlayer())
{
Utils.sendMessage(user, user.getTranslation("challenges.messages.already-completed"));
Utils.sendMessage(user,
this.getWorld(),
Constants.MESSAGES + "already-completed");
}
else
{
Expand All @@ -137,7 +143,9 @@ else if (!args.get(1).isEmpty())
{
if (user.isPlayer())
{
Utils.sendMessage(user, user.getTranslation("challenges.errors.unknown-challenge"));
Utils.sendMessage(user,
this.getWorld(),
Constants.ERRORS + "unknown-challenge");
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ public boolean execute(User user, String label, List<String> args)
if (args.isEmpty())
{
this.manager.load();
Utils.sendMessage(user, user.getTranslation("general.success"));
Utils.sendMessage(user, this.getWorld(), "general.success");
return true;
}
else if (args.get(0).equalsIgnoreCase("hard"))
{
this.manager.reload();
Utils.sendMessage(user, user.getTranslation("general.success"));
Utils.sendMessage(user, this.getWorld(), "general.success");
return true;
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public boolean execute(User user, String label, List<String> args)
{
if (user.isPlayer())
{
Utils.sendMessage(user, user.getTranslation("challenges.errors.no-name"));
Utils.sendMessage(user, this.getWorld(), Constants.ERRORS + "no-name");
}
else
{
Expand All @@ -67,7 +67,7 @@ else if (args.size() < 2)
{
if (user.isPlayer())
{
Utils.sendMessage(user, user.getTranslation("challenges.errors.missing-arguments"));
Utils.sendMessage(user, this.getWorld(), Constants.ERRORS + "missing-arguments");
}
else
{
Expand All @@ -82,8 +82,11 @@ else if (!args.get(1).isEmpty())
{
if (user.isPlayer())
{
Utils.sendMessage(user, user.getTranslation("general.errors.unknown-player",
TextVariables.NAME, args.get(0)));
Utils.sendMessage(user,
this.getWorld(),
Constants.ERRORS + "unknown-player",
TextVariables.NAME,
args.get(0));
}
else
{
Expand All @@ -102,8 +105,11 @@ else if (!args.get(1).isEmpty())

if (user.isPlayer())
{
Utils.sendMessage(user, user.getTranslation("challenges.messages.reset-all",
Constants.PARAMETER_PLAYER, target.getName()));
Utils.sendMessage(user,
this.getWorld(),
Constants.MESSAGES + "reset-all",
Constants.PARAMETER_PLAYER,
target.getName());
}
else
{
Expand All @@ -125,9 +131,11 @@ else if (!args.get(1).isEmpty())

if (user.isPlayer())
{
Utils.sendMessage(user, user.getTranslation("challenges.messages.reset",
Utils.sendMessage(user,
this.getWorld(),
Constants.MESSAGES + "reset",
Constants.PARAMETER_NAME, challenge.getFriendlyName(),
Constants.PARAMETER_PLAYER, target.getName()));
Constants.PARAMETER_PLAYER, target.getName());
}
else
{
Expand All @@ -139,7 +147,9 @@ else if (!args.get(1).isEmpty())
{
if (user.isPlayer())
{
Utils.sendMessage(user, user.getTranslation("challenges.messages.not-completed"));
Utils.sendMessage(user,
this.getWorld(),
Constants.MESSAGES + "not-completed");
}
else
{
Expand All @@ -153,7 +163,9 @@ else if (!args.get(1).isEmpty())
{
if (user.isPlayer())
{
Utils.sendMessage(user, user.getTranslation("challenges.errors.unknown-challenge"));
Utils.sendMessage(user,
this.getWorld(),
Constants.ERRORS + "unknown-challenge");
}
else
{
Expand Down

0 comments on commit 9953459

Please sign in to comment.