From 4400ac4297b6a3a61bd24df7119f2dfb6233fe15 Mon Sep 17 00:00:00 2001 From: Fabrizio La Rosa Date: Sun, 12 Jul 2020 13:16:18 +0200 Subject: [PATCH] Fixed npe in chat command --- .../command/commands/island/ChatCommand.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/songoda/skyblock/command/commands/island/ChatCommand.java b/src/main/java/com/songoda/skyblock/command/commands/island/ChatCommand.java index a1142150..2b902c89 100644 --- a/src/main/java/com/songoda/skyblock/command/commands/island/ChatCommand.java +++ b/src/main/java/com/songoda/skyblock/command/commands/island/ChatCommand.java @@ -67,13 +67,18 @@ public class ChatCommand extends SubCommand { if (playerData.getOwner() != null) { island = plugin.getIslandManager().getIsland(player); } - - Island finalIsland = island; - Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> { - PlayerIslandChatEvent islandChatEvent = new PlayerIslandChatEvent(player, finalIsland.getAPIWrapper(), - String.join(" ", args), configLoad.getString("Island.Chat.Format.Message")); - Bukkit.getServer().getPluginManager().callEvent(islandChatEvent); - }); + + if (island != null) { + Island finalIsland = island; + Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> { + PlayerIslandChatEvent islandChatEvent = new PlayerIslandChatEvent(player, finalIsland.getAPIWrapper(), + String.join(" ", args), configLoad.getString("Island.Chat.Format.Message")); + Bukkit.getServer().getPluginManager().callEvent(islandChatEvent); + }); + } else { + messageManager.sendMessage(player, configLoad.getString("Command.Island.Chat.Owner.Message")); + soundManager.playSound(player, CompatibleSound.BLOCK_ANVIL_LAND.getSound(), 1.0F, 1.0F); + } } } }