Add support for gamemode-specific translations.

This was a request from Floris
This commit is contained in:
BONNe 2023-03-31 11:12:08 +03:00
parent e0377fd352
commit 9953459e50
14 changed files with 254 additions and 151 deletions

View File

@ -55,7 +55,7 @@ public class ChallengesGlobalPlayerCommand extends CompositeCommand
if (this.gameModeAddons.isEmpty()) if (this.gameModeAddons.isEmpty())
{ {
Utils.sendMessage(user, user.getTranslation(Constants.ERRORS + "not-hooked")); Utils.sendMessage(user, user.getWorld(), Constants.ERRORS + "not-hooked");
return false; return false;
} }
else if (this.gameModeAddons.size() == 1) else if (this.gameModeAddons.size() == 1)
@ -80,7 +80,7 @@ public class ChallengesGlobalPlayerCommand extends CompositeCommand
} }
} }
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) else if (this.<ChallengesAddon>getAddon().getChallengesSettings().getUserGuiMode() == GuiMode.GAMEMODE_LIST)
{ {

View File

@ -8,6 +8,7 @@ import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.util.Util; import world.bentobox.bentobox.util.Util;
import world.bentobox.challenges.ChallengesAddon; import world.bentobox.challenges.ChallengesAddon;
import world.bentobox.challenges.panel.user.ChallengesPanel; import world.bentobox.challenges.panel.user.ChallengesPanel;
import world.bentobox.challenges.utils.Constants;
import world.bentobox.challenges.utils.Utils; import world.bentobox.challenges.utils.Utils;
@ -31,7 +32,7 @@ public class ChallengesPlayerCommand extends CompositeCommand
if (!this.getIWM().inWorld(user.getWorld()) || if (!this.getIWM().inWorld(user.getWorld()) ||
!Util.sameWorld(this.getWorld(), user.getWorld())) { !Util.sameWorld(this.getWorld(), user.getWorld())) {
// Not a GameMode world. // Not a GameMode world.
Utils.sendMessage(user, user.getTranslation("general.errors.wrong-world")); Utils.sendMessage(user, user.getWorld(), "general.errors.wrong-world");
return false; return false;
} }
@ -47,13 +48,13 @@ public class ChallengesPlayerCommand extends CompositeCommand
map(GameModeAddon::getAdminCommand). map(GameModeAddon::getAdminCommand).
map(optionalAdminCommand -> optionalAdminCommand.map(CompositeCommand::getTopLabel).orElse(this.getTopLabel())). map(optionalAdminCommand -> optionalAdminCommand.map(CompositeCommand::getTopLabel).orElse(this.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]", "[command]",
topLabel + " " + this.<ChallengesAddon>getAddon().getChallengesSettings().getAdminMainCommand().split(" ")[0])); topLabel + " " + this.<ChallengesAddon>getAddon().getChallengesSettings().getAdminMainCommand().split(" ")[0]);
} }
else else
{ {
Utils.sendMessage(user, user.getTranslation("challenges.errors.no-challenges")); Utils.sendMessage(user, this.getWorld(), Constants.ERRORS + "no-challenges");
} }
return false; return false;
@ -62,14 +63,14 @@ public class ChallengesPlayerCommand extends CompositeCommand
if (this.getIslands().getIsland(this.getWorld(), user) == null) if (this.getIslands().getIsland(this.getWorld(), user) == null)
{ {
// Do not open gui if there is no island for this player. // 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; return false;
} else if (ChallengesAddon.CHALLENGES_WORLD_PROTECTION.isSetForWorld(this.getWorld()) && } else if (ChallengesAddon.CHALLENGES_WORLD_PROTECTION.isSetForWorld(this.getWorld()) &&
!this.getIslands().locationIsOnIsland(user.getPlayer(), user.getLocation())) !this.getIslands().locationIsOnIsland(user.getPlayer(), user.getLocation()))
{ {
// Do not open gui if player is not on the island, but challenges requires island for // Do not open gui if player is not on the island, but challenges requires island for
// completion. // completion.
Utils.sendMessage(user, user.getTranslation("challenges.errors.not-on-island")); Utils.sendMessage(user, this.getWorld(), Constants.ERRORS + "not-on-island");
return false; return false;
} }

View File

@ -11,6 +11,7 @@ import world.bentobox.bentobox.util.Util;
import world.bentobox.challenges.ChallengesAddon; import world.bentobox.challenges.ChallengesAddon;
import world.bentobox.challenges.database.object.Challenge; import world.bentobox.challenges.database.object.Challenge;
import world.bentobox.challenges.tasks.TryToComplete; import world.bentobox.challenges.tasks.TryToComplete;
import world.bentobox.challenges.utils.Constants;
import world.bentobox.challenges.utils.Utils; import world.bentobox.challenges.utils.Utils;
@ -54,7 +55,7 @@ public class CompleteChallengeCommand extends CompositeCommand
{ {
if (args.isEmpty()) 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); this.showHelp(this, user);
return false; return false;
} }
@ -73,7 +74,7 @@ public class CompleteChallengeCommand extends CompositeCommand
if (!canMultipleTimes && count > 1) 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; count = 1;
} }
@ -87,7 +88,7 @@ public class CompleteChallengeCommand extends CompositeCommand
} }
else else
{ {
Utils.sendMessage(user, user.getTranslation("challenges.errors.unknown-challenge")); Utils.sendMessage(user, this.getWorld(), Constants.ERRORS + "unknown-challenge");
this.showHelp(this, user); this.showHelp(this, user);
return false; return false;
} }

View File

@ -53,7 +53,7 @@ public class ChallengesGlobalAdminCommand extends CompositeCommand
if (this.gameModeAddons.isEmpty()) if (this.gameModeAddons.isEmpty())
{ {
Utils.sendMessage(user, user.getTranslation(Constants.ERRORS + "not-hooked")); Utils.sendMessage(user, this.getWorld(), Constants.ERRORS + "not-hooked");
return false; return false;
} }
else if (this.gameModeAddons.size() == 1) else if (this.gameModeAddons.size() == 1)

View File

@ -56,7 +56,7 @@ public class CompleteCommand extends CompositeCommand
{ {
if (user.isPlayer()) if (user.isPlayer())
{ {
Utils.sendMessage(user, user.getTranslation("challenges.errors.no-name")); Utils.sendMessage(user, this.getWorld(), Constants.ERRORS + "no-name");
} }
else else
{ {
@ -67,7 +67,7 @@ public class CompleteCommand extends CompositeCommand
{ {
if (user.isPlayer()) if (user.isPlayer())
{ {
Utils.sendMessage(user, user.getTranslation("challenges.errors.missing-arguments")); Utils.sendMessage(user, this.getWorld(), Constants.ERRORS + "missing-arguments");
} }
else else
{ {
@ -82,9 +82,11 @@ public class CompleteCommand extends CompositeCommand
{ {
if (user.isPlayer()) if (user.isPlayer())
{ {
Utils.sendMessage(user, user.getTranslation("general.errors.unknown-player", Utils.sendMessage(user,
this.getWorld(),
"general.errors.unknown-player",
TextVariables.NAME, TextVariables.NAME,
args.get(0))); args.get(0));
} }
else else
{ {
@ -109,9 +111,11 @@ public class CompleteCommand extends CompositeCommand
if (user.isPlayer()) 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_NAME, challenge.getFriendlyName(),
Constants.PARAMETER_PLAYER, target.getName())); Constants.PARAMETER_PLAYER, target.getName());
} }
else else
{ {
@ -123,7 +127,9 @@ public class CompleteCommand extends CompositeCommand
{ {
if (user.isPlayer()) if (user.isPlayer())
{ {
Utils.sendMessage(user, user.getTranslation("challenges.messages.already-completed")); Utils.sendMessage(user,
this.getWorld(),
Constants.MESSAGES + "already-completed");
} }
else else
{ {
@ -137,7 +143,9 @@ public class CompleteCommand extends CompositeCommand
{ {
if (user.isPlayer()) if (user.isPlayer())
{ {
Utils.sendMessage(user, user.getTranslation("challenges.errors.unknown-challenge")); Utils.sendMessage(user,
this.getWorld(),
Constants.ERRORS + "unknown-challenge");
} }
else else
{ {

View File

@ -49,13 +49,13 @@ public class ReloadChallenges extends CompositeCommand
if (args.isEmpty()) if (args.isEmpty())
{ {
this.manager.load(); this.manager.load();
Utils.sendMessage(user, user.getTranslation("general.success")); Utils.sendMessage(user, this.getWorld(), "general.success");
return true; return true;
} }
else if (args.get(0).equalsIgnoreCase("hard")) else if (args.get(0).equalsIgnoreCase("hard"))
{ {
this.manager.reload(); this.manager.reload();
Utils.sendMessage(user, user.getTranslation("general.success")); Utils.sendMessage(user, this.getWorld(), "general.success");
return true; return true;
} }
else else

View File

@ -56,7 +56,7 @@ public class ResetCommand extends CompositeCommand
{ {
if (user.isPlayer()) if (user.isPlayer())
{ {
Utils.sendMessage(user, user.getTranslation("challenges.errors.no-name")); Utils.sendMessage(user, this.getWorld(), Constants.ERRORS + "no-name");
} }
else else
{ {
@ -67,7 +67,7 @@ public class ResetCommand extends CompositeCommand
{ {
if (user.isPlayer()) if (user.isPlayer())
{ {
Utils.sendMessage(user, user.getTranslation("challenges.errors.missing-arguments")); Utils.sendMessage(user, this.getWorld(), Constants.ERRORS + "missing-arguments");
} }
else else
{ {
@ -82,8 +82,11 @@ public class ResetCommand extends CompositeCommand
{ {
if (user.isPlayer()) if (user.isPlayer())
{ {
Utils.sendMessage(user, user.getTranslation("general.errors.unknown-player", Utils.sendMessage(user,
TextVariables.NAME, args.get(0))); this.getWorld(),
Constants.ERRORS + "unknown-player",
TextVariables.NAME,
args.get(0));
} }
else else
{ {
@ -102,8 +105,11 @@ public class ResetCommand extends CompositeCommand
if (user.isPlayer()) if (user.isPlayer())
{ {
Utils.sendMessage(user, user.getTranslation("challenges.messages.reset-all", Utils.sendMessage(user,
Constants.PARAMETER_PLAYER, target.getName())); this.getWorld(),
Constants.MESSAGES + "reset-all",
Constants.PARAMETER_PLAYER,
target.getName());
} }
else else
{ {
@ -125,9 +131,11 @@ public class ResetCommand extends CompositeCommand
if (user.isPlayer()) 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_NAME, challenge.getFriendlyName(),
Constants.PARAMETER_PLAYER, target.getName())); Constants.PARAMETER_PLAYER, target.getName());
} }
else else
{ {
@ -139,7 +147,9 @@ public class ResetCommand extends CompositeCommand
{ {
if (user.isPlayer()) if (user.isPlayer())
{ {
Utils.sendMessage(user, user.getTranslation("challenges.messages.not-completed")); Utils.sendMessage(user,
this.getWorld(),
Constants.MESSAGES + "not-completed");
} }
else else
{ {
@ -153,7 +163,9 @@ public class ResetCommand extends CompositeCommand
{ {
if (user.isPlayer()) if (user.isPlayer())
{ {
Utils.sendMessage(user, user.getTranslation("challenges.errors.unknown-challenge")); Utils.sendMessage(user,
this.getWorld(),
Constants.ERRORS + "unknown-challenge");
} }
else else
{ {

View File

@ -82,7 +82,11 @@ public class ChallengesImportManager
{ {
if (user != null) if (user != null)
{ {
Utils.sendMessage(user, user.getTranslation(Constants.ERRORS + "no-file", Constants.PARAMETER_FILE, file)); Utils.sendMessage(user,
world,
Constants.ERRORS + "no-file",
Constants.PARAMETER_FILE,
file);
} }
return; return;
@ -98,8 +102,11 @@ public class ChallengesImportManager
{ {
if (user != null) if (user != null)
{ {
Utils.sendMessage(user, user.getTranslation(Constants.ERRORS + "no-load", Utils.sendMessage(user,
Constants.PARAMETER_FILE, file, TextVariables.DESCRIPTION, e.getMessage())); world,
Constants.ERRORS + "no-load",
Constants.PARAMETER_FILE, file,
TextVariables.DESCRIPTION, e.getMessage());
} }
this.addon.logError("Exception when loading file. " + e.getMessage()); this.addon.logError("Exception when loading file. " + e.getMessage());
@ -114,8 +121,9 @@ public class ChallengesImportManager
if (user != null) if (user != null)
{ {
Utils.sendMessage(user, Utils.sendMessage(user,
user.getTranslation(Constants.ERRORS + "not-a-gamemode-world", world,
Constants.PARAMETER_WORLD, world.getName())); Constants.ERRORS + "not-a-gamemode-world",
Constants.PARAMETER_WORLD, world.getName());
} }
this.addon.logWarning("Given world is not a gamemode world."); this.addon.logWarning("Given world is not a gamemode world.");
@ -151,6 +159,7 @@ public class ChallengesImportManager
challengeCount = reader.getKeys(false).stream(). challengeCount = reader.getKeys(false).stream().
mapToInt(challengeId -> this.createChallenge(challengeId, mapToInt(challengeId -> this.createChallenge(challengeId,
prefix, prefix,
world,
reader.getConfigurationSection(challengeId))). reader.getConfigurationSection(challengeId))).
sum(); sum();
} }
@ -174,9 +183,10 @@ public class ChallengesImportManager
if (user != null) if (user != null)
{ {
Utils.sendMessage(user, Utils.sendMessage(user,
user.getTranslation(Constants.MESSAGES + "import-count", world,
"[levels]", String.valueOf(levelCount), Constants.MESSAGES + "import-count",
"[challenges]", String.valueOf(challengeCount))); "[levels]", String.valueOf(levelCount),
"[challenges]", String.valueOf(challengeCount));
} }
this.addon.log("Imported " + challengeCount + " challenges and " + this.addon.log("Imported " + challengeCount + " challenges and " +
@ -188,11 +198,13 @@ public class ChallengesImportManager
* This method creates challenge from given config section. * This method creates challenge from given config section.
* @param challengeId Challenge ID. * @param challengeId Challenge ID.
* @param prefix GameMode prefix. * @param prefix GameMode prefix.
* @param world world where challenge is created.
* @param section Configuration Section that contains information. * @param section Configuration Section that contains information.
* @return 1 if challenge is created, otherwise 0. * @return 1 if challenge is created, otherwise 0.
*/ */
private int createChallenge(String challengeId, private int createChallenge(String challengeId,
String prefix, String prefix,
World world,
@Nullable ConfigurationSection section) @Nullable ConfigurationSection section)
{ {
if (section == null) if (section == null)
@ -266,7 +278,7 @@ public class ChallengesImportManager
} }
this.addon.getChallengesManager().saveChallenge(challenge); this.addon.getChallengesManager().saveChallenge(challenge);
this.addon.getChallengesManager().loadChallenge(challenge, true, null, true); this.addon.getChallengesManager().loadChallenge(challenge, world, true, null, true);
} }
catch (Exception e) catch (Exception e)
{ {
@ -632,7 +644,7 @@ public class ChallengesImportManager
} }
this.addon.getChallengesManager().saveLevel(level); this.addon.getChallengesManager().saveLevel(level);
this.addon.getChallengesManager().loadLevel(level, true, null, true); this.addon.getChallengesManager().loadLevel(level, world,true, null, true);
} }
catch (Exception ignored) catch (Exception ignored)
{ {
@ -696,7 +708,7 @@ public class ChallengesImportManager
challenge.setLevel(uniqueIDPrefix + challenge.getLevel()); challenge.setLevel(uniqueIDPrefix + challenge.getLevel());
} }
// Load challenge in memory // Load challenge in memory
manager.loadChallenge(challenge, false, user, user == null); manager.loadChallenge(challenge, world, false, user, user == null);
}); });
downloadedChallenges.getLevelList().forEach(challengeLevel -> { downloadedChallenges.getLevelList().forEach(challengeLevel -> {
@ -709,7 +721,7 @@ public class ChallengesImportManager
map(challenge -> uniqueIDPrefix + challenge). map(challenge -> uniqueIDPrefix + challenge).
collect(Collectors.toSet())); collect(Collectors.toSet()));
// Load level in memory // Load level in memory
manager.loadLevel(challengeLevel, false, user, user == null); manager.loadLevel(challengeLevel, world, false, user, user == null);
}); });
} }
catch (Exception e) catch (Exception e)
@ -746,7 +758,7 @@ public class ChallengesImportManager
{ {
if (user.isPlayer()) if (user.isPlayer())
{ {
Utils.sendMessage(user, user.getTranslation("challenges.errors.exist-challenges-or-levels")); Utils.sendMessage(user, world, Constants.ERRORS + "exist-challenges-or-levels");
} }
else else
{ {
@ -773,7 +785,7 @@ public class ChallengesImportManager
challenge.setLevel(uniqueIDPrefix + challenge.getLevel()); challenge.setLevel(uniqueIDPrefix + challenge.getLevel());
} }
// Load challenge in memory // Load challenge in memory
manager.loadChallenge(challenge, false, user, user == null); manager.loadChallenge(challenge, world, false, user, user == null);
}); });
downloadedChallenges.getLevelList().forEach(challengeLevel -> { downloadedChallenges.getLevelList().forEach(challengeLevel -> {
@ -786,7 +798,7 @@ public class ChallengesImportManager
map(challenge -> uniqueIDPrefix + challenge). map(challenge -> uniqueIDPrefix + challenge).
collect(Collectors.toSet())); collect(Collectors.toSet()));
// Load level in memory // Load level in memory
manager.loadLevel(challengeLevel, false, user, user == null); manager.loadLevel(challengeLevel, world, false, user, user == null);
}); });
} }
catch (Exception e) catch (Exception e)
@ -815,8 +827,9 @@ public class ChallengesImportManager
if (user.isPlayer()) if (user.isPlayer())
{ {
Utils.sendMessage(user, Utils.sendMessage(user,
user.getTranslation(Constants.ERRORS + "file-exist", world,
Constants.PARAMETER_FILE, fileName)); Constants.ERRORS + "file-exist",
Constants.PARAMETER_FILE, fileName);
} }
else else
{ {
@ -882,9 +895,10 @@ public class ChallengesImportManager
if (user.isPlayer()) if (user.isPlayer())
{ {
Utils.sendMessage(user, Utils.sendMessage(user,
user.getTranslation(Constants.ERRORS + "no-load", world,
Constants.PARAMETER_FILE, fileName, Constants.ERRORS + "no-load",
TextVariables.DESCRIPTION, e.getMessage())); Constants.PARAMETER_FILE, fileName,
TextVariables.DESCRIPTION, e.getMessage());
} }
this.addon.logError("Could not save json file: " + e.getMessage()); this.addon.logError("Could not save json file: " + e.getMessage());
@ -894,9 +908,10 @@ public class ChallengesImportManager
if (user.isPlayer()) if (user.isPlayer())
{ {
Utils.sendMessage(user, Utils.sendMessage(user,
user.getTranslation(Constants.CONVERSATIONS + "database-export-completed", world,
Constants.PARAMETER_WORLD, world.getName(), Constants.CONVERSATIONS + "database-export-completed",
Constants.PARAMETER_FILE, fileName)); Constants.PARAMETER_WORLD, world.getName(),
Constants.PARAMETER_FILE, fileName);
} }
else else
{ {

View File

@ -28,6 +28,7 @@ import world.bentobox.challenges.events.ChallengeCompletedEvent;
import world.bentobox.challenges.events.ChallengeResetAllEvent; import world.bentobox.challenges.events.ChallengeResetAllEvent;
import world.bentobox.challenges.events.ChallengeResetEvent; import world.bentobox.challenges.events.ChallengeResetEvent;
import world.bentobox.challenges.events.LevelCompletedEvent; import world.bentobox.challenges.events.LevelCompletedEvent;
import world.bentobox.challenges.utils.Constants;
import world.bentobox.challenges.utils.LevelStatus; import world.bentobox.challenges.utils.LevelStatus;
import world.bentobox.challenges.utils.Utils; import world.bentobox.challenges.utils.Utils;
@ -97,7 +98,6 @@ public class ChallengesManager
* String for free Challenge Level. * String for free Challenge Level.
*/ */
public static final String FREE = ""; public static final String FREE = "";
public static final String VALUE = "[value]";
public static final String USER_ID = "user-id"; public static final String USER_ID = "user-id";
public static final String CHALLENGE_ID = "challenge-id"; public static final String CHALLENGE_ID = "challenge-id";
public static final String ADMIN_ID = "admin-id"; public static final String ADMIN_ID = "admin-id";
@ -230,7 +230,7 @@ public class ChallengesManager
*/ */
private void loadChallenge(@NonNull Challenge challenge) private void loadChallenge(@NonNull Challenge challenge)
{ {
this.loadChallenge(challenge, true, null, true); this.loadChallenge(challenge, null, true, null, true);
} }
@ -244,9 +244,10 @@ public class ChallengesManager
* @return - true if imported * @return - true if imported
*/ */
public boolean loadChallenge(@Nullable Challenge challenge, public boolean loadChallenge(@Nullable Challenge challenge,
boolean overwrite, World world,
User user, boolean overwrite,
boolean silent) User user,
boolean silent)
{ {
// This may happen if database somehow failed to load challenge and return // This may happen if database somehow failed to load challenge and return
// null as input. // null as input.
@ -254,7 +255,10 @@ public class ChallengesManager
{ {
if (!silent) if (!silent)
{ {
Utils.sendMessage(user, user.getTranslation("load-error", "[value]", "NULL")); Utils.sendMessage(user,
world,
Constants.ERRORS + "load-error",
Constants.PARAMETER_VALUE, "NULL");
} }
return false; return false;
@ -264,8 +268,10 @@ public class ChallengesManager
{ {
if (!silent) if (!silent)
{ {
Utils.sendMessage(user, user.getTranslation("challenges.errors.invalid-challenge", Utils.sendMessage(user,
"[challenge]", challenge.getUniqueId())); world,
Constants.ERRORS + "invalid-challenge",
Constants.PARAMETER_CHALLENGE, challenge.getUniqueId());
} }
this.addon.logWarning("Data for challenge `" + challenge.getUniqueId() + "` is not valid. It could be NULL element in item-stack!"); this.addon.logWarning("Data for challenge `" + challenge.getUniqueId() + "` is not valid. It could be NULL element in item-stack!");
@ -280,8 +286,10 @@ public class ChallengesManager
{ {
if (!silent) if (!silent)
{ {
Utils.sendMessage(user, user.getTranslation("challenges.messages.load-skipping", Utils.sendMessage(user,
VALUE, challenge.getFriendlyName())); world,
Constants.MESSAGES + "load-skipping",
Constants.PARAMETER_VALUE, challenge.getFriendlyName());
} }
return false; return false;
@ -290,8 +298,10 @@ public class ChallengesManager
{ {
if (!silent) if (!silent)
{ {
Utils.sendMessage(user, user.getTranslation("challenges.messages.load-overwriting", Utils.sendMessage(user,
VALUE, challenge.getFriendlyName())); world,
Constants.MESSAGES + "load-overwriting",
Constants.PARAMETER_VALUE, challenge.getFriendlyName());
} }
} }
} }
@ -299,8 +309,10 @@ public class ChallengesManager
{ {
if (!silent) if (!silent)
{ {
Utils.sendMessage(user, user.getTranslation("challenges.messages.load-add", Utils.sendMessage(user,
VALUE, challenge.getFriendlyName())); world,
Constants.MESSAGES + "load-add",
Constants.PARAMETER_VALUE, challenge.getFriendlyName());
} }
} }
@ -316,7 +328,7 @@ public class ChallengesManager
*/ */
private void loadLevel(@NonNull ChallengeLevel level) private void loadLevel(@NonNull ChallengeLevel level)
{ {
this.loadLevel(level, true, null, true); this.loadLevel(level, null, true, null, true);
} }
@ -331,6 +343,7 @@ public class ChallengesManager
* @return boolean that indicate about load status. * @return boolean that indicate about load status.
*/ */
public boolean loadLevel(@Nullable ChallengeLevel level, public boolean loadLevel(@Nullable ChallengeLevel level,
World world,
boolean overwrite, boolean overwrite,
User user, User user,
boolean silent) boolean silent)
@ -341,7 +354,10 @@ public class ChallengesManager
{ {
if (!silent) if (!silent)
{ {
Utils.sendMessage(user, user.getTranslation("load-error", "[value]", "NULL")); Utils.sendMessage(user,
world,
Constants.ERRORS + "load-error",
Constants.PARAMETER_VALUE, "NULL");
} }
return false; return false;
@ -351,8 +367,10 @@ public class ChallengesManager
{ {
if (!silent) if (!silent)
{ {
Utils.sendMessage(user, user.getTranslation("challenges.errors.invalid-level", Utils.sendMessage(user,
"[level]", level.getUniqueId())); world,
Constants.ERRORS + "invalid-level",
"[level]", level.getUniqueId());
} }
this.addon.logWarning("Data for level `" + level.getUniqueId() + "` is not valid. It could be NULL element in item-stack!"); this.addon.logWarning("Data for level `" + level.getUniqueId() + "` is not valid. It could be NULL element in item-stack!");
@ -363,8 +381,10 @@ public class ChallengesManager
{ {
if (user != null) if (user != null)
{ {
Utils.sendMessage(user, user.getTranslation("challenges.errors.load-error", Utils.sendMessage(user,
VALUE, level.getFriendlyName())); world,
Constants.ERRORS + "load-error",
Constants.PARAMETER_VALUE, level.getFriendlyName());
} }
else else
{ {
@ -380,8 +400,10 @@ public class ChallengesManager
{ {
if (!silent) if (!silent)
{ {
Utils.sendMessage(user, user.getTranslation("challenges.messages.load-skipping", Utils.sendMessage(user,
VALUE, level.getFriendlyName())); world,
Constants.MESSAGES + "load-skipping",
Constants.PARAMETER_VALUE, level.getFriendlyName());
} }
return false; return false;
@ -390,8 +412,10 @@ public class ChallengesManager
{ {
if (!silent) if (!silent)
{ {
Utils.sendMessage(user, user.getTranslation("challenges.messages.load-overwriting", Utils.sendMessage(user,
VALUE, level.getFriendlyName())); world,
Constants.MESSAGES + "load-overwriting",
Constants.PARAMETER_VALUE, level.getFriendlyName());
} }
} }
} }
@ -399,8 +423,10 @@ public class ChallengesManager
{ {
if (!silent) if (!silent)
{ {
Utils.sendMessage(user, user.getTranslation("challenges.messages.load-add", Utils.sendMessage(user,
VALUE, level.getFriendlyName())); world,
Constants.MESSAGES + "load-add",
Constants.PARAMETER_VALUE, level.getFriendlyName());
} }
} }
@ -486,7 +512,7 @@ public class ChallengesManager
if (!this.challengeCacheData.containsKey(uniqueID)) if (!this.challengeCacheData.containsKey(uniqueID))
{ {
if (!this.challengeDatabase.objectExists(uniqueID) || if (!this.challengeDatabase.objectExists(uniqueID) ||
!this.loadChallenge(this.challengeDatabase.loadObject(uniqueID), false, null, true)) !this.loadChallenge(this.challengeDatabase.loadObject(uniqueID), Bukkit.getWorld(level.getWorld()), false, null, true))
{ {
this.addon.logError("Cannot find " + uniqueID + " challenge for " + level.getUniqueId()); this.addon.logError("Cannot find " + uniqueID + " challenge for " + level.getUniqueId());
return false; return false;
@ -640,7 +666,9 @@ public class ChallengesManager
if (user.isPlayer()) if (user.isPlayer())
{ {
Utils.sendMessage(user, user.getTranslation("challenges.messages.migrate-start")); Utils.sendMessage(user,
world,
Constants.MESSAGES + "migrate-start");
} }
else else
{ {
@ -656,7 +684,9 @@ public class ChallengesManager
if (user.isPlayer()) if (user.isPlayer())
{ {
Utils.sendMessage(user, user.getTranslation("challenges.messages.migrate-end")); Utils.sendMessage(user,
world,
Constants.MESSAGES + "migrate-end");
} }
else else
{ {
@ -667,7 +697,9 @@ public class ChallengesManager
{ {
if (user.isPlayer()) if (user.isPlayer())
{ {
Utils.sendMessage(user, user.getTranslation("challenges.messages.migrate-not")); Utils.sendMessage(user,
world,
Constants.MESSAGES + "migrate-not");
} }
else else
{ {

View File

@ -156,7 +156,7 @@ public class EditChallengePanel extends CommonPanel
// This will ensure that all main things will be always stored // This will ensure that all main things will be always stored
this.addon.getChallengesManager().saveChallenge(this.challenge); this.addon.getChallengesManager().saveChallenge(this.challenge);
// If for some reason challenge is not loaded, do it. // If for some reason challenge is not loaded, do it.
this.addon.getChallengesManager().loadChallenge(this.challenge, false, null, true); this.addon.getChallengesManager().loadChallenge(this.challenge, this.world,false, null, true);
panelBuilder.build(); panelBuilder.build();
} }
@ -445,8 +445,10 @@ public class EditChallengePanel extends CommonPanel
else else
{ {
Utils.sendMessage(this.user, Utils.sendMessage(this.user,
this.user.getTranslation(Constants.CONVERSATIONS + "invalid-challenge", this.world,
"[challenge]", this.challenge.getFriendlyName())); Constants.CONVERSATIONS + "invalid-challenge",
Constants.PARAMETER_CHALLENGE,
this.challenge.getFriendlyName());
this.challenge.setDeployed(false); this.challenge.setDeployed(false);
} }

View File

@ -166,8 +166,9 @@ public class LibraryPanel extends CommonPagedPanel<LibraryEntry>
{ {
if (this.libraryEntries.isEmpty()) if (this.libraryEntries.isEmpty())
{ {
Utils.sendMessage(this.user, this.user.getTranslation( Utils.sendMessage(this.user,
Constants.ERRORS + "no-library-entries")); this.world,
Constants.ERRORS + "no-library-entries");
return; return;
} }
@ -311,8 +312,9 @@ public class LibraryPanel extends CommonPagedPanel<LibraryEntry>
{ {
this.blockedForDownland = true; this.blockedForDownland = true;
Utils.sendMessage(this.user, this.user.getTranslation( Utils.sendMessage(this.user,
Constants.MESSAGES + "start-downloading")); this.world,
Constants.MESSAGES + "start-downloading");
// Run download task after 5 ticks. // Run download task after 5 ticks.
this.updateTask = this.addon.getPlugin().getServer().getScheduler(). this.updateTask = this.addon.getPlugin().getServer().getScheduler().

View File

@ -77,7 +77,7 @@ public class ChallengesPanel extends CommonPanel
if (!this.containsChallenges) if (!this.containsChallenges)
{ {
this.addon.logError("There are no challenges set up!"); this.addon.logError("There are no challenges set up!");
Utils.sendMessage(user, user.getTranslation(Constants.ERRORS + "no-challenges")); Utils.sendMessage(this.user, this.world, Constants.ERRORS + "no-challenges");
return; return;
} }

View File

@ -265,18 +265,21 @@ public class TryToComplete
// Send message about first completion only if it is completed only once. // Send message about first completion only if it is completed only once.
if (result.getFactor() == 1) if (result.getFactor() == 1)
{ {
Utils.sendMessage(this.user, this.user.getTranslation("challenges.messages.you-completed-challenge", Utils.sendMessage(this.user,
"[value]", this.challenge.getFriendlyName())); this.world,
Constants.MESSAGES + "you-completed-challenge",
Constants.PARAMETER_VALUE, this.challenge.getFriendlyName());
} }
if (this.addon.getChallengesSettings().isBroadcastMessages()) if (this.addon.getChallengesSettings().isBroadcastMessages())
{ {
Bukkit.getOnlinePlayers().stream(). Bukkit.getOnlinePlayers().stream().
map(User::getInstance). map(User::getInstance).
forEach(user -> Utils.sendMessage(user, user.getTranslation( forEach(user -> Utils.sendMessage(user,
"challenges.messages.name-has-completed-challenge", this.world,
Constants.MESSAGES + "name-has-completed-challenge",
Constants.PARAMETER_NAME, this.user.getName(), Constants.PARAMETER_NAME, this.user.getName(),
"[value]", this.challenge.getFriendlyName()))); Constants.PARAMETER_VALUE, this.challenge.getFriendlyName()));
} }
// sends title to player on challenge completion // sends title to player on challenge completion
@ -327,14 +330,18 @@ public class TryToComplete
if (result.getFactor() > 1) if (result.getFactor() > 1)
{ {
Utils.sendMessage(this.user, this.user.getTranslation("challenges.messages.you-repeated-challenge-multiple", Utils.sendMessage(this.user,
"[value]", this.challenge.getFriendlyName(), this.world,
"[count]", Integer.toString(result.getFactor()))); Constants.MESSAGES + "you-repeated-challenge-multiple",
Constants.PARAMETER_VALUE, this.challenge.getFriendlyName(),
"[count]", Integer.toString(result.getFactor()));
} }
else else
{ {
Utils.sendMessage(this.user, this.user.getTranslation("challenges.messages.you-repeated-challenge", Utils.sendMessage(this.user,
"[value]", this.challenge.getFriendlyName())); this.world,
Constants.MESSAGES + "you-repeated-challenge",
Constants.PARAMETER_VALUE, this.challenge.getFriendlyName());
} }
} }
@ -372,17 +379,20 @@ public class TryToComplete
// Run commands // Run commands
this.runCommands(level.getRewardCommands()); this.runCommands(level.getRewardCommands());
Utils.sendMessage(this.user, this.user.getTranslation("challenges.messages.you-completed-level", Utils.sendMessage(this.user,
"[value]", level.getFriendlyName())); this.world,
Constants.MESSAGES + "you-completed-level",
Constants.PARAMETER_VALUE, level.getFriendlyName());
if (this.addon.getChallengesSettings().isBroadcastMessages()) if (this.addon.getChallengesSettings().isBroadcastMessages())
{ {
Bukkit.getOnlinePlayers().stream(). Bukkit.getOnlinePlayers().stream().
map(User::getInstance). map(User::getInstance).
forEach(user -> Utils.sendMessage(user, user.getTranslation( forEach(user -> Utils.sendMessage(user,
"challenges.messages.name-has-completed-level", this.world,
Constants.MESSAGES + "name-has-completed-level",
Constants.PARAMETER_NAME, this.user.getName(), Constants.PARAMETER_NAME, this.user.getName(),
"[value]", level.getFriendlyName()))); Constants.PARAMETER_VALUE, level.getFriendlyName()));
} }
this.manager.setLevelComplete(this.user, this.world, level); this.manager.setLevelComplete(this.user, this.world, level);
@ -447,7 +457,8 @@ public class TryToComplete
if (sumEverything != removedAmount) if (sumEverything != removedAmount)
{ {
Utils.sendMessage(this.user, Utils.sendMessage(this.user,
this.user.getTranslation("challenges.errors.cannot-remove-items")); this.world,
Constants.ERRORS + "cannot-remove-items");
result.removedItems = removedItems; result.removedItems = removedItems;
result.meetsRequirements = false; result.meetsRequirements = false;
@ -661,18 +672,18 @@ public class TryToComplete
// Check the world // Check the world
if (!this.challenge.isDeployed()) if (!this.challenge.isDeployed())
{ {
Utils.sendMessage(this.user, this.user.getTranslation("challenges.errors.not-deployed")); Utils.sendMessage(this.user, this.world, Constants.ERRORS + "not-deployed");
result = EMPTY_RESULT; result = EMPTY_RESULT;
} }
else if (maxTimes < 1) else if (maxTimes < 1)
{ {
Utils.sendMessage(this.user, this.user.getTranslation("challenges.errors.not-valid-integer")); Utils.sendMessage(this.user, this.world, Constants.ERRORS + "not-valid-integer");
result = EMPTY_RESULT; result = EMPTY_RESULT;
} }
else if (Util.getWorld(this.world) != Util.getWorld(this.user.getWorld()) || else if (Util.getWorld(this.world) != Util.getWorld(this.user.getWorld()) ||
!this.challenge.matchGameMode(Utils.getGameMode(this.world))) !this.challenge.matchGameMode(Utils.getGameMode(this.world)))
{ {
Utils.sendMessage(this.user, this.user.getTranslation("general.errors.wrong-world")); Utils.sendMessage(this.user, this.world, "general.errors.wrong-world");
result = EMPTY_RESULT; result = EMPTY_RESULT;
} }
// Player is not on island // Player is not on island
@ -680,7 +691,7 @@ public class TryToComplete
ChallengesAddon.CHALLENGES_WORLD_PROTECTION.isSetForWorld(this.world) && ChallengesAddon.CHALLENGES_WORLD_PROTECTION.isSetForWorld(this.world) &&
!this.addon.getIslands().locationIsOnIsland(this.user.getPlayer(), this.user.getLocation())) !this.addon.getIslands().locationIsOnIsland(this.user.getPlayer(), this.user.getLocation()))
{ {
Utils.sendMessage(this.user, this.user.getTranslation("challenges.errors.not-on-island")); Utils.sendMessage(this.user, this.world, Constants.MESSAGES + "not-on-island");
result = EMPTY_RESULT; result = EMPTY_RESULT;
} }
// Check player permission // Check player permission
@ -688,27 +699,27 @@ public class TryToComplete
map(i -> i.isAllowed(this.user, ChallengesAddon.CHALLENGES_ISLAND_PROTECTION)). map(i -> i.isAllowed(this.user, ChallengesAddon.CHALLENGES_ISLAND_PROTECTION)).
orElse(false)) orElse(false))
{ {
Utils.sendMessage(this.user, this.user.getTranslation("challenges.errors.no-rank")); Utils.sendMessage(this.user, this.world, Constants.MESSAGES + "no-rank");
result = EMPTY_RESULT; result = EMPTY_RESULT;
} }
// Check if user has unlocked challenges level. // Check if user has unlocked challenges level.
else if (!this.challenge.getLevel().equals(ChallengesManager.FREE) && else if (!this.challenge.getLevel().equals(ChallengesManager.FREE) &&
!this.manager.isLevelUnlocked(this.user, this.world, this.manager.getLevel(this.challenge.getLevel()))) !this.manager.isLevelUnlocked(this.user, this.world, this.manager.getLevel(this.challenge.getLevel())))
{ {
Utils.sendMessage(this.user, this.user.getTranslation("challenges.errors.challenge-level-not-available")); Utils.sendMessage(this.user, this.world, Constants.ERRORS + "challenge-level-not-available");
result = EMPTY_RESULT; result = EMPTY_RESULT;
} }
// Check max times // Check max times
else if (this.challenge.isRepeatable() && this.challenge.getMaxTimes() > 0 && else if (this.challenge.isRepeatable() && this.challenge.getMaxTimes() > 0 &&
this.manager.getChallengeTimes(this.user, this.world, this.challenge) >= this.challenge.getMaxTimes()) this.manager.getChallengeTimes(this.user, this.world, this.challenge) >= this.challenge.getMaxTimes())
{ {
Utils.sendMessage(this.user, this.user.getTranslation("challenges.errors.not-repeatable")); Utils.sendMessage(this.user, this.world, Constants.ERRORS + "not-repeatable");
result = EMPTY_RESULT; result = EMPTY_RESULT;
} }
// Check repeatability // Check repeatability
else if (!this.challenge.isRepeatable() && this.manager.isChallengeComplete(this.user, this.world, this.challenge)) else if (!this.challenge.isRepeatable() && this.manager.isChallengeComplete(this.user, this.world, this.challenge))
{ {
Utils.sendMessage(this.user, this.user.getTranslation("challenges.errors.not-repeatable")); Utils.sendMessage(this.user, this.world, Constants.ERRORS + "not-repeatable");
result = EMPTY_RESULT; result = EMPTY_RESULT;
} }
// Check if timeout is not broken // Check if timeout is not broken
@ -717,22 +728,22 @@ public class TryToComplete
long missing = this.manager.getLastCompletionDate(this.user, this.world, challenge) + long missing = this.manager.getLastCompletionDate(this.user, this.world, challenge) +
this.challenge.getTimeout() - System.currentTimeMillis(); this.challenge.getTimeout() - System.currentTimeMillis();
Utils.sendMessage(this.user, this.user.getTranslation("challenges.errors.timeout", Utils.sendMessage(this.user, this.world, Constants.ERRORS + "timeout",
"[timeout]", Utils.parseDuration(Duration.ofMillis(this.challenge.getTimeout()), this.user), "[timeout]", Utils.parseDuration(Duration.ofMillis(this.challenge.getTimeout()), this.user),
"[wait-time]", Utils.parseDuration(Duration.ofMillis(missing), this.user))); "[wait-time]", Utils.parseDuration(Duration.ofMillis(missing), this.user));
result = EMPTY_RESULT; result = EMPTY_RESULT;
} }
// Check environment // Check environment
else if (!this.challenge.getEnvironment().isEmpty() && else if (!this.challenge.getEnvironment().isEmpty() &&
!this.challenge.getEnvironment().contains(this.user.getWorld().getEnvironment())) !this.challenge.getEnvironment().contains(this.user.getWorld().getEnvironment()))
{ {
Utils.sendMessage(this.user, this.user.getTranslation("challenges.errors.wrong-environment")); Utils.sendMessage(this.user, this.world, Constants.ERRORS + "wrong-environment");
result = EMPTY_RESULT; result = EMPTY_RESULT;
} }
// Check permission // Check permission
else if (!this.checkPermissions()) else if (!this.checkPermissions())
{ {
Utils.sendMessage(this.user, this.user.getTranslation("general.errors.no-permission")); Utils.sendMessage(this.user, this.world, Constants.ERRORS + "no-permission");
result = EMPTY_RESULT; result = EMPTY_RESULT;
} }
else if (type.equals(ChallengeType.INVENTORY_TYPE)) else if (type.equals(ChallengeType.INVENTORY_TYPE))
@ -929,9 +940,9 @@ public class TryToComplete
if (numInInventory < required.getAmount()) if (numInInventory < required.getAmount())
{ {
Utils.sendMessage(this.user, this.user.getTranslation("challenges.errors.not-enough-items", Utils.sendMessage(this.user, this.world, Constants.ERRORS + "not-enough-items",
"[items]", "[items]",
Utils.prettifyObject(required, this.user))); Utils.prettifyObject(required, this.user));
return EMPTY_RESULT; return EMPTY_RESULT;
} }
@ -1194,13 +1205,16 @@ public class TryToComplete
return new ChallengeResult().setMeetsRequirements().setCompleteFactor(factor).setBlockQueue(blockFromWorld); return new ChallengeResult().setMeetsRequirements().setCompleteFactor(factor).setBlockQueue(blockFromWorld);
} }
Utils.sendMessage(this.user, this.user.getTranslation("challenges.errors.not-close-enough", Utils.sendMessage(this.user,
"[number]", String.valueOf(this.getIslandRequirements().getSearchRadius()))); this.world,
Constants.ERRORS + "not-close-enough",
Constants.PARAMETER_NUMBER, String.valueOf(this.getIslandRequirements().getSearchRadius()));
blocks.forEach((k, v) -> Utils.sendMessage(this.user, blocks.forEach((k, v) -> Utils.sendMessage(this.user,
this.user.getTranslation("challenges.errors.you-still-need", this.world,
"[amount]", String.valueOf(v), Constants.ERRORS + "you-still-need",
"[item]", Utils.prettifyObject(k, this.user)))); "[amount]", String.valueOf(v),
"[item]", Utils.prettifyObject(k, this.user)));
// kick garbage collector // kick garbage collector
@ -1280,9 +1294,11 @@ public class TryToComplete
} }
minimalRequirements.forEach((reqEnt, amount) -> minimalRequirements.forEach((reqEnt, amount) ->
Utils.sendMessage(this.user, this.user.getTranslation("challenges.errors.you-still-need", Utils.sendMessage(this.user,
this.world,
Constants.ERRORS + "you-still-need",
"[amount]", String.valueOf(amount), "[amount]", String.valueOf(amount),
"[item]", Utils.prettifyObject(reqEnt, this.user)))); "[item]", Utils.prettifyObject(reqEnt, this.user)));
// Kick garbage collector // Kick garbage collector
entitiesFound.clear(); entitiesFound.clear();
@ -1363,42 +1379,47 @@ public class TryToComplete
if (!this.addon.isLevelProvided() && requirements.getRequiredIslandLevel() != 0) if (!this.addon.isLevelProvided() && requirements.getRequiredIslandLevel() != 0)
{ {
Utils.sendMessage(this.user, this.user.getTranslation("challenges.errors.missing-addon")); Utils.sendMessage(this.user, this.world, Constants.ERRORS + "missing-addon");
} }
else if (!this.addon.isEconomyProvided() && else if (!this.addon.isEconomyProvided() &&
requirements.getRequiredMoney() != 0) requirements.getRequiredMoney() != 0)
{ {
Utils.sendMessage(this.user, this.user.getTranslation("challenges.errors.missing-addon")); Utils.sendMessage(this.user, this.world, Constants.ERRORS + "missing-addon");
} }
else if (this.addon.isEconomyProvided() && requirements.getRequiredMoney() < 0) else if (this.addon.isEconomyProvided() && requirements.getRequiredMoney() < 0)
{ {
Utils.sendMessage(this.user, this.user.getTranslation("challenges.errors.incorrect")); Utils.sendMessage(this.user, this.world, Constants.ERRORS + "incorrect");
} }
else if (this.addon.isEconomyProvided() && else if (this.addon.isEconomyProvided() &&
!this.addon.getEconomyProvider().has(this.user, requirements.getRequiredMoney())) !this.addon.getEconomyProvider().has(this.user, requirements.getRequiredMoney()))
{ {
Utils.sendMessage(this.user, this.user.getTranslation("challenges.errors.not-enough-money", Utils.sendMessage(this.user,
"[value]", this.world,
Double.toString(requirements.getRequiredMoney()))); Constants.ERRORS + "not-enough-money",
Constants.PARAMETER_VALUE, Double.toString(requirements.getRequiredMoney()));
} }
else if (requirements.getRequiredExperience() < 0) else if (requirements.getRequiredExperience() < 0)
{ {
Utils.sendMessage(this.user, this.user.getTranslation("challenges.errors.incorrect")); Utils.sendMessage(this.user, this.world, Constants.ERRORS + "incorrect");
} }
else if (this.user.getPlayer().getTotalExperience() < requirements.getRequiredExperience() && else if (this.user.getPlayer().getTotalExperience() < requirements.getRequiredExperience() &&
this.user.getPlayer().getGameMode() != GameMode.CREATIVE) this.user.getPlayer().getGameMode() != GameMode.CREATIVE)
{ {
// Players in creative gamemode has infinite amount of EXP. // Players in creative gamemode has infinite amount of EXP.
Utils.sendMessage(this.user, this.user.getTranslation("challenges.errors.not-enough-experience", Utils.sendMessage(this.user,
"[value]", this.world,
Integer.toString(requirements.getRequiredExperience()))); Constants.ERRORS + "not-enough-experience",
Constants.PARAMETER_VALUE,
Integer.toString(requirements.getRequiredExperience()));
} }
else if (this.addon.isLevelProvided() && else if (this.addon.isLevelProvided() &&
this.addon.getLevelAddon().getIslandLevel(this.world, this.user.getUniqueId()) < requirements.getRequiredIslandLevel()) this.addon.getLevelAddon().getIslandLevel(this.world, this.user.getUniqueId()) < requirements.getRequiredIslandLevel())
{ {
Utils.sendMessage(this.user, this.user.getTranslation("challenges.errors.island-level", Utils.sendMessage(this.user,
this.world,
Constants.ERRORS + "island-level",
TextVariables.NUMBER, TextVariables.NUMBER,
String.valueOf(requirements.getRequiredIslandLevel()))); String.valueOf(requirements.getRequiredIslandLevel()));
} }
else else
{ {
@ -1464,24 +1485,30 @@ public class TryToComplete
switch (Objects.requireNonNull(requirements.getStatistic()).getType()) switch (Objects.requireNonNull(requirements.getStatistic()).getType())
{ {
case ITEM, BLOCK -> { case ITEM, BLOCK -> {
Utils.sendMessage(this.user, this.user.getTranslation("challenges.errors.requirement-not-met-material", Utils.sendMessage(this.user,
this.world,
Constants.ERRORS + "requirement-not-met-material",
TextVariables.NUMBER, String.valueOf(requirements.getAmount()), TextVariables.NUMBER, String.valueOf(requirements.getAmount()),
"[statistic]", Utils.prettifyObject(requirements.getStatistic(), this.user), "[statistic]", Utils.prettifyObject(requirements.getStatistic(), this.user),
"[material]", Utils.prettifyObject(requirements.getMaterial(), this.user), "[material]", Utils.prettifyObject(requirements.getMaterial(), this.user),
"[value]", String.valueOf(currentValue))); Constants.PARAMETER_VALUE, String.valueOf(currentValue));
} }
case ENTITY -> { case ENTITY -> {
Utils.sendMessage(this.user, this.user.getTranslation("challenges.errors.requirement-not-met-entity", Utils.sendMessage(this.user,
this.world,
Constants.ERRORS + "requirement-not-met-entity",
TextVariables.NUMBER, String.valueOf(requirements.getAmount()), TextVariables.NUMBER, String.valueOf(requirements.getAmount()),
"[statistic]", Utils.prettifyObject(requirements.getStatistic(), this.user), "[statistic]", Utils.prettifyObject(requirements.getStatistic(), this.user),
"[entity]", Utils.prettifyObject(requirements.getEntity(), this.user), "[entity]", Utils.prettifyObject(requirements.getEntity(), this.user),
"[value]", String.valueOf(currentValue))); Constants.PARAMETER_VALUE, String.valueOf(currentValue));
} }
default -> { default -> {
Utils.sendMessage(this.user, this.user.getTranslation("challenges.errors.requirement-not-met", Utils.sendMessage(this.user,
this.world,
Constants.ERRORS + "requirement-not-met",
TextVariables.NUMBER, String.valueOf(requirements.getAmount()), TextVariables.NUMBER, String.valueOf(requirements.getAmount()),
"[statistic]", Utils.prettifyObject(requirements.getStatistic(), this.user), "[statistic]", Utils.prettifyObject(requirements.getStatistic(), this.user),
"[value]", String.valueOf(currentValue))); Constants.PARAMETER_VALUE, String.valueOf(currentValue));
} }
} }
} }

View File

@ -186,11 +186,14 @@ public class Utils
* Send given message to user and add prefix to the start of the message. * Send given message to user and add prefix to the start of the message.
* *
* @param user User who need to receive message. * @param user User who need to receive message.
* @param message String of message that must be send. * @param world Reference to world where message must be send.
* @param translation String of message that must be send.
* @param parameters Parameters that must be added to translation.
*/ */
public static void sendMessage(User user, String message) public static void sendMessage(User user, World world, String translation, String... parameters)
{ {
user.sendMessage(user.getTranslation(Constants.CONVERSATIONS + "prefix") + message); user.sendMessage(user.getTranslation(world, Constants.CONVERSATIONS + "prefix") +
user.getTranslation(world, translation, parameters));
} }