mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-22 02:35:21 +01:00
Merge pull request #2481 from BentoBoxWorld/placeholder_translation
Placeholder translation
This commit is contained in:
commit
8e3f368602
2
pom.xml
2
pom.xml
@ -88,7 +88,7 @@
|
||||
<!-- Do not change unless you want different name for local builds. -->
|
||||
<build.number>-LOCAL</build.number>
|
||||
<!-- This allows to change between versions. -->
|
||||
<build.version>2.5.2</build.version>
|
||||
<build.version>2.5.3</build.version>
|
||||
<sonar.organization>bentobox-world</sonar.organization>
|
||||
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
|
||||
<server.jars>${project.basedir}/lib</server.jars>
|
||||
|
@ -505,12 +505,6 @@ public class User implements MetaDataAble {
|
||||
private String replacePrefixes(String translation, String[] variables) {
|
||||
for (String prefix : plugin.getLocalesManager().getAvailablePrefixes(this)) {
|
||||
String prefixTranslation = getTranslation("prefixes." + prefix);
|
||||
// Replace the [gamemode] text variable
|
||||
prefixTranslation = prefixTranslation.replace("[gamemode]",
|
||||
addon != null ? addon.getDescription().getName() : "[gamemode]");
|
||||
// Replace the [friendly_name] text variable
|
||||
prefixTranslation = prefixTranslation.replace("[friendly_name]",
|
||||
isPlayer() ? plugin.getIWM().getFriendlyName(getWorld()) : "[friendly_name]");
|
||||
|
||||
// Replace the prefix in the actual message
|
||||
translation = translation.replace("[prefix_" + prefix + "]", prefixTranslation);
|
||||
@ -530,6 +524,16 @@ public class User implements MetaDataAble {
|
||||
if (player != null) {
|
||||
translation = plugin.getPlaceholdersManager().replacePlaceholders(player, translation);
|
||||
}
|
||||
|
||||
// Replace game mode and friendly name in general
|
||||
// Replace the [gamemode] text variable
|
||||
translation = translation.replace("[gamemode]",
|
||||
addon != null ? addon.getDescription().getName() : "[gamemode]");
|
||||
if (getWorld() != null) {
|
||||
// Replace the [friendly_name] text variable
|
||||
translation = translation.replace("[friendly_name]",
|
||||
isPlayer() ? plugin.getIWM().getFriendlyName(getWorld()) : "[friendly_name]");
|
||||
}
|
||||
return translation;
|
||||
}
|
||||
|
||||
|
@ -119,11 +119,16 @@ public class UserTest {
|
||||
// Player
|
||||
when(player.getServer()).thenReturn(server);
|
||||
when(server.getOnlinePlayers()).thenReturn(Collections.emptySet());
|
||||
@NonNull
|
||||
World world = mock(World.class);
|
||||
when(world.getName()).thenReturn("BSkyBlock");
|
||||
when(player.getWorld()).thenReturn(world);
|
||||
|
||||
// IWM
|
||||
when(plugin.getIWM()).thenReturn(iwm);
|
||||
// Addon
|
||||
when(iwm .getAddon(any())).thenReturn(Optional.empty());
|
||||
when(iwm.getAddon(any())).thenReturn(Optional.empty());
|
||||
when(iwm.getFriendlyName(world)).thenReturn("BSkyBlock-Fiendly");
|
||||
|
||||
user = User.getInstance(player);
|
||||
|
||||
@ -930,7 +935,7 @@ public class UserTest {
|
||||
when(addon.getDescription()).thenReturn(new Builder("main", "gameAddon", "1.0").build());
|
||||
p.setAddon(addon);
|
||||
p.getTranslation(TEST_TRANSLATION);
|
||||
verify(addon).getDescription();
|
||||
verify(addon, times(2)).getDescription();
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user