Replace static access to Bukkit

This commit is contained in:
Aust1n46 2022-05-11 23:23:55 -05:00
parent cc791c2dae
commit d5822b8840
14 changed files with 567 additions and 700 deletions

View File

@ -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;
}

View File

@ -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;
@ -59,13 +58,14 @@ public class VentureChatSpigotFlatFileController {
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!"));
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)) {
Bukkit.getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&c - Skipping Offline UUID: " + uuid));
plugin.getServer().getConsoleSender().sendMessage(FormatUtils.FormatStringAll("&8[&eVentureChat&8]&c - Skipping Offline UUID: " + uuid));
continue;
}
String name = playerData.getConfigurationSection("players." + uuid).getString("name");
@ -90,7 +90,7 @@ public class VentureChatSpigotFlatFileController {
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);
plugin.getServer().getConsoleSender().sendMessage("[VentureChat] Null Mute Time: " + parts[0] + " " + name);
continue;
}
String channelName = parts[0];
@ -103,7 +103,9 @@ public class VentureChatSpigotFlatFileController {
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;
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";
@ -112,7 +114,8 @@ public class VentureChatSpigotFlatFileController {
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);
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);
@ -120,8 +123,8 @@ public class VentureChatSpigotFlatFileController {
} 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!"));
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();
}
@ -133,16 +136,15 @@ public class VentureChatSpigotFlatFileController {
if (!playerDataDirectory.exists()) {
playerDataDirectory.mkdirs();
}
Files.walk(Paths.get(playerDataDirectoryPath))
.filter(Files::isRegularFile)
.forEach((path) -> readPlayerDataFile(path));
Files.walk(Paths.get(playerDataDirectoryPath)).filter(Files::isRegularFile).forEach((path) -> readPlayerDataFile(path));
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* Loads the player data file for a specific player. Corrupt/invalid data files are skipped and deleted.
* Loads the player data file for a specific player. Corrupt/invalid data files
* are skipped and deleted.
*
* @param path
*/
@ -157,8 +159,8 @@ public class VentureChatSpigotFlatFileController {
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."));
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;
}
@ -200,10 +202,11 @@ public class VentureChatSpigotFlatFileController {
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);
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."));
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;
}

View File

@ -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;
}

View File

@ -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);

View File

@ -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());

View File

@ -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!");

View File

@ -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()) {

View File

@ -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,11 +53,17 @@ public class ChatListener implements Listener {
@Inject
private ConfigService configService;
// this event isn't always asynchronous even though the event's name starts with "Async"
@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);
@ -66,151 +71,126 @@ public class ChatListener implements Listener {
});
}
public void handleTrueAsyncPlayerChatEvent(AsyncPlayerChatEvent event) {
boolean bungee = false;
String chat = event.getMessage();
String format;
Set<Player> 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()) {
mcp.getPlayer().sendMessage(FormatUtils.FormatStringAll(chat));
mcp.setEditing(false);
return;
}
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())) {
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}", mcp.getName())
if (p.isSpy()) {
p.getPlayer().sendMessage(LocalizedMessage.EXIT_PRIVATE_CONVERSATION_SPY.toString().replace("{player_sender}", ventureChatPlayer.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);
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()) {
mcp.getPlayer().sendMessage(LocalizedMessage.BLOCKING_MESSAGE.toString()
.replace("{player}", tp.getName()));
event.setCancelled(true);
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(mcp.isFilter()) {
if (ventureChatPlayer.isFilter()) {
filtered = formatService.FilterChat(filtered);
}
if(mcp.getPlayer().hasPermission("venturechat.color.legacy")) {
if (ventureChatPlayer.getPlayer().hasPermission("venturechat.color.legacy")) {
filtered = FormatUtils.FormatStringLegacyColor(filtered);
}
if(mcp.getPlayer().hasPermission("venturechat.color")) {
if (ventureChatPlayer.getPlayer().hasPermission("venturechat.color")) {
filtered = FormatUtils.FormatStringColor(filtered);
}
if(mcp.getPlayer().hasPermission("venturechat.format")) {
if (ventureChatPlayer.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(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(!mcp.getPlayer().hasPermission("venturechat.spy.override")) {
for(VentureChatPlayer p : playerApiService.getOnlineMineverseChatPlayers()) {
if(p.getName().equals(mcp.getName()) || p.getName().equals(tp.getName())) {
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()) {
if (p.isSpy()) {
p.getPlayer().sendMessage(spy);
}
}
}
tp.getPlayer().sendMessage(send);
mcp.getPlayer().sendMessage(echo);
if(tp.isNotifications()) {
ventureChatPlayer.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");
ventureChatPlayer.setReplyPlayer(tp.getUuid());
tp.setReplyPlayer(ventureChatPlayer.getUuid());
if (databaseService.isEnabled()) {
databaseService.writeVentureChat(ventureChatPlayer.getUuid().toString(), ventureChatPlayer.getName(), "Local", "Messaging_Component", chat.replace("'", "''"),
"Chat");
}
}
return;
}
if(mcp.isPartyChat() && !mcp.isQuickChat()) {
if(mcp.hasParty()) {
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(mcp.getParty().toString()) || p.isSpy())) {
for (VentureChatPlayer p : playerApiService.getOnlineMineverseChatPlayers()) {
if ((p.hasParty() && p.getParty().toString().equals(ventureChatPlayer.getParty().toString()) || p.isSpy())) {
String filtered = chat;
if(mcp.isFilter()) {
if (ventureChatPlayer.isFilter()) {
filtered = formatService.FilterChat(filtered);
}
if(mcp.getPlayer().hasPermission("venturechat.color.legacy")) {
if (ventureChatPlayer.getPlayer().hasPermission("venturechat.color.legacy")) {
filtered = FormatUtils.FormatStringLegacyColor(filtered);
}
if(mcp.getPlayer().hasPermission("venturechat.color")) {
if (ventureChatPlayer.getPlayer().hasPermission("venturechat.color")) {
filtered = FormatUtils.FormatStringColor(filtered);
}
if(mcp.getPlayer().hasPermission("venturechat.format")) {
if (ventureChatPlayer.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;
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);
}
}
Bukkit.getConsoleSender().sendMessage(partyformat);
if(databaseService.isEnabled()) {
databaseService.writeVentureChat(mcp.getUuid().toString(), mcp.getName(), "Local", "Party_Component", chat.replace("'", "''"), "Chat");
plugin.getServer().getConsoleSender().sendMessage(partyformat);
if (databaseService.isEnabled()) {
databaseService.writeVentureChat(ventureChatPlayer.getUuid().toString(), ventureChatPlayer.getName(), "Local", "Party_Component", chat.replace("'", "''"), "Chat");
}
return;
}
mcp.getPlayer().sendMessage(ChatColor.RED + "You are not in a party.");
return;
ventureChatPlayer.getPlayer().sendMessage(ChatColor.RED + "You are not in a party.");
}
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());
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();
@ -219,61 +199,68 @@ public class ChatListener implements Listener {
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()));
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 {
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()) {
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()));
}
}
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()));
ventureChatPlayer.setQuickChat(false);
}
else {
mcp.getPlayer()
.sendMessage(LocalizedMessage.CHANNEL_MUTED.toString()
.replace("{channel_color}", eventChannel.getColor())
.replace("{channel_name}", eventChannel.getName()));
}
}
mcp.setQuickChat(false);
private void handleTrueAsyncPlayerChatEvent(final AsyncPlayerChatEvent event) {
String chat = event.getMessage();
String format;
VentureChatPlayer mcp = playerApiService.getOnlineMineverseChatPlayer(event.getPlayer());
ChatChannel eventChannel = mcp.getCurrentChannel();
if (mcp.isEditing()) {
mcp.getPlayer().sendMessage(FormatUtils.FormatStringAll(chat));
mcp.setEditing(false);
return;
}
Double chDistance = (double) 0;
String curColor = "";
if(eventChannel.hasPermission() && !mcp.getPlayer().hasPermission(eventChannel.getPermission())) {
if (mcp.isQuickChat()) {
eventChannel = mcp.getQuickChannel();
}
if (mcp.hasConversation() && !mcp.isQuickChat()) {
processPrivateMessageConversation(mcp, chat);
return;
}
if (mcp.isPartyChat() && !mcp.isQuickChat()) {
processPartyChat(mcp, chat);
return;
}
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;
}
}
@ -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);
@ -352,146 +330,138 @@ public class ChatListener implements Listener {
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()) {
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<Player> 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;
}
@ -500,11 +470,12 @@ public class ChatListener implements Listener {
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);
@ -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("")) {
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;

View File

@ -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");

View File

@ -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<ChatMessage>();
this.jsonFormat = jsonFormat;
this.cooldowns = new HashMap<ChatChannel, Long>();
@ -96,22 +87,8 @@ public class VentureChatPlayer {
listening.add(currentChannel.getName());
this.mutes = new HashMap<String, MuteContainer>();
this.blockedCommands = new HashSet<String>();
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<ChatMessage>();
this.jsonFormat = "Default";
this.cooldowns = new HashMap<ChatChannel, Long>();

View File

@ -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();

View File

@ -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;
}

View File

@ -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;
@ -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);

View File

@ -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<Object> 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();
}