From a26341e36f9c2bb069dc19a06ae4339134863c47 Mon Sep 17 00:00:00 2001 From: Florian CUNY Date: Wed, 17 Apr 2019 22:58:17 +0200 Subject: [PATCH 1/2] Fixed BentoBox still disabling if running on incompatible server This fixes commit https://github.com/BentoBoxWorld/BentoBox/commit/0d6f87242005c542bc1ce04ef392861229fdeb31. --- src/main/java/world/bentobox/bentobox/BentoBox.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/world/bentobox/bentobox/BentoBox.java b/src/main/java/world/bentobox/bentobox/BentoBox.java index bfaadf47a..9f08b592d 100644 --- a/src/main/java/world/bentobox/bentobox/BentoBox.java +++ b/src/main/java/world/bentobox/bentobox/BentoBox.java @@ -88,10 +88,10 @@ public class BentoBox extends JavaPlugin { if (!ServerCompatibility.getInstance().checkCompatibility(this).isCanLaunch()) { // The server's most likely incompatible. // Show a warning - getServer().getLogger().warning("************ Disclaimer **************"); - getServer().getLogger().warning("BentoBox may not be compatible with this server!"); - getServer().getLogger().warning("BentoBox is tested only on the latest version of Spigot."); - return; + logWarning("************ Disclaimer **************"); + logWarning("BentoBox may not be compatible with this server!"); + logWarning("BentoBox is tested only on the latest version of Spigot."); + logWarning("**************************************"); } // Not loaded From 7499b19fea827e44bfb58d346c5086a7fe0f70ad Mon Sep 17 00:00:00 2001 From: tastybento Date: Wed, 17 Apr 2019 22:22:16 -0700 Subject: [PATCH 2/2] Added offline message event. This event is fired if the player is offline but the recipient of a message. --- .../api/events/OfflineMessageEvent.java | 38 +++++++++++++++++++ .../bentobox/bentobox/api/user/User.java | 11 ++++-- .../admin/team/AdminTeamAddCommandTest.java | 1 + .../team/AdminTeamDisbandCommandTest.java | 1 + .../admin/team/AdminTeamKickCommandTest.java | 1 + .../team/IslandTeamKickCommandTest.java | 1 + .../bentobox/bentobox/api/user/UserTest.java | 7 ++-- 7 files changed, 54 insertions(+), 6 deletions(-) create mode 100644 src/main/java/world/bentobox/bentobox/api/events/OfflineMessageEvent.java diff --git a/src/main/java/world/bentobox/bentobox/api/events/OfflineMessageEvent.java b/src/main/java/world/bentobox/bentobox/api/events/OfflineMessageEvent.java new file mode 100644 index 000000000..c3d3d8663 --- /dev/null +++ b/src/main/java/world/bentobox/bentobox/api/events/OfflineMessageEvent.java @@ -0,0 +1,38 @@ +package world.bentobox.bentobox.api.events; + +import java.util.UUID; + +/** + * Fired when a message is going to an offline player + * + * @author tastybento + * @since 1.5.0 + */ +public class OfflineMessageEvent extends PremadeEvent { + private final UUID offlinePlayer; + private final String message; + + /** + * @param offlinePlayer + * @param message + */ + public OfflineMessageEvent(UUID offlinePlayer, String message) { + this.offlinePlayer = offlinePlayer; + this.message = message; + } + + /** + * @return the offlinePlayer + */ + public UUID getOfflinePlayer() { + return offlinePlayer; + } + + /** + * @return the message + */ + public String getMessage() { + return message; + } + +} 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 c6970c86a..f0f60a699 100644 --- a/src/main/java/world/bentobox/bentobox/api/user/User.java +++ b/src/main/java/world/bentobox/bentobox/api/user/User.java @@ -21,11 +21,12 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.PlayerInventory; import org.bukkit.permissions.PermissionAttachmentInfo; import org.bukkit.util.Vector; - import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; + import world.bentobox.bentobox.BentoBox; import world.bentobox.bentobox.api.addons.Addon; +import world.bentobox.bentobox.api.events.OfflineMessageEvent; /** * Combines {@link Player}, {@link OfflinePlayer} and {@link CommandSender} to provide convenience methods related to @@ -131,6 +132,7 @@ public class User { private Player player; private OfflinePlayer offlinePlayer; private final UUID playerUUID; + @Nullable private final CommandSender sender; private Addon addon; @@ -368,8 +370,8 @@ public class User { */ public void sendMessage(String reference, String... variables) { String message = getTranslation(reference, variables); - if (!ChatColor.stripColor(message).trim().isEmpty() && sender != null) { - sender.sendMessage(message); + if (!ChatColor.stripColor(message).trim().isEmpty()) { + sendRawMessage(message); } } @@ -380,6 +382,9 @@ public class User { public void sendRawMessage(String message) { if (sender != null) { sender.sendMessage(message); + } else { + // Offline player fire event + Bukkit.getPluginManager().callEvent(new OfflineMessageEvent(this.playerUUID, message)); } } diff --git a/src/test/java/world/bentobox/bentobox/api/commands/admin/team/AdminTeamAddCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/admin/team/AdminTeamAddCommandTest.java index 3c1e27548..502b2bb82 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/admin/team/AdminTeamAddCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/admin/team/AdminTeamAddCommandTest.java @@ -103,6 +103,7 @@ public class AdminTeamAddCommandTest { BukkitScheduler sch = mock(BukkitScheduler.class); PowerMockito.mockStatic(Bukkit.class); when(Bukkit.getScheduler()).thenReturn(sch); + when(Bukkit.getPluginManager()).thenReturn(mock(PluginManager.class)); // Locales LocalesManager lm = mock(LocalesManager.class); diff --git a/src/test/java/world/bentobox/bentobox/api/commands/admin/team/AdminTeamDisbandCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/admin/team/AdminTeamDisbandCommandTest.java index abbfe36f6..a488079ed 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/admin/team/AdminTeamDisbandCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/admin/team/AdminTeamDisbandCommandTest.java @@ -108,6 +108,7 @@ public class AdminTeamDisbandCommandTest { BukkitScheduler sch = mock(BukkitScheduler.class); PowerMockito.mockStatic(Bukkit.class); when(Bukkit.getScheduler()).thenReturn(sch); + when(Bukkit.getPluginManager()).thenReturn(mock(PluginManager.class)); // Locales LocalesManager lm = mock(LocalesManager.class); diff --git a/src/test/java/world/bentobox/bentobox/api/commands/admin/team/AdminTeamKickCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/admin/team/AdminTeamKickCommandTest.java index 3ac702eab..9ceccc924 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/admin/team/AdminTeamKickCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/admin/team/AdminTeamKickCommandTest.java @@ -107,6 +107,7 @@ public class AdminTeamKickCommandTest { BukkitScheduler sch = mock(BukkitScheduler.class); PowerMockito.mockStatic(Bukkit.class); when(Bukkit.getScheduler()).thenReturn(sch); + when(Bukkit.getPluginManager()).thenReturn(mock(PluginManager.class)); // Locales LocalesManager lm = mock(LocalesManager.class); diff --git a/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamKickCommandTest.java b/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamKickCommandTest.java index f4d8f650c..a41a307b2 100644 --- a/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamKickCommandTest.java +++ b/src/test/java/world/bentobox/bentobox/api/commands/island/team/IslandTeamKickCommandTest.java @@ -112,6 +112,7 @@ public class IslandTeamKickCommandTest { BukkitScheduler sch = mock(BukkitScheduler.class); PowerMockito.mockStatic(Bukkit.class); when(Bukkit.getScheduler()).thenReturn(sch); + when(Bukkit.getPluginManager()).thenReturn(mock(PluginManager.class)); // Locales LocalesManager lm = mock(LocalesManager.class); 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 92635fee8..021e8f228 100644 --- a/src/test/java/world/bentobox/bentobox/api/user/UserTest.java +++ b/src/test/java/world/bentobox/bentobox/api/user/UserTest.java @@ -84,6 +84,7 @@ public class UserTest { when(Bukkit.getServer()).thenReturn(server); when(Bukkit.getPlayer(Mockito.any(UUID.class))).thenReturn(player); when(Bukkit.getLogger()).thenReturn(Logger.getAnonymousLogger()); + when(Bukkit.getPluginManager()).thenReturn(mock(PluginManager.class)); iwm = mock(IslandWorldManager.class); when(plugin.getIWM()).thenReturn(iwm); @@ -451,8 +452,8 @@ public class UserTest { User u = User.getInstance(player); assertEquals(33, u.getPermissionValue("bskyblock.max", 2)); } - - + + /** * Test for {@link User#getPermissionValue(String, int)} */ @@ -473,7 +474,7 @@ public class UserTest { User u = User.getInstance(player); assertEquals(-1, u.getPermissionValue("bskyblock.max", 2)); } - + /** * Test for {@link User#getPermissionValue(String, int)} */