mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-21 18:25:12 +01:00
Convert placeholders for [gamemode] and [friendly_name]
This commit is contained in:
parent
b73f63a644
commit
3d3965fe17
@ -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