diff --git a/src/main/java/com/songoda/skyblock/command/commands/admin/ChatSpyCommand.java b/src/main/java/com/songoda/skyblock/command/commands/admin/ChatSpyCommand.java index 6974a548..6b62c118 100644 --- a/src/main/java/com/songoda/skyblock/command/commands/admin/ChatSpyCommand.java +++ b/src/main/java/com/songoda/skyblock/command/commands/admin/ChatSpyCommand.java @@ -53,12 +53,13 @@ public class ChatSpyCommand extends SubCommand { } break; case "add": - if(args.length > 2){ + if(args.length == 2){ OfflinePlayer offlinePlayer = new OfflinePlayer(args[1]); Island island = islandManager.getIslandByPlayer(offlinePlayer.getBukkitOfflinePlayer()); if(island != null) { playerData.addChatSpyIsland(island); - messageManager.sendMessage(player, languageLoad.getString("Command.Island.Admin.ChatSpy.Add.Message")); + messageManager.sendMessage(player, languageLoad.getString("Command.Island.Admin.ChatSpy.Add.Message") + .replace("%owner", new OfflinePlayer(island.getOwnerUUID()).getName())); } else { messageManager.sendMessage(player, languageLoad.getString("Command.Island.Admin.ChatSpy.NullIsland.Message")); } @@ -68,12 +69,13 @@ public class ChatSpyCommand extends SubCommand { } break; case "remove": - if(args.length > 2){ + if(args.length == 2){ OfflinePlayer offlinePlayer = new OfflinePlayer(args[1]); Island island = islandManager.getIslandByPlayer(offlinePlayer.getBukkitOfflinePlayer()); if(island != null) { playerData.removeChatSpyIsland(island); - messageManager.sendMessage(player, languageLoad.getString("Command.Island.Admin.ChatSpy.Remove.Message")); + messageManager.sendMessage(player, languageLoad.getString("Command.Island.Admin.ChatSpy.Remove.Message") + .replace("%owner", new OfflinePlayer(island.getOwnerUUID()).getName())); } else { messageManager.sendMessage(player, languageLoad.getString("Command.Island.Admin.ChatSpy.NullIsland.Message")); } 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 19a8cbc9..26fd9782 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 @@ -4,24 +4,20 @@ import com.songoda.core.compatibility.CompatibleSound; import com.songoda.skyblock.api.event.player.PlayerIslandChatEvent; import com.songoda.skyblock.api.event.player.PlayerIslandChatSwitchEvent; import com.songoda.skyblock.command.SubCommand; -import com.songoda.skyblock.config.FileManager; import com.songoda.skyblock.config.FileManager.Config; import com.songoda.skyblock.island.Island; import com.songoda.skyblock.island.IslandManager; import com.songoda.skyblock.island.IslandRole; import com.songoda.skyblock.message.MessageManager; -import com.songoda.skyblock.placeholder.PlaceholderManager; import com.songoda.skyblock.playerdata.PlayerData; import com.songoda.skyblock.playerdata.PlayerDataManager; import com.songoda.skyblock.sound.SoundManager; import org.bukkit.Bukkit; -import org.bukkit.ChatColor; import org.bukkit.command.ConsoleCommandSender; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; import java.io.File; -import java.util.UUID; public class ChatCommand extends SubCommand { @@ -31,7 +27,6 @@ public class ChatCommand extends SubCommand { MessageManager messageManager = skyblock.getMessageManager(); IslandManager islandManager = skyblock.getIslandManager(); SoundManager soundManager = skyblock.getSoundManager(); - FileManager fileManager = skyblock.getFileManager(); Config config = skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")); FileConfiguration configLoad = config.getFileConfiguration(); @@ -73,37 +68,11 @@ public class ChatCommand extends SubCommand { island = skyblock.getIslandManager().getIsland(player); } - String islandRole = ""; - - if (island.hasRole(IslandRole.Member, player.getUniqueId())) { - islandRole = configLoad.getString("Island.Chat.Format.Role.Member"); - } else if (island.hasRole(IslandRole.Operator, player.getUniqueId())) { - islandRole = configLoad.getString("Island.Chat.Format.Role.Operator"); - } else if (island.hasRole(IslandRole.Owner, player.getUniqueId())) { - islandRole = configLoad.getString("Island.Chat.Format.Role.Owner"); - } - Island finalIsland = island; - String finalIslandRole = islandRole; Bukkit.getScheduler().runTaskAsynchronously(skyblock, () -> { PlayerIslandChatEvent islandChatEvent = new PlayerIslandChatEvent(player, finalIsland.getAPIWrapper(), String.join(" ", args), configLoad.getString("Island.Chat.Format.Message")); Bukkit.getServer().getPluginManager().callEvent(islandChatEvent); - - if (!islandChatEvent.isCancelled()) { - for (UUID islandMembersOnlineList : islandManager.getMembersOnline(finalIsland)) { - Player targetPlayer = Bukkit.getServer().getPlayer(islandMembersOnlineList); - String message = ChatColor.translateAlternateColorCodes('&', messageManager.replaceMessage(targetPlayer, - islandChatEvent.getFormat().replace("%role", finalIslandRole).replace("%player", player.getName()))) - .replace("%message", islandChatEvent.getMessage()); - targetPlayer.sendMessage(message); - } - - if (fileManager.getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration().getBoolean("Island.Chat.OutputToConsole")) { - messageManager.sendMessage(Bukkit.getConsoleSender(), islandChatEvent.getFormat().replace("%role", finalIslandRole).replace("%player", player.getName()) - .replace("%message", islandChatEvent.getMessage())); - } - } }); } } diff --git a/src/main/java/com/songoda/skyblock/listeners/Chat.java b/src/main/java/com/songoda/skyblock/listeners/Chat.java index fb984512..5cf1d898 100644 --- a/src/main/java/com/songoda/skyblock/listeners/Chat.java +++ b/src/main/java/com/songoda/skyblock/listeners/Chat.java @@ -66,21 +66,21 @@ public class Chat implements Listener { if (playerData.isChat()) { event.setCancelled(true); - Config config = skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")); - FileConfiguration configLoad = config.getFileConfiguration(); + Config language = skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")); + FileConfiguration languageLoad = language.getFileConfiguration(); String islandRole = ""; if (island.hasRole(IslandRole.Member, player.getUniqueId())) { - islandRole = configLoad.getString("Island.Chat.Format.Role.Member"); + islandRole = languageLoad.getString("Island.Chat.Format.Role.Member"); } else if (island.hasRole(IslandRole.Operator, player.getUniqueId())) { - islandRole = configLoad.getString("Island.Chat.Format.Role.Operator"); + islandRole = languageLoad.getString("Island.Chat.Format.Role.Operator"); } else if (island.hasRole(IslandRole.Owner, player.getUniqueId())) { - islandRole = configLoad.getString("Island.Chat.Format.Role.Owner"); + islandRole = languageLoad.getString("Island.Chat.Format.Role.Owner"); } PlayerIslandChatEvent islandChatEvent = new PlayerIslandChatEvent(player, island.getAPIWrapper(), - event.getMessage(), configLoad.getString("Island.Chat.Format.Message")); + event.getMessage(), languageLoad.getString("Island.Chat.Format.Message")); Bukkit.getServer().getPluginManager().callEvent(islandChatEvent); if (!islandChatEvent.isCancelled()) { @@ -113,4 +113,60 @@ public class Chat implements Listener { } } } + + @EventHandler(priority = EventPriority.MONITOR,ignoreCancelled = true) + public void onIslandChat(PlayerIslandChatEvent event) { + PlaceholderManager placeholderManager = skyblock.getPlaceholderManager(); + PlayerDataManager playerDataManager = skyblock.getPlayerDataManager(); + MessageManager messageManager = skyblock.getMessageManager(); + IslandManager islandManager = skyblock.getIslandManager(); + FileManager fileManager = skyblock.getFileManager(); + + Island island = event.getIsland().getIsland(); + Player player = event.getPlayer(); + + Config language = skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")); + FileConfiguration languageLoad = language.getFileConfiguration(); + + String islandRole = null; + + if (island.hasRole(IslandRole.Member, player.getUniqueId())) { + islandRole = languageLoad.getString("Island.Chat.Format.Role.Member"); + } else if (island.hasRole(IslandRole.Operator, player.getUniqueId())) { + islandRole = languageLoad.getString("Island.Chat.Format.Role.Operator"); + } else if (island.hasRole(IslandRole.Owner, player.getUniqueId())) { + islandRole = languageLoad.getString("Island.Chat.Format.Role.Owner"); + } + if(islandRole == null) { + islandRole = ""; + } + + + for (UUID islandMembersOnlineList : islandManager.getMembersOnline(island)) { + Player targetPlayer = Bukkit.getServer().getPlayer(islandMembersOnlineList); + String message = ChatColor.translateAlternateColorCodes('&', messageManager.replaceMessage(targetPlayer, + event.getFormat().replace("%role", islandRole).replace("%player", player.getName()))) + .replace("%message", event.getMessage()); + messageManager.sendMessage(targetPlayer, message); + } + + // Spy + for(Player targetPlayer : Bukkit.getServer().getOnlinePlayers()){ + if(!targetPlayer.equals(event.getPlayer()) && targetPlayer.hasPermission("fabledskyblock.admin.chatspy")) { + PlayerData pd = playerDataManager.getPlayerData(targetPlayer); + if(pd != null && pd.isChatSpy() && (pd.isGlobalChatSpy() || pd.isChatSpyIsland(island))) { + String message = ChatColor.translateAlternateColorCodes('&', messageManager.replaceMessage(targetPlayer, + languageLoad.getString("Island.Chat.Spy.Format.Message").replace("%role", islandRole).replace("%player", player.getName()))) + .replace("%islandOwner", new OfflinePlayer(island.getOwnerUUID()).getName()) + .replace("%message", event.getMessage()); + messageManager.sendMessage(targetPlayer, message); + } + } + } + + if (fileManager.getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration().getBoolean("Island.Chat.OutputToConsole")) { + messageManager.sendMessage(Bukkit.getConsoleSender(), event.getFormat().replace("%role", islandRole).replace("%player", player.getName()) + .replace("%message", event.getMessage())); + } + } } diff --git a/src/main/java/com/songoda/skyblock/playerdata/PlayerData.java b/src/main/java/com/songoda/skyblock/playerdata/PlayerData.java index c878f9cf..69bbf8f9 100644 --- a/src/main/java/com/songoda/skyblock/playerdata/PlayerData.java +++ b/src/main/java/com/songoda/skyblock/playerdata/PlayerData.java @@ -60,6 +60,7 @@ public class PlayerData { area = new Area(); chatSpy = getConfig().getFileConfiguration().getBoolean("ChatSpy", false); + spiedIslands = new HashSet<>(); if (getConfig().getFileConfiguration().getString("ChatSpiedIslands") != null) { for (String islandUUID : getConfig().getFileConfiguration().getStringList("ChatSpiedIslands")) {