From d5822b88406d89daa1da746f786018e3f24295da Mon Sep 17 00:00:00 2001 From: Aust1n46 Date: Wed, 11 May 2022 23:23:55 -0500 Subject: [PATCH] Replace static access to Bukkit --- .../controllers/PluginMessageController.java | 29 +- .../VentureChatSpigotFlatFileController.java | 469 +++++++-------- .../chat/initators/commands/Channel.java | 3 +- .../chat/initators/commands/Chatinfo.java | 3 +- .../chat/initators/commands/Chatreload.java | 7 +- .../chat/initators/commands/Party.java | 36 -- .../initators/commands/VentureChatGui.java | 5 +- .../initiators/listeners/ChatListener.java | 545 +++++++++--------- .../listeners/PreProcessCommandListener.java | 4 +- .../chat/model/VentureChatPlayer.java | 23 - .../Aust1n46/chat/service/ConfigService.java | 3 +- .../Aust1n46/chat/service/UUIDService.java | 17 +- .../service/VentureChatDatabaseService.java | 24 +- .../service/VentureChatFormatService.java | 99 ++-- 14 files changed, 567 insertions(+), 700 deletions(-) diff --git a/src/main/java/venture/Aust1n46/chat/controllers/PluginMessageController.java b/src/main/java/venture/Aust1n46/chat/controllers/PluginMessageController.java index 229eb95..d6b80b2 100644 --- a/src/main/java/venture/Aust1n46/chat/controllers/PluginMessageController.java +++ b/src/main/java/venture/Aust1n46/chat/controllers/PluginMessageController.java @@ -11,7 +11,6 @@ import java.util.List; import java.util.Set; import java.util.UUID; -import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.entity.Player; @@ -90,7 +89,7 @@ public class PluginMessageController { // System.out.println(mcp.getPlayer().getServer().getServerName()); // out.writeUTF(mcp.getPlayer().getServer().getServerName()); out.writeUTF(mcp.getUuid().toString()); - Bukkit.getServer().getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() { + plugin.getServer().getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() { @Override public void run() { if (!mcp.isOnline() || mcp.isHasPlayed()) { @@ -195,18 +194,18 @@ public class PluginMessageController { } } - Bukkit.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() { + plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() { @Override public void run() { // Create VentureChatEvent VentureChatEvent ventureChatEvent = new VentureChatEvent(null, senderName, primaryGroup, chatChannelObject, recipients, recipients.size(), format, chat, globalJSON, hash, false); // Fire event and wait for other plugin listeners to act on it - Bukkit.getServer().getPluginManager().callEvent(ventureChatEvent); + plugin.getServer().getPluginManager().callEvent(ventureChatEvent); } }); - Bukkit.getConsoleSender().sendMessage(consoleChat); + plugin.getServer().getConsoleSender().sendMessage(consoleChat); if (databaseService.isEnabled()) { databaseService.writeVentureChat(senderUUID.toString(), senderName, server, chatchannel, chat.replace("'", "''"), "Chat"); @@ -314,7 +313,7 @@ public class PluginMessageController { } if (subchannel.equals("Sync")) { if (plugin.getConfig().getString("loglevel", "info").equals("debug")) { - Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&e - Received update...")); + plugin.getServer().getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&e - Received update...")); } String uuid = msgin.readUTF(); VentureChatPlayer p = playerApiService.getOnlineMineverseChatPlayer(UUID.fromString(uuid)); @@ -515,7 +514,7 @@ public class PluginMessageController { String timeString = FormatUtils.parseTimeStringFromMillis(time); if (reason.isEmpty()) { if (senderIdentifier.equals("VentureChat:Console")) { - Bukkit.getConsoleSender().sendMessage(LocalizedMessage.MUTE_PLAYER_SENDER_TIME.toString().replace("{player}", playerToMute) + plugin.getServer().getConsoleSender().sendMessage(LocalizedMessage.MUTE_PLAYER_SENDER_TIME.toString().replace("{player}", playerToMute) .replace("{channel_color}", chatChannelObj.getColor()).replace("{channel_name}", chatChannelObj.getName()).replace("{time}", timeString)); } else { UUID sender = UUID.fromString(senderIdentifier); @@ -525,7 +524,7 @@ public class PluginMessageController { } } else { if (senderIdentifier.equals("VentureChat:Console")) { - Bukkit.getConsoleSender() + plugin.getServer().getConsoleSender() .sendMessage(LocalizedMessage.MUTE_PLAYER_SENDER_TIME_REASON.toString().replace("{player}", playerToMute) .replace("{channel_color}", chatChannelObj.getColor()).replace("{channel_name}", chatChannelObj.getName()) .replace("{time}", timeString).replace("{reason}", reason)); @@ -541,7 +540,7 @@ public class PluginMessageController { } else { if (reason.isEmpty()) { if (senderIdentifier.equals("VentureChat:Console")) { - Bukkit.getConsoleSender().sendMessage(LocalizedMessage.MUTE_PLAYER_SENDER.toString().replace("{player}", playerToMute) + plugin.getServer().getConsoleSender().sendMessage(LocalizedMessage.MUTE_PLAYER_SENDER.toString().replace("{player}", playerToMute) .replace("{channel_color}", chatChannelObj.getColor()).replace("{channel_name}", chatChannelObj.getName())); } else { UUID sender = UUID.fromString(senderIdentifier); @@ -551,7 +550,7 @@ public class PluginMessageController { } } else { if (senderIdentifier.equals("VentureChat:Console")) { - Bukkit.getConsoleSender().sendMessage(LocalizedMessage.MUTE_PLAYER_SENDER_REASON.toString().replace("{player}", playerToMute) + plugin.getServer().getConsoleSender().sendMessage(LocalizedMessage.MUTE_PLAYER_SENDER_REASON.toString().replace("{player}", playerToMute) .replace("{channel_color}", chatChannelObj.getColor()).replace("{channel_name}", chatChannelObj.getName()).replace("{reason}", reason)); } else { UUID sender = UUID.fromString(senderIdentifier); @@ -567,7 +566,7 @@ public class PluginMessageController { String senderIdentifier = msgin.readUTF(); String playerToMute = msgin.readUTF(); if (senderIdentifier.equals("VentureChat:Console")) { - Bukkit.getConsoleSender().sendMessage(LocalizedMessage.PLAYER_OFFLINE.toString().replace("{args}", playerToMute)); + plugin.getServer().getConsoleSender().sendMessage(LocalizedMessage.PLAYER_OFFLINE.toString().replace("{args}", playerToMute)); return; } UUID sender = UUID.fromString(senderIdentifier); @@ -584,7 +583,7 @@ public class PluginMessageController { } ChatChannel chatChannelObj = configService.getChannel(channelName); if (senderIdentifier.equals("VentureChat:Console")) { - Bukkit.getConsoleSender().sendMessage(LocalizedMessage.PLAYER_ALREADY_MUTED.toString().replace("{player}", playerToMute) + plugin.getServer().getConsoleSender().sendMessage(LocalizedMessage.PLAYER_ALREADY_MUTED.toString().replace("{player}", playerToMute) .replace("{channel_color}", chatChannelObj.getColor()).replace("{channel_name}", chatChannelObj.getName())); return; } @@ -650,7 +649,7 @@ public class PluginMessageController { } ChatChannel chatChannelObj = configService.getChannel(channelName); if (senderIdentifier.equals("VentureChat:Console")) { - Bukkit.getConsoleSender().sendMessage(LocalizedMessage.UNMUTE_PLAYER_SENDER.toString().replace("{player}", playerToUnmute) + plugin.getServer().getConsoleSender().sendMessage(LocalizedMessage.UNMUTE_PLAYER_SENDER.toString().replace("{player}", playerToUnmute) .replace("{channel_color}", chatChannelObj.getColor()).replace("{channel_name}", chatChannelObj.getName())); } else { UUID sender = UUID.fromString(senderIdentifier); @@ -664,7 +663,7 @@ public class PluginMessageController { String senderIdentifier = msgin.readUTF(); String playerToUnmute = msgin.readUTF(); if (senderIdentifier.equals("VentureChat:Console")) { - Bukkit.getConsoleSender().sendMessage(LocalizedMessage.PLAYER_OFFLINE.toString().replace("{args}", playerToUnmute)); + plugin.getServer().getConsoleSender().sendMessage(LocalizedMessage.PLAYER_OFFLINE.toString().replace("{args}", playerToUnmute)); return; } UUID sender = UUID.fromString(senderIdentifier); @@ -681,7 +680,7 @@ public class PluginMessageController { } ChatChannel chatChannelObj = configService.getChannel(channelName); if (senderIdentifier.equals("VentureChat:Console")) { - Bukkit.getConsoleSender().sendMessage(LocalizedMessage.PLAYER_NOT_MUTED.toString().replace("{player}", playerToUnmute) + plugin.getServer().getConsoleSender().sendMessage(LocalizedMessage.PLAYER_NOT_MUTED.toString().replace("{player}", playerToUnmute) .replace("{channel_color}", chatChannelObj.getColor()).replace("{channel_name}", chatChannelObj.getName())); return; } diff --git a/src/main/java/venture/Aust1n46/chat/controllers/VentureChatSpigotFlatFileController.java b/src/main/java/venture/Aust1n46/chat/controllers/VentureChatSpigotFlatFileController.java index 10f1ddb..f0df798 100644 --- a/src/main/java/venture/Aust1n46/chat/controllers/VentureChatSpigotFlatFileController.java +++ b/src/main/java/venture/Aust1n46/chat/controllers/VentureChatSpigotFlatFileController.java @@ -13,7 +13,6 @@ import java.util.Set; import java.util.StringTokenizer; import java.util.UUID; -import org.bukkit.Bukkit; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; @@ -37,246 +36,250 @@ import venture.Aust1n46.chat.utilities.FormatUtils; */ @Singleton public class VentureChatSpigotFlatFileController { - @Inject - private VentureChat plugin; - @Inject - private UUIDService uuidService; - @Inject - private VentureChatPlayerApiService ventureChatApi; - @Inject + @Inject + private VentureChat plugin; + @Inject + private UUIDService uuidService; + @Inject + private VentureChatPlayerApiService ventureChatApi; + @Inject private ConfigService configService; - - private String playerDataDirectoryPath; - - @Inject - public void postConstruct() { - playerDataDirectoryPath = plugin.getDataFolder().getAbsolutePath() + "/PlayerData"; - } - - public void loadLegacyPlayerData() { - File legacyPlayerDataFile = new File(plugin.getDataFolder().getAbsolutePath(), "Players.yml"); - if (!legacyPlayerDataFile.isFile()) { - return; - } - try { - Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&c - Detected Legacy Player Data!")); - Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&c - Converting to new structure and deleting old Players.yml file!")); - FileConfiguration playerData = YamlConfiguration.loadConfiguration(legacyPlayerDataFile); - for (String uuidString : playerData.getConfigurationSection("players").getKeys(false)) { - UUID uuid = UUID.fromString(uuidString); - if (uuidService.shouldSkipOfflineUUID(uuid)) { - Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&c - Skipping Offline UUID: " + uuid)); - continue; - } - String name = playerData.getConfigurationSection("players." + uuid).getString("name"); - String currentChannelName = playerData.getConfigurationSection("players." + uuid).getString("current"); - ChatChannel currentChannel = configService.isChannel(currentChannelName) ? configService.getChannel(currentChannelName) : configService.getDefaultChannel(); - Set ignores = new HashSet(); - StringTokenizer i = new StringTokenizer(playerData.getConfigurationSection("players." + uuidString).getString("ignores"), ","); - while (i.hasMoreTokens()) { - ignores.add(UUID.fromString(i.nextToken())); - } - Set listening = new HashSet(); - StringTokenizer l = new StringTokenizer(playerData.getConfigurationSection("players." + uuidString).getString("listen"), ","); - while (l.hasMoreTokens()) { - String channel = l.nextToken(); - if (configService.isChannel(channel)) { - listening.add(channel); - } - } - HashMap mutes = new HashMap(); - StringTokenizer m = new StringTokenizer(playerData.getConfigurationSection("players." + uuidString).getString("mutes"), ","); - while (m.hasMoreTokens()) { - String[] parts = m.nextToken().split(":"); - if (configService.isChannel(parts[0])) { - if (parts[1].equals("null")) { - Bukkit.getConsoleSender().sendMessage("[VentureChat] Null Mute Time: " + parts[0] + " " + name); - continue; - } - String channelName = parts[0]; - mutes.put(channelName, new MuteContainer(channelName, Long.parseLong(parts[1]))); - } - } - Set blockedCommands = new HashSet(); - StringTokenizer b = new StringTokenizer(playerData.getConfigurationSection("players." + uuidString).getString("blockedcommands"), ","); - while (b.hasMoreTokens()) { - blockedCommands.add(b.nextToken()); - } - boolean host = playerData.getConfigurationSection("players." + uuidString).getBoolean("host"); - UUID party = playerData.getConfigurationSection("players." + uuidString).getString("party").length() > 0 ? UUID.fromString(playerData.getConfigurationSection("players." + uuidString).getString("party")) : null; - boolean filter = playerData.getConfigurationSection("players." + uuidString).getBoolean("filter"); - boolean notifications = playerData.getConfigurationSection("players." + uuidString).getBoolean("notifications"); - String jsonFormat = "Default"; - boolean spy = playerData.getConfigurationSection("players." + uuidString).getBoolean("spy", false); - boolean commandSpy = playerData.getConfigurationSection("players." + uuidString).getBoolean("commandspy", false); - boolean rangedSpy = playerData.getConfigurationSection("players." + uuidString).getBoolean("rangedspy", false); - boolean messageToggle = playerData.getConfigurationSection("players." + uuidString).getBoolean("messagetoggle", true); - boolean bungeeToggle = playerData.getConfigurationSection("players." + uuidString).getBoolean("bungeetoggle", true); - VentureChatPlayer mcp = new VentureChatPlayer(uuid, name, currentChannel, ignores, listening, mutes, blockedCommands, host, party, filter, notifications, jsonFormat, spy, commandSpy, rangedSpy, messageToggle, bungeeToggle); - mcp.setModified(true); - ventureChatApi.addMineverseChatPlayerToMap(mcp); - ventureChatApi.addNameToMap(mcp); - } - } catch (Exception e) { - ventureChatApi.clearMineverseChatPlayerMap(); - ventureChatApi.clearNameMap(); - Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&c - Error Loading Legacy Player Data!")); - Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&c - Deleted Players.yml file!")); - } finally { - legacyPlayerDataFile.delete(); - } - } - public void loadPlayerData() { - try { - File playerDataDirectory = new File(playerDataDirectoryPath); - if (!playerDataDirectory.exists()) { - playerDataDirectory.mkdirs(); - } - Files.walk(Paths.get(playerDataDirectoryPath)) - .filter(Files::isRegularFile) - .forEach((path) -> readPlayerDataFile(path)); - } catch (IOException e) { - e.printStackTrace(); - } - } + private String playerDataDirectoryPath; - /** - * Loads the player data file for a specific player. Corrupt/invalid data files are skipped and deleted. - * - * @param path - */ - private void readPlayerDataFile(Path path) { - VentureChatPlayer mcp; - File playerDataFile = path.toFile(); - if (!playerDataFile.exists()) { - return; - } - try { - FileConfiguration playerDataFileYamlConfiguration = YamlConfiguration.loadConfiguration(playerDataFile); - String uuidString = playerDataFile.getName().replace(".yml", ""); - UUID uuid = UUID.fromString(uuidString); - if (uuidService.shouldSkipOfflineUUID(uuid)) { - Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&c - Skipping Offline UUID: " + uuid)); - Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&c - File will be skipped and deleted.")); - playerDataFile.delete(); - return; - } - String name = playerDataFileYamlConfiguration.getString("name"); - String currentChannelName = playerDataFileYamlConfiguration.getString("current"); - ChatChannel currentChannel = configService.isChannel(currentChannelName) ? configService.getChannel(currentChannelName) : configService.getDefaultChannel(); - Set ignores = new HashSet(); - StringTokenizer i = new StringTokenizer(playerDataFileYamlConfiguration.getString("ignores"), ","); - while (i.hasMoreTokens()) { - ignores.add(UUID.fromString(i.nextToken())); - } - Set listening = new HashSet(); - StringTokenizer l = new StringTokenizer(playerDataFileYamlConfiguration.getString("listen"), ","); - while (l.hasMoreTokens()) { - String channel = l.nextToken(); - if (configService.isChannel(channel)) { - listening.add(channel); - } - } - HashMap mutes = new HashMap(); - ConfigurationSection muteSection = playerDataFileYamlConfiguration.getConfigurationSection("mutes"); - for (String channelName : muteSection.getKeys(false)) { - ConfigurationSection channelSection = muteSection.getConfigurationSection(channelName); - mutes.put(channelName, new MuteContainer(channelName, channelSection.getLong("time"), channelSection.getString("reason"))); - } + @Inject + public void postConstruct() { + playerDataDirectoryPath = plugin.getDataFolder().getAbsolutePath() + "/PlayerData"; + } - Set blockedCommands = new HashSet(); - StringTokenizer b = new StringTokenizer(playerDataFileYamlConfiguration.getString("blockedcommands"), ","); - while (b.hasMoreTokens()) { - blockedCommands.add(b.nextToken()); - } - boolean host = playerDataFileYamlConfiguration.getBoolean("host"); - UUID party = playerDataFileYamlConfiguration.getString("party").length() > 0 ? UUID.fromString(playerDataFileYamlConfiguration.getString("party")) : null; - boolean filter = playerDataFileYamlConfiguration.getBoolean("filter"); - boolean notifications = playerDataFileYamlConfiguration.getBoolean("notifications"); - String jsonFormat = "Default"; - boolean spy = playerDataFileYamlConfiguration.getBoolean("spy", false); - boolean commandSpy = playerDataFileYamlConfiguration.getBoolean("commandspy", false); - boolean rangedSpy = playerDataFileYamlConfiguration.getBoolean("rangedspy", false); - boolean messageToggle = playerDataFileYamlConfiguration.getBoolean("messagetoggle", true); - boolean bungeeToggle = playerDataFileYamlConfiguration.getBoolean("bungeetoggle", true); - mcp = new VentureChatPlayer(uuid, name, currentChannel, ignores, listening, mutes, blockedCommands, host, party, filter, notifications, jsonFormat, spy, commandSpy, rangedSpy, messageToggle, bungeeToggle); - } catch (Exception e) { - Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&c - Error Loading Data File: " + playerDataFile.getName())); - Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&c - File will be skipped and deleted.")); - playerDataFile.delete(); - return; - } - if (mcp != null) { - ventureChatApi.addMineverseChatPlayerToMap(mcp); - ventureChatApi.addNameToMap(mcp); - } - } + public void loadLegacyPlayerData() { + File legacyPlayerDataFile = new File(plugin.getDataFolder().getAbsolutePath(), "Players.yml"); + if (!legacyPlayerDataFile.isFile()) { + return; + } + try { + plugin.getServer().getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&c - Detected Legacy Player Data!")); + plugin.getServer().getConsoleSender() + .sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&c - Converting to new structure and deleting old Players.yml file!")); + FileConfiguration playerData = YamlConfiguration.loadConfiguration(legacyPlayerDataFile); + for (String uuidString : playerData.getConfigurationSection("players").getKeys(false)) { + UUID uuid = UUID.fromString(uuidString); + if (uuidService.shouldSkipOfflineUUID(uuid)) { + plugin.getServer().getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&c - Skipping Offline UUID: " + uuid)); + continue; + } + String name = playerData.getConfigurationSection("players." + uuid).getString("name"); + String currentChannelName = playerData.getConfigurationSection("players." + uuid).getString("current"); + ChatChannel currentChannel = configService.isChannel(currentChannelName) ? configService.getChannel(currentChannelName) : configService.getDefaultChannel(); + Set ignores = new HashSet(); + StringTokenizer i = new StringTokenizer(playerData.getConfigurationSection("players." + uuidString).getString("ignores"), ","); + while (i.hasMoreTokens()) { + ignores.add(UUID.fromString(i.nextToken())); + } + Set listening = new HashSet(); + StringTokenizer l = new StringTokenizer(playerData.getConfigurationSection("players." + uuidString).getString("listen"), ","); + while (l.hasMoreTokens()) { + String channel = l.nextToken(); + if (configService.isChannel(channel)) { + listening.add(channel); + } + } + HashMap mutes = new HashMap(); + StringTokenizer m = new StringTokenizer(playerData.getConfigurationSection("players." + uuidString).getString("mutes"), ","); + while (m.hasMoreTokens()) { + String[] parts = m.nextToken().split(":"); + if (configService.isChannel(parts[0])) { + if (parts[1].equals("null")) { + plugin.getServer().getConsoleSender().sendMessage("[VentureChat] Null Mute Time: " + parts[0] + " " + name); + continue; + } + String channelName = parts[0]; + mutes.put(channelName, new MuteContainer(channelName, Long.parseLong(parts[1]))); + } + } + Set blockedCommands = new HashSet(); + StringTokenizer b = new StringTokenizer(playerData.getConfigurationSection("players." + uuidString).getString("blockedcommands"), ","); + while (b.hasMoreTokens()) { + blockedCommands.add(b.nextToken()); + } + boolean host = playerData.getConfigurationSection("players." + uuidString).getBoolean("host"); + UUID party = playerData.getConfigurationSection("players." + uuidString).getString("party").length() > 0 + ? UUID.fromString(playerData.getConfigurationSection("players." + uuidString).getString("party")) + : null; + boolean filter = playerData.getConfigurationSection("players." + uuidString).getBoolean("filter"); + boolean notifications = playerData.getConfigurationSection("players." + uuidString).getBoolean("notifications"); + String jsonFormat = "Default"; + boolean spy = playerData.getConfigurationSection("players." + uuidString).getBoolean("spy", false); + boolean commandSpy = playerData.getConfigurationSection("players." + uuidString).getBoolean("commandspy", false); + boolean rangedSpy = playerData.getConfigurationSection("players." + uuidString).getBoolean("rangedspy", false); + boolean messageToggle = playerData.getConfigurationSection("players." + uuidString).getBoolean("messagetoggle", true); + boolean bungeeToggle = playerData.getConfigurationSection("players." + uuidString).getBoolean("bungeetoggle", true); + VentureChatPlayer mcp = new VentureChatPlayer(uuid, name, currentChannel, ignores, listening, mutes, blockedCommands, host, party, filter, notifications, + jsonFormat, spy, commandSpy, rangedSpy, messageToggle, bungeeToggle); + mcp.setModified(true); + ventureChatApi.addMineverseChatPlayerToMap(mcp); + ventureChatApi.addNameToMap(mcp); + } + } catch (Exception e) { + ventureChatApi.clearMineverseChatPlayerMap(); + ventureChatApi.clearNameMap(); + plugin.getServer().getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&c - Error Loading Legacy Player Data!")); + plugin.getServer().getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&c - Deleted Players.yml file!")); + } finally { + legacyPlayerDataFile.delete(); + } + } - public void savePlayerData(VentureChatPlayer mcp) { - if (mcp == null || uuidService.shouldSkipOfflineUUID(mcp.getUuid()) || (!mcp.isOnline() && !mcp.isModified())) { - return; - } - try { - File playerDataFile = new File(playerDataDirectoryPath, mcp.getUuid() + ".yml"); - FileConfiguration playerDataFileYamlConfiguration = YamlConfiguration.loadConfiguration(playerDataFile); - if (!playerDataFile.exists()) { - playerDataFileYamlConfiguration.save(playerDataFile); - } + public void loadPlayerData() { + try { + File playerDataDirectory = new File(playerDataDirectoryPath); + if (!playerDataDirectory.exists()) { + playerDataDirectory.mkdirs(); + } + Files.walk(Paths.get(playerDataDirectoryPath)).filter(Files::isRegularFile).forEach((path) -> readPlayerDataFile(path)); + } catch (IOException e) { + e.printStackTrace(); + } + } - playerDataFileYamlConfiguration.set("name", mcp.getName()); - playerDataFileYamlConfiguration.set("current", mcp.getCurrentChannel().getName()); - String ignores = ""; - for (UUID s : mcp.getIgnores()) { - ignores += s.toString() + ","; - } - playerDataFileYamlConfiguration.set("ignores", ignores); - String listening = ""; - for (String channel : mcp.getListening()) { - ChatChannel c = configService.getChannel(channel); - listening += c.getName() + ","; - } - String blockedCommands = ""; - for (String s : mcp.getBlockedCommands()) { - blockedCommands += s + ","; - } - if (listening.length() > 0) { - listening = listening.substring(0, listening.length() - 1); - } - playerDataFileYamlConfiguration.set("listen", listening); + /** + * Loads the player data file for a specific player. Corrupt/invalid data files + * are skipped and deleted. + * + * @param path + */ + private void readPlayerDataFile(Path path) { + VentureChatPlayer mcp; + File playerDataFile = path.toFile(); + if (!playerDataFile.exists()) { + return; + } + try { + FileConfiguration playerDataFileYamlConfiguration = YamlConfiguration.loadConfiguration(playerDataFile); + String uuidString = playerDataFile.getName().replace(".yml", ""); + UUID uuid = UUID.fromString(uuidString); + if (uuidService.shouldSkipOfflineUUID(uuid)) { + plugin.getServer().getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&c - Skipping Offline UUID: " + uuid)); + plugin.getServer().getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&c - File will be skipped and deleted.")); + playerDataFile.delete(); + return; + } + String name = playerDataFileYamlConfiguration.getString("name"); + String currentChannelName = playerDataFileYamlConfiguration.getString("current"); + ChatChannel currentChannel = configService.isChannel(currentChannelName) ? configService.getChannel(currentChannelName) : configService.getDefaultChannel(); + Set ignores = new HashSet(); + StringTokenizer i = new StringTokenizer(playerDataFileYamlConfiguration.getString("ignores"), ","); + while (i.hasMoreTokens()) { + ignores.add(UUID.fromString(i.nextToken())); + } + Set listening = new HashSet(); + StringTokenizer l = new StringTokenizer(playerDataFileYamlConfiguration.getString("listen"), ","); + while (l.hasMoreTokens()) { + String channel = l.nextToken(); + if (configService.isChannel(channel)) { + listening.add(channel); + } + } + HashMap mutes = new HashMap(); + ConfigurationSection muteSection = playerDataFileYamlConfiguration.getConfigurationSection("mutes"); + for (String channelName : muteSection.getKeys(false)) { + ConfigurationSection channelSection = muteSection.getConfigurationSection(channelName); + mutes.put(channelName, new MuteContainer(channelName, channelSection.getLong("time"), channelSection.getString("reason"))); + } - ConfigurationSection muteSection = playerDataFileYamlConfiguration.createSection("mutes"); - for (MuteContainer mute : mcp.getMutes()) { - ConfigurationSection channelSection = muteSection.createSection(mute.getChannel()); - channelSection.set("time", mute.getDuration()); - channelSection.set("reason", mute.getReason()); - } + Set blockedCommands = new HashSet(); + StringTokenizer b = new StringTokenizer(playerDataFileYamlConfiguration.getString("blockedcommands"), ","); + while (b.hasMoreTokens()) { + blockedCommands.add(b.nextToken()); + } + boolean host = playerDataFileYamlConfiguration.getBoolean("host"); + UUID party = playerDataFileYamlConfiguration.getString("party").length() > 0 ? UUID.fromString(playerDataFileYamlConfiguration.getString("party")) : null; + boolean filter = playerDataFileYamlConfiguration.getBoolean("filter"); + boolean notifications = playerDataFileYamlConfiguration.getBoolean("notifications"); + String jsonFormat = "Default"; + boolean spy = playerDataFileYamlConfiguration.getBoolean("spy", false); + boolean commandSpy = playerDataFileYamlConfiguration.getBoolean("commandspy", false); + boolean rangedSpy = playerDataFileYamlConfiguration.getBoolean("rangedspy", false); + boolean messageToggle = playerDataFileYamlConfiguration.getBoolean("messagetoggle", true); + boolean bungeeToggle = playerDataFileYamlConfiguration.getBoolean("bungeetoggle", true); + mcp = new VentureChatPlayer(uuid, name, currentChannel, ignores, listening, mutes, blockedCommands, host, party, filter, notifications, jsonFormat, spy, commandSpy, + rangedSpy, messageToggle, bungeeToggle); + } catch (Exception e) { + plugin.getServer().getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&c - Error Loading Data File: " + playerDataFile.getName())); + plugin.getServer().getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&c - File will be skipped and deleted.")); + playerDataFile.delete(); + return; + } + if (mcp != null) { + ventureChatApi.addMineverseChatPlayerToMap(mcp); + ventureChatApi.addNameToMap(mcp); + } + } - playerDataFileYamlConfiguration.set("blockedcommands", blockedCommands); - playerDataFileYamlConfiguration.set("host", mcp.isHost()); - playerDataFileYamlConfiguration.set("party", mcp.hasParty() ? mcp.getParty().toString() : ""); - playerDataFileYamlConfiguration.set("filter", mcp.isFilter()); - playerDataFileYamlConfiguration.set("notifications", mcp.isNotifications()); - playerDataFileYamlConfiguration.set("spy", mcp.isSpy()); - playerDataFileYamlConfiguration.set("commandspy", mcp.hasCommandSpy()); - playerDataFileYamlConfiguration.set("rangedspy", mcp.getRangedSpy()); - playerDataFileYamlConfiguration.set("messagetoggle", mcp.isMessageToggle()); - playerDataFileYamlConfiguration.set("bungeetoggle", mcp.isBungeeToggle()); - Calendar currentDate = Calendar.getInstance(); - SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MMM/dd HH:mm:ss"); - String dateNow = formatter.format(currentDate.getTime()); - playerDataFileYamlConfiguration.set("date", dateNow); - mcp.setModified(false); + public void savePlayerData(VentureChatPlayer mcp) { + if (mcp == null || uuidService.shouldSkipOfflineUUID(mcp.getUuid()) || (!mcp.isOnline() && !mcp.isModified())) { + return; + } + try { + File playerDataFile = new File(playerDataDirectoryPath, mcp.getUuid() + ".yml"); + FileConfiguration playerDataFileYamlConfiguration = YamlConfiguration.loadConfiguration(playerDataFile); + if (!playerDataFile.exists()) { + playerDataFileYamlConfiguration.save(playerDataFile); + } - playerDataFileYamlConfiguration.save(playerDataFile); - } catch (IOException e) { - e.printStackTrace(); - } - } + playerDataFileYamlConfiguration.set("name", mcp.getName()); + playerDataFileYamlConfiguration.set("current", mcp.getCurrentChannel().getName()); + String ignores = ""; + for (UUID s : mcp.getIgnores()) { + ignores += s.toString() + ","; + } + playerDataFileYamlConfiguration.set("ignores", ignores); + String listening = ""; + for (String channel : mcp.getListening()) { + ChatChannel c = configService.getChannel(channel); + listening += c.getName() + ","; + } + String blockedCommands = ""; + for (String s : mcp.getBlockedCommands()) { + blockedCommands += s + ","; + } + if (listening.length() > 0) { + listening = listening.substring(0, listening.length() - 1); + } + playerDataFileYamlConfiguration.set("listen", listening); - public void savePlayerData() { - for (VentureChatPlayer p : ventureChatApi.getMineverseChatPlayers()) { - savePlayerData(p); - } - } + ConfigurationSection muteSection = playerDataFileYamlConfiguration.createSection("mutes"); + for (MuteContainer mute : mcp.getMutes()) { + ConfigurationSection channelSection = muteSection.createSection(mute.getChannel()); + channelSection.set("time", mute.getDuration()); + channelSection.set("reason", mute.getReason()); + } + + playerDataFileYamlConfiguration.set("blockedcommands", blockedCommands); + playerDataFileYamlConfiguration.set("host", mcp.isHost()); + playerDataFileYamlConfiguration.set("party", mcp.hasParty() ? mcp.getParty().toString() : ""); + playerDataFileYamlConfiguration.set("filter", mcp.isFilter()); + playerDataFileYamlConfiguration.set("notifications", mcp.isNotifications()); + playerDataFileYamlConfiguration.set("spy", mcp.isSpy()); + playerDataFileYamlConfiguration.set("commandspy", mcp.hasCommandSpy()); + playerDataFileYamlConfiguration.set("rangedspy", mcp.getRangedSpy()); + playerDataFileYamlConfiguration.set("messagetoggle", mcp.isMessageToggle()); + playerDataFileYamlConfiguration.set("bungeetoggle", mcp.isBungeeToggle()); + Calendar currentDate = Calendar.getInstance(); + SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MMM/dd HH:mm:ss"); + String dateNow = formatter.format(currentDate.getTime()); + playerDataFileYamlConfiguration.set("date", dateNow); + mcp.setModified(false); + + playerDataFileYamlConfiguration.save(playerDataFile); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public void savePlayerData() { + for (VentureChatPlayer p : ventureChatApi.getMineverseChatPlayers()) { + savePlayerData(p); + } + } } diff --git a/src/main/java/venture/Aust1n46/chat/initators/commands/Channel.java b/src/main/java/venture/Aust1n46/chat/initators/commands/Channel.java index e2150fb..f6390be 100644 --- a/src/main/java/venture/Aust1n46/chat/initators/commands/Channel.java +++ b/src/main/java/venture/Aust1n46/chat/initators/commands/Channel.java @@ -1,6 +1,5 @@ package venture.Aust1n46.chat.initators.commands; -import org.bukkit.Bukkit; import org.bukkit.entity.Player; import com.google.inject.Inject; @@ -40,7 +39,7 @@ public class Channel extends PlayerCommand { ChatChannel channel = configService.getChannel(args[0]); ChannelJoinEvent channelJoinEvent = new ChannelJoinEvent(mcp.getPlayer(), channel, LocalizedMessage.SET_CHANNEL.toString().replace("{channel_color}", channel.getColor() + "").replace("{channel_name}", channel.getName())); - Bukkit.getServer().getPluginManager().callEvent(channelJoinEvent); + plugin.getServer().getPluginManager().callEvent(channelJoinEvent); handleChannelJoinEvent(channelJoinEvent); return; } diff --git a/src/main/java/venture/Aust1n46/chat/initators/commands/Chatinfo.java b/src/main/java/venture/Aust1n46/chat/initators/commands/Chatinfo.java index 8fc5bf1..7a4bd59 100644 --- a/src/main/java/venture/Aust1n46/chat/initators/commands/Chatinfo.java +++ b/src/main/java/venture/Aust1n46/chat/initators/commands/Chatinfo.java @@ -1,6 +1,5 @@ package venture.Aust1n46.chat.initators.commands; -import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -29,7 +28,7 @@ public class Chatinfo extends UniversalCommand { if (sender.hasPermission("venturechat.chatinfo")) { if (args.length == 0) { if (!(sender instanceof Player)) { - Bukkit.getServer().getConsoleSender().sendMessage(ChatColor.RED + "This command must be run by a player; use /ci [name]"); + plugin.getServer().getConsoleSender().sendMessage(ChatColor.RED + "This command must be run by a player; use /ci [name]"); return; } VentureChatPlayer mcp = playerApiService.getOnlineMineverseChatPlayer((Player) sender); diff --git a/src/main/java/venture/Aust1n46/chat/initators/commands/Chatreload.java b/src/main/java/venture/Aust1n46/chat/initators/commands/Chatreload.java index 7aaee6f..51a671c 100644 --- a/src/main/java/venture/Aust1n46/chat/initators/commands/Chatreload.java +++ b/src/main/java/venture/Aust1n46/chat/initators/commands/Chatreload.java @@ -2,7 +2,6 @@ package venture.Aust1n46.chat.initators.commands; import java.util.UUID; -import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -49,9 +48,9 @@ public class Chatreload extends UniversalCommand { for (Player p : plugin.getServer().getOnlinePlayers()) { VentureChatPlayer mcp = playerApiService.getMineverseChatPlayer(p); if (mcp == null) { - Bukkit.getConsoleSender() + plugin.getServer().getConsoleSender() .sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&c - Could not find player data post reload for currently online player: " + p.getName())); - Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&c - There could be an issue with your player data saving.")); + plugin.getServer().getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&c - There could be an issue with your player data saving.")); String name = p.getName(); UUID uuid = p.getUniqueId(); mcp = new VentureChatPlayer(uuid, name, configService.getDefaultChannel()); @@ -72,7 +71,7 @@ public class Chatreload extends UniversalCommand { playerApiService.addNameToMap(mcp); } - Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&e - Config reloaded")); + plugin.getServer().getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&e - Config reloaded")); for (VentureChatPlayer player : playerApiService.getOnlineMineverseChatPlayers()) { if (player.getPlayer().hasPermission("venturechat.reload")) { player.getPlayer().sendMessage(LocalizedMessage.CONFIG_RELOADED.toString()); diff --git a/src/main/java/venture/Aust1n46/chat/initators/commands/Party.java b/src/main/java/venture/Aust1n46/chat/initators/commands/Party.java index 4bb9061..44e32b7 100644 --- a/src/main/java/venture/Aust1n46/chat/initators/commands/Party.java +++ b/src/main/java/venture/Aust1n46/chat/initators/commands/Party.java @@ -72,11 +72,6 @@ public class Party extends PlayerCommand { if (player != null) { if (player.isHost()) { if (!mcp.hasParty()) { - /* - * if(plugin.getMetadata(player, "MineverseChat.party.ban." + tp.getName(), - * plugin)) { player.sendMessage(ChatColor.RED + "You are banned from " + - * tp.getName() + "'s party."); break; } - */ mcp.getPlayer().sendMessage(ChatColor.GREEN + "Joined " + player.getName() + "'s party."); mcp.setParty(player.getUuid()); player.getPlayer().sendMessage(ChatColor.GREEN + mcp.getName() + " joined your party."); @@ -151,37 +146,6 @@ public class Party extends PlayerCommand { mcp.getPlayer().sendMessage(ChatColor.RED + "You are not hosting a party."); break; } - /* - * case "ban": { if(mcp.isHost()) { if(args.length > 1) { Player tp = - * Bukkit.getPlayer(args[1]); if(tp != null) { - * if(!tp.getName().equals(player.getName())) { - * tp.setMetadata("MineverseChat.party.ban." + player.getUniqueId().toString(), - * new FixedMetadataValue(plugin, true)); if(plugin.getMetadataString(tp, - * "MineverseChat.party", plugin).equals(plugin.getMetadataString(player, - * "MineverseChat.party", plugin))) { tp.setMetadata("MineverseChat.party", new - * FixedMetadataValue(plugin, "")); } tp.sendMessage(ChatColor.RED + - * "You have been banned from " + player.getName() + "'s party."); - * player.sendMessage(ChatColor.RED + "You have banned " + tp.getName() + - * " from your party."); break; } player.sendMessage(ChatColor.RED + - * "You cannot ban yourself."); break; } player.sendMessage(ChatColor.RED + - * "Player: " + ChatColor.GOLD + args[1] + ChatColor.RED + " is not online."); - * break; } player.sendMessage(ChatColor.RED + - * "Invalid command: /party ban [playername]"); break; } - * player.sendMessage(ChatColor.RED + "You are not hosting a party."); break; } - * case "unban": { if(plugin.getMetadata(player, "MineverseChat.party.host", - * plugin)) { if(args.length > 1) { Player tp = Bukkit.getPlayer(args[1]); if(tp - * != null) { if(!tp.getName().equals(player.getName())) { - * tp.setMetadata("MineverseChat.party.ban." + player.getUniqueId(), new - * FixedMetadataValue(plugin, false)); tp.sendMessage(ChatColor.RED + - * "You have been unbanned from " + player.getName() + "'s party."); - * player.sendMessage(ChatColor.RED + "You have unbanned " + tp.getName() + - * " from your party."); break; } player.sendMessage(ChatColor.RED + - * "You cannot unban yourself."); break; } player.sendMessage(ChatColor.RED + - * "Player: " + ChatColor.GOLD + args[1] + ChatColor.RED + " is not online."); - * break; } player.sendMessage(ChatColor.RED + - * "Invalid command: /party unban [playername]"); break; } - * player.sendMessage(ChatColor.RED + "You are not hosting a party."); break; } - */ case "info": { if (!mcp.getPlayer().hasPermission("venturechat.party.info")) { mcp.getPlayer().sendMessage(ChatColor.RED + "You do not have permission for this command!"); diff --git a/src/main/java/venture/Aust1n46/chat/initators/commands/VentureChatGui.java b/src/main/java/venture/Aust1n46/chat/initators/commands/VentureChatGui.java index 7f7928d..a790d3f 100644 --- a/src/main/java/venture/Aust1n46/chat/initators/commands/VentureChatGui.java +++ b/src/main/java/venture/Aust1n46/chat/initators/commands/VentureChatGui.java @@ -3,7 +3,6 @@ package venture.Aust1n46.chat.initators.commands; import java.util.ArrayList; import java.util.List; -import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -79,7 +78,7 @@ public class VentureChatGui extends PlayerCommand { @SuppressWarnings("deprecation") private void openInventory(VentureChatPlayer mcp, VentureChatPlayer target, ChatChannel channel, int hash) { - Inventory inv = Bukkit.createInventory(null, this.getSlots(), "VentureChat: " + target.getName() + " GUI"); + Inventory inv = plugin.getServer().createInventory(null, this.getSlots(), "VentureChat: " + target.getName() + " GUI"); ItemStack close = null; ItemStack skull = null; if (versionService.is1_7()) { @@ -136,7 +135,7 @@ public class VentureChatGui extends PlayerCommand { @SuppressWarnings("deprecation") private void openInventoryDiscord(VentureChatPlayer mcp, ChatChannel channel, int hash) { - Inventory inv = Bukkit.createInventory(null, this.getSlots(), "VentureChat: Discord_Message GUI"); + Inventory inv = plugin.getServer().createInventory(null, this.getSlots(), "VentureChat: Discord_Message GUI"); ItemStack close = null; ItemStack skull = null; if (versionService.is1_7()) { diff --git a/src/main/java/venture/Aust1n46/chat/initiators/listeners/ChatListener.java b/src/main/java/venture/Aust1n46/chat/initiators/listeners/ChatListener.java index 6a0eac7..e46a239 100644 --- a/src/main/java/venture/Aust1n46/chat/initiators/listeners/ChatListener.java +++ b/src/main/java/venture/Aust1n46/chat/initiators/listeners/ChatListener.java @@ -4,7 +4,6 @@ import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; import java.util.Set; -import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.entity.Player; @@ -40,7 +39,7 @@ import venture.Aust1n46.chat.utilities.FormatUtils; @SuppressWarnings("deprecation") @Singleton public class ChatListener implements Listener { - private final boolean essentialsDiscordHook = Bukkit.getPluginManager().isPluginEnabled("EssentialsDiscord"); + private boolean essentialsDiscordHook; @Inject private VentureChat plugin; @Inject @@ -54,226 +53,214 @@ public class ChatListener implements Listener { @Inject private ConfigService configService; - // this event isn't always asynchronous even though the event's name starts with "Async" - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + @Inject + public void postConstruct() { + essentialsDiscordHook = plugin.getServer().getPluginManager().isPluginEnabled("EssentialsDiscord"); + } + + // this event isn't always asynchronous even though the event's name starts with + // "Async" + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onAsyncPlayerChatEvent(AsyncPlayerChatEvent event) { event.setCancelled(true); - Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() { + plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() { @Override public void run() { handleTrueAsyncPlayerChatEvent(event); } }); } - - public void handleTrueAsyncPlayerChatEvent(AsyncPlayerChatEvent event) { - boolean bungee = false; + + private void processPrivateMessageConversation(final VentureChatPlayer ventureChatPlayer, final String chat) { + VentureChatPlayer tp = playerApiService.getMineverseChatPlayer(ventureChatPlayer.getConversation()); + if (!tp.isOnline()) { + ventureChatPlayer.getPlayer().sendMessage(ChatColor.RED + tp.getName() + " is not available."); + if (!ventureChatPlayer.getPlayer().hasPermission("venturechat.spy.override")) { + for (VentureChatPlayer p : playerApiService.getOnlineMineverseChatPlayers()) { + if (p.getName().equals(ventureChatPlayer.getName())) { + continue; + } + if (p.isSpy()) { + p.getPlayer().sendMessage(LocalizedMessage.EXIT_PRIVATE_CONVERSATION_SPY.toString().replace("{player_sender}", ventureChatPlayer.getName()) + .replace("{player_receiver}", tp.getName())); + } + } + } + ventureChatPlayer.setConversation(null); + } else { + if (tp.getIgnores().contains(ventureChatPlayer.getUuid())) { + ventureChatPlayer.getPlayer().sendMessage(LocalizedMessage.IGNORING_MESSAGE.toString().replace("{player}", tp.getName())); + return; + } + if (!tp.isMessageToggle()) { + ventureChatPlayer.getPlayer().sendMessage(LocalizedMessage.BLOCKING_MESSAGE.toString().replace("{player}", tp.getName())); + return; + } + String filtered = chat; + String echo = ""; + String send = ""; + String spy = ""; + if (ventureChatPlayer.isFilter()) { + filtered = formatService.FilterChat(filtered); + } + if (ventureChatPlayer.getPlayer().hasPermission("venturechat.color.legacy")) { + filtered = FormatUtils.FormatStringLegacyColor(filtered); + } + if (ventureChatPlayer.getPlayer().hasPermission("venturechat.color")) { + filtered = FormatUtils.FormatStringColor(filtered); + } + if (ventureChatPlayer.getPlayer().hasPermission("venturechat.format")) { + filtered = FormatUtils.FormatString(filtered); + } + filtered = " " + filtered; + + send = FormatUtils.FormatStringAll( + PlaceholderAPI.setBracketPlaceholders(ventureChatPlayer.getPlayer(), plugin.getConfig().getString("tellformatfrom").replaceAll("sender_", ""))); + echo = FormatUtils + .FormatStringAll(PlaceholderAPI.setBracketPlaceholders(ventureChatPlayer.getPlayer(), plugin.getConfig().getString("tellformatto").replaceAll("sender_", ""))); + spy = FormatUtils + .FormatStringAll(PlaceholderAPI.setBracketPlaceholders(ventureChatPlayer.getPlayer(), plugin.getConfig().getString("tellformatspy").replaceAll("sender_", ""))); + + send = FormatUtils.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(tp.getPlayer(), send.replaceAll("receiver_", ""))) + filtered; + echo = FormatUtils.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(tp.getPlayer(), echo.replaceAll("receiver_", ""))) + filtered; + spy = FormatUtils.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(tp.getPlayer(), spy.replaceAll("receiver_", ""))) + filtered; + + if (!ventureChatPlayer.getPlayer().hasPermission("venturechat.spy.override")) { + for (VentureChatPlayer p : playerApiService.getOnlineMineverseChatPlayers()) { + if (p.getName().equals(ventureChatPlayer.getName()) || p.getName().equals(tp.getName())) { + continue; + } + if (p.isSpy()) { + p.getPlayer().sendMessage(spy); + } + } + } + tp.getPlayer().sendMessage(send); + ventureChatPlayer.getPlayer().sendMessage(echo); + if (tp.isNotifications()) { + formatService.playMessageSound(tp); + } + ventureChatPlayer.setReplyPlayer(tp.getUuid()); + tp.setReplyPlayer(ventureChatPlayer.getUuid()); + if (databaseService.isEnabled()) { + databaseService.writeVentureChat(ventureChatPlayer.getUuid().toString(), ventureChatPlayer.getName(), "Local", "Messaging_Component", chat.replace("'", "''"), + "Chat"); + } + } + } + + private void processPartyChat(final VentureChatPlayer ventureChatPlayer, final String chat) { + if (ventureChatPlayer.hasParty()) { + String partyformat = ""; + for (VentureChatPlayer p : playerApiService.getOnlineMineverseChatPlayers()) { + if ((p.hasParty() && p.getParty().toString().equals(ventureChatPlayer.getParty().toString()) || p.isSpy())) { + String filtered = chat; + if (ventureChatPlayer.isFilter()) { + filtered = formatService.FilterChat(filtered); + } + if (ventureChatPlayer.getPlayer().hasPermission("venturechat.color.legacy")) { + filtered = FormatUtils.FormatStringLegacyColor(filtered); + } + if (ventureChatPlayer.getPlayer().hasPermission("venturechat.color")) { + filtered = FormatUtils.FormatStringColor(filtered); + } + if (ventureChatPlayer.getPlayer().hasPermission("venturechat.format")) { + filtered = FormatUtils.FormatString(filtered); + } + filtered = " " + filtered; + if (plugin.getConfig().getString("partyformat").equalsIgnoreCase("Default")) { + partyformat = ChatColor.GREEN + "[" + playerApiService.getMineverseChatPlayer(ventureChatPlayer.getParty()).getName() + "'s Party] " + + ventureChatPlayer.getName() + ":" + filtered; + } else { + partyformat = FormatUtils.FormatStringAll( + plugin.getConfig().getString("partyformat").replace("{host}", playerApiService.getMineverseChatPlayer(ventureChatPlayer.getParty()).getName()) + .replace("{player}", ventureChatPlayer.getName())) + + filtered; + } + p.getPlayer().sendMessage(partyformat); + } + } + plugin.getServer().getConsoleSender().sendMessage(partyformat); + if (databaseService.isEnabled()) { + databaseService.writeVentureChat(ventureChatPlayer.getUuid().toString(), ventureChatPlayer.getName(), "Local", "Party_Component", chat.replace("'", "''"), "Chat"); + } + return; + } + ventureChatPlayer.getPlayer().sendMessage(ChatColor.RED + "You are not in a party."); + } + + private void processMute(final VentureChatPlayer ventureChatPlayer, final ChatChannel channel) { + MuteContainer muteContainer = ventureChatPlayer.getMute(channel.getName()); + if (muteContainer.hasDuration()) { + long dateTimeMillis = System.currentTimeMillis(); + long muteTimeMillis = muteContainer.getDuration(); + long remainingMuteTime = muteTimeMillis - dateTimeMillis; + if (remainingMuteTime < 1000) { + remainingMuteTime = 1000; + } + String timeString = FormatUtils.parseTimeStringFromMillis(remainingMuteTime); + if (muteContainer.hasReason()) { + ventureChatPlayer.getPlayer().sendMessage(LocalizedMessage.CHANNEL_MUTED_TIMED_REASON.toString().replace("{channel_color}", channel.getColor()) + .replace("{channel_name}", channel.getName()).replace("{time}", timeString).replace("{reason}", muteContainer.getReason())); + } else { + ventureChatPlayer.getPlayer().sendMessage(LocalizedMessage.CHANNEL_MUTED_TIMED.toString().replace("{channel_color}", channel.getColor()) + .replace("{channel_name}", channel.getName()).replace("{time}", timeString)); + } + } else { + if (muteContainer.hasReason()) { + ventureChatPlayer.getPlayer().sendMessage(LocalizedMessage.CHANNEL_MUTED_REASON.toString().replace("{channel_color}", channel.getColor()) + .replace("{channel_name}", channel.getName()).replace("{reason}", muteContainer.getReason())); + } else { + ventureChatPlayer.getPlayer() + .sendMessage(LocalizedMessage.CHANNEL_MUTED.toString().replace("{channel_color}", channel.getColor()).replace("{channel_name}", channel.getName())); + } + } + ventureChatPlayer.setQuickChat(false); + } + + private void handleTrueAsyncPlayerChatEvent(final AsyncPlayerChatEvent event) { String chat = event.getMessage(); String format; - Set recipients = event.getRecipients(); - int recipientCount = recipients.size(); // Don't count vanished players VentureChatPlayer mcp = playerApiService.getOnlineMineverseChatPlayer(event.getPlayer()); ChatChannel eventChannel = mcp.getCurrentChannel(); - - if(mcp.isEditing()) { + if (mcp.isEditing()) { mcp.getPlayer().sendMessage(FormatUtils.FormatStringAll(chat)); mcp.setEditing(false); return; } - - if(mcp.isQuickChat()) { + if (mcp.isQuickChat()) { eventChannel = mcp.getQuickChannel(); } - - if(mcp.hasConversation() && !mcp.isQuickChat()) { - VentureChatPlayer tp = playerApiService.getMineverseChatPlayer(mcp.getConversation()); - if(!tp.isOnline()) { - mcp.getPlayer().sendMessage(ChatColor.RED + tp.getName() + " is not available."); - if(!mcp.getPlayer().hasPermission("venturechat.spy.override")) { - for(VentureChatPlayer p : playerApiService.getOnlineMineverseChatPlayers()) { - if(p.getName().equals(mcp.getName())) { - continue; - } - if(p.isSpy()) { - p.getPlayer().sendMessage(LocalizedMessage.EXIT_PRIVATE_CONVERSATION_SPY.toString() - .replace("{player_sender}", mcp.getName()) - .replace("{player_receiver}", tp.getName())); - } - } - } - mcp.setConversation(null); - } - else { - if(tp.getIgnores().contains(mcp.getUuid())) { - mcp.getPlayer().sendMessage(LocalizedMessage.IGNORING_MESSAGE.toString() - .replace("{player}", tp.getName())); - event.setCancelled(true); - return; - } - if(!tp.isMessageToggle()) { - mcp.getPlayer().sendMessage(LocalizedMessage.BLOCKING_MESSAGE.toString() - .replace("{player}", tp.getName())); - event.setCancelled(true); - return; - } - String filtered = chat; - String echo = ""; - String send = ""; - String spy = ""; - if(mcp.isFilter()) { - filtered = formatService.FilterChat(filtered); - } - if(mcp.getPlayer().hasPermission("venturechat.color.legacy")) { - filtered = FormatUtils.FormatStringLegacyColor(filtered); - } - if(mcp.getPlayer().hasPermission("venturechat.color")) { - filtered = FormatUtils.FormatStringColor(filtered); - } - if(mcp.getPlayer().hasPermission("venturechat.format")) { - filtered = FormatUtils.FormatString(filtered); - } - filtered = " " + filtered; - - send = FormatUtils.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(mcp.getPlayer(), plugin.getConfig().getString("tellformatfrom").replaceAll("sender_", ""))); - echo = FormatUtils.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(mcp.getPlayer(), plugin.getConfig().getString("tellformatto").replaceAll("sender_", ""))); - spy = FormatUtils.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(mcp.getPlayer(), plugin.getConfig().getString("tellformatspy").replaceAll("sender_", ""))); - - send = FormatUtils.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(tp.getPlayer(), send.replaceAll("receiver_", ""))) + filtered; - echo = FormatUtils.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(tp.getPlayer(), echo.replaceAll("receiver_", ""))) + filtered; - spy = FormatUtils.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(tp.getPlayer(), spy.replaceAll("receiver_", ""))) + filtered; - - if(!mcp.getPlayer().hasPermission("venturechat.spy.override")) { - for(VentureChatPlayer p : playerApiService.getOnlineMineverseChatPlayers()) { - if(p.getName().equals(mcp.getName()) || p.getName().equals(tp.getName())) { - continue; - } - if(p.isSpy()) { - p.getPlayer().sendMessage(spy); - } - } - } - tp.getPlayer().sendMessage(send); - mcp.getPlayer().sendMessage(echo); - if(tp.isNotifications()) { - formatService.playMessageSound(tp); - } - mcp.setReplyPlayer(tp.getUuid()); - tp.setReplyPlayer(mcp.getUuid()); - if(databaseService.isEnabled()) { - databaseService.writeVentureChat(mcp.getUuid().toString(), mcp.getName(), "Local", "Messaging_Component", chat.replace("'", "''"), "Chat"); - } - } + if (mcp.hasConversation() && !mcp.isQuickChat()) { + processPrivateMessageConversation(mcp, chat); return; } - - if(mcp.isPartyChat() && !mcp.isQuickChat()) { - if(mcp.hasParty()) { - String partyformat = ""; - for(VentureChatPlayer p : playerApiService.getOnlineMineverseChatPlayers()) { - if((p.hasParty() && p.getParty().toString().equals(mcp.getParty().toString()) || p.isSpy())) { - String filtered = chat; - if(mcp.isFilter()) { - filtered = formatService.FilterChat(filtered); - } - if(mcp.getPlayer().hasPermission("venturechat.color.legacy")) { - filtered = FormatUtils.FormatStringLegacyColor(filtered); - } - if(mcp.getPlayer().hasPermission("venturechat.color")) { - filtered = FormatUtils.FormatStringColor(filtered); - } - if(mcp.getPlayer().hasPermission("venturechat.format")) { - filtered = FormatUtils.FormatString(filtered); - } - filtered = " " + filtered; - if(plugin.getConfig().getString("partyformat").equalsIgnoreCase("Default")) { - partyformat = ChatColor.GREEN + "[" + playerApiService.getMineverseChatPlayer(mcp.getParty()).getName() + "'s Party] " + mcp.getName() + ":" + filtered; - } - else { - partyformat = FormatUtils.FormatStringAll(plugin.getConfig().getString("partyformat").replace("{host}", playerApiService.getMineverseChatPlayer(mcp.getParty()).getName()).replace("{player}", mcp.getName())) + filtered; - } - p.getPlayer().sendMessage(partyformat); - } - } - Bukkit.getConsoleSender().sendMessage(partyformat); - if(databaseService.isEnabled()) { - databaseService.writeVentureChat(mcp.getUuid().toString(), mcp.getName(), "Local", "Party_Component", chat.replace("'", "''"), "Chat"); - } - return; - } - mcp.getPlayer().sendMessage(ChatColor.RED + "You are not in a party."); + if (mcp.isPartyChat() && !mcp.isQuickChat()) { + processPartyChat(mcp, chat); return; } - - Location locreceip; - Location locsender = mcp.getPlayer().getLocation(); - Location diff; - Boolean filterthis = true; - mcp.addListening(eventChannel.getName()); - if (mcp.isMuted(eventChannel.getName())) { - MuteContainer muteContainer = mcp.getMute(eventChannel.getName()); - if (muteContainer.hasDuration()) { - long dateTimeMillis = System.currentTimeMillis(); - long muteTimeMillis = muteContainer.getDuration(); - long remainingMuteTime = muteTimeMillis - dateTimeMillis; - if (remainingMuteTime < 1000) { - remainingMuteTime = 1000; - } - String timeString = FormatUtils.parseTimeStringFromMillis(remainingMuteTime); - if(muteContainer.hasReason()) { - mcp.getPlayer() - .sendMessage(LocalizedMessage.CHANNEL_MUTED_TIMED_REASON.toString() - .replace("{channel_color}", eventChannel.getColor()) - .replace("{channel_name}", eventChannel.getName()) - .replace("{time}", timeString) - .replace("{reason}", muteContainer.getReason())); - } - else { - mcp.getPlayer() - .sendMessage(LocalizedMessage.CHANNEL_MUTED_TIMED.toString() - .replace("{channel_color}", eventChannel.getColor()) - .replace("{channel_name}", eventChannel.getName()) - .replace("{time}", timeString)); - } - } - else { - if(muteContainer.hasReason()) { - mcp.getPlayer() - .sendMessage(LocalizedMessage.CHANNEL_MUTED_REASON.toString() - .replace("{channel_color}", eventChannel.getColor()) - .replace("{channel_name}", eventChannel.getName()) - .replace("{reason}", muteContainer.getReason())); - } - else { - mcp.getPlayer() - .sendMessage(LocalizedMessage.CHANNEL_MUTED.toString() - .replace("{channel_color}", eventChannel.getColor()) - .replace("{channel_name}", eventChannel.getName())); - } - } - mcp.setQuickChat(false); - return; - } - Double chDistance = (double) 0; - String curColor = ""; - if(eventChannel.hasPermission() && !mcp.getPlayer().hasPermission(eventChannel.getPermission())) { + if (eventChannel.hasPermission() && !mcp.getPlayer().hasPermission(eventChannel.getPermission())) { mcp.getPlayer().sendMessage(LocalizedMessage.CHANNEL_NO_PERMISSION.toString()); mcp.setQuickChat(false); mcp.removeListening(eventChannel.getName()); mcp.setCurrentChannel(configService.getDefaultChannel()); return; + } else { + mcp.addListening(eventChannel.getName()); } - if(eventChannel.hasSpeakPermission() && !mcp.getPlayer().hasPermission(eventChannel.getSpeakPermission())) { + if (eventChannel.hasSpeakPermission() && !mcp.getPlayer().hasPermission(eventChannel.getSpeakPermission())) { mcp.getPlayer().sendMessage(LocalizedMessage.CHANNEL_NO_SPEAK_PERMISSIONS.toString()); mcp.setQuickChat(false); return; } - curColor = eventChannel.getChatColor(); - bungee = eventChannel.getBungee(); - + if (mcp.isMuted(eventChannel.getName())) { + processMute(mcp, eventChannel); + return; + } + long dateTimeSeconds = System.currentTimeMillis() / FormatUtils.MILLISECONDS_PER_SECOND; - int chCooldown = 0; - if(eventChannel.hasCooldown()) { + if (eventChannel.hasCooldown()) { chCooldown = eventChannel.getCooldown(); } try { @@ -282,10 +269,8 @@ public class ChatListener implements Listener { if (dateTimeSeconds < cooldownTime) { long remainingCooldownTime = cooldownTime - dateTimeSeconds; String cooldownString = FormatUtils.parseTimeStringFromMillis(remainingCooldownTime * FormatUtils.MILLISECONDS_PER_SECOND); - mcp.getPlayer().sendMessage(LocalizedMessage.CHANNEL_COOLDOWN.toString() - .replace("{cooldown}", cooldownString)); + mcp.getPlayer().sendMessage(LocalizedMessage.CHANNEL_COOLDOWN.toString().replace("{cooldown}", cooldownString)); mcp.setQuickChat(false); - bungee = false; return; } } @@ -297,7 +282,7 @@ public class ChatListener implements Listener { } catch (NumberFormatException e) { e.printStackTrace(); } - + if (mcp.hasSpam(eventChannel) && plugin.getConfig().getConfigurationSection("antispam").getBoolean("enabled") && !mcp.getPlayer().hasPermission("venturechat.spam.bypass")) { long spamcount = mcp.getSpam().get(eventChannel).get(0); @@ -305,29 +290,22 @@ public class ChatListener implements Listener { long spamtimeconfig = plugin.getConfig().getConfigurationSection("antispam").getLong("spamnumber"); String mutedForTime = plugin.getConfig().getConfigurationSection("antispam").getString("mutetime", "0"); long dateTime = System.currentTimeMillis(); - if (dateTimeSeconds < spamtime - + plugin.getConfig().getConfigurationSection("antispam").getLong("spamtime")) { + if (dateTimeSeconds < spamtime + plugin.getConfig().getConfigurationSection("antispam").getLong("spamtime")) { if (spamcount + 1 >= spamtimeconfig) { long time = FormatUtils.parseTimeStringToMillis(mutedForTime); if (time > 0) { mcp.addMute(eventChannel.getName(), dateTime + time, LocalizedMessage.SPAM_MUTE_REASON_TEXT.toString()); String timeString = FormatUtils.parseTimeStringFromMillis(time); mcp.getPlayer() - .sendMessage(LocalizedMessage.MUTE_PLAYER_PLAYER_TIME_REASON.toString() - .replace("{channel_color}", eventChannel.getColor()) - .replace("{channel_name}", eventChannel.getName()) - .replace("{time}", timeString) + .sendMessage(LocalizedMessage.MUTE_PLAYER_PLAYER_TIME_REASON.toString().replace("{channel_color}", eventChannel.getColor()) + .replace("{channel_name}", eventChannel.getName()).replace("{time}", timeString) .replace("{reason}", LocalizedMessage.SPAM_MUTE_REASON_TEXT.toString())); - } - else { + } else { mcp.addMute(eventChannel.getName(), LocalizedMessage.SPAM_MUTE_REASON_TEXT.toString()); - mcp.getPlayer() - .sendMessage(LocalizedMessage.MUTE_PLAYER_PLAYER_REASON.toString() - .replace("{channel_color}", eventChannel.getColor()) - .replace("{channel_name}", eventChannel.getName()) - .replace("{reason}", LocalizedMessage.SPAM_MUTE_REASON_TEXT.toString())); + mcp.getPlayer().sendMessage(LocalizedMessage.MUTE_PLAYER_PLAYER_REASON.toString().replace("{channel_color}", eventChannel.getColor()) + .replace("{channel_name}", eventChannel.getName()).replace("{reason}", LocalizedMessage.SPAM_MUTE_REASON_TEXT.toString())); } - if(eventChannel.getBungee()) { + if (eventChannel.getBungee()) { pluginMessageController.synchronize(mcp, true); } mcp.getSpam().get(eventChannel).set(0, 0L); @@ -351,165 +329,158 @@ public class ChatListener implements Listener { mcp.getSpam().get(eventChannel).add(0, 1L); mcp.getSpam().get(eventChannel).add(1, dateTimeSeconds); } - - if(eventChannel.hasDistance()) { - chDistance = eventChannel.getDistance(); - } - + format = FormatUtils.FormatStringAll(eventChannel.getFormat()); - - filterthis = eventChannel.isFiltered(); - if(filterthis) { - if(mcp.isFilter()) { - chat = formatService.FilterChat(chat); - } + + if (eventChannel.isFiltered() && mcp.isFilter()) { + chat = formatService.FilterChat(chat); } PluginManager pluginManager = plugin.getServer().getPluginManager(); - for(VentureChatPlayer p : playerApiService.getOnlineMineverseChatPlayers()) { - if(p.getPlayer() != mcp.getPlayer()) { - if(!configService.isListening(p, eventChannel.getName())) { + Set recipients = event.getRecipients(); + int recipientCount = recipients.size(); // Don't count vanished players + for (VentureChatPlayer p : playerApiService.getOnlineMineverseChatPlayers()) { + if (p.getPlayer() != mcp.getPlayer()) { + if (!configService.isListening(p, eventChannel.getName())) { recipients.remove(p.getPlayer()); recipientCount--; continue; } - if(plugin.getConfig().getBoolean("ignorechat", false) && p.getIgnores().contains(mcp.getUuid())) { + if (plugin.getConfig().getBoolean("ignorechat", false) && p.getIgnores().contains(mcp.getUuid())) { recipients.remove(p.getPlayer()); recipientCount--; continue; } - if(plugin.getConfig().getBoolean("enable_towny_channel") && pluginManager.isPluginEnabled("Towny")) { + if (plugin.getConfig().getBoolean("enable_towny_channel") && pluginManager.isPluginEnabled("Towny")) { try { TownyUniverse towny = TownyUniverse.getInstance(); - if(eventChannel.getName().equalsIgnoreCase("Town")) { + if (eventChannel.getName().equalsIgnoreCase("Town")) { Resident r = towny.getResident(p.getName()); Resident pp = towny.getResident(mcp.getName()); - if(!pp.hasTown()) { + if (!pp.hasTown()) { recipients.remove(p.getPlayer()); recipientCount--; continue; - } - else if(!r.hasTown()) { + } else if (!r.hasTown()) { recipients.remove(p.getPlayer()); recipientCount--; continue; - } - else if(!(r.getTown().getName().equals(pp.getTown().getName()))) { + } else if (!(r.getTown().getName().equals(pp.getTown().getName()))) { recipients.remove(p.getPlayer()); recipientCount--; continue; } } - if(eventChannel.getName().equalsIgnoreCase("Nation")) { + if (eventChannel.getName().equalsIgnoreCase("Nation")) { Resident r = towny.getResident(p.getName()); Resident pp = towny.getResident(mcp.getName()); - if(!pp.hasNation()) { + if (!pp.hasNation()) { recipients.remove(p.getPlayer()); recipientCount--; continue; - } - else if(!r.hasNation()) { + } else if (!r.hasNation()) { recipients.remove(p.getPlayer()); recipientCount--; continue; - } - else if(!(r.getTown().getNation().getName().equals(pp.getTown().getNation().getName()))) { + } else if (!(r.getTown().getNation().getName().equals(pp.getTown().getNation().getName()))) { recipients.remove(p.getPlayer()); recipientCount--; continue; } } - } - catch(Exception ex) { + } catch (Exception ex) { ex.printStackTrace(); } } - if(plugin.getConfig().getBoolean("enable_factions_channel") && pluginManager.isPluginEnabled("Factions")) { + if (plugin.getConfig().getBoolean("enable_factions_channel") && pluginManager.isPluginEnabled("Factions")) { try { - if(eventChannel.getName().equalsIgnoreCase("Faction")) { + if (eventChannel.getName().equalsIgnoreCase("Faction")) { MPlayer mplayer = MPlayer.get(mcp.getPlayer()); MPlayer mplayerp = MPlayer.get(p.getPlayer()); - if(!mplayer.hasFaction()) { + if (!mplayer.hasFaction()) { recipients.remove(p.getPlayer()); recipientCount--; - } - else if(!mplayerp.hasFaction()) { + } else if (!mplayerp.hasFaction()) { recipients.remove(p.getPlayer()); recipientCount--; - } - else if(!(mplayer.getFactionName().equals(mplayerp.getFactionName()))) { + } else if (!(mplayer.getFactionName().equals(mplayerp.getFactionName()))) { recipients.remove(p.getPlayer()); recipientCount--; } } - } - catch(Exception ex) { + } catch (Exception ex) { ex.printStackTrace(); } } - if(chDistance > (double) 0 && !bungee && !p.getRangedSpy()) { - locreceip = p.getPlayer().getLocation(); - if(locreceip.getWorld() == mcp.getPlayer().getWorld()) { - diff = locreceip.subtract(locsender); - if(Math.abs(diff.getX()) > chDistance || Math.abs(diff.getZ()) > chDistance || Math.abs(diff.getY()) > chDistance) { + double chDistance = 0D; + if (eventChannel.hasDistance()) { + chDistance = eventChannel.getDistance(); + } + if (chDistance > (double) 0 && !eventChannel.getBungee() && !p.getRangedSpy()) { + final Location locreceip = p.getPlayer().getLocation(); + if (locreceip.getWorld() == mcp.getPlayer().getWorld()) { + final Location locsender = mcp.getPlayer().getLocation(); + final Location diff = locreceip.subtract(locsender); + if (Math.abs(diff.getX()) > chDistance || Math.abs(diff.getZ()) > chDistance || Math.abs(diff.getY()) > chDistance) { recipients.remove(p.getPlayer()); recipientCount--; continue; } - if(!mcp.getPlayer().canSee(p.getPlayer())) { + if (!mcp.getPlayer().canSee(p.getPlayer())) { recipientCount--; continue; } - } - else { + } else { recipients.remove(p.getPlayer()); recipientCount--; continue; } } - if(!mcp.getPlayer().canSee(p.getPlayer())) { + if (!mcp.getPlayer().canSee(p.getPlayer())) { recipientCount--; continue; } } } - - if(mcp.getPlayer().hasPermission("venturechat.color.legacy")) { + + if (mcp.getPlayer().hasPermission("venturechat.color.legacy")) { chat = FormatUtils.FormatStringLegacyColor(chat); } - if(mcp.getPlayer().hasPermission("venturechat.color")) { + if (mcp.getPlayer().hasPermission("venturechat.color")) { chat = FormatUtils.FormatStringColor(chat); } - if(mcp.getPlayer().hasPermission("venturechat.format")) { + if (mcp.getPlayer().hasPermission("venturechat.format")) { chat = FormatUtils.FormatString(chat); } - if(!mcp.isQuickChat()) { + if (!mcp.isQuickChat()) { chat = " " + chat; } - if(curColor.equalsIgnoreCase("None")) { - // Format the placeholders and their color codes to determine the last color code to use for the chat message color + final String curColor = eventChannel.getChatColor(); + if (curColor.equalsIgnoreCase("None")) { + // Format the placeholders and their color codes to determine the last color + // code to use for the chat message color chat = formatService.getLastCode(FormatUtils.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(mcp.getPlayer(), format))) + chat; - } - else { + } else { chat = curColor + chat; } - - String globalJSON = formatService.convertToJson(mcp, format, chat); + + String globalJSON = formatService.convertToJson(mcp, format, chat); format = FormatUtils.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(mcp.getPlayer(), FormatUtils.FormatStringAll(format))); String message = FormatUtils.stripColor(format + chat); // UTF-8 encoding issues. int hash = message.hashCode(); - - //Create VentureChatEvent - VentureChatEvent ventureChatEvent = new VentureChatEvent(mcp, mcp.getName(), plugin.getVaultPermission().getPrimaryGroup(mcp.getPlayer()), eventChannel, recipients, recipientCount, format, chat, globalJSON, hash, bungee); - //Fire event and wait for other plugin listeners to act on it - Bukkit.getServer().getPluginManager().callEvent(ventureChatEvent); - //Call method to send the processed chat + + // Create VentureChatEvent + VentureChatEvent ventureChatEvent = new VentureChatEvent(mcp, mcp.getName(), plugin.getVaultPermission().getPrimaryGroup(mcp.getPlayer()), eventChannel, recipients, + recipientCount, format, chat, globalJSON, hash, eventChannel.getBungee()); + // Fire event and wait for other plugin listeners to act on it + plugin.getServer().getPluginManager().callEvent(ventureChatEvent); + // Call method to send the processed chat handleVentureChatEvent(ventureChatEvent); // Reset quick chat flag mcp.setQuickChat(false); } - + public void handleVentureChatEvent(VentureChatEvent event) { VentureChatPlayer ventureChatPlayer = event.getVentureChatPlayer(); ChatChannel channel = event.getChannel(); @@ -523,28 +494,27 @@ public class ChatListener implements Listener { boolean bungee = event.isBungee(); if (essentialsDiscordHook && channel.isDefaultchannel()) { - Bukkit.getServicesManager().load(DiscordService.class).sendChatMessage(ventureChatPlayer.getPlayer(), chat); + plugin.getServer().getServicesManager().load(DiscordService.class).sendChatMessage(ventureChatPlayer.getPlayer(), chat); } - - if(!bungee) { - if(databaseService.isEnabled()) { + + if (!bungee) { + if (databaseService.isEnabled()) { databaseService.writeVentureChat(ventureChatPlayer.getUuid().toString(), ventureChatPlayer.getName(), "Local", channel.getName(), chat.replace("'", "''"), "Chat"); } - - if(recipientCount == 1) { - if(!plugin.getConfig().getString("emptychannelalert", "&6No one is listening to you.").equals("")) { - ventureChatPlayer.getPlayer().sendMessage(FormatUtils.FormatStringAll(plugin.getConfig().getString("emptychannelalert", "&6No one is listening to you."))); + + if (recipientCount == 1) { + if (!plugin.getConfig().getString("emptychannelalert", "&6No one is listening to you.").equals("")) { + ventureChatPlayer.getPlayer().sendMessage(FormatUtils.FormatStringAll(plugin.getConfig().getString("emptychannelalert", "&6No one is listening to you."))); } } - for(Player p : recipients) { + for (Player p : recipients) { String json = formatService.formatModerationGUI(globalJSON, p, ventureChatPlayer.getName(), channel.getName(), hash); PacketContainer packet = formatService.createPacketPlayOutChat(json); formatService.sendPacketPlayOutChat(p, packet); } - Bukkit.getConsoleSender().sendMessage(consoleChat); + plugin.getServer().getConsoleSender().sendMessage(consoleChat); return; - } - else { + } else { ByteArrayOutputStream byteOutStream = new ByteArrayOutputStream(); DataOutputStream out = new DataOutputStream(byteOutStream); try { @@ -556,11 +526,11 @@ public class ChatListener implements Listener { out.writeInt(hash); out.writeUTF(format); out.writeUTF(chat); - if(plugin.getConfig().getString("loglevel", "info").equals("debug")) { + if (plugin.getConfig().getString("loglevel", "info").equals("debug")) { System.out.println(out.size() + " size bytes without json"); } out.writeUTF(globalJSON); - if(plugin.getConfig().getString("loglevel", "info").equals("debug")) { + if (plugin.getConfig().getString("loglevel", "info").equals("debug")) { System.out.println(out.size() + " bytes size with json"); } out.writeUTF(plugin.getVaultPermission().getPrimaryGroup(ventureChatPlayer.getPlayer())); // look into not sending this @@ -568,8 +538,7 @@ public class ChatListener implements Listener { out.writeUTF(displayName); pluginMessageController.sendPluginMessage(byteOutStream); out.close(); - } - catch(Exception e) { + } catch (Exception e) { e.printStackTrace(); } return; diff --git a/src/main/java/venture/Aust1n46/chat/initiators/listeners/PreProcessCommandListener.java b/src/main/java/venture/Aust1n46/chat/initiators/listeners/PreProcessCommandListener.java index 169120c..b7349d1 100644 --- a/src/main/java/venture/Aust1n46/chat/initiators/listeners/PreProcessCommandListener.java +++ b/src/main/java/venture/Aust1n46/chat/initiators/listeners/PreProcessCommandListener.java @@ -2,7 +2,6 @@ package venture.Aust1n46.chat.initiators.listeners; import java.io.FileNotFoundException; -import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.command.Command; @@ -59,7 +58,8 @@ public class PreProcessCommandListener implements CommandExecutor, Listener { @EventHandler public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) throws FileNotFoundException { if (event.getPlayer() == null) { - Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&c - Event.getPlayer() returned null in PlayerCommandPreprocessEvent")); + plugin.getServer().getConsoleSender() + .sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&c - Event.getPlayer() returned null in PlayerCommandPreprocessEvent")); return; } ConfigurationSection cs = plugin.getConfig().getConfigurationSection("commandspy"); diff --git a/src/main/java/venture/Aust1n46/chat/model/VentureChatPlayer.java b/src/main/java/venture/Aust1n46/chat/model/VentureChatPlayer.java index 88b9b86..ac8e158 100644 --- a/src/main/java/venture/Aust1n46/chat/model/VentureChatPlayer.java +++ b/src/main/java/venture/Aust1n46/chat/model/VentureChatPlayer.java @@ -67,18 +67,9 @@ public class VentureChatPlayer { this.party = party; this.filter = filter; this.notifications = notifications; - this.online = false; - this.player = null; - this.hasPlayed = false; - this.conversation = null; this.spy = spy; this.rangedSpy = rangedSpy; this.commandSpy = commandSpy; - this.quickChat = false; - this.quickChannel = null; - this.replyPlayer = null; - this.partyChat = false; - this.modified = false; this.messages = new ArrayList(); this.jsonFormat = jsonFormat; this.cooldowns = new HashMap(); @@ -96,22 +87,8 @@ public class VentureChatPlayer { listening.add(currentChannel.getName()); this.mutes = new HashMap(); this.blockedCommands = new HashSet(); - this.host = false; - this.party = null; this.filter = true; this.notifications = true; - this.online = false; - this.player = null; - this.hasPlayed = false; - this.conversation = null; - this.spy = false; - this.rangedSpy = false; - this.commandSpy = false; - this.quickChat = false; - this.quickChannel = null; - this.replyPlayer = null; - this.partyChat = false; - this.modified = false; this.messages = new ArrayList(); this.jsonFormat = "Default"; this.cooldowns = new HashMap(); diff --git a/src/main/java/venture/Aust1n46/chat/service/ConfigService.java b/src/main/java/venture/Aust1n46/chat/service/ConfigService.java index 7175045..db64598 100644 --- a/src/main/java/venture/Aust1n46/chat/service/ConfigService.java +++ b/src/main/java/venture/Aust1n46/chat/service/ConfigService.java @@ -6,7 +6,6 @@ import java.util.HashMap; import java.util.HashSet; import java.util.List; -import org.bukkit.Bukkit; import org.bukkit.configuration.ConfigurationSection; import com.google.inject.Inject; @@ -65,7 +64,7 @@ public class ConfigService { } // Error handling for missing default channel in the config. if (defaultChatChannel == null) { - Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&e - &cNo default channel found!")); + plugin.getServer().getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&e - &cNo default channel found!")); defaultChatChannel = new ChatChannel("MissingDefault", "red", "red", "None", "None", false, true, true, "md", 0, true, false, 0, "&f[&cMissingDefault&f]", "{venturechat_channel_prefix} {vault_prefix}{player_displayname}&c:"); defaultColor = defaultChatChannel.getColor(); diff --git a/src/main/java/venture/Aust1n46/chat/service/UUIDService.java b/src/main/java/venture/Aust1n46/chat/service/UUIDService.java index 9ab80f0..01d77e6 100644 --- a/src/main/java/venture/Aust1n46/chat/service/UUIDService.java +++ b/src/main/java/venture/Aust1n46/chat/service/UUIDService.java @@ -2,8 +2,6 @@ package venture.Aust1n46.chat.service; import java.util.UUID; -import org.bukkit.Bukkit; - import com.google.inject.Inject; import com.google.inject.Singleton; @@ -21,16 +19,17 @@ public class UUIDService { public void checkOfflineUUIDWarning(UUID uuid) { if (shouldSkipOfflineUUID(uuid)) { - Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&c - Detected Offline UUID!")); - Bukkit.getConsoleSender() + plugin.getServer().getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&c - Detected Offline UUID!")); + plugin.getServer().getConsoleSender() .sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&c - If you are using BungeeCord, make sure you have properly setup IP Forwarding.")); - Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&c - https://www.spigotmc.org/wiki/bungeecord-ip-forwarding/")); - Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&c - You can access this wiki page from the log file or just Google it.")); - Bukkit.getConsoleSender().sendMessage(FormatUtils + plugin.getServer().getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&c - https://www.spigotmc.org/wiki/bungeecord-ip-forwarding/")); + plugin.getServer().getConsoleSender() + .sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&c - You can access this wiki page from the log file or just Google it.")); + plugin.getServer().getConsoleSender().sendMessage(FormatUtils .FormatStringAll("&8[&eVentureChat&8]&c - If you're running a \"cracked\" server, player data might not be stored properly, and thus, you are on your own.")); - Bukkit.getConsoleSender().sendMessage(FormatUtils + plugin.getServer().getConsoleSender().sendMessage(FormatUtils .FormatStringAll("&8[&eVentureChat&8]&c - If you run your server in offline mode, you will probably lose your player data when switching to online mode!")); - Bukkit.getConsoleSender().sendMessage(FormatUtils + plugin.getServer().getConsoleSender().sendMessage(FormatUtils .FormatStringAll("&8[&eVentureChat&8]&c - No player data will be saved in offline mode unless you set the \"cracked\" server acknowledgement in the config!")); return; } diff --git a/src/main/java/venture/Aust1n46/chat/service/VentureChatDatabaseService.java b/src/main/java/venture/Aust1n46/chat/service/VentureChatDatabaseService.java index 00e5a63..92a5d4b 100644 --- a/src/main/java/venture/Aust1n46/chat/service/VentureChatDatabaseService.java +++ b/src/main/java/venture/Aust1n46/chat/service/VentureChatDatabaseService.java @@ -6,7 +6,6 @@ import java.sql.SQLException; import java.text.SimpleDateFormat; import java.util.Calendar; -import org.bukkit.Bukkit; import org.bukkit.configuration.ConfigurationSection; import com.google.inject.Inject; @@ -23,8 +22,8 @@ import venture.Aust1n46.chat.utilities.FormatUtils; @Singleton public class VentureChatDatabaseService { @Inject - private VentureChat plugin; - + private VentureChat plugin; + private HikariDataSource dataSource; @Inject @@ -42,8 +41,7 @@ public class VentureChatDatabaseService { // config.setDriverClassName(org.postgresql.Driver.class.getName()); // final String jdbcUrl = String.format("jdbc:postgresql://%s:%d/%s", hostname, // port, database); - final String jdbcUrl = String.format("jdbc:mysql://%s:%d/%s?autoReconnect=true&useSSL=false", host, - port, database); + final String jdbcUrl = String.format("jdbc:mysql://%s:%d/%s?autoReconnect=true&useSSL=false", host, port, database); config.setJdbcUrl(jdbcUrl); config.setUsername(user); config.setPassword(password); @@ -51,16 +49,14 @@ public class VentureChatDatabaseService { config.addDataSourceProperty("prepStmtCacheSize", "250"); config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048"); dataSource = new HikariDataSource(config); - final String SQL_CREATE_TABLE = "CREATE TABLE IF NOT EXISTS VentureChat " - + "(ID SERIAL PRIMARY KEY, ChatTime TEXT, UUID TEXT, Name TEXT, " + final String SQL_CREATE_TABLE = "CREATE TABLE IF NOT EXISTS VentureChat " + "(ID SERIAL PRIMARY KEY, ChatTime TEXT, UUID TEXT, Name TEXT, " + "Server TEXT, Channel TEXT, Text TEXT, Type TEXT)"; final Connection conn = dataSource.getConnection(); final PreparedStatement statement = conn.prepareStatement(SQL_CREATE_TABLE); statement.executeUpdate(); } } catch (Exception exception) { - Bukkit.getConsoleSender().sendMessage( - FormatUtils.FormatStringAll("&8[&eVentureChat&8]&c - Database could not be loaded. Is it running?")); + plugin.getServer().getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&c - Database could not be loaded. Is it running?")); } } @@ -68,16 +64,14 @@ public class VentureChatDatabaseService { return dataSource != null; } - public void writeVentureChat(String uuid, String name, String server, String channel, String text, - String type) { + public void writeVentureChat(String uuid, String name, String server, String channel, String text, String type) { Calendar currentDate = Calendar.getInstance(); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String date = formatter.format(currentDate.getTime()); - Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> { + plugin.getServer().getScheduler().runTaskAsynchronously(plugin, () -> { try (final Connection conn = dataSource.getConnection(); - final PreparedStatement statement = conn.prepareStatement( - "INSERT INTO VentureChat " + "(ChatTime, UUID, Name, Server, Channel, Text, Type) " - + "VALUES (?, ?, ?, ?, ?, ?, ?)")) { + final PreparedStatement statement = conn + .prepareStatement("INSERT INTO VentureChat " + "(ChatTime, UUID, Name, Server, Channel, Text, Type) " + "VALUES (?, ?, ?, ?, ?, ?, ?)")) { statement.setString(1, date); statement.setString(2, uuid); statement.setString(3, name); diff --git a/src/main/java/venture/Aust1n46/chat/service/VentureChatFormatService.java b/src/main/java/venture/Aust1n46/chat/service/VentureChatFormatService.java index 7ac9006..5ecddbd 100644 --- a/src/main/java/venture/Aust1n46/chat/service/VentureChatFormatService.java +++ b/src/main/java/venture/Aust1n46/chat/service/VentureChatFormatService.java @@ -14,7 +14,6 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; -import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Sound; import org.bukkit.entity.Player; @@ -109,8 +108,7 @@ public class VentureChatFormatService { indexStart = matcher.start(); indexEnd = matcher.end(); placeholder = remaining.substring(indexStart, indexEnd); - formattedPlaceholder = FormatUtils - .FormatStringAll(PlaceholderAPI.setBracketPlaceholders(icp.getPlayer(), placeholder)); + formattedPlaceholder = FormatUtils.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(icp.getPlayer(), placeholder)); temp += convertToJsonColors(lastCode + remaining.substring(0, indexStart)) + ","; lastCode = getLastCode(lastCode + remaining.substring(0, indexStart)); String action = ""; @@ -119,22 +117,17 @@ public class VentureChatFormatService { for (JsonAttribute jsonAttribute : format.getJsonAttributes()) { if (placeholder.contains(jsonAttribute.getName().replace("{", "").replace("}", ""))) { action = jsonAttribute.getClickAction(); - text = FormatUtils.FormatStringAll( - PlaceholderAPI.setBracketPlaceholders(icp.getPlayer(), jsonAttribute.getClickText())); + text = FormatUtils.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(icp.getPlayer(), jsonAttribute.getClickText())); for (String st : jsonAttribute.getHoverText()) { hover += FormatUtils.FormatStringAll(st) + "\n"; } } } if (!hover.isEmpty()) { - hover = FormatUtils.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(icp.getPlayer(), - hover.substring(0, hover.length() - 1))); + hover = FormatUtils.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(icp.getPlayer(), hover.substring(0, hover.length() - 1))); } - temp += convertToJsonColors(lastCode + formattedPlaceholder, - ",\"clickEvent\":{\"action\":\"" + action + "\",\"value\":\"" + text - + "\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[" - + convertToJsonColors(hover) + "]}}") - + ","; + temp += convertToJsonColors(lastCode + formattedPlaceholder, ",\"clickEvent\":{\"action\":\"" + action + "\",\"value\":\"" + text + + "\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[" + convertToJsonColors(hover) + "]}}") + ","; lastCode = getLastCode(lastCode + formattedPlaceholder); remaining = remaining.substring(indexEnd); } else { @@ -159,9 +152,8 @@ public class VentureChatFormatService { String link = ""; String lastCode = DEFAULT_COLOR_CODE; do { - Pattern pattern = Pattern.compile( - "([a-zA-Z0-9" + BUKKIT_COLOR_CODE_PREFIX + "\\-:/]+\\.[a-zA-Z/0-9" + BUKKIT_COLOR_CODE_PREFIX - + "\\-:_#]+(\\.[a-zA-Z/0-9." + BUKKIT_COLOR_CODE_PREFIX + "\\-:;,#\\?\\+=_]+)?)"); + Pattern pattern = Pattern.compile("([a-zA-Z0-9" + BUKKIT_COLOR_CODE_PREFIX + "\\-:/]+\\.[a-zA-Z/0-9" + BUKKIT_COLOR_CODE_PREFIX + "\\-:_#]+(\\.[a-zA-Z/0-9." + + BUKKIT_COLOR_CODE_PREFIX + "\\-:;,#\\?\\+=_]+)?)"); Matcher matcher = pattern.matcher(remaining); if (matcher.find()) { indexLink = matcher.start(); @@ -173,11 +165,9 @@ public class VentureChatFormatService { if (ChatColor.stripColor(link).contains("https://")) https = "s"; temp += convertToJsonColors(lastCode + link, - ",\"underlined\":\"" + underlineURLs() - + "\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"http" + https + "://" + ",\"underlined\":\"" + underlineURLs() + "\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"http" + https + "://" + ChatColor.stripColor(link.replace("http://", "").replace("https://", "")) - + "\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[" - + convertToJsonColors(lastCode + link) + "]}}") + + "\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[" + convertToJsonColors(lastCode + link) + "]}}") + ","; lastCode = getLastCode(lastCode + link); remaining = remaining.substring(indexLinkEnd); @@ -196,25 +186,18 @@ public class VentureChatFormatService { if (String.valueOf(ch[a + 1]).matches("[lkomnLKOMN]") && ch[a] == BUKKIT_COLOR_CODE_PREFIX_CHAR) { ts += String.valueOf(ch[a]) + ch[a + 1]; a++; - } else if (String.valueOf(ch[a + 1]).matches("[0123456789abcdefrABCDEFR]") - && ch[a] == BUKKIT_COLOR_CODE_PREFIX_CHAR) { + } else if (String.valueOf(ch[a + 1]).matches("[0123456789abcdefrABCDEFR]") && ch[a] == BUKKIT_COLOR_CODE_PREFIX_CHAR) { ts = String.valueOf(ch[a]) + ch[a + 1]; a++; } else if (ch[a + 1] == 'x' && ch[a] == BUKKIT_COLOR_CODE_PREFIX_CHAR) { if (ch.length > a + 13) { - if (String.valueOf(ch[a + 3]).matches("[0123456789abcdefABCDEF]") - && String.valueOf(ch[a + 5]).matches("[0123456789abcdefABCDEF]") - && String.valueOf(ch[a + 7]).matches("[0123456789abcdefABCDEF]") - && String.valueOf(ch[a + 9]).matches("[0123456789abcdefABCDEF]") - && String.valueOf(ch[a + 11]).matches("[0123456789abcdefABCDEF]") - && String.valueOf(ch[a + 13]).matches("[0123456789abcdefABCDEF]") - && ch[a + 2] == BUKKIT_COLOR_CODE_PREFIX_CHAR && ch[a + 4] == BUKKIT_COLOR_CODE_PREFIX_CHAR - && ch[a + 6] == BUKKIT_COLOR_CODE_PREFIX_CHAR && ch[a + 8] == BUKKIT_COLOR_CODE_PREFIX_CHAR - && ch[a + 10] == BUKKIT_COLOR_CODE_PREFIX_CHAR - && ch[a + 12] == BUKKIT_COLOR_CODE_PREFIX_CHAR) { - ts = String.valueOf(ch[a]) + ch[a + 1] + ch[a + 2] + ch[a + 3] + ch[a + 4] + ch[a + 5] - + ch[a + 6] + ch[a + 7] + ch[a + 8] + ch[a + 9] + ch[a + 10] + ch[a + 11] + ch[a + 12] - + ch[a + 13]; + if (String.valueOf(ch[a + 3]).matches("[0123456789abcdefABCDEF]") && String.valueOf(ch[a + 5]).matches("[0123456789abcdefABCDEF]") + && String.valueOf(ch[a + 7]).matches("[0123456789abcdefABCDEF]") && String.valueOf(ch[a + 9]).matches("[0123456789abcdefABCDEF]") + && String.valueOf(ch[a + 11]).matches("[0123456789abcdefABCDEF]") && String.valueOf(ch[a + 13]).matches("[0123456789abcdefABCDEF]") + && ch[a + 2] == BUKKIT_COLOR_CODE_PREFIX_CHAR && ch[a + 4] == BUKKIT_COLOR_CODE_PREFIX_CHAR && ch[a + 6] == BUKKIT_COLOR_CODE_PREFIX_CHAR + && ch[a + 8] == BUKKIT_COLOR_CODE_PREFIX_CHAR && ch[a + 10] == BUKKIT_COLOR_CODE_PREFIX_CHAR && ch[a + 12] == BUKKIT_COLOR_CODE_PREFIX_CHAR) { + ts = String.valueOf(ch[a]) + ch[a + 1] + ch[a + 2] + ch[a + 3] + ch[a + 4] + ch[a + 5] + ch[a + 6] + ch[a + 7] + ch[a + 8] + ch[a + 9] + ch[a + 10] + + ch[a + 11] + ch[a + 12] + ch[a + 13]; a += 13; } } @@ -266,9 +249,7 @@ public class VentureChatFormatService { color = remaining.substring(1, indexColor + LEGACY_COLOR_CODE_LENGTH); if (color.equals(BUKKIT_HEX_COLOR_CODE_PREFIX)) { if (remaining.length() >= HEX_COLOR_CODE_LENGTH) { - color = HEX_COLOR_CODE_PREFIX - + remaining.substring(LEGACY_COLOR_CODE_LENGTH, indexColor + HEX_COLOR_CODE_LENGTH) - .replace(BUKKIT_COLOR_CODE_PREFIX, ""); + color = HEX_COLOR_CODE_PREFIX + remaining.substring(LEGACY_COLOR_CODE_LENGTH, indexColor + HEX_COLOR_CODE_LENGTH).replace(BUKKIT_COLOR_CODE_PREFIX, ""); colorLength = HEX_COLOR_CODE_LENGTH; bold = false; obfuscated = false; @@ -341,8 +322,7 @@ public class VentureChatFormatService { if (indexNextColor == -1) { indexNextColor = remaining.length(); } - temp += "{\"text\":\"" + remaining.substring(0, indexNextColor) + "\",\"color\":\"" - + hexidecimalToJsonColorRGB(color) + "\"" + modifier + extensions + "},"; + temp += "{\"text\":\"" + remaining.substring(0, indexNextColor) + "\",\"color\":\"" + hexidecimalToJsonColorRGB(color) + "\"" + modifier + extensions + "},"; remaining = remaining.substring(indexNextColor); } while (remaining.length() > 1 && indexColor != -1); if (temp.length() > 1) @@ -418,11 +398,9 @@ public class VentureChatFormatService { if (player.hasPermission("venturechat.gui")) { json = json.substring(0, json.length() - 1); json += "," + convertToJsonColors(FormatUtils.FormatStringAll(plugin.getConfig().getString("guiicon")), - ",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/vchatgui " + sender + " " + channelName - + " " + hash + ",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/vchatgui " + sender + " " + channelName + " " + hash + "\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[" - + convertToJsonColors(FormatUtils.FormatStringAll(plugin.getConfig().getString("guitext"))) - + "]}}") + + convertToJsonColors(FormatUtils.FormatStringAll(plugin.getConfig().getString("guitext"))) + "]}}") + "]"; } return json; @@ -463,10 +441,8 @@ public class VentureChatFormatService { splitComponents(finalList, o, c); for (Object component : finalList) { try { - if (versionService.is1_8() || versionService.is1_9() || versionService.is1_10() - || versionService.is1_11() || versionService.is1_12() || versionService.is1_13() - || versionService.is1_14() || versionService.is1_15() || versionService.is1_16() - || versionService.is1_17()) { + if (versionService.is1_8() || versionService.is1_9() || versionService.is1_10() || versionService.is1_11() || versionService.is1_12() || versionService.is1_13() + || versionService.is1_14() || versionService.is1_15() || versionService.is1_16() || versionService.is1_17()) { String text = (String) component.getClass().getMethod("getText").invoke(component); Object chatModifier = component.getClass().getMethod("getChatModifier").invoke(component); Object color = chatModifier.getClass().getMethod("getColor").invoke(chatModifier); @@ -475,13 +451,10 @@ public class VentureChatFormatService { colorString = color.getClass().getMethod("b").invoke(color).toString(); } boolean bold = (boolean) chatModifier.getClass().getMethod("isBold").invoke(chatModifier); - boolean strikethrough = (boolean) chatModifier.getClass().getMethod("isStrikethrough") - .invoke(chatModifier); + boolean strikethrough = (boolean) chatModifier.getClass().getMethod("isStrikethrough").invoke(chatModifier); boolean italic = (boolean) chatModifier.getClass().getMethod("isItalic").invoke(chatModifier); - boolean underlined = (boolean) chatModifier.getClass().getMethod("isUnderlined") - .invoke(chatModifier); - boolean obfuscated = (boolean) chatModifier.getClass().getMethod("isRandom") - .invoke(chatModifier); + boolean underlined = (boolean) chatModifier.getClass().getMethod("isUnderlined").invoke(chatModifier); + boolean obfuscated = (boolean) chatModifier.getClass().getMethod("isRandom").invoke(chatModifier); JSONObject jsonObject = new JSONObject(); jsonObject.put("text", text); jsonObject.put("color", colorString); @@ -537,10 +510,8 @@ public class VentureChatFormatService { for (Object component : finalList) { if (versionService.is1_7()) { stringbuilder.append((String) component.getClass().getMethod("e").invoke(component)); - } else if (versionService.is1_8() || versionService.is1_9() || versionService.is1_10() - || versionService.is1_11() || versionService.is1_12() || versionService.is1_13() - || versionService.is1_14() || versionService.is1_15() || versionService.is1_16() - || versionService.is1_17()) { + } else if (versionService.is1_8() || versionService.is1_9() || versionService.is1_10() || versionService.is1_11() || versionService.is1_12() + || versionService.is1_13() || versionService.is1_14() || versionService.is1_15() || versionService.is1_16() || versionService.is1_17()) { stringbuilder.append((String) component.getClass().getMethod("getText").invoke(component)); } else { stringbuilder.append((String) component.getClass().getMethod("getString").invoke(component)); @@ -553,9 +524,8 @@ public class VentureChatFormatService { } private void splitComponents(List finalList, Object o, Class c) throws Exception { - if (versionService.is1_7() || versionService.is1_8() || versionService.is1_9() || versionService.is1_10() - || versionService.is1_11() || versionService.is1_12() || versionService.is1_13() - || (versionService.is1_14() && !versionService.is1_14_4())) { + if (versionService.is1_7() || versionService.is1_8() || versionService.is1_9() || versionService.is1_10() || versionService.is1_11() || versionService.is1_12() + || versionService.is1_13() || (versionService.is1_14() && !versionService.is1_14_4())) { ArrayList list = (ArrayList) c.getMethod("a").invoke(o, new Object[0]); for (Object component : list) { ArrayList innerList = (ArrayList) c.getMethod("a").invoke(component, new Object[0]); @@ -565,8 +535,7 @@ public class VentureChatFormatService { finalList.add(component); } } - } else if (versionService.is1_14_4() || versionService.is1_15() || versionService.is1_16() - || versionService.is1_17()) { + } else if (versionService.is1_14_4() || versionService.is1_15() || versionService.is1_16() || versionService.is1_17()) { ArrayList list = (ArrayList) c.getMethod("getSiblings").invoke(o, new Object[0]); for (Object component : list) { ArrayList innerList = (ArrayList) c.getMethod("getSiblings").invoke(component, new Object[0]); @@ -629,12 +598,10 @@ public class VentureChatFormatService { } private Sound getSound(String soundName) { - if (Arrays.asList(Sound.values()).stream().map(Sound::toString).collect(Collectors.toList()) - .contains(soundName)) { + if (Arrays.asList(Sound.values()).stream().map(Sound::toString).collect(Collectors.toList()).contains(soundName)) { return Sound.valueOf(soundName); } - Bukkit.getConsoleSender() - .sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&c - Message sound invalid!")); + plugin.getServer().getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&c - Message sound invalid!")); return getDefaultMessageSound(); }