mirror of
https://github.com/songoda/FabledSkyBlock.git
synced 2025-01-10 09:47:42 +01:00
Fixed ChatSpy
This commit is contained in:
parent
fe9b01e0d9
commit
f136290436
@ -53,12 +53,13 @@ public class ChatSpyCommand extends SubCommand {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "add":
|
case "add":
|
||||||
if(args.length > 2){
|
if(args.length == 2){
|
||||||
OfflinePlayer offlinePlayer = new OfflinePlayer(args[1]);
|
OfflinePlayer offlinePlayer = new OfflinePlayer(args[1]);
|
||||||
Island island = islandManager.getIslandByPlayer(offlinePlayer.getBukkitOfflinePlayer());
|
Island island = islandManager.getIslandByPlayer(offlinePlayer.getBukkitOfflinePlayer());
|
||||||
if(island != null) {
|
if(island != null) {
|
||||||
playerData.addChatSpyIsland(island);
|
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 {
|
} else {
|
||||||
messageManager.sendMessage(player, languageLoad.getString("Command.Island.Admin.ChatSpy.NullIsland.Message"));
|
messageManager.sendMessage(player, languageLoad.getString("Command.Island.Admin.ChatSpy.NullIsland.Message"));
|
||||||
}
|
}
|
||||||
@ -68,12 +69,13 @@ public class ChatSpyCommand extends SubCommand {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "remove":
|
case "remove":
|
||||||
if(args.length > 2){
|
if(args.length == 2){
|
||||||
OfflinePlayer offlinePlayer = new OfflinePlayer(args[1]);
|
OfflinePlayer offlinePlayer = new OfflinePlayer(args[1]);
|
||||||
Island island = islandManager.getIslandByPlayer(offlinePlayer.getBukkitOfflinePlayer());
|
Island island = islandManager.getIslandByPlayer(offlinePlayer.getBukkitOfflinePlayer());
|
||||||
if(island != null) {
|
if(island != null) {
|
||||||
playerData.removeChatSpyIsland(island);
|
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 {
|
} else {
|
||||||
messageManager.sendMessage(player, languageLoad.getString("Command.Island.Admin.ChatSpy.NullIsland.Message"));
|
messageManager.sendMessage(player, languageLoad.getString("Command.Island.Admin.ChatSpy.NullIsland.Message"));
|
||||||
}
|
}
|
||||||
|
@ -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.PlayerIslandChatEvent;
|
||||||
import com.songoda.skyblock.api.event.player.PlayerIslandChatSwitchEvent;
|
import com.songoda.skyblock.api.event.player.PlayerIslandChatSwitchEvent;
|
||||||
import com.songoda.skyblock.command.SubCommand;
|
import com.songoda.skyblock.command.SubCommand;
|
||||||
import com.songoda.skyblock.config.FileManager;
|
|
||||||
import com.songoda.skyblock.config.FileManager.Config;
|
import com.songoda.skyblock.config.FileManager.Config;
|
||||||
import com.songoda.skyblock.island.Island;
|
import com.songoda.skyblock.island.Island;
|
||||||
import com.songoda.skyblock.island.IslandManager;
|
import com.songoda.skyblock.island.IslandManager;
|
||||||
import com.songoda.skyblock.island.IslandRole;
|
import com.songoda.skyblock.island.IslandRole;
|
||||||
import com.songoda.skyblock.message.MessageManager;
|
import com.songoda.skyblock.message.MessageManager;
|
||||||
import com.songoda.skyblock.placeholder.PlaceholderManager;
|
|
||||||
import com.songoda.skyblock.playerdata.PlayerData;
|
import com.songoda.skyblock.playerdata.PlayerData;
|
||||||
import com.songoda.skyblock.playerdata.PlayerDataManager;
|
import com.songoda.skyblock.playerdata.PlayerDataManager;
|
||||||
import com.songoda.skyblock.sound.SoundManager;
|
import com.songoda.skyblock.sound.SoundManager;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.command.ConsoleCommandSender;
|
import org.bukkit.command.ConsoleCommandSender;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class ChatCommand extends SubCommand {
|
public class ChatCommand extends SubCommand {
|
||||||
|
|
||||||
@ -31,7 +27,6 @@ public class ChatCommand extends SubCommand {
|
|||||||
MessageManager messageManager = skyblock.getMessageManager();
|
MessageManager messageManager = skyblock.getMessageManager();
|
||||||
IslandManager islandManager = skyblock.getIslandManager();
|
IslandManager islandManager = skyblock.getIslandManager();
|
||||||
SoundManager soundManager = skyblock.getSoundManager();
|
SoundManager soundManager = skyblock.getSoundManager();
|
||||||
FileManager fileManager = skyblock.getFileManager();
|
|
||||||
|
|
||||||
Config config = skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml"));
|
Config config = skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml"));
|
||||||
FileConfiguration configLoad = config.getFileConfiguration();
|
FileConfiguration configLoad = config.getFileConfiguration();
|
||||||
@ -73,37 +68,11 @@ public class ChatCommand extends SubCommand {
|
|||||||
island = skyblock.getIslandManager().getIsland(player);
|
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;
|
Island finalIsland = island;
|
||||||
String finalIslandRole = islandRole;
|
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(skyblock, () -> {
|
Bukkit.getScheduler().runTaskAsynchronously(skyblock, () -> {
|
||||||
PlayerIslandChatEvent islandChatEvent = new PlayerIslandChatEvent(player, finalIsland.getAPIWrapper(),
|
PlayerIslandChatEvent islandChatEvent = new PlayerIslandChatEvent(player, finalIsland.getAPIWrapper(),
|
||||||
String.join(" ", args), configLoad.getString("Island.Chat.Format.Message"));
|
String.join(" ", args), configLoad.getString("Island.Chat.Format.Message"));
|
||||||
Bukkit.getServer().getPluginManager().callEvent(islandChatEvent);
|
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()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -66,21 +66,21 @@ public class Chat implements Listener {
|
|||||||
if (playerData.isChat()) {
|
if (playerData.isChat()) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
|
|
||||||
Config config = skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml"));
|
Config language = skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml"));
|
||||||
FileConfiguration configLoad = config.getFileConfiguration();
|
FileConfiguration languageLoad = language.getFileConfiguration();
|
||||||
|
|
||||||
String islandRole = "";
|
String islandRole = "";
|
||||||
|
|
||||||
if (island.hasRole(IslandRole.Member, player.getUniqueId())) {
|
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())) {
|
} 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())) {
|
} 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(),
|
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);
|
Bukkit.getServer().getPluginManager().callEvent(islandChatEvent);
|
||||||
|
|
||||||
if (!islandChatEvent.isCancelled()) {
|
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()));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,6 +60,7 @@ public class PlayerData {
|
|||||||
area = new Area();
|
area = new Area();
|
||||||
|
|
||||||
chatSpy = getConfig().getFileConfiguration().getBoolean("ChatSpy", false);
|
chatSpy = getConfig().getFileConfiguration().getBoolean("ChatSpy", false);
|
||||||
|
spiedIslands = new HashSet<>();
|
||||||
|
|
||||||
if (getConfig().getFileConfiguration().getString("ChatSpiedIslands") != null) {
|
if (getConfig().getFileConfiguration().getString("ChatSpiedIslands") != null) {
|
||||||
for (String islandUUID : getConfig().getFileConfiguration().getStringList("ChatSpiedIslands")) {
|
for (String islandUUID : getConfig().getFileConfiguration().getStringList("ChatSpiedIslands")) {
|
||||||
|
Loading…
Reference in New Issue
Block a user