From 4456c5f356585720b89d23b2864375f6773c4a10 Mon Sep 17 00:00:00 2001 From: Fabrizio La Rosa Date: Sat, 4 Jul 2020 07:09:16 +0200 Subject: [PATCH] New ChatSpy admin command --- .../skyblock/command/CommandManager.java | 3 +- .../commands/admin/ChatSpyCommand.java | 61 +++++++++++++++++++ .../com/songoda/skyblock/listeners/Chat.java | 16 ++++- .../skyblock/playerdata/PlayerData.java | 13 ++++ src/main/resources/language.yml | 14 +++++ 5 files changed, 105 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/songoda/skyblock/command/commands/admin/ChatSpyCommand.java diff --git a/src/main/java/com/songoda/skyblock/command/CommandManager.java b/src/main/java/com/songoda/skyblock/command/CommandManager.java index 97778834..84ef286a 100644 --- a/src/main/java/com/songoda/skyblock/command/CommandManager.java +++ b/src/main/java/com/songoda/skyblock/command/CommandManager.java @@ -116,7 +116,8 @@ public class CommandManager implements CommandExecutor, TabCompleter { new com.songoda.skyblock.command.commands.admin.UpgradeCommand(), new StackableCommand(), new AdminBank(), - new SetMaxMembers() + new SetMaxMembers(), + new ChatSpyCommand() ); } 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 new file mode 100644 index 00000000..cc397517 --- /dev/null +++ b/src/main/java/com/songoda/skyblock/command/commands/admin/ChatSpyCommand.java @@ -0,0 +1,61 @@ +package com.songoda.skyblock.command.commands.admin; + +import com.songoda.skyblock.command.SubCommand; +import com.songoda.skyblock.config.FileManager; +import com.songoda.skyblock.message.MessageManager; +import com.songoda.skyblock.playerdata.PlayerData; +import com.songoda.skyblock.playerdata.PlayerDataManager; +import org.bukkit.command.ConsoleCommandSender; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.entity.Player; + +import java.io.File; + +public class ChatSpyCommand extends SubCommand { + + @Override + public void onCommandByPlayer(Player player, String[] args) { + MessageManager messageManager = skyblock.getMessageManager(); + PlayerDataManager playerDataManager = skyblock.getPlayerDataManager(); + FileManager fileManager = skyblock.getFileManager(); + + FileManager.Config language = fileManager.getConfig(new File(skyblock.getDataFolder(), "language.yml")); + FileConfiguration languageLoad = language.getFileConfiguration(); + + PlayerData playerData = playerDataManager.getPlayerData(player); + if(playerData != null) { + if(playerData.isChatSpy()){ + playerData.setChatSpy(false); + messageManager.sendMessage(player, languageLoad.getString("Command.Island.Admin.ChatSpy.Disabled.Message")); + } else { + playerData.setChatSpy(true); + messageManager.sendMessage(player, languageLoad.getString("Command.Island.Admin.ChatSpy.Enabled.Message")); + } + } + } + + @Override + public void onCommandByConsole(ConsoleCommandSender sender, String[] args) { + sender.sendMessage("SkyBlock | Error: You must be a player to perform that command."); + } + + @Override + public String getName() { + return "chatspy"; + } + + @Override + public String getInfoMessagePath() { + return "Command.Island.Admin.ChatSpy.Info.Message"; + } + + @Override + public String[] getAliases() { + return new String[]{"spychat", "spy"}; + } + + @Override + public String[] getArguments() { + return new String[0]; + } +} diff --git a/src/main/java/com/songoda/skyblock/listeners/Chat.java b/src/main/java/com/songoda/skyblock/listeners/Chat.java index 9ea6a431..573a90d2 100644 --- a/src/main/java/com/songoda/skyblock/listeners/Chat.java +++ b/src/main/java/com/songoda/skyblock/listeners/Chat.java @@ -11,6 +11,7 @@ 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.utils.player.OfflinePlayer; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.configuration.file.FileConfiguration; @@ -88,7 +89,20 @@ public class Chat implements Listener { String message = ChatColor.translateAlternateColorCodes('&', messageManager.replaceMessage(targetPlayer, islandChatEvent.getFormat().replace("%role", islandRole).replace("%player", player.getName()))) .replace("%message", islandChatEvent.getMessage()); - targetPlayer.sendMessage(message); + messageManager.sendMessage(targetPlayer, message); + } + + for(Player targetPlayer : Bukkit.getServer().getOnlinePlayers()){ + if(targetPlayer.hasPermission("fabledskyblock.admin.chatspy")) { + PlayerData pd = playerDataManager.getPlayerData(targetPlayer); + if(pd != null && pd.isChatSpy()) { + String message = ChatColor.translateAlternateColorCodes('&', messageManager.replaceMessage(targetPlayer, + islandChatEvent.getFormat().replace("%role", islandRole).replace("%player", player.getName()))) + .replace("%islandOwner", new OfflinePlayer(island.getOwnerUUID()).getName()) + .replace("%message", islandChatEvent.getMessage()); + messageManager.sendMessage(targetPlayer, message); + } + } } if (fileManager.getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration().getBoolean("Island.Chat.OutputToConsole")) { diff --git a/src/main/java/com/songoda/skyblock/playerdata/PlayerData.java b/src/main/java/com/songoda/skyblock/playerdata/PlayerData.java index e72addcd..9490d12f 100644 --- a/src/main/java/com/songoda/skyblock/playerdata/PlayerData.java +++ b/src/main/java/com/songoda/skyblock/playerdata/PlayerData.java @@ -33,6 +33,8 @@ public class PlayerData { private Object sort; private Area area; + + private boolean chatSpy; private boolean chat; private boolean preview; @@ -52,6 +54,8 @@ public class PlayerData { area = new Area(); + chatSpy = getConfig().getFileConfiguration().getBoolean("ChatSpy", false); + chat = false; preview = false; transactions = new ArrayList<>(); @@ -307,4 +311,13 @@ public class PlayerData { public List getTransactions() { return transactions; } + + public boolean isChatSpy() { + return chatSpy; + } + + public void setChatSpy(boolean chatSpy) { + this.chatSpy = chatSpy; + getConfig().getFileConfiguration().set("ChatSpy", chatSpy); + } } diff --git a/src/main/resources/language.yml b/src/main/resources/language.yml index b62e7ec4..6812a057 100644 --- a/src/main/resources/language.yml +++ b/src/main/resources/language.yml @@ -176,6 +176,13 @@ Command: Message: 'Succesfully removed %ammount% from %player%''s island' SuccesDeposit: Message: 'Succesfully added %ammount% to %player%''s island' + ChatSpy: + Info: + Message: '&f&oToggle island chat spy.' + Enabled: + Message: '&bSkyBlock &8| &aInfo&8: &eChat spy enabled.' + Disabled: + Message: '&bSkyBlock &8| &aInfo&8: &eChat spy disabled.' Reload: Info: Message: '&f&oReload all loaded files.' @@ -3542,6 +3549,13 @@ Island: Message: '&8[&bSkyBlock &8| &dChat&8] %role &e%player&8: &f%message' Untoggled: Message: '&bSkyBlock &8| &aInfo&8: &eThe Island chat has been untoggled because there are no Island Members online. Chat messages will now be visible for all players.' + Spy: + Format: + Role: + Member: '&a[Member]' + Operator: '&b[Operator]' + Owner: '&c[Owner]' + Message: '&8[&bSkyBlock &8| &dChatSpy&8] [&7%islandOwner&8] &e%player&8: &f%message' SpawnProtection: Break: Message: '&bSkyBlock &8| &cError&8: &eYou cannot break the spawn point of the Island.'