Skip to content

Commit c99c69a

Browse files
committed
Set addon on login.
This is required so that the Game Mode context is set for any translations that involve prefixes. If this isn't done, then the context is not set until the player issues a command.
1 parent 6a2b515 commit c99c69a

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/main/java/world/bentobox/bentobox/listeners/JoinLeaveListener.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ public void onPlayerJoin(final PlayerJoinEvent event) {
5353
// plugins
5454
return;
5555
}
56+
// Set the addon in the User object - required to have the right context for prefixes in translations
57+
plugin.getIWM().getAddon(event.getPlayer().getWorld()).ifPresent(gm -> user.setAddon(gm));
58+
59+
// Get the UUID
5660
UUID playerUUID = event.getPlayer().getUniqueId();
5761

5862
// Check if player hasn't joined before

src/test/java/world/bentobox/bentobox/listeners/JoinLeaveListenerTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import world.bentobox.bentobox.BentoBox;
4444
import world.bentobox.bentobox.RanksManagerBeforeClassTest;
4545
import world.bentobox.bentobox.Settings;
46+
import world.bentobox.bentobox.api.addons.AddonDescription;
4647
import world.bentobox.bentobox.api.addons.GameModeAddon;
4748
import world.bentobox.bentobox.api.user.User;
4849
import world.bentobox.bentobox.database.objects.Island;
@@ -91,6 +92,8 @@ public class JoinLeaveListenerTest extends RanksManagerBeforeClassTest {
9192
@Mock
9293
private AddonsManager am;
9394

95+
private AddonDescription desc;
96+
9497
/**
9598
*/
9699
@Before
@@ -107,6 +110,8 @@ public void setUp() throws Exception {
107110
when(iwm.isOnLeaveResetInventory(any())).thenReturn(true);
108111
when(iwm.getOverWorlds()).thenReturn(Collections.singletonList(world));
109112
when(iwm.getResetEpoch(any())).thenReturn(20L);
113+
desc = new AddonDescription.Builder("main", "BSkyBlock", "1.0.0").build();
114+
when(gameMode.getDescription()).thenReturn(desc);
110115
Optional<GameModeAddon> opGm = Optional.of(gameMode);
111116
when(iwm.getAddon(any())).thenReturn(opGm);
112117
when(gameMode.getPermissionPrefix()).thenReturn("acidisland.");

0 commit comments

Comments
 (0)