From b73f63a644393c220921cf50f49f8460222a87ed Mon Sep 17 00:00:00 2001 From: tastybento Date: Thu, 22 Aug 2024 16:53:39 -0700 Subject: [PATCH 1/2] Version 2.5.3 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index a685afaa0..4294b7b9e 100644 --- a/pom.xml +++ b/pom.xml @@ -88,7 +88,7 @@ -LOCAL - 2.5.2 + 2.5.3 bentobox-world https://sonarcloud.io ${project.basedir}/lib From 3d3965fe1732683ba9744166167695ce43b2e06f Mon Sep 17 00:00:00 2001 From: tastybento Date: Thu, 22 Aug 2024 16:54:16 -0700 Subject: [PATCH 2/2] Convert placeholders for [gamemode] and [friendly_name] --- .../world/bentobox/bentobox/api/user/User.java | 16 ++++++++++------ .../bentobox/bentobox/api/user/UserTest.java | 9 +++++++-- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/main/java/world/bentobox/bentobox/api/user/User.java b/src/main/java/world/bentobox/bentobox/api/user/User.java index f9508eb37..7d0e4f12a 100644 --- a/src/main/java/world/bentobox/bentobox/api/user/User.java +++ b/src/main/java/world/bentobox/bentobox/api/user/User.java @@ -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; } diff --git a/src/test/java/world/bentobox/bentobox/api/user/UserTest.java b/src/test/java/world/bentobox/bentobox/api/user/UserTest.java index 5a93797dd..1500e5f46 100644 --- a/src/test/java/world/bentobox/bentobox/api/user/UserTest.java +++ b/src/test/java/world/bentobox/bentobox/api/user/UserTest.java @@ -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(); } /**