diff --git a/src/main/java/world/bentobox/bentobox/listeners/flags/worldsettings/EnterExitListener.java b/src/main/java/world/bentobox/bentobox/listeners/flags/worldsettings/EnterExitListener.java index 6b874b106..e26b4252b 100644 --- a/src/main/java/world/bentobox/bentobox/listeners/flags/worldsettings/EnterExitListener.java +++ b/src/main/java/world/bentobox/bentobox/listeners/flags/worldsettings/EnterExitListener.java @@ -100,8 +100,15 @@ public class EnterExitListener extends FlagListener { // Send message if island is owned by someone if (island.isOwned()) { // Leave messages are always specific to this world - user.notify(island.getWorld(), "protection.flags.ENTER_EXIT_MESSAGES.now-leaving", TextVariables.NAME, (island.getName() != null) ? island.getName() : - user.getTranslation(island.getWorld(), "protection.flags.ENTER_EXIT_MESSAGES.island", TextVariables.NAME, getPlugin().getPlayers().getName(island.getOwner()))); + + // Send specific message if the player is member of this island + if (island.getMemberSet().contains(user.getUniqueId())) { + user.notify(island.getWorld(), "protection.flags.ENTER_EXIT_MESSAGES.now-leaving-your-island", TextVariables.NAME, (island.getName() != null) ? island.getName() : + user.getTranslation(island.getWorld(), "protection.flags.ENTER_EXIT_MESSAGES.island", TextVariables.NAME, getPlugin().getPlayers().getName(island.getOwner()))); + } else { + user.notify(island.getWorld(), "protection.flags.ENTER_EXIT_MESSAGES.now-leaving", TextVariables.NAME, (island.getName() != null) ? island.getName() : + user.getTranslation(island.getWorld(), "protection.flags.ENTER_EXIT_MESSAGES.island", TextVariables.NAME, getPlugin().getPlayers().getName(island.getOwner()))); + } } // Send message if island is unowned, but has a name else if (island.getName() != null) { @@ -123,9 +130,15 @@ public class EnterExitListener extends FlagListener { // Send message if island is owned by someone if (island.isOwned()) { - // Leave messages are always specific to this world - user.notify(island.getWorld(), "protection.flags.ENTER_EXIT_MESSAGES.now-entering", TextVariables.NAME, (island.getName() != null) ? island.getName() : - user.getTranslation(island.getWorld(), "protection.flags.ENTER_EXIT_MESSAGES.island", TextVariables.NAME, getPlugin().getPlayers().getName(island.getOwner()))); + // Enter messages are always specific to this world + // Send specific message if the player is member of this island + if (island.getMemberSet().contains(user.getUniqueId())) { + user.notify(island.getWorld(), "protection.flags.ENTER_EXIT_MESSAGES.now-entering-your-island", TextVariables.NAME, (island.getName() != null) ? island.getName() : + user.getTranslation(island.getWorld(), "protection.flags.ENTER_EXIT_MESSAGES.island", TextVariables.NAME, getPlugin().getPlayers().getName(island.getOwner()))); + } else { + user.notify(island.getWorld(), "protection.flags.ENTER_EXIT_MESSAGES.now-entering", TextVariables.NAME, (island.getName() != null) ? island.getName() : + user.getTranslation(island.getWorld(), "protection.flags.ENTER_EXIT_MESSAGES.island", TextVariables.NAME, getPlugin().getPlayers().getName(island.getOwner()))); + } } // Send message if island is unowned, but has a name else if (island.getName() != null) { diff --git a/src/main/resources/locales/en-US.yml b/src/main/resources/locales/en-US.yml index 32c6f12a7..0a825b85d 100644 --- a/src/main/resources/locales/en-US.yml +++ b/src/main/resources/locales/en-US.yml @@ -834,8 +834,10 @@ protection: description: "Display entry and exit messages" island: "[name]'s island" name: "Enter/Exit messages" - now-entering: "&b Now entering [name]" - now-leaving: "&b Now leaving [name]" + now-entering: "&a Now entering &b [name]&a ." + now-entering-your-island: "&a Now entering your island." + now-leaving: "&a Now leaving &b [name]&a ." + now-leaving-your-island: "&a Now leaving your island." EXPERIENCE_BOTTLE_THROWING: name: "Experience bottle throwing" description: "Toggle throwing experience bottles." diff --git a/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/EnterExitListenerTest.java b/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/EnterExitListenerTest.java index c22304c78..659fd40c7 100644 --- a/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/EnterExitListenerTest.java +++ b/src/test/java/world/bentobox/bentobox/listeners/flags/worldsettings/EnterExitListenerTest.java @@ -14,6 +14,8 @@ import java.util.Map; import java.util.Optional; import java.util.UUID; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Sets; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; @@ -136,6 +138,7 @@ public class EnterExitListenerTest { when(island.getCenter()).thenReturn(loc); when(island.getProtectionRange()).thenReturn(PROTECTION_RANGE); when(island.getOwner()).thenReturn(uuid); + when(island.getMemberSet()).thenReturn(ImmutableSet.of(uuid)); when(island.isOwned()).thenReturn(true); when(im.getIsland(any(), any(UUID.class))).thenReturn(island); @@ -376,4 +379,5 @@ public class EnterExitListenerTest { verify(pim).callEvent(any(IslandExitEvent.class)); } + // TODO add tests to make sure the enter/exit messages work properly when on an island the player is part of. }