mirror of
https://github.com/songoda/FabledSkyBlock.git
synced 2024-11-07 11:10:04 +01:00
Per-Island Chat Spy
This commit is contained in:
parent
1a50f15128
commit
11c72f9256
@ -1,28 +1,90 @@
|
||||
package com.songoda.skyblock.command.commands.admin;
|
||||
|
||||
import com.songoda.core.compatibility.CompatibleSound;
|
||||
import com.songoda.core.hooks.EconomyManager;
|
||||
import com.songoda.skyblock.command.SubCommand;
|
||||
import com.songoda.skyblock.config.FileManager;
|
||||
import com.songoda.skyblock.gui.bank.GuiBank;
|
||||
import com.songoda.skyblock.island.Island;
|
||||
import com.songoda.skyblock.island.IslandManager;
|
||||
import com.songoda.skyblock.message.MessageManager;
|
||||
import com.songoda.skyblock.playerdata.PlayerData;
|
||||
import com.songoda.skyblock.playerdata.PlayerDataManager;
|
||||
import com.songoda.skyblock.sound.SoundManager;
|
||||
import com.songoda.skyblock.utils.player.OfflinePlayer;
|
||||
import org.bukkit.Bukkit;
|
||||
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 ChatSpyCommand extends SubCommand {
|
||||
|
||||
@Override
|
||||
public void onCommandByPlayer(Player player, String[] args) {
|
||||
MessageManager messageManager = skyblock.getMessageManager();
|
||||
PlayerDataManager playerDataManager = skyblock.getPlayerDataManager();
|
||||
MessageManager messageManager = skyblock.getMessageManager();
|
||||
IslandManager islandManager = skyblock.getIslandManager();
|
||||
FileManager fileManager = skyblock.getFileManager();
|
||||
SoundManager soundManager = skyblock.getSoundManager();
|
||||
|
||||
FileManager.Config language = fileManager.getConfig(new File(skyblock.getDataFolder(), "language.yml"));
|
||||
FileConfiguration languageLoad = language.getFileConfiguration();
|
||||
|
||||
PlayerData playerData = playerDataManager.getPlayerData(player);
|
||||
|
||||
if (args.length < 1) {
|
||||
toggleSpy(player, messageManager, languageLoad, playerData);
|
||||
} else {
|
||||
switch (args[0].toLowerCase()) {
|
||||
case "toggle":
|
||||
toggleSpy(player, messageManager, languageLoad, playerData);
|
||||
break;
|
||||
case "global":
|
||||
if(!playerData.isGlobalChatSpy()){
|
||||
playerData.enableGlobalChatSpy();
|
||||
messageManager.sendMessage(player, languageLoad.getString("Command.Island.Admin.Bank.ByConsole.Message"));
|
||||
} else {
|
||||
messageManager.sendMessage(player, languageLoad.getString("Command.Island.Admin.Bank.ByConsole.Message"));
|
||||
soundManager.playSound(player, CompatibleSound.BLOCK_ANVIL_LAND.getSound(), 1f, 1f);
|
||||
}
|
||||
break;
|
||||
case "add":
|
||||
if(args.length > 2){
|
||||
Island island = islandManager.getIslandByPlayer(new OfflinePlayer(UUID.fromString(args[1])).getBukkitOfflinePlayer());
|
||||
if(island != null) {
|
||||
playerData.addChatSpyIsland(island);
|
||||
}
|
||||
} else {
|
||||
messageManager.sendMessage(player, languageLoad.getString("Command.Island.Admin.Bank.Unexpected.Message"));
|
||||
soundManager.playSound(player, CompatibleSound.BLOCK_ANVIL_LAND.getSound(), 1f, 1f);
|
||||
}
|
||||
break;
|
||||
case "remove":
|
||||
if(args.length > 2){
|
||||
Island island = islandManager.getIslandByPlayer(new OfflinePlayer(UUID.fromString(args[1])).getBukkitOfflinePlayer());
|
||||
if(island != null) {
|
||||
playerData.removeChatSpyIsland(island);
|
||||
}
|
||||
} else {
|
||||
messageManager.sendMessage(player, languageLoad.getString("Command.Island.Admin.Bank.Unexpected.Message"));
|
||||
soundManager.playSound(player, CompatibleSound.BLOCK_ANVIL_LAND.getSound(), 1f, 1f);
|
||||
}
|
||||
break;
|
||||
case "list":
|
||||
|
||||
break;
|
||||
default:
|
||||
messageManager.sendMessage(player, languageLoad.getString("Command.Island.Admin.Bank.Unexpected.Message"));
|
||||
soundManager.playSound(player, CompatibleSound.BLOCK_ANVIL_LAND.getSound(), 1f, 1f);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void toggleSpy(Player player, MessageManager messageManager, FileConfiguration languageLoad, PlayerData playerData) {
|
||||
if(playerData != null) {
|
||||
if(playerData.isChatSpy()){
|
||||
playerData.setChatSpy(false);
|
||||
|
@ -95,7 +95,7 @@ public class Chat implements Listener {
|
||||
for(Player targetPlayer : Bukkit.getServer().getOnlinePlayers()){
|
||||
if(targetPlayer.hasPermission("fabledskyblock.admin.chatspy")) {
|
||||
PlayerData pd = playerDataManager.getPlayerData(targetPlayer);
|
||||
if(pd != null && pd.isChatSpy()) {
|
||||
if(pd != null && pd.isChatSpy() && (pd.isGlobalChatSpy() || pd.isChatSpyIsland(island))) {
|
||||
String message = ChatColor.translateAlternateColorCodes('&', messageManager.replaceMessage(targetPlayer,
|
||||
islandChatEvent.getFormat().replace("%role", islandRole).replace("%player", player.getName())))
|
||||
.replace("%islandOwner", new OfflinePlayer(island.getOwnerUUID()).getName())
|
||||
|
@ -5,6 +5,7 @@ import com.songoda.skyblock.bank.BankManager;
|
||||
import com.songoda.skyblock.bank.Transaction;
|
||||
import com.songoda.skyblock.config.FileManager.Config;
|
||||
import com.songoda.skyblock.confirmation.Confirmation;
|
||||
import com.songoda.skyblock.island.Island;
|
||||
import com.songoda.skyblock.menus.MenuType;
|
||||
import com.songoda.skyblock.utils.structure.Area;
|
||||
|
||||
@ -18,6 +19,7 @@ import java.util.*;
|
||||
|
||||
public class PlayerData {
|
||||
|
||||
private final SkyBlock skyblock;
|
||||
private UUID uuid;
|
||||
private UUID islandOwnerUUID;
|
||||
private UUID ownershipUUID;
|
||||
@ -35,6 +37,7 @@ public class PlayerData {
|
||||
private Area area;
|
||||
|
||||
private boolean chatSpy;
|
||||
private Set<UUID> spiedIslands;
|
||||
|
||||
private boolean chat;
|
||||
private boolean preview;
|
||||
@ -44,6 +47,8 @@ public class PlayerData {
|
||||
private List<Transaction> transactions;
|
||||
|
||||
public PlayerData(Player player) {
|
||||
this.skyblock = SkyBlock.getInstance();
|
||||
|
||||
uuid = player.getUniqueId();
|
||||
islandOwnerUUID = null;
|
||||
|
||||
@ -56,6 +61,12 @@ public class PlayerData {
|
||||
|
||||
chatSpy = getConfig().getFileConfiguration().getBoolean("ChatSpy", false);
|
||||
|
||||
if (getConfig().getFileConfiguration().getString("ChatSpiedIslands") != null) {
|
||||
for (String islandUUID : getConfig().getFileConfiguration().getStringList("ChatSpiedIslands")) {
|
||||
spiedIslands.add(UUID.fromString(islandUUID));
|
||||
}
|
||||
}
|
||||
|
||||
chat = false;
|
||||
preview = false;
|
||||
transactions = new ArrayList<>();
|
||||
@ -270,7 +281,7 @@ public class PlayerData {
|
||||
}
|
||||
}
|
||||
|
||||
public void save() {
|
||||
public synchronized void save() {
|
||||
transactions = BankManager.getInstance().getTransactionList(getPlayerUUID());
|
||||
Config config = getConfig();
|
||||
FileConfiguration configLoad = config.getFileConfiguration();
|
||||
@ -288,6 +299,10 @@ public class PlayerData {
|
||||
}else {
|
||||
configLoad.set("Bank.Transactions.Size", 0);
|
||||
}
|
||||
|
||||
configLoad.set("ChatSpy", chatSpy);
|
||||
configLoad.set("ChatSpiedIslands", spiedIslands);
|
||||
|
||||
try {
|
||||
configLoad.save(config.getFile());
|
||||
} catch (IOException e) {
|
||||
@ -318,6 +333,41 @@ public class PlayerData {
|
||||
|
||||
public void setChatSpy(boolean chatSpy) {
|
||||
this.chatSpy = chatSpy;
|
||||
getConfig().getFileConfiguration().set("ChatSpy", chatSpy);
|
||||
Bukkit.getScheduler().runTaskAsynchronously(skyblock, this::save);
|
||||
}
|
||||
|
||||
public void addChatSpyIsland(UUID uuid) {
|
||||
spiedIslands.add(uuid);
|
||||
Bukkit.getScheduler().runTaskAsynchronously(skyblock, this::save);
|
||||
}
|
||||
|
||||
public boolean isChatSpyIsland(UUID uuid) {
|
||||
return spiedIslands.contains(uuid);
|
||||
}
|
||||
|
||||
public void removeChatSpyIsland(UUID uuid) {
|
||||
spiedIslands.remove(uuid);
|
||||
Bukkit.getScheduler().runTaskAsynchronously(skyblock, this::save);
|
||||
}
|
||||
|
||||
public void addChatSpyIsland(Island island) {
|
||||
this.addChatSpyIsland(island.getOwnerUUID());
|
||||
}
|
||||
|
||||
public boolean isChatSpyIsland(Island island) {
|
||||
return this.isChatSpyIsland(island.getOwnerUUID());
|
||||
}
|
||||
|
||||
public void removeChatSpyIsland(Island island) {
|
||||
this.removeChatSpyIsland(island.getOwnerUUID());
|
||||
}
|
||||
|
||||
public boolean isGlobalChatSpy() {
|
||||
return spiedIslands.isEmpty();
|
||||
}
|
||||
|
||||
public void enableGlobalChatSpy() {
|
||||
spiedIslands.clear();
|
||||
Bukkit.getScheduler().runTaskAsynchronously(skyblock, this::save);
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ import java.util.UUID;
|
||||
public class OfflinePlayer {
|
||||
|
||||
private UUID uuid;
|
||||
org.bukkit.OfflinePlayer bukkitOfflinePlayer;
|
||||
|
||||
private String name;
|
||||
private String memberSince;
|
||||
@ -25,11 +26,10 @@ public class OfflinePlayer {
|
||||
SkyBlock skyblock = SkyBlock.getInstance();
|
||||
UserCacheManager userCacheManager = skyblock.getUserCacheManager();
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
org.bukkit.OfflinePlayer offlinePlayer = Bukkit.getServer().getOfflinePlayer(name);
|
||||
bukkitOfflinePlayer = Bukkit.getServer().getOfflinePlayer(name);
|
||||
|
||||
this.name = offlinePlayer.getName();
|
||||
this.uuid = offlinePlayer.getUniqueId();
|
||||
this.name = bukkitOfflinePlayer.getName();
|
||||
this.uuid = bukkitOfflinePlayer.getUniqueId();
|
||||
|
||||
if (this.uuid == null && userCacheManager.hasUser(name)) {
|
||||
this.uuid = userCacheManager.getUser(name);
|
||||
@ -51,9 +51,9 @@ public class OfflinePlayer {
|
||||
SkyBlock skyblock = SkyBlock.getInstance();
|
||||
UserCacheManager userCacheManager = skyblock.getUserCacheManager();
|
||||
|
||||
org.bukkit.OfflinePlayer offlinePlayer = Bukkit.getServer().getOfflinePlayer(uuid);
|
||||
bukkitOfflinePlayer = Bukkit.getServer().getOfflinePlayer(uuid);
|
||||
|
||||
this.name = offlinePlayer.getName();
|
||||
this.name = bukkitOfflinePlayer.getName();
|
||||
this.uuid = uuid;
|
||||
|
||||
if (this.name == null && userCacheManager.hasUser(uuid)) {
|
||||
@ -103,4 +103,8 @@ public class OfflinePlayer {
|
||||
public int getPlaytime() {
|
||||
return playtime;
|
||||
}
|
||||
|
||||
public org.bukkit.OfflinePlayer getBukkitOfflinePlayer() {
|
||||
return bukkitOfflinePlayer;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user