Model refactoring

This commit is contained in:
Aust1n46 2024-05-19 09:44:05 -05:00
parent 254c261528
commit d7e2ed8b9c
38 changed files with 410 additions and 798 deletions

View File

@ -6,15 +6,14 @@ import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.stream.Collectors;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.comphenix.protocol.events.PacketContainer;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Singleton; import com.google.inject.Singleton;
@ -26,9 +25,9 @@ import venture.Aust1n46.chat.model.ChatChannel;
import venture.Aust1n46.chat.model.MuteContainer; import venture.Aust1n46.chat.model.MuteContainer;
import venture.Aust1n46.chat.model.VentureChatPlayer; import venture.Aust1n46.chat.model.VentureChatPlayer;
import venture.Aust1n46.chat.service.ConfigService; import venture.Aust1n46.chat.service.ConfigService;
import venture.Aust1n46.chat.service.VentureChatDatabaseService;
import venture.Aust1n46.chat.service.FormatService; import venture.Aust1n46.chat.service.FormatService;
import venture.Aust1n46.chat.service.PlayerApiService; import venture.Aust1n46.chat.service.PlayerApiService;
import venture.Aust1n46.chat.service.VentureChatDatabaseService;
import venture.Aust1n46.chat.utilities.FormatUtils; import venture.Aust1n46.chat.utilities.FormatUtils;
@Singleton @Singleton
@ -105,14 +104,14 @@ public class PluginMessageController {
int channelCount = 0; int channelCount = 0;
for (String c : mcp.getListening()) { for (String c : mcp.getListening()) {
ChatChannel channel = configService.getChannel(c); ChatChannel channel = configService.getChannel(c);
if (channel.getBungee()) { if (channel.isBungeeEnabled()) {
channelCount++; channelCount++;
} }
} }
out.write(channelCount); out.write(channelCount);
for (String c : mcp.getListening()) { for (String c : mcp.getListening()) {
ChatChannel channel = configService.getChannel(c); ChatChannel channel = configService.getChannel(c);
if (channel.getBungee()) { if (channel.isBungeeEnabled()) {
out.writeUTF(channel.getName()); out.writeUTF(channel.getName());
} }
} }
@ -120,7 +119,7 @@ public class PluginMessageController {
int muteCount = 0; int muteCount = 0;
for (MuteContainer mute : mcp.getMutes().values()) { for (MuteContainer mute : mcp.getMutes().values()) {
ChatChannel channel = configService.getChannel(mute.getChannel()); ChatChannel channel = configService.getChannel(mute.getChannel());
if (channel.getBungee()) { if (channel.isBungeeEnabled()) {
muteCount++; muteCount++;
} }
} }
@ -128,7 +127,7 @@ public class PluginMessageController {
out.write(muteCount); out.write(muteCount);
for (MuteContainer mute : mcp.getMutes().values()) { for (MuteContainer mute : mcp.getMutes().values()) {
ChatChannel channel = configService.getChannel(mute.getChannel()); ChatChannel channel = configService.getChannel(mute.getChannel());
if (channel.getBungee()) { if (channel.isBungeeEnabled()) {
out.writeUTF(channel.getName()); out.writeUTF(channel.getName());
out.writeLong(mute.getDuration()); out.writeLong(mute.getDuration());
out.writeUTF(mute.getReason()); out.writeUTF(mute.getReason());
@ -167,69 +166,41 @@ public class PluginMessageController {
ByteArrayOutputStream stream = new ByteArrayOutputStream(); ByteArrayOutputStream stream = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(stream); DataOutputStream out = new DataOutputStream(stream);
if (subchannel.equals("Chat")) { if (subchannel.equals("Chat")) {
String server = msgin.readUTF(); final String server = msgin.readUTF();
String chatchannel = msgin.readUTF(); final String chatChannelName = msgin.readUTF();
String senderName = msgin.readUTF(); final String senderName = msgin.readUTF();
UUID senderUUID = UUID.fromString(msgin.readUTF()); final UUID senderUUID = UUID.fromString(msgin.readUTF());
int hash = msgin.readInt(); final int hash = msgin.readInt();
String format = msgin.readUTF(); final String format = msgin.readUTF();
String chat = msgin.readUTF(); final String chat = msgin.readUTF();
String consoleChat = format + chat; final String consoleChat = format + chat;
String globalJSON = msgin.readUTF(); final String globalJSON = msgin.readUTF();
String primaryGroup = msgin.readUTF(); final String primaryGroup = msgin.readUTF();
final ChatChannel chatChannel = configService.getChannel(chatChannelName);
if (!configService.isChannel(chatchannel)) { if (chatChannel == null || !chatChannel.isBungeeEnabled()) {
return; return;
} }
ChatChannel chatChannelObject = configService.getChannel(chatchannel); final Set<Player> recipients = playerApiService.getOnlineMineverseChatPlayers()
.stream()
if (!chatChannelObject.getBungee()) { .filter(vcp -> configService.isListening(vcp, chatChannelName))
return; .filter(vcp -> vcp.isBungeeToggle() || playerApiService.getOnlineMineverseChatPlayer(senderName) == null)
} .filter(vcp -> !configService.isIgnoreChatEnabled() || !vcp.getIgnores().contains(senderUUID))
.map(VentureChatPlayer::getPlayer)
Set<Player> recipients = new HashSet<Player>(); .collect(Collectors.toSet());
for (VentureChatPlayer p : playerApiService.getOnlineMineverseChatPlayers()) {
if (configService.isListening(p, chatChannelObject.getName())) {
recipients.add(p.getPlayer());
}
}
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() { plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
@Override @Override
public void run() { public void run() {
// Create VentureChatEvent final VentureChatEvent ventureChatEvent = new VentureChatEvent(null, senderName, primaryGroup, chatChannel, recipients, recipients.size(), format, chat,
VentureChatEvent ventureChatEvent = new VentureChatEvent(null, senderName, primaryGroup, chatChannelObject, recipients, recipients.size(), format, chat,
globalJSON, hash, false); globalJSON, hash, false);
// Fire event and wait for other plugin listeners to act on it // This event cannot be modified or cancelled
plugin.getServer().getPluginManager().callEvent(ventureChatEvent); plugin.getServer().getPluginManager().callEvent(ventureChatEvent);
} }
}); });
plugin.getServer().getConsoleSender().sendMessage(consoleChat);
if (databaseService.isEnabled()) { if (databaseService.isEnabled()) {
databaseService.writeVentureChat(senderUUID.toString(), senderName, server, chatchannel, chat.replace("'", "''"), "Chat"); databaseService.writeVentureChat(senderUUID.toString(), senderName, server, chatChannelName, chat.replace("'", "''"), "Chat");
}
for (VentureChatPlayer p : playerApiService.getOnlineMineverseChatPlayers()) {
if (configService.isListening(p, chatChannelObject.getName())) {
if (!p.isBungeeToggle() && playerApiService.getOnlineMineverseChatPlayer(senderName) == null) {
continue;
}
String json = formatService.formatModerationGUI(globalJSON, p.getPlayer(), senderName, chatchannel, hash);
PacketContainer packet = formatService.createPacketPlayOutChat(json);
if (plugin.getConfig().getBoolean("ignorechat", false)) {
if (!p.getIgnores().contains(senderUUID)) {
// System.out.println("Chat sent");
formatService.sendPacketPlayOutChat(p.getPlayer(), packet);
}
continue;
}
formatService.sendPacketPlayOutChat(p.getPlayer(), packet);
}
} }
formatService.createAndSendChatMessage(globalJSON, chatChannelName, hash, recipients, senderName);
plugin.getServer().getConsoleSender().sendMessage(consoleChat);
} }
if (subchannel.equals("DiscordSRV")) { if (subchannel.equals("DiscordSRV")) {
String chatChannel = msgin.readUTF(); String chatChannel = msgin.readUTF();
@ -238,20 +209,10 @@ public class PluginMessageController {
return; return;
} }
ChatChannel chatChannelObj = configService.getChannel(chatChannel); ChatChannel chatChannelObj = configService.getChannel(chatChannel);
if (!chatChannelObj.getBungee()) { if (!chatChannelObj.isBungeeEnabled()) {
return; return;
} }
formatService.createAndSendExternalChatMessage(message, chatChannelObj.getName(), "Discord");
String json = formatService.convertPlainTextToJson(message, true);
int hash = (message.replaceAll("([<5B>]([a-z0-9]))", "")).hashCode();
for (VentureChatPlayer p : playerApiService.getOnlineMineverseChatPlayers()) {
if (configService.isListening(p, chatChannelObj.getName())) {
String finalJSON = formatService.formatModerationGUI(json, p.getPlayer(), "Discord", chatChannelObj.getName(), hash);
PacketContainer packet = formatService.createPacketPlayOutChat(finalJSON);
formatService.sendPacketPlayOutChat(p.getPlayer(), packet);
}
}
} }
if (subchannel.equals("PlayerNames")) { if (subchannel.equals("PlayerNames")) {
playerApiService.clearNetworkPlayerNames(); playerApiService.clearNetworkPlayerNames();
@ -323,7 +284,7 @@ public class PluginMessageController {
for (Object ch : p.getListening().toArray()) { for (Object ch : p.getListening().toArray()) {
String c = ch.toString(); String c = ch.toString();
ChatChannel cha = configService.getChannel(c); ChatChannel cha = configService.getChannel(c);
if (cha.getBungee()) { if (cha.isBungeeEnabled()) {
p.getListening().remove(c); p.getListening().remove(c);
} }
} }
@ -332,12 +293,12 @@ public class PluginMessageController {
String ch = msgin.readUTF(); String ch = msgin.readUTF();
if (configService.isChannel(ch)) { if (configService.isChannel(ch)) {
ChatChannel cha = configService.getChannel(ch); ChatChannel cha = configService.getChannel(ch);
if (!cha.hasPermission() || p.getPlayer().hasPermission(cha.getPermission())) { if (!cha.isPermissionRequired() || p.getPlayer().hasPermission(cha.getPermission())) {
p.getListening().add(ch); p.getListening().add(ch);
} }
} }
} }
p.getMutes().values().removeIf(mute -> configService.getChannel(mute.getChannel()).getBungee()); p.getMutes().values().removeIf(mute -> configService.getChannel(mute.getChannel()).isBungeeEnabled());
int sizeB = msgin.read(); int sizeB = msgin.read();
// System.out.println(sizeB + " mute size"); // System.out.println(sizeB + " mute size");
for (int b = 0; b < sizeB; b++) { for (int b = 0; b < sizeB; b++) {
@ -366,9 +327,9 @@ public class PluginMessageController {
if (!p.isHasPlayed()) { if (!p.isHasPlayed()) {
boolean isThereABungeeChannel = false; boolean isThereABungeeChannel = false;
for (ChatChannel ch : configService.getAutojoinList()) { for (ChatChannel ch : configService.getAutojoinList()) {
if ((!ch.hasPermission() || p.getPlayer().hasPermission(ch.getPermission())) && !configService.isListening(p, ch.getName())) { if ((!ch.isPermissionRequired() || p.getPlayer().hasPermission(ch.getPermission())) && !configService.isListening(p, ch.getName())) {
p.getListening().add(ch.getName()); p.getListening().add(ch.getName());
if (ch.getBungee()) { if (ch.isBungeeEnabled()) {
isThereABungeeChannel = true; isThereABungeeChannel = true;
} }
} }

View File

@ -87,8 +87,8 @@ public class ProxyController {
source.sendConsoleMessage("&8[&eVentureChat&8]&c You probably have an issue with your player data saving and/or your login data sync!"); source.sendConsoleMessage("&8[&eVentureChat&8]&c You probably have an issue with your player data saving and/or your login data sync!");
return; return;
} }
smcp.clearMessagePackets(); smcp.setMessagePackets(0);
smcp.clearMessageData(); smcp.getMessageData().clear();
out.writeUTF("Chwho"); out.writeUTF("Chwho");
out.writeUTF("Get"); out.writeUTF("Get");
out.writeUTF(server); out.writeUTF(server);
@ -110,10 +110,10 @@ public class ProxyController {
source.sendConsoleMessage("&8[&eVentureChat&8]&c You probably have an issue with your player data saving and/or your login data sync!"); source.sendConsoleMessage("&8[&eVentureChat&8]&c You probably have an issue with your player data saving and/or your login data sync!");
return; return;
} }
smcp.incrementMessagePackets(); smcp.setMessagePackets(smcp.getMessagePackets() + 1);
int players = in.readInt(); int players = in.readInt();
for(int a = 0; a < players; a++) { for(int a = 0; a < players; a++) {
smcp.addData(in.readUTF()); smcp.getMessageData().add(in.readUTF());
} }
AtomicInteger servers = new AtomicInteger(0); AtomicInteger servers = new AtomicInteger(0);
source.getServers().forEach(send -> { source.getServers().forEach(send -> {
@ -122,7 +122,7 @@ public class ProxyController {
} }
}); });
if(smcp.getMessagePackets() >= servers.get()) { if(smcp.getMessagePackets() >= servers.get()) {
smcp.clearMessagePackets(); smcp.setMessagePackets(0);
out.writeUTF("Chwho"); out.writeUTF("Chwho");
out.writeUTF("Receive"); out.writeUTF("Receive");
out.writeUTF(sender); out.writeUTF(sender);
@ -131,7 +131,7 @@ public class ProxyController {
for(String s : smcp.getMessageData()) { for(String s : smcp.getMessageData()) {
out.writeUTF(s); out.writeUTF(s);
} }
smcp.clearMessageData(); smcp.getMessageData().clear();
source.sendPluginMessage(server, outstream.toByteArray()); source.sendPluginMessage(server, outstream.toByteArray());
} }
} }
@ -158,7 +158,7 @@ public class ProxyController {
source.sendConsoleMessage("&8[&eVentureChat&8]&c You probably have an issue with your player data saving and/or your login data sync!"); source.sendConsoleMessage("&8[&eVentureChat&8]&c You probably have an issue with your player data saving and/or your login data sync!");
return; return;
} }
smcp.clearMessagePackets(); smcp.setMessagePackets(0);
out.writeUTF("Ignore"); out.writeUTF("Ignore");
out.writeUTF("Send"); out.writeUTF("Send");
out.writeUTF(server); out.writeUTF(server);
@ -180,7 +180,7 @@ public class ProxyController {
source.sendConsoleMessage("&8[&eVentureChat&8]&c You probably have an issue with your player data saving and/or your login data sync!"); source.sendConsoleMessage("&8[&eVentureChat&8]&c You probably have an issue with your player data saving and/or your login data sync!");
return; return;
} }
smcp.incrementMessagePackets(); smcp.setMessagePackets(smcp.getMessagePackets() + 1);
AtomicInteger servers = new AtomicInteger(0); AtomicInteger servers = new AtomicInteger(0);
source.getServers().forEach(send -> { source.getServers().forEach(send -> {
if(!send.isEmpty()) { if(!send.isEmpty()) {
@ -188,7 +188,7 @@ public class ProxyController {
} }
}); });
if(smcp.getMessagePackets() >= servers.get()) { if(smcp.getMessagePackets() >= servers.get()) {
smcp.clearMessagePackets(); smcp.setMessagePackets(0);
out.writeUTF("Ignore"); out.writeUTF("Ignore");
out.writeUTF("Offline"); out.writeUTF("Offline");
out.writeUTF(player); out.writeUTF(player);
@ -398,7 +398,7 @@ public class ProxyController {
source.sendConsoleMessage("&8[&eVentureChat&8]&c You probably have an issue with your player data saving and/or your login data sync!"); source.sendConsoleMessage("&8[&eVentureChat&8]&c You probably have an issue with your player data saving and/or your login data sync!");
return; return;
} }
smcp.clearMessagePackets(); smcp.setMessagePackets(0);
out.writeUTF("Message"); out.writeUTF("Message");
out.writeUTF("Send"); out.writeUTF("Send");
out.writeUTF(server); out.writeUTF(server);
@ -425,7 +425,7 @@ public class ProxyController {
source.sendConsoleMessage("&8[&eVentureChat&8]&c You probably have an issue with your player data saving and/or your login data sync!"); source.sendConsoleMessage("&8[&eVentureChat&8]&c You probably have an issue with your player data saving and/or your login data sync!");
return; return;
} }
smcp.incrementMessagePackets(); smcp.setMessagePackets(smcp.getMessagePackets() + 1);
AtomicInteger servers = new AtomicInteger(0); AtomicInteger servers = new AtomicInteger(0);
source.getServers().forEach(send -> { source.getServers().forEach(send -> {
if(!send.isEmpty()) { if(!send.isEmpty()) {
@ -433,7 +433,7 @@ public class ProxyController {
} }
}); });
if(smcp.getMessagePackets() >= servers.get()) { if(smcp.getMessagePackets() >= servers.get()) {
smcp.clearMessagePackets(); smcp.setMessagePackets(0);
out.writeUTF("Message"); out.writeUTF("Message");
out.writeUTF("Offline"); out.writeUTF("Offline");
out.writeUTF(player); out.writeUTF(player);
@ -507,7 +507,7 @@ public class ProxyController {
UUID uuid = UUID.fromString(in.readUTF()); UUID uuid = UUID.fromString(in.readUTF());
SynchronizedVentureChatPlayer smcp = playerApiService.getSynchronizedMineverseChatPlayer(uuid); SynchronizedVentureChatPlayer smcp = playerApiService.getSynchronizedMineverseChatPlayer(uuid);
if(smcp == null) { if(smcp == null) {
smcp = new SynchronizedVentureChatPlayer(uuid); smcp = SynchronizedVentureChatPlayer.builder().uuid(uuid).build();
playerApiService.addSynchronizedMineverseChatPlayerToMap(smcp); playerApiService.addSynchronizedMineverseChatPlayerToMap(smcp);
} }
out.writeUTF("Sync"); out.writeUTF("Sync");
@ -521,7 +521,7 @@ public class ProxyController {
int muteCount = smcp.getMutes().size(); int muteCount = smcp.getMutes().size();
//System.out.println(muteCount); //System.out.println(muteCount);
out.write(muteCount); out.write(muteCount);
for(MuteContainer muteContainer : smcp.getMutes()) { for(MuteContainer muteContainer : smcp.getMutes().values()) {
out.writeUTF(muteContainer.getChannel()); out.writeUTF(muteContainer.getChannel());
out.writeLong(muteContainer.getDuration()); out.writeLong(muteContainer.getDuration());
out.writeUTF(muteContainer.getReason()); out.writeUTF(muteContainer.getReason());
@ -529,7 +529,7 @@ public class ProxyController {
//System.out.println(smcp.isSpy() + " spy value"); //System.out.println(smcp.isSpy() + " spy value");
//System.out.println(out.size() + " size before"); //System.out.println(out.size() + " size before");
out.writeBoolean(smcp.isSpy()); out.writeBoolean(smcp.isSpy());
out.writeBoolean(smcp.getMessageToggle()); out.writeBoolean(smcp.isMessageToggleEnabled());
//System.out.println(out.size() + " size after"); //System.out.println(out.size() + " size after");
int ignoreCount = smcp.getIgnores().size(); int ignoreCount = smcp.getIgnores().size();
//System.out.println(ignoreCount + " ignore size"); //System.out.println(ignoreCount + " ignore size");
@ -545,16 +545,16 @@ public class ProxyController {
UUID uuid = UUID.fromString(in.readUTF()); UUID uuid = UUID.fromString(in.readUTF());
SynchronizedVentureChatPlayer smcp = playerApiService.getSynchronizedMineverseChatPlayer(uuid); SynchronizedVentureChatPlayer smcp = playerApiService.getSynchronizedMineverseChatPlayer(uuid);
if(smcp == null) { if(smcp == null) {
smcp = new SynchronizedVentureChatPlayer(uuid); smcp = SynchronizedVentureChatPlayer.builder().uuid(uuid).build();
playerApiService.addSynchronizedMineverseChatPlayerToMap(smcp); playerApiService.addSynchronizedMineverseChatPlayerToMap(smcp);
} }
smcp.getListening().clear(); smcp.getListening().clear();
smcp.clearMutes(); smcp.getMutes().clear();
smcp.getIgnores().clear(); smcp.getIgnores().clear();
int sizeL = in.read(); int sizeL = in.read();
//System.out.println(sizeL + " listening"); //System.out.println(sizeL + " listening");
for(int a = 0; a < sizeL; a++) { for(int a = 0; a < sizeL; a++) {
smcp.addListening(in.readUTF()); smcp.getListening().add(in.readUTF());
} }
int sizeM = in.read(); int sizeM = in.read();
for(int b = 0; b < sizeM; b++) { for(int b = 0; b < sizeM; b++) {
@ -562,16 +562,16 @@ public class ProxyController {
long muteTime = in.readLong(); long muteTime = in.readLong();
String muteReason = in.readUTF(); String muteReason = in.readUTF();
//System.out.println(mute); //System.out.println(mute);
smcp.addMute(mute, muteTime, muteReason); smcp.getMutes().put(mute, new MuteContainer(mute, muteTime, muteReason));
} }
int sizeI = in.read(); int sizeI = in.read();
for(int c = 0; c < sizeI; c++) { for(int c = 0; c < sizeI; c++) {
String ignore = in.readUTF(); String ignore = in.readUTF();
//System.out.println(mute); //System.out.println(mute);
smcp.addIgnore(playerApiService.getSynchronizedMineverseChatPlayer(UUID.fromString(ignore))); smcp.getIgnores().add(UUID.fromString(ignore));
} }
smcp.setSpy(in.readBoolean()); smcp.setSpy(in.readBoolean());
smcp.setMessageToggle(in.readBoolean()); smcp.setMessageToggleEnabled(in.readBoolean());
} }
} }
} }

View File

@ -29,168 +29,168 @@ import venture.Aust1n46.chat.service.ProxyUuidService;
*/ */
public class ProxyFlatFileController { public class ProxyFlatFileController {
@Inject @Inject
private ProxyUuidService uuidService; private ProxyUuidService uuidService;
@Inject @Inject
private ProxyPlayerApiService playerApiService; private ProxyPlayerApiService playerApiService;
public void loadLegacyBungeePlayerData(File dataFolder, VentureChatProxySource source) {
File sync = new File(dataFolder, "BungeePlayers.yml");
if (!sync.exists()) {
return;
}
try {
source.sendConsoleMessage("&8[&eVentureChat&8]&c - Detected Legacy Player Data!");
source.sendConsoleMessage("&8[&eVentureChat&8]&c - Converting to new structure and deleting old BungeePlayers.yml file!");
Configuration playerData = ConfigurationProvider.getProvider(YamlConfiguration.class).load(sync);
for (String uuidString : playerData.getKeys()) {
UUID uuid = UUID.fromString(uuidString);
if (uuidService.shouldSkipOfflineUUIDProxy(uuid, source)) {
source.sendConsoleMessage("&8[&eVentureChat&8]&c - Skipping Offline UUID: " + uuid);
continue;
}
Set<String> listening = new HashSet<String>();
StringTokenizer l = new StringTokenizer(playerData.getString(uuidString + ".channels"), ",");
while (l.hasMoreTokens()) {
String channel = l.nextToken();
listening.add(channel);
}
HashMap<String, MuteContainer> mutes = new HashMap<String, MuteContainer>();
StringTokenizer m = new StringTokenizer(playerData.getString(uuidString + ".mutes"), ",");
while (m.hasMoreTokens()) {
String[] parts = m.nextToken().split(":");
String channelName = parts[0];
mutes.put(channelName, new MuteContainer(channelName, Long.parseLong(parts[1]), ""));
}
HashSet<UUID> ignores = new HashSet<UUID>();
StringTokenizer n = new StringTokenizer(playerData.getString(uuidString + ".ignores"), ",");
while (n.hasMoreTokens()) {
String ignore = n.nextToken();
ignores.add(UUID.fromString(ignore));
}
boolean spy = playerData.getBoolean(uuidString + ".spy");
boolean messageToggle = playerData.getBoolean(uuidString + ".messagetoggle");
playerApiService.addSynchronizedMineverseChatPlayerToMap(new SynchronizedVentureChatPlayer(uuid, listening, mutes, ignores, spy, messageToggle));
}
} catch (Exception e) {
playerApiService.clearProxyPlayerMap();
source.sendConsoleMessage("&8[&eVentureChat&8]&c - Error Loading Legacy Player Data!");
source.sendConsoleMessage("&8[&eVentureChat&8]&c - Deleted BungeePlayers.yml file!");
} finally {
sync.delete();
}
}
public void loadProxyPlayerData(File dataFolder, VentureChatProxySource source) { public void loadLegacyBungeePlayerData(File dataFolder, VentureChatProxySource source) {
try { File sync = new File(dataFolder, "BungeePlayers.yml");
File playerDataDirectory = dataFolder; if (!sync.exists()) {
if (!playerDataDirectory.exists()) { return;
playerDataDirectory.mkdirs(); }
} try {
Files.walk(Paths.get(dataFolder.getAbsolutePath())) source.sendConsoleMessage("&8[&eVentureChat&8]&c - Detected Legacy Player Data!");
.filter(Files::isRegularFile) source.sendConsoleMessage("&8[&eVentureChat&8]&c - Converting to new structure and deleting old BungeePlayers.yml file!");
.forEach((path) -> readProxyPlayerDataFile(path, source)); Configuration playerData = ConfigurationProvider.getProvider(YamlConfiguration.class).load(sync);
} catch (IOException e) { for (String uuidString : playerData.getKeys()) {
e.printStackTrace(); UUID uuid = UUID.fromString(uuidString);
} if (uuidService.shouldSkipOfflineUUIDProxy(uuid, source)) {
} source.sendConsoleMessage("&8[&eVentureChat&8]&c - Skipping Offline UUID: " + uuid);
continue;
}
Set<String> listening = new HashSet<String>();
StringTokenizer l = new StringTokenizer(playerData.getString(uuidString + ".channels"), ",");
while (l.hasMoreTokens()) {
String channel = l.nextToken();
listening.add(channel);
}
HashMap<String, MuteContainer> mutes = new HashMap<String, MuteContainer>();
StringTokenizer m = new StringTokenizer(playerData.getString(uuidString + ".mutes"), ",");
while (m.hasMoreTokens()) {
String[] parts = m.nextToken().split(":");
String channelName = parts[0];
mutes.put(channelName, new MuteContainer(channelName, Long.parseLong(parts[1]), ""));
}
HashSet<UUID> ignores = new HashSet<UUID>();
StringTokenizer n = new StringTokenizer(playerData.getString(uuidString + ".ignores"), ",");
while (n.hasMoreTokens()) {
String ignore = n.nextToken();
ignores.add(UUID.fromString(ignore));
}
boolean spy = playerData.getBoolean(uuidString + ".spy");
boolean messageToggle = playerData.getBoolean(uuidString + ".messagetoggle");
playerApiService.addSynchronizedMineverseChatPlayerToMap(
SynchronizedVentureChatPlayer.builder().uuid(uuid).listening(listening).mutes(mutes).ignores(ignores).spy(spy).messageToggleEnabled(messageToggle).build());
}
} catch (Exception e) {
playerApiService.clearProxyPlayerMap();
source.sendConsoleMessage("&8[&eVentureChat&8]&c - Error Loading Legacy Player Data!");
source.sendConsoleMessage("&8[&eVentureChat&8]&c - Deleted BungeePlayers.yml file!");
} finally {
sync.delete();
}
}
private void readProxyPlayerDataFile(Path path, VentureChatProxySource source) { public void loadProxyPlayerData(File dataFolder, VentureChatProxySource source) {
SynchronizedVentureChatPlayer smcp; try {
File proxyPlayerDataFile = path.toFile(); File playerDataDirectory = dataFolder;
if (!proxyPlayerDataFile.exists()) { if (!playerDataDirectory.exists()) {
return; playerDataDirectory.mkdirs();
} }
try { Files.walk(Paths.get(dataFolder.getAbsolutePath())).filter(Files::isRegularFile).forEach((path) -> readProxyPlayerDataFile(path, source));
Configuration proxyPlayerDataFileConfiguration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(proxyPlayerDataFile); } catch (IOException e) {
String uuidString = proxyPlayerDataFile.getName().replace(".yml", ""); e.printStackTrace();
UUID uuid = UUID.fromString(uuidString); }
if (uuidService.shouldSkipOfflineUUIDProxy(uuid, source)) { }
source.sendConsoleMessage("&8[&eVentureChat&8]&c - Skipping Offline UUID: " + uuid);
source.sendConsoleMessage("&8[&eVentureChat&8]&c - File will be skipped and deleted.");
proxyPlayerDataFile.delete();
return;
}
Set<String> listening = new HashSet<String>();
StringTokenizer l = new StringTokenizer(proxyPlayerDataFileConfiguration.getString("channels"), ",");
while (l.hasMoreTokens()) {
String channel = l.nextToken();
listening.add(channel);
}
HashMap<String, MuteContainer> mutes = new HashMap<String, MuteContainer>();
Configuration muteSection = proxyPlayerDataFileConfiguration.getSection("mutes");
for (String channelName : muteSection.getKeys()) {
Configuration channelSection = muteSection.getSection(channelName);
mutes.put(channelName, new MuteContainer(channelName, channelSection.getLong("time"), channelSection.getString("reason")));
}
HashSet<UUID> ignores = new HashSet<UUID>();
StringTokenizer n = new StringTokenizer(proxyPlayerDataFileConfiguration.getString("ignores"), ",");
while (n.hasMoreTokens()) {
String ignore = n.nextToken();
ignores.add(UUID.fromString(ignore));
}
boolean spy = proxyPlayerDataFileConfiguration.getBoolean("spy");
boolean messageToggle = proxyPlayerDataFileConfiguration.getBoolean("messagetoggle");
smcp = new SynchronizedVentureChatPlayer(uuid, listening, mutes, ignores, spy, messageToggle);
} catch (Exception e) {
source.sendConsoleMessage("&8[&eVentureChat&8]&c - Error Loading Data File: " + proxyPlayerDataFile.getName());
source.sendConsoleMessage("&8[&eVentureChat&8]&c - File will be skipped and deleted.");
proxyPlayerDataFile.delete();
return;
}
if (smcp != null) {
playerApiService.addSynchronizedMineverseChatPlayerToMap(smcp);
}
}
public void saveProxyPlayerData(File dataFolder, VentureChatProxySource source) { private void readProxyPlayerDataFile(Path path, VentureChatProxySource source) {
try { SynchronizedVentureChatPlayer smcp;
for (SynchronizedVentureChatPlayer p : playerApiService.getSynchronizedMineverseChatPlayers()) { File proxyPlayerDataFile = path.toFile();
if (uuidService.shouldSkipOfflineUUIDProxy(p.getUUID(), source)) { if (!proxyPlayerDataFile.exists()) {
return; return;
} }
File proxyPlayerDataFile = new File(dataFolder.getAbsolutePath(), p.getUUID() + ".yml"); try {
if (!proxyPlayerDataFile.exists()) { Configuration proxyPlayerDataFileConfiguration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(proxyPlayerDataFile);
proxyPlayerDataFile.createNewFile(); String uuidString = proxyPlayerDataFile.getName().replace(".yml", "");
} UUID uuid = UUID.fromString(uuidString);
Configuration proxyPlayerDataFileConfiguration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(proxyPlayerDataFile); if (uuidService.shouldSkipOfflineUUIDProxy(uuid, source)) {
source.sendConsoleMessage("&8[&eVentureChat&8]&c - Skipping Offline UUID: " + uuid);
source.sendConsoleMessage("&8[&eVentureChat&8]&c - File will be skipped and deleted.");
proxyPlayerDataFile.delete();
return;
}
Set<String> listening = new HashSet<String>();
StringTokenizer l = new StringTokenizer(proxyPlayerDataFileConfiguration.getString("channels"), ",");
while (l.hasMoreTokens()) {
String channel = l.nextToken();
listening.add(channel);
}
HashMap<String, MuteContainer> mutes = new HashMap<String, MuteContainer>();
Configuration muteSection = proxyPlayerDataFileConfiguration.getSection("mutes");
for (String channelName : muteSection.getKeys()) {
Configuration channelSection = muteSection.getSection(channelName);
mutes.put(channelName, new MuteContainer(channelName, channelSection.getLong("time"), channelSection.getString("reason")));
}
HashSet<UUID> ignores = new HashSet<UUID>();
StringTokenizer n = new StringTokenizer(proxyPlayerDataFileConfiguration.getString("ignores"), ",");
while (n.hasMoreTokens()) {
String ignore = n.nextToken();
ignores.add(UUID.fromString(ignore));
}
boolean spy = proxyPlayerDataFileConfiguration.getBoolean("spy");
boolean messageToggle = proxyPlayerDataFileConfiguration.getBoolean("messagetoggle");
// smcp = new SynchronizedVentureChatPlayer(uuid, listening, mutes, ignores, spy, messageToggle);
smcp = SynchronizedVentureChatPlayer.builder().uuid(uuid).listening(listening).mutes(mutes).ignores(ignores).spy(spy).messageToggleEnabled(messageToggle).build();
} catch (Exception e) {
source.sendConsoleMessage("&8[&eVentureChat&8]&c - Error Loading Data File: " + proxyPlayerDataFile.getName());
source.sendConsoleMessage("&8[&eVentureChat&8]&c - File will be skipped and deleted.");
proxyPlayerDataFile.delete();
return;
}
if (smcp != null) {
playerApiService.addSynchronizedMineverseChatPlayerToMap(smcp);
}
}
String listen = ""; public void saveProxyPlayerData(File dataFolder, VentureChatProxySource source) {
for (String s : p.getListening()) try {
listen += s + ","; for (SynchronizedVentureChatPlayer p : playerApiService.getSynchronizedMineverseChatPlayers()) {
String ignore = ""; if (uuidService.shouldSkipOfflineUUIDProxy(p.getUuid(), source)) {
for (UUID s : p.getIgnores()) return;
ignore += s.toString() + ","; }
if (listen.length() > 0) File proxyPlayerDataFile = new File(dataFolder.getAbsolutePath(), p.getUuid() + ".yml");
listen = listen.substring(0, listen.length() - 1); if (!proxyPlayerDataFile.exists()) {
if (ignore.length() > 0) proxyPlayerDataFile.createNewFile();
ignore = ignore.substring(0, ignore.length() - 1); }
proxyPlayerDataFileConfiguration.set("channels", listen); Configuration proxyPlayerDataFileConfiguration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(proxyPlayerDataFile);
Configuration muteSection = createSection(proxyPlayerDataFileConfiguration, "mutes");
for (MuteContainer mute : p.getMutes()) {
Configuration channelSection = createSection(muteSection, mute.getChannel());
channelSection.set("time", mute.getDuration());
channelSection.set("reason", mute.getReason());
}
proxyPlayerDataFileConfiguration.set("ignores", ignore);
proxyPlayerDataFileConfiguration.set("spy", p.isSpy());
proxyPlayerDataFileConfiguration.set("messagetoggle", p.getMessageToggle());
ConfigurationProvider.getProvider(YamlConfiguration.class).save(proxyPlayerDataFileConfiguration, proxyPlayerDataFile);
}
} catch (IOException e) {
e.printStackTrace();
}
}
/** String listen = "";
* Create a new {@link Configuration} section. for (String s : p.getListening())
* listen += s + ",";
* @param configurationSection String ignore = "";
* @param sectionKey for (UUID s : p.getIgnores())
* @return Configuration ignore += s.toString() + ",";
*/ if (listen.length() > 0)
private Configuration createSection(Configuration configurationSection, String sectionKey) { listen = listen.substring(0, listen.length() - 1);
configurationSection.set(sectionKey, null); if (ignore.length() > 0)
return configurationSection.getSection(sectionKey); ignore = ignore.substring(0, ignore.length() - 1);
} proxyPlayerDataFileConfiguration.set("channels", listen);
Configuration muteSection = createSection(proxyPlayerDataFileConfiguration, "mutes");
for (MuteContainer mute : p.getMutes().values()) {
Configuration channelSection = createSection(muteSection, mute.getChannel());
channelSection.set("time", mute.getDuration());
channelSection.set("reason", mute.getReason());
}
proxyPlayerDataFileConfiguration.set("ignores", ignore);
proxyPlayerDataFileConfiguration.set("spy", p.isSpy());
proxyPlayerDataFileConfiguration.set("messagetoggle", p.isMessageToggleEnabled());
ConfigurationProvider.getProvider(YamlConfiguration.class).save(proxyPlayerDataFileConfiguration, proxyPlayerDataFile);
}
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* Create a new {@link Configuration} section.
*
* @param configurationSection
* @param sectionKey
* @return Configuration
*/
private Configuration createSection(Configuration configurationSection, String sectionKey) {
configurationSection.set(sectionKey, null);
return configurationSection.getSection(sectionKey);
}
} }

View File

@ -106,7 +106,7 @@ public class SpigotFlatFileController {
UUID party = playerData.getConfigurationSection("players." + uuidString).getString("party").length() > 0 UUID party = playerData.getConfigurationSection("players." + uuidString).getString("party").length() > 0
? UUID.fromString(playerData.getConfigurationSection("players." + uuidString).getString("party")) ? UUID.fromString(playerData.getConfigurationSection("players." + uuidString).getString("party"))
: null; : null;
boolean filter = playerData.getConfigurationSection("players." + uuidString).getBoolean("filter"); boolean filterEnabled = playerData.getConfigurationSection("players." + uuidString).getBoolean("filter");
boolean notifications = playerData.getConfigurationSection("players." + uuidString).getBoolean("notifications"); boolean notifications = playerData.getConfigurationSection("players." + uuidString).getBoolean("notifications");
String jsonFormat = "Default"; String jsonFormat = "Default";
boolean spy = playerData.getConfigurationSection("players." + uuidString).getBoolean("spy", false); boolean spy = playerData.getConfigurationSection("players." + uuidString).getBoolean("spy", false);
@ -124,7 +124,7 @@ public class SpigotFlatFileController {
.blockedCommands(blockedCommands) .blockedCommands(blockedCommands)
.host(host) .host(host)
.party(party) .party(party)
.filter(filter) .filterEnabled(filterEnabled)
.notifications(notifications) .notifications(notifications)
.jsonFormat(jsonFormat) .jsonFormat(jsonFormat)
.spy(spy) .spy(spy)
@ -211,7 +211,7 @@ public class SpigotFlatFileController {
} }
boolean host = playerDataFileYamlConfiguration.getBoolean("host"); boolean host = playerDataFileYamlConfiguration.getBoolean("host");
UUID party = playerDataFileYamlConfiguration.getString("party").length() > 0 ? UUID.fromString(playerDataFileYamlConfiguration.getString("party")) : null; UUID party = playerDataFileYamlConfiguration.getString("party").length() > 0 ? UUID.fromString(playerDataFileYamlConfiguration.getString("party")) : null;
boolean filter = playerDataFileYamlConfiguration.getBoolean("filter"); boolean filterEnabled = playerDataFileYamlConfiguration.getBoolean("filter");
boolean notifications = playerDataFileYamlConfiguration.getBoolean("notifications"); boolean notifications = playerDataFileYamlConfiguration.getBoolean("notifications");
String jsonFormat = "Default"; String jsonFormat = "Default";
boolean spy = playerDataFileYamlConfiguration.getBoolean("spy", false); boolean spy = playerDataFileYamlConfiguration.getBoolean("spy", false);
@ -229,7 +229,7 @@ public class SpigotFlatFileController {
.blockedCommands(blockedCommands) .blockedCommands(blockedCommands)
.host(host) .host(host)
.party(party) .party(party)
.filter(filter) .filterEnabled(filterEnabled)
.notifications(notifications) .notifications(notifications)
.jsonFormat(jsonFormat) .jsonFormat(jsonFormat)
.spy(spy) .spy(spy)
@ -292,7 +292,7 @@ public class SpigotFlatFileController {
playerDataFileYamlConfiguration.set("blockedcommands", blockedCommands); playerDataFileYamlConfiguration.set("blockedcommands", blockedCommands);
playerDataFileYamlConfiguration.set("host", mcp.isHost()); playerDataFileYamlConfiguration.set("host", mcp.isHost());
playerDataFileYamlConfiguration.set("party", mcp.getParty() != null ? mcp.getParty().toString() : ""); playerDataFileYamlConfiguration.set("party", mcp.getParty() != null ? mcp.getParty().toString() : "");
playerDataFileYamlConfiguration.set("filter", mcp.isFilter()); playerDataFileYamlConfiguration.set("filter", mcp.isFilterEnabled());
playerDataFileYamlConfiguration.set("notifications", mcp.isNotifications()); playerDataFileYamlConfiguration.set("notifications", mcp.isNotifications());
playerDataFileYamlConfiguration.set("spy", configService.isSpy(mcp)); playerDataFileYamlConfiguration.set("spy", configService.isSpy(mcp));
playerDataFileYamlConfiguration.set("commandspy", configService.isCommandSpy(mcp)); playerDataFileYamlConfiguration.set("commandspy", configService.isCommandSpy(mcp));

View File

@ -51,7 +51,7 @@ public class Channel extends PlayerCommand {
return; return;
ChatChannel channel = event.getChannel(); ChatChannel channel = event.getChannel();
VentureChatPlayer mcp = playerApiService.getOnlineMineverseChatPlayer(event.getPlayer()); VentureChatPlayer mcp = playerApiService.getOnlineMineverseChatPlayer(event.getPlayer());
if (channel.hasPermission()) { if (channel.isPermissionRequired()) {
if (!mcp.getPlayer().hasPermission(channel.getPermission())) { if (!mcp.getPlayer().hasPermission(channel.getPermission())) {
mcp.getListening().remove(channel.getName()); mcp.getListening().remove(channel.getName());
mcp.getPlayer().sendMessage(LocalizedMessage.CHANNEL_NO_PERMISSION.toString()); mcp.getPlayer().sendMessage(LocalizedMessage.CHANNEL_NO_PERMISSION.toString());
@ -72,7 +72,7 @@ public class Channel extends PlayerCommand {
mcp.getListening().add(channel.getName()); mcp.getListening().add(channel.getName());
mcp.setCurrentChannel(channel); mcp.setCurrentChannel(channel);
mcp.getPlayer().sendMessage(event.getMessage()); mcp.getPlayer().sendMessage(event.getMessage());
if (channel.getBungee()) { if (channel.isBungeeEnabled()) {
pluginMessageController.synchronize(mcp, true); pluginMessageController.synchronize(mcp, true);
} }
} }

View File

@ -45,7 +45,7 @@ public class ChannelAlias extends PlayerCommand {
} }
mcp.getListening().add(channel.getName()); mcp.getListening().add(channel.getName());
mcp.setCurrentChannel(channel); mcp.setCurrentChannel(channel);
if (channel.getBungee()) { if (channel.isBungeeEnabled()) {
pluginMessageController.synchronize(mcp, true); pluginMessageController.synchronize(mcp, true);
} }
return; return;
@ -53,7 +53,7 @@ public class ChannelAlias extends PlayerCommand {
mcp.setQuickChat(true); mcp.setQuickChat(true);
mcp.setQuickChannel(channel); mcp.setQuickChannel(channel);
mcp.getListening().add(channel.getName()); mcp.getListening().add(channel.getName());
if (channel.getBungee()) { if (channel.isBungeeEnabled()) {
pluginMessageController.synchronize(mcp, true); pluginMessageController.synchronize(mcp, true);
} }
String msg = ""; String msg = "";

View File

@ -31,7 +31,7 @@ public class Channelinfo extends UniversalCommand {
sender.sendMessage(ChatColor.RED + "Invalid channel: " + args[0]); sender.sendMessage(ChatColor.RED + "Invalid channel: " + args[0]);
return; return;
} }
if (chname.hasPermission()) { if (chname.isPermissionRequired()) {
if (!sender.hasPermission(chname.getPermission())) { if (!sender.hasPermission(chname.getPermission())) {
sender.sendMessage(ChatColor.RED + "You do not have permission to look at this channel."); sender.sendMessage(ChatColor.RED + "You do not have permission to look at this channel.");
return; return;
@ -42,29 +42,29 @@ public class Channelinfo extends UniversalCommand {
sender.sendMessage(ChatColor.GOLD + "Color: " + chname.getColor() + chname.getColorRaw()); sender.sendMessage(ChatColor.GOLD + "Color: " + chname.getColor() + chname.getColorRaw());
sender.sendMessage(ChatColor.GOLD + "ChatColor: " + (chname.getChatColor().equalsIgnoreCase("None") ? FormatUtils.DEFAULT_COLOR_CODE : chname.getChatColor()) sender.sendMessage(ChatColor.GOLD + "ChatColor: " + (chname.getChatColor().equalsIgnoreCase("None") ? FormatUtils.DEFAULT_COLOR_CODE : chname.getChatColor())
+ chname.getChatColorRaw()); + chname.getChatColorRaw());
if (chname.hasPermission()) { if (chname.isPermissionRequired()) {
sender.sendMessage(ChatColor.GOLD + "Permission: " + chname.getColor() + chname.getPermission()); sender.sendMessage(ChatColor.GOLD + "Permission: " + chname.getColor() + chname.getPermission());
} else { } else {
sender.sendMessage(ChatColor.GOLD + "Permission: " + chname.getColor() + "None"); sender.sendMessage(ChatColor.GOLD + "Permission: " + chname.getColor() + "None");
} }
if (chname.hasSpeakPermission()) { if (chname.isSpeakPermissionRequired()) {
sender.sendMessage(ChatColor.GOLD + "Speak Permission: " + chname.getColor() + chname.getSpeakPermission()); sender.sendMessage(ChatColor.GOLD + "Speak Permission: " + chname.getColor() + chname.getSpeakPermission());
} else { } else {
sender.sendMessage(ChatColor.GOLD + "Speak Permission: " + chname.getColor() + "None"); sender.sendMessage(ChatColor.GOLD + "Speak Permission: " + chname.getColor() + "None");
} }
sender.sendMessage(ChatColor.GOLD + "Autojoin: " + chname.getColor() + chname.getAutojoin()); sender.sendMessage(ChatColor.GOLD + "Autojoin: " + chname.getColor() + chname.isAutoJoinEnabled());
sender.sendMessage(ChatColor.GOLD + "Default: " + chname.getColor() + chname.hasDistance()); sender.sendMessage(ChatColor.GOLD + "Default: " + chname.getColor() + chname.isDefaultChannel());
if (!chname.hasDistance() || chname.getBungee()) { if (chname.getDistance() <= 0 || chname.isBungeeEnabled()) {
sender.sendMessage(ChatColor.GOLD + "Distance: " + ChatColor.RED + "N/A"); sender.sendMessage(ChatColor.GOLD + "Distance: " + ChatColor.RED + "N/A");
} else { } else {
sender.sendMessage(ChatColor.GOLD + "Distance: " + chname.getColor() + chname.getDistance()); sender.sendMessage(ChatColor.GOLD + "Distance: " + chname.getColor() + chname.getDistance());
} }
if (!chname.hasCooldown()) { if (chname.getCooldown() <= 0) {
sender.sendMessage(ChatColor.GOLD + "Cooldown: " + ChatColor.RED + "N/A"); sender.sendMessage(ChatColor.GOLD + "Cooldown: " + ChatColor.RED + "N/A");
} else { } else {
sender.sendMessage(ChatColor.GOLD + "Cooldown: " + chname.getColor() + chname.getCooldown()); sender.sendMessage(ChatColor.GOLD + "Cooldown: " + chname.getColor() + chname.getCooldown());
} }
sender.sendMessage(ChatColor.GOLD + "Bungeecord: " + chname.getColor() + chname.getBungee()); sender.sendMessage(ChatColor.GOLD + "Bungeecord: " + chname.getColor() + chname.isBungeeEnabled());
sender.sendMessage(ChatColor.GOLD + "Format: " + chname.getColor() + chname.getFormat()); sender.sendMessage(ChatColor.GOLD + "Format: " + chname.getColor() + chname.getFormat());
return; return;
} else { } else {

View File

@ -81,7 +81,7 @@ public class Chatinfo extends UniversalCommand {
} else { } else {
mcp.getPlayer().sendMessage(ChatColor.GOLD + "Ranged spy: " + ChatColor.RED + "false"); mcp.getPlayer().sendMessage(ChatColor.GOLD + "Ranged spy: " + ChatColor.RED + "false");
} }
if (mcp.isFilter()) { if (mcp.isFilterEnabled()) {
mcp.getPlayer().sendMessage(ChatColor.GOLD + "Filter: " + ChatColor.GREEN + "true"); mcp.getPlayer().sendMessage(ChatColor.GOLD + "Filter: " + ChatColor.GREEN + "true");
} else { } else {
mcp.getPlayer().sendMessage(ChatColor.GOLD + "Filter: " + ChatColor.RED + "false"); mcp.getPlayer().sendMessage(ChatColor.GOLD + "Filter: " + ChatColor.RED + "false");
@ -141,7 +141,7 @@ public class Chatinfo extends UniversalCommand {
} else { } else {
sender.sendMessage(ChatColor.GOLD + "Ranged spy: " + ChatColor.RED + "false"); sender.sendMessage(ChatColor.GOLD + "Ranged spy: " + ChatColor.RED + "false");
} }
if (p.isFilter()) { if (p.isFilterEnabled()) {
sender.sendMessage(ChatColor.GOLD + "Filter: " + ChatColor.GREEN + "true"); sender.sendMessage(ChatColor.GOLD + "Filter: " + ChatColor.GREEN + "true");
} else { } else {
sender.sendMessage(ChatColor.GOLD + "Filter: " + ChatColor.RED + "false"); sender.sendMessage(ChatColor.GOLD + "Filter: " + ChatColor.RED + "false");

View File

@ -22,7 +22,7 @@ public class Chlist extends UniversalCommand {
public void executeCommand(CommandSender sender, String command, String[] args) { public void executeCommand(CommandSender sender, String command, String[] args) {
sender.sendMessage(LocalizedMessage.CHANNEL_LIST_HEADER.toString()); sender.sendMessage(LocalizedMessage.CHANNEL_LIST_HEADER.toString());
for (ChatChannel chname : configService.getChatChannels()) { for (ChatChannel chname : configService.getChatChannels()) {
if (chname.hasPermission()) { if (chname.isPermissionRequired()) {
if (sender.hasPermission(chname.getPermission())) { if (sender.hasPermission(chname.getPermission())) {
sender.sendMessage(LocalizedMessage.CHANNEL_LIST_WITH_PERMISSIONS.toString() sender.sendMessage(LocalizedMessage.CHANNEL_LIST_WITH_PERMISSIONS.toString()
.replace("{channel_color}", (chname.getColor()).toString()) .replace("{channel_color}", (chname.getColor()).toString())

View File

@ -47,7 +47,7 @@ public class Chwho extends UniversalCommand {
if (args.length > 0) { if (args.length > 0) {
ChatChannel channel = configService.getChannel(args[0]); ChatChannel channel = configService.getChannel(args[0]);
if (channel != null) { if (channel != null) {
if (channel.hasPermission()) { if (channel.isPermissionRequired()) {
if (!sender.hasPermission(channel.getPermission())) { if (!sender.hasPermission(channel.getPermission())) {
VentureChatPlayer mcp = playerApiService.getOnlineMineverseChatPlayer(((Player) sender)); VentureChatPlayer mcp = playerApiService.getOnlineMineverseChatPlayer(((Player) sender));
mcp.getListening().remove(channel.getName()); mcp.getListening().remove(channel.getName());
@ -56,7 +56,7 @@ public class Chwho extends UniversalCommand {
} }
} }
if (channel.getBungee() && sender instanceof Player) { if (channel.isBungeeEnabled() && sender instanceof Player) {
VentureChatPlayer mcp = playerApiService.getOnlineMineverseChatPlayer((Player) sender); VentureChatPlayer mcp = playerApiService.getOnlineMineverseChatPlayer((Player) sender);
ByteArrayOutputStream byteOutStream = new ByteArrayOutputStream(); ByteArrayOutputStream byteOutStream = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(byteOutStream); DataOutputStream out = new DataOutputStream(byteOutStream);
@ -82,7 +82,7 @@ public class Chwho extends UniversalCommand {
continue; continue;
} }
} }
if (channel.hasDistance() && sender instanceof Player) { if (channel.getDistance() > 0 && sender instanceof Player) {
if (!this.isPlayerWithinDistance((Player) sender, p.getPlayer(), channel.getDistance())) { if (!this.isPlayerWithinDistance((Player) sender, p.getPlayer(), channel.getDistance())) {
continue; continue;
} }

View File

@ -22,12 +22,12 @@ public class Filter extends PlayerCommand {
public void executeCommand(Player sender, String command, String[] args) { public void executeCommand(Player sender, String command, String[] args) {
VentureChatPlayer mcp = playerApiService.getOnlineMineverseChatPlayer((Player) sender); VentureChatPlayer mcp = playerApiService.getOnlineMineverseChatPlayer((Player) sender);
if (mcp.getPlayer().hasPermission("venturechat.ignorefilter")) { if (mcp.getPlayer().hasPermission("venturechat.ignorefilter")) {
if (!mcp.isFilter()) { if (!mcp.isFilterEnabled()) {
mcp.setFilter(true); mcp.setFilterEnabled(true);
mcp.getPlayer().sendMessage(LocalizedMessage.FILTER_ON.toString()); mcp.getPlayer().sendMessage(LocalizedMessage.FILTER_ON.toString());
return; return;
} }
mcp.setFilter(false); mcp.setFilterEnabled(false);
mcp.getPlayer().sendMessage(LocalizedMessage.FILTER_OFF.toString()); mcp.getPlayer().sendMessage(LocalizedMessage.FILTER_OFF.toString());
return; return;
} }

View File

@ -52,11 +52,11 @@ public class Kickchannel extends UniversalCommand {
} else { } else {
player.setModified(true); player.setModified(true);
} }
boolean isThereABungeeChannel = channel.getBungee(); boolean isThereABungeeChannel = channel.isBungeeEnabled();
if (player.getListening().size() == 0) { if (player.getListening().size() == 0) {
player.getListening().add(configService.getDefaultChannel().getName()); player.getListening().add(configService.getDefaultChannel().getName());
player.setCurrentChannel(configService.getDefaultChannel()); player.setCurrentChannel(configService.getDefaultChannel());
if (configService.getDefaultChannel().getBungee()) { if (configService.getDefaultChannel().isBungeeEnabled()) {
isThereABungeeChannel = true; isThereABungeeChannel = true;
} }
if (player.isOnline()) { if (player.isOnline()) {

View File

@ -42,7 +42,7 @@ public class Kickchannelall extends UniversalCommand {
for (String channel : player.getListening()) { for (String channel : player.getListening()) {
if (configService.isChannel(channel)) { if (configService.isChannel(channel)) {
ChatChannel chatChannelObj = configService.getChannel(channel); ChatChannel chatChannelObj = configService.getChannel(channel);
if (chatChannelObj.getBungee()) { if (chatChannelObj.isBungeeEnabled()) {
isThereABungeeChannel = true; isThereABungeeChannel = true;
} }
} }
@ -51,7 +51,7 @@ public class Kickchannelall extends UniversalCommand {
sender.sendMessage(LocalizedMessage.KICK_CHANNEL_ALL_SENDER.toString().replace("{player}", player.getName())); sender.sendMessage(LocalizedMessage.KICK_CHANNEL_ALL_SENDER.toString().replace("{player}", player.getName()));
player.getListening().add(configService.getDefaultChannel().getName()); player.getListening().add(configService.getDefaultChannel().getName());
player.setCurrentChannel(configService.getDefaultChannel()); player.setCurrentChannel(configService.getDefaultChannel());
if (configService.getDefaultChannel().getBungee()) { if (configService.getDefaultChannel().isBungeeEnabled()) {
isThereABungeeChannel = true; isThereABungeeChannel = true;
} }
if (isThereABungeeChannel) { if (isThereABungeeChannel) {

View File

@ -37,11 +37,11 @@ public class Leave extends PlayerCommand {
} }
mcp.getListening().remove(channel.getName()); mcp.getListening().remove(channel.getName());
mcp.getPlayer().sendMessage(LocalizedMessage.LEAVE_CHANNEL.toString().replace("{channel_color}", channel.getColor() + "").replace("{channel_name}", channel.getName())); mcp.getPlayer().sendMessage(LocalizedMessage.LEAVE_CHANNEL.toString().replace("{channel_color}", channel.getColor() + "").replace("{channel_name}", channel.getName()));
boolean isThereABungeeChannel = channel.getBungee(); boolean isThereABungeeChannel = channel.isBungeeEnabled();
if (mcp.getListening().size() == 0) { if (mcp.getListening().size() == 0) {
mcp.getListening().add(configService.getDefaultChannel().getName()); mcp.getListening().add(configService.getDefaultChannel().getName());
mcp.setCurrentChannel(configService.getDefaultChannel()); mcp.setCurrentChannel(configService.getDefaultChannel());
if (configService.getDefaultChannel().getBungee()) { if (configService.getDefaultChannel().isBungeeEnabled()) {
isThereABungeeChannel = true; isThereABungeeChannel = true;
} }
mcp.getPlayer().sendMessage(LocalizedMessage.MUST_LISTEN_ONE_CHANNEL.toString()); mcp.getPlayer().sendMessage(LocalizedMessage.MUST_LISTEN_ONE_CHANNEL.toString());

View File

@ -34,7 +34,7 @@ public class Listen extends PlayerCommand {
mcp.getPlayer().sendMessage(LocalizedMessage.INVALID_CHANNEL.toString().replace("{args}", args[0])); mcp.getPlayer().sendMessage(LocalizedMessage.INVALID_CHANNEL.toString().replace("{args}", args[0]));
return; return;
} }
if (channel.hasPermission()) { if (channel.isPermissionRequired()) {
if (!mcp.getPlayer().hasPermission(channel.getPermission())) { if (!mcp.getPlayer().hasPermission(channel.getPermission())) {
mcp.getListening().remove(channel.getName()); mcp.getListening().remove(channel.getName());
mcp.getPlayer().sendMessage(LocalizedMessage.CHANNEL_NO_PERMISSION.toString()); mcp.getPlayer().sendMessage(LocalizedMessage.CHANNEL_NO_PERMISSION.toString());
@ -44,7 +44,7 @@ public class Listen extends PlayerCommand {
mcp.getListening().add(channel.getName()); mcp.getListening().add(channel.getName());
mcp.getPlayer() mcp.getPlayer()
.sendMessage(LocalizedMessage.LISTEN_CHANNEL.toString().replace("{channel_color}", channel.getColor() + "").replace("{channel_name}", channel.getName())); .sendMessage(LocalizedMessage.LISTEN_CHANNEL.toString().replace("{channel_color}", channel.getColor() + "").replace("{channel_name}", channel.getName()));
if (channel.getBungee()) { if (channel.isBungeeEnabled()) {
pluginMessageController.synchronize(mcp, true); pluginMessageController.synchronize(mcp, true);
} }
return; return;

View File

@ -31,7 +31,7 @@ public class Me extends UniversalCommand {
for (int x = 0; x < args.length; x++) for (int x = 0; x < args.length; x++)
if (args[x].length() > 0) if (args[x].length() > 0)
msg += " " + args[x]; msg += " " + args[x];
if (sender instanceof Player && playerApiService.getOnlineMineverseChatPlayer((Player) sender).isFilter()) { if (sender instanceof Player && playerApiService.getOnlineMineverseChatPlayer((Player) sender).isFilterEnabled()) {
msg = formatService.filterChat(msg); msg = formatService.filterChat(msg);
} }
if (sender.hasPermission("venturechat.color.legacy")) { if (sender.hasPermission("venturechat.color.legacy")) {

View File

@ -85,7 +85,7 @@ public class Message extends PlayerCommand {
for (int r = 1; r < args.length; r++) { for (int r = 1; r < args.length; r++) {
msg += " " + args[r]; msg += " " + args[r];
} }
if (mcp.isFilter()) { if (mcp.isFilterEnabled()) {
msg = formatService.filterChat(msg); msg = formatService.filterChat(msg);
} }
if (mcp.getPlayer().hasPermission("venturechat.color.legacy")) { if (mcp.getPlayer().hasPermission("venturechat.color.legacy")) {
@ -184,7 +184,7 @@ public class Message extends PlayerCommand {
msgBuilder.append(" " + args[r]); msgBuilder.append(" " + args[r]);
} }
String msg = msgBuilder.toString(); String msg = msgBuilder.toString();
if (mcp.isFilter()) { if (mcp.isFilterEnabled()) {
msg = formatService.filterChat(msg); msg = formatService.filterChat(msg);
} }
if (mcp.getPlayer().hasPermission("venturechat.color.legacy")) { if (mcp.getPlayer().hasPermission("venturechat.color.legacy")) {

View File

@ -69,7 +69,7 @@ public class Mute extends UniversalCommand {
} }
reason = FormatUtils.FormatStringAll(reasonBuilder.toString().trim()); reason = FormatUtils.FormatStringAll(reasonBuilder.toString().trim());
} }
if (channel.getBungee()) { if (channel.isBungeeEnabled()) {
sendBungeeCordMute(sender, args[1], channel, time, reason); sendBungeeCordMute(sender, args[1], channel, time, reason);
return; return;
} }
@ -157,7 +157,7 @@ public class Mute extends UniversalCommand {
if (args.length == 2) { if (args.length == 2) {
if (configService.isChannel(args[0])) { if (configService.isChannel(args[0])) {
ChatChannel chatChannelObj = configService.getChannel(args[0]); ChatChannel chatChannelObj = configService.getChannel(args[0]);
if (chatChannelObj.getBungee()) { if (chatChannelObj.isBungeeEnabled()) {
StringUtil.copyPartialMatches(args[1], playerApiService.getNetworkPlayerNames(), completions); StringUtil.copyPartialMatches(args[1], playerApiService.getNetworkPlayerNames(), completions);
Collections.sort(completions); Collections.sort(completions);
return completions; return completions;

View File

@ -52,7 +52,7 @@ public class Muteall extends UniversalCommand {
for (ChatChannel channel : configService.getChatChannels()) { for (ChatChannel channel : configService.getChatChannels()) {
if (channel.isMutable()) { if (channel.isMutable()) {
player.getMutes().put(channel.getName(), new MuteContainer(channel.getName(), 0, "")); player.getMutes().put(channel.getName(), new MuteContainer(channel.getName(), 0, ""));
if (channel.getBungee()) { if (channel.isBungeeEnabled()) {
bungee = true; bungee = true;
} }
} }
@ -71,7 +71,7 @@ public class Muteall extends UniversalCommand {
for (ChatChannel channel : configService.getChatChannels()) { for (ChatChannel channel : configService.getChatChannels()) {
if (channel.isMutable()) { if (channel.isMutable()) {
player.getMutes().put(channel.getName(), new MuteContainer(channel.getName(), 0, reason)); player.getMutes().put(channel.getName(), new MuteContainer(channel.getName(), 0, reason));
if (channel.getBungee()) { if (channel.isBungeeEnabled()) {
bungee = true; bungee = true;
} }
} }

View File

@ -251,7 +251,7 @@ public class Party extends PlayerCommand {
if (args[x].length() > 0) if (args[x].length() > 0)
msg += " " + args[x]; msg += " " + args[x];
} }
if (mcp.isFilter()) { if (mcp.isFilterEnabled()) {
msg = formatService.filterChat(msg); msg = formatService.filterChat(msg);
} }
if (mcp.getPlayer().hasPermission("venturechat.color.legacy")) { if (mcp.getPlayer().hasPermission("venturechat.color.legacy")) {

View File

@ -70,7 +70,7 @@ public class Removemessage extends UniversalCommand {
sender.sendMessage(LocalizedMessage.INVALID_HASH.toString()); sender.sendMessage(LocalizedMessage.INVALID_HASH.toString());
return; return;
} }
if (args.length > 1 && configService.isChannel(args[1]) && configService.getChannel(args[1]).getBungee()) { if (args.length > 1 && configService.isChannel(args[1]) && configService.getChannel(args[1]).isBungeeEnabled()) {
ByteArrayOutputStream byteOutStream = new ByteArrayOutputStream(); ByteArrayOutputStream byteOutStream = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(byteOutStream); DataOutputStream out = new DataOutputStream(byteOutStream);
try { try {

View File

@ -73,7 +73,7 @@ public class Reply extends PlayerCommand {
if (args.length > 0) { if (args.length > 0) {
for (int r = 0; r < args.length; r++) for (int r = 0; r < args.length; r++)
msg += " " + args[r]; msg += " " + args[r];
if (mcp.isFilter()) { if (mcp.isFilterEnabled()) {
msg = formatService.filterChat(msg); msg = formatService.filterChat(msg);
} }
if (mcp.getPlayer().hasPermission("venturechat.color.legacy")) { if (mcp.getPlayer().hasPermission("venturechat.color.legacy")) {
@ -130,7 +130,7 @@ public class Reply extends PlayerCommand {
msgBuilder.append(" " + args[r]); msgBuilder.append(" " + args[r]);
} }
String msg = msgBuilder.toString(); String msg = msgBuilder.toString();
if (mcp.isFilter()) { if (mcp.isFilterEnabled()) {
msg = formatService.filterChat(msg); msg = formatService.filterChat(msg);
} }
if (mcp.getPlayer().hasPermission("venturechat.color.legacy")) { if (mcp.getPlayer().hasPermission("venturechat.color.legacy")) {

View File

@ -42,7 +42,7 @@ public class Setchannel extends UniversalCommand {
sender.sendMessage(LocalizedMessage.INVALID_CHANNEL.toString().replace("{args}", args[1])); sender.sendMessage(LocalizedMessage.INVALID_CHANNEL.toString().replace("{args}", args[1]));
return; return;
} }
if (channel.hasPermission()) { if (channel.isPermissionRequired()) {
if (!player.isOnline()) { if (!player.isOnline()) {
sender.sendMessage(LocalizedMessage.PLAYER_OFFLINE_NO_PERMISSIONS_CHECK.toString()); sender.sendMessage(LocalizedMessage.PLAYER_OFFLINE_NO_PERMISSIONS_CHECK.toString());
return; return;
@ -78,7 +78,7 @@ public class Setchannel extends UniversalCommand {
else { else {
player.setModified(true); player.setModified(true);
} }
if (channel.getBungee()) { if (channel.isBungeeEnabled()) {
pluginMessageController.synchronize(player, true); pluginMessageController.synchronize(player, true);
} }
return; return;

View File

@ -39,7 +39,7 @@ public class Setchannelall extends UniversalCommand {
} }
boolean isThereABungeeChannel = false; boolean isThereABungeeChannel = false;
for (ChatChannel channel : configService.getChatChannels()) { for (ChatChannel channel : configService.getChatChannels()) {
if (channel.hasPermission()) { if (channel.isPermissionRequired()) {
if (!player.isOnline()) { if (!player.isOnline()) {
sender.sendMessage(LocalizedMessage.PLAYER_OFFLINE_NO_PERMISSIONS_CHECK.toString()); sender.sendMessage(LocalizedMessage.PLAYER_OFFLINE_NO_PERMISSIONS_CHECK.toString());
return; return;
@ -52,7 +52,7 @@ public class Setchannelall extends UniversalCommand {
} else { } else {
player.getListening().add(channel.getName()); player.getListening().add(channel.getName());
} }
if (channel.getBungee()) { if (channel.isBungeeEnabled()) {
isThereABungeeChannel = true; isThereABungeeChannel = true;
} }
} }

View File

@ -43,7 +43,7 @@ public class Unmute extends UniversalCommand {
} }
if (configService.isChannel(args[0])) { if (configService.isChannel(args[0])) {
ChatChannel channel = configService.getChannel(args[0]); ChatChannel channel = configService.getChannel(args[0]);
if (channel.getBungee()) { if (channel.isBungeeEnabled()) {
sendBungeeCordUnmute(sender, args[1], channel); sendBungeeCordUnmute(sender, args[1], channel);
return; return;
} }
@ -87,7 +87,7 @@ public class Unmute extends UniversalCommand {
if (args.length == 2) { if (args.length == 2) {
if (configService.isChannel(args[0])) { if (configService.isChannel(args[0])) {
ChatChannel chatChannelObj = configService.getChannel(args[0]); ChatChannel chatChannelObj = configService.getChannel(args[0]);
if (chatChannelObj.getBungee()) { if (chatChannelObj.isBungeeEnabled()) {
StringUtil.copyPartialMatches(args[1], playerApiService.getNetworkPlayerNames(), completions); StringUtil.copyPartialMatches(args[1], playerApiService.getNetworkPlayerNames(), completions);
Collections.sort(completions); Collections.sort(completions);
return completions; return completions;

View File

@ -40,7 +40,7 @@ public class Unmuteall extends UniversalCommand {
boolean bungee = false; boolean bungee = false;
for (ChatChannel channel : configService.getChatChannels()) { for (ChatChannel channel : configService.getChatChannels()) {
player.getMutes().remove(channel.getName()); player.getMutes().remove(channel.getName());
if (channel.getBungee()) { if (channel.isBungeeEnabled()) {
bungee = true; bungee = true;
} }
} }

View File

@ -14,7 +14,6 @@ import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import com.comphenix.protocol.events.PacketContainer;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Singleton; import com.google.inject.Singleton;
import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.entity.MPlayer;
@ -31,9 +30,9 @@ import venture.Aust1n46.chat.model.ChatChannel;
import venture.Aust1n46.chat.model.MuteContainer; import venture.Aust1n46.chat.model.MuteContainer;
import venture.Aust1n46.chat.model.VentureChatPlayer; import venture.Aust1n46.chat.model.VentureChatPlayer;
import venture.Aust1n46.chat.service.ConfigService; import venture.Aust1n46.chat.service.ConfigService;
import venture.Aust1n46.chat.service.VentureChatDatabaseService;
import venture.Aust1n46.chat.service.FormatService; import venture.Aust1n46.chat.service.FormatService;
import venture.Aust1n46.chat.service.PlayerApiService; import venture.Aust1n46.chat.service.PlayerApiService;
import venture.Aust1n46.chat.service.VentureChatDatabaseService;
import venture.Aust1n46.chat.utilities.FormatUtils; import venture.Aust1n46.chat.utilities.FormatUtils;
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@ -100,7 +99,7 @@ public class ChatListener implements Listener {
String echo = ""; String echo = "";
String send = ""; String send = "";
String spy = ""; String spy = "";
if (ventureChatPlayer.isFilter()) { if (ventureChatPlayer.isFilterEnabled()) {
filtered = formatService.filterChat(filtered); filtered = formatService.filterChat(filtered);
} }
if (ventureChatPlayer.getPlayer().hasPermission("venturechat.color.legacy")) { if (ventureChatPlayer.getPlayer().hasPermission("venturechat.color.legacy")) {
@ -155,7 +154,7 @@ public class ChatListener implements Listener {
for (VentureChatPlayer p : playerApiService.getOnlineMineverseChatPlayers()) { for (VentureChatPlayer p : playerApiService.getOnlineMineverseChatPlayers()) {
if ((p.getParty() != null && p.getParty().toString().equals(ventureChatPlayer.getParty().toString()) || configService.isSpy(p))) { if ((p.getParty() != null && p.getParty().toString().equals(ventureChatPlayer.getParty().toString()) || configService.isSpy(p))) {
String filtered = chat; String filtered = chat;
if (ventureChatPlayer.isFilter()) { if (ventureChatPlayer.isFilterEnabled()) {
filtered = formatService.filterChat(filtered); filtered = formatService.filterChat(filtered);
} }
if (ventureChatPlayer.getPlayer().hasPermission("venturechat.color.legacy")) { if (ventureChatPlayer.getPlayer().hasPermission("venturechat.color.legacy")) {
@ -239,7 +238,7 @@ public class ChatListener implements Listener {
processPartyChat(mcp, chat); processPartyChat(mcp, chat);
return; return;
} }
if (eventChannel.hasPermission() && !mcp.getPlayer().hasPermission(eventChannel.getPermission())) { if (eventChannel.isPermissionRequired() && !mcp.getPlayer().hasPermission(eventChannel.getPermission())) {
mcp.getPlayer().sendMessage(LocalizedMessage.CHANNEL_NO_PERMISSION.toString()); mcp.getPlayer().sendMessage(LocalizedMessage.CHANNEL_NO_PERMISSION.toString());
mcp.setQuickChat(false); mcp.setQuickChat(false);
mcp.getListening().remove(eventChannel.getName()); mcp.getListening().remove(eventChannel.getName());
@ -248,7 +247,7 @@ public class ChatListener implements Listener {
} else { } else {
mcp.getListening().add(eventChannel.getName()); mcp.getListening().add(eventChannel.getName());
} }
if (eventChannel.hasSpeakPermission() && !mcp.getPlayer().hasPermission(eventChannel.getSpeakPermission())) { if (eventChannel.isSpeakPermissionRequired() && !mcp.getPlayer().hasPermission(eventChannel.getSpeakPermission())) {
mcp.getPlayer().sendMessage(LocalizedMessage.CHANNEL_NO_SPEAK_PERMISSIONS.toString()); mcp.getPlayer().sendMessage(LocalizedMessage.CHANNEL_NO_SPEAK_PERMISSIONS.toString());
mcp.setQuickChat(false); mcp.setQuickChat(false);
return; return;
@ -260,7 +259,7 @@ public class ChatListener implements Listener {
long dateTimeSeconds = System.currentTimeMillis() / FormatUtils.MILLISECONDS_PER_SECOND; long dateTimeSeconds = System.currentTimeMillis() / FormatUtils.MILLISECONDS_PER_SECOND;
int chCooldown = 0; int chCooldown = 0;
if (eventChannel.hasCooldown()) { if (eventChannel.getCooldown() > 0) {
chCooldown = eventChannel.getCooldown(); chCooldown = eventChannel.getCooldown();
} }
try { try {
@ -274,7 +273,7 @@ public class ChatListener implements Listener {
return; return;
} }
} }
if (eventChannel.hasCooldown()) { if (eventChannel.getCooldown() > 0) {
if (!mcp.getPlayer().hasPermission("venturechat.cooldown.bypass")) { if (!mcp.getPlayer().hasPermission("venturechat.cooldown.bypass")) {
mcp.getCooldowns().put(eventChannel, dateTimeSeconds + chCooldown); mcp.getCooldowns().put(eventChannel, dateTimeSeconds + chCooldown);
} }
@ -306,7 +305,7 @@ public class ChatListener implements Listener {
mcp.getPlayer().sendMessage(LocalizedMessage.MUTE_PLAYER_PLAYER_REASON.toString().replace("{channel_color}", eventChannel.getColor()) 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())); .replace("{channel_name}", eventChannel.getName()).replace("{reason}", LocalizedMessage.SPAM_MUTE_REASON_TEXT.toString()));
} }
if (eventChannel.getBungee()) { if (eventChannel.isBungeeEnabled()) {
pluginMessageController.synchronize(mcp, true); pluginMessageController.synchronize(mcp, true);
} }
mcp.getSpam().get(eventChannel).set(0, 0L); mcp.getSpam().get(eventChannel).set(0, 0L);
@ -333,7 +332,7 @@ public class ChatListener implements Listener {
format = FormatUtils.FormatStringAll(eventChannel.getFormat()); format = FormatUtils.FormatStringAll(eventChannel.getFormat());
if (eventChannel.isFiltered() && mcp.isFilter()) { if (eventChannel.isFiltered() && mcp.isFilterEnabled()) {
chat = formatService.filterChat(chat); chat = formatService.filterChat(chat);
} }
PluginManager pluginManager = plugin.getServer().getPluginManager(); PluginManager pluginManager = plugin.getServer().getPluginManager();
@ -414,11 +413,8 @@ public class ChatListener implements Listener {
} }
} }
double chDistance = 0D; double chDistance = Math.max(eventChannel.getDistance(), 0);
if (eventChannel.hasDistance()) { if (chDistance > (double) 0 && !eventChannel.isBungeeEnabled() && !configService.isRangedSpy(p)) {
chDistance = eventChannel.getDistance();
}
if (chDistance > (double) 0 && !eventChannel.getBungee() && !configService.isRangedSpy(p)) {
final Location locreceip = p.getPlayer().getLocation(); final Location locreceip = p.getPlayer().getLocation();
if (locreceip.getWorld() == mcp.getPlayer().getWorld()) { if (locreceip.getWorld() == mcp.getPlayer().getWorld()) {
final Location locsender = mcp.getPlayer().getLocation(); final Location locsender = mcp.getPlayer().getLocation();
@ -470,7 +466,7 @@ public class ChatListener implements Listener {
format = FormatUtils.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(mcp.getPlayer(), FormatUtils.FormatStringAll(format))); format = FormatUtils.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(mcp.getPlayer(), FormatUtils.FormatStringAll(format)));
String message = FormatUtils.stripColor(format + chat); // UTF-8 encoding issues. String message = FormatUtils.stripColor(format + chat); // UTF-8 encoding issues.
final VentureChatEvent ventureChatEvent = new VentureChatEvent(mcp, mcp.getName(), plugin.getVaultPermission().getPrimaryGroup(mcp.getPlayer()), eventChannel, recipients, final VentureChatEvent ventureChatEvent = new VentureChatEvent(mcp, mcp.getName(), plugin.getVaultPermission().getPrimaryGroup(mcp.getPlayer()), eventChannel, recipients,
recipientCount, format, chat, globalJSON, message.hashCode(), eventChannel.getBungee()); recipientCount, format, chat, globalJSON, message.hashCode(), eventChannel.isBungeeEnabled());
plugin.getServer().getPluginManager().callEvent(ventureChatEvent); plugin.getServer().getPluginManager().callEvent(ventureChatEvent);
handleVentureChatEvent(ventureChatEvent); handleVentureChatEvent(ventureChatEvent);
mcp.setQuickChat(false); mcp.setQuickChat(false);
@ -487,26 +483,19 @@ public class ChatListener implements Listener {
String globalJSON = event.getGlobalJSON(); String globalJSON = event.getGlobalJSON();
int hash = event.getHash(); int hash = event.getHash();
boolean bungee = event.isBungee(); boolean bungee = event.isBungee();
if (essentialsDiscordHook && channel.isDefaultChannel()) {
if (essentialsDiscordHook && channel.isDefaultchannel()) {
plugin.getServer().getServicesManager().load(DiscordService.class).sendChatMessage(ventureChatPlayer.getPlayer(), chat); plugin.getServer().getServicesManager().load(DiscordService.class).sendChatMessage(ventureChatPlayer.getPlayer(), chat);
} }
if (!bungee) { if (!bungee) {
if (databaseService.isEnabled()) { if (databaseService.isEnabled()) {
databaseService.writeVentureChat(ventureChatPlayer.getUuid().toString(), ventureChatPlayer.getName(), "Local", channel.getName(), chat.replace("'", "''"), "Chat"); databaseService.writeVentureChat(ventureChatPlayer.getUuid().toString(), ventureChatPlayer.getName(), "Local", channel.getName(), chat.replace("'", "''"), "Chat");
} }
if (recipientCount == 1) { if (recipientCount == 1) {
if (!plugin.getConfig().getString("emptychannelalert", "&6No one is listening to you.").equals("")) { if (!plugin.getConfig().getString("emptychannelalert", "&6No one is listening to you.").isEmpty()) {
ventureChatPlayer.getPlayer().sendMessage(FormatUtils.FormatStringAll(plugin.getConfig().getString("emptychannelalert", "&6No one is listening to you."))); ventureChatPlayer.getPlayer().sendMessage(FormatUtils.FormatStringAll(plugin.getConfig().getString("emptychannelalert", "&6No one is listening to you.")));
} }
} }
for (Player p : recipients) { formatService.createAndSendChatMessage(globalJSON, channel.getName(), hash, recipients, ventureChatPlayer.getName());
String json = formatService.formatModerationGUI(globalJSON, p, ventureChatPlayer.getName(), channel.getName(), hash);
PacketContainer packet = formatService.createPacketPlayOutChat(json);
formatService.sendPacketPlayOutChat(p, packet);
}
plugin.getServer().getConsoleSender().sendMessage(consoleChat); plugin.getServer().getConsoleSender().sendMessage(consoleChat);
return; return;
} else { } else {

View File

@ -100,7 +100,7 @@ public class LoginListener implements Listener {
} }
mcp.setJsonFormat(jsonFormat); mcp.setJsonFormat(jsonFormat);
for (ChatChannel ch : configService.getAutojoinList()) { for (ChatChannel ch : configService.getAutojoinList()) {
if (ch.hasPermission()) { if (ch.isPermissionRequired()) {
if (mcp.getPlayer().hasPermission(ch.getPermission())) { if (mcp.getPlayer().hasPermission(ch.getPermission())) {
mcp.getListening().add(ch.getName()); mcp.getListening().add(ch.getName());
} }

View File

@ -152,7 +152,7 @@ public class PreProcessCommandListener implements CommandExecutor, Listener {
if (!configService.areAliasesRegisteredAsCommands()) { if (!configService.areAliasesRegisteredAsCommands()) {
for (ChatChannel channel : configService.getChatChannels()) { for (ChatChannel channel : configService.getChatChannels()) {
if (!channel.hasPermission() || mcp.getPlayer().hasPermission(channel.getPermission())) { if (!channel.isPermissionRequired() || mcp.getPlayer().hasPermission(channel.getPermission())) {
if (message.equals("/" + channel.getAlias())) { if (message.equals("/" + channel.getAlias())) {
mcp.getPlayer().sendMessage( mcp.getPlayer().sendMessage(
LocalizedMessage.SET_CHANNEL.toString().replace("{channel_color}", channel.getColor() + "").replace("{channel_name}", channel.getName())); LocalizedMessage.SET_CHANNEL.toString().replace("{channel_color}", channel.getColor() + "").replace("{channel_name}", channel.getName()));
@ -169,7 +169,7 @@ public class PreProcessCommandListener implements CommandExecutor, Listener {
} }
mcp.getListening().add(channel.getName()); mcp.getListening().add(channel.getName());
mcp.setCurrentChannel(channel); mcp.setCurrentChannel(channel);
if (channel.getBungee()) { if (channel.isBungeeEnabled()) {
pluginMessageController.synchronize(mcp, true); pluginMessageController.synchronize(mcp, true);
} }
event.setCancelled(true); event.setCancelled(true);
@ -178,7 +178,7 @@ public class PreProcessCommandListener implements CommandExecutor, Listener {
if (message.toLowerCase().startsWith("/" + channel.getAlias() + " ")) { if (message.toLowerCase().startsWith("/" + channel.getAlias() + " ")) {
message = message.substring(channel.getAlias().length() + 1); message = message.substring(channel.getAlias().length() + 1);
mcp.getListening().add(channel.getName()); mcp.getListening().add(channel.getName());
if (channel.getBungee()) { if (channel.isBungeeEnabled()) {
pluginMessageController.synchronize(mcp, true); pluginMessageController.synchronize(mcp, true);
} }
mcp.setQuickChannel(channel); mcp.setQuickChannel(channel);
@ -218,7 +218,7 @@ public class PreProcessCommandListener implements CommandExecutor, Listener {
mcp.setQuickChat(true); mcp.setQuickChat(true);
mcp.setQuickChannel(channel); mcp.setQuickChannel(channel);
mcp.getListening().add(channel.getName()); mcp.getListening().add(channel.getName());
if (channel.getBungee()) { if (channel.isBungeeEnabled()) {
pluginMessageController.synchronize(mcp, true); pluginMessageController.synchronize(mcp, true);
} }
String msg = ""; String msg = "";

View File

@ -52,7 +52,7 @@ public class UnmuteScheduler {
iterator.remove(); iterator.remove();
p.getPlayer().sendMessage(LocalizedMessage.UNMUTE_PLAYER_PLAYER.toString().replace("{player}", p.getName()) p.getPlayer().sendMessage(LocalizedMessage.UNMUTE_PLAYER_PLAYER.toString().replace("{player}", p.getName())
.replace("{channel_color}", channel.getColor()).replace("{channel_name}", mute.getChannel())); .replace("{channel_color}", channel.getColor()).replace("{channel_name}", mute.getChannel()));
if (channel.getBungee()) { if (channel.isBungeeEnabled()) {
pluginMessageController.synchronize(p, true); pluginMessageController.synchronize(p, true);
} }
} }

View File

@ -1,335 +1,40 @@
package venture.Aust1n46.chat.model; package venture.Aust1n46.chat.model;
import org.bukkit.ChatColor; import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import venture.Aust1n46.chat.service.FormatService; @Getter
import venture.Aust1n46.chat.utilities.FormatUtils; @Setter
@ToString
/** @AllArgsConstructor
* Chat channel object pojo. Class also contains static initialization methods
* for reading chat channels from the config file.
*
* @author Aust1n46
*/
public class ChatChannel { public class ChatChannel {
private static final String PERMISSION_PREFIX = "venturechat."; public static final String NO_PERMISSIONS = "venturechat.none";
private static final String NO_PERMISSIONS = "venturechat.none";
private String name; private String name;
private String color;
private String colorRaw;
private String chatColor;
private String chatColorRaw;
private String permission; private String permission;
private String speakPermission; private String speakPermission;
private boolean mutable; private boolean mutable;
private String color; private boolean filtered;
private String chatColor;
private boolean defaultChannel; private boolean defaultChannel;
private boolean autojoin;
private String alias; private String alias;
private double distance; private double distance;
private boolean filter; private boolean autoJoinEnabled;
private boolean bungee; private boolean bungeeEnabled;
private String format;
private int cooldown; private int cooldown;
private String format;
private String prefix; private String prefix;
/** public boolean isPermissionRequired() {
* Parameterized constructor a {@link ChatChannel}. return !NO_PERMISSIONS.equalsIgnoreCase(permission);
*
* @param name
* @param color
* @param chatColor
* @param permission
* @param speakPermission
* @param mutable
* @param filter
* @param defaultChannel
* @param alias
* @param distance
* @param autojoin
* @param bungee
* @param cooldown
* @param format
*/
public ChatChannel(String name, String color, String chatColor, String permission, String speakPermission,
boolean mutable, boolean filter, boolean defaultChannel, String alias, double distance, boolean autojoin,
boolean bungee, int cooldown, String prefix, String format) {
this.name = name;
this.color = color;
this.chatColor = chatColor;
this.permission = PERMISSION_PREFIX + permission;
this.speakPermission = PERMISSION_PREFIX + speakPermission;
this.mutable = mutable;
this.filter = filter;
this.defaultChannel = defaultChannel;
this.alias = alias;
this.distance = distance;
this.autojoin = autojoin;
this.bungee = bungee;
this.cooldown = cooldown;
this.format = format;
this.prefix = prefix;
} }
/** public boolean isSpeakPermissionRequired() {
* Deprecated parameterized constructor a {@link ChatChannel}. return !NO_PERMISSIONS.equalsIgnoreCase(speakPermission);
*
* @param name
* @param color
* @param chatColor
* @param permission
* @param speakPermission
* @param mutable
* @param filter
* @param defaultChannel
* @param alias
* @param distance
* @param autojoin
* @param bungee
* @param cooldown
* @param format
*/
@Deprecated
public ChatChannel(String name, String color, String chatColor, String permission, String speakPermission,
Boolean mutable, Boolean filter, Boolean defaultChannel, String alias, Double distance, Boolean autojoin,
Boolean bungee, int cooldown, String format) {
this.name = name;
this.color = color;
this.chatColor = chatColor;
this.permission = PERMISSION_PREFIX + permission;
this.speakPermission = PERMISSION_PREFIX + speakPermission;
this.mutable = mutable;
this.filter = filter;
this.defaultChannel = defaultChannel;
this.alias = alias;
this.distance = distance;
this.autojoin = autojoin;
this.bungee = bungee;
this.cooldown = cooldown;
this.format = format;
}
/**
* Get the name of the chat channel.
*
* @return {@link String}
*/
public String getName() {
return name;
}
/**
* Get the format of the chat channel.
*
* @return {@link String}
*/
public String getFormat() {
return format;
}
/**
* Get the cooldown of the chat channel in seconds.
*
* @return int
*/
public int getCooldown() {
return cooldown;
}
/**
* Get the prefix of the chat channel.
* @return String
*/
public String getPrefix() {
return prefix;
}
/**
* Check if the chat channel is BungeeCord enabled.
*
* @return {@link Boolean#TRUE} if the chat channel is BungeeCord enabled,
* {@link Boolean#FALSE} otherwise.
*/
public Boolean getBungee() {
return Boolean.valueOf(bungee);
}
/**
* Get the permissions node for the chat channel.
*
* @return {@link String}
*/
public String getPermission() {
return permission;
}
/**
* Check if autojoin is enabled for the chat channel.
*
* @return {@link Boolean#TRUE} if autojoin is enabled, {@link Boolean#FALSE}
* otherwise.
*/
public Boolean getAutojoin() {
return Boolean.valueOf(autojoin);
}
/**
* Check if the chat channel allows muting.
*
* @return {@link Boolean#TRUE} if muting is allowed, {@link Boolean#FALSE}
* otherwise.
*/
public Boolean isMutable() {
return Boolean.valueOf(mutable);
}
/**
* Get the formatted color of the chat channel.
*
* @return {@link String}. Returns {@link FormatService#DEFAULT_COLOR_CODE} if the
* color is invalid.
*/
public String getColor() {
if (FormatUtils.isValidColor(color)) {
return String.valueOf(ChatColor.valueOf(color.toUpperCase()));
}
if (FormatUtils.isValidHexColor(color)) {
return FormatUtils.convertHexColorCodeToBukkitColorCode(color);
}
return FormatUtils.DEFAULT_COLOR_CODE;
}
/**
* Get the raw color value of the chat channel.
*
* @return {@link String}
*/
public String getColorRaw() {
return color;
}
/**
* Get the formatted chat color of the chat channel.
*
* @return {@link String}. Returns {@link FormatService#DEFAULT_COLOR_CODE} if the chat
* color is invalid.
*/
public String getChatColor() {
if (chatColor.equalsIgnoreCase("None")) {
return chatColor;
}
if (FormatUtils.isValidColor(chatColor)) {
return String.valueOf(ChatColor.valueOf(chatColor.toUpperCase()));
}
if (FormatUtils.isValidHexColor(chatColor)) {
return FormatUtils.convertHexColorCodeToBukkitColorCode(chatColor);
}
return FormatUtils.DEFAULT_COLOR_CODE;
}
/**
* Get the raw chat color value of the chat channel.
*
* @return {@link String}
*/
public String getChatColorRaw() {
return chatColor;
}
/**
* Check if the chat channel is the default chat channel.
*
* @return {@link Boolean#TRUE} if the chat channel is the default chat channel,
* {@link Boolean#FALSE} otherwise.
*/
public Boolean isDefaultchannel() {
return Boolean.valueOf(defaultChannel);
}
/**
* Get the alias of the chat channel.
*
* @return {@link String}
*/
public String getAlias() {
return alias;
}
/**
* Get the distance of the chat channel in blocks.
*
* @return {@link Double}
*/
public Double getDistance() {
return Double.valueOf(distance);
}
/**
* Checks if the chat channel has a distance set.
*
* @return {@link Boolean#TRUE} if the distance is greater than zero,
* {@link Boolean#FALSE} otherwise.
*/
public Boolean hasDistance() {
return Boolean.valueOf(distance > 0);
}
/**
* Checks if the chat channel has a cooldown set.
*
* @return {@link Boolean#TRUE} if the cooldown is greater than zero,
* {@link Boolean#FALSE} otherwise.
*/
public Boolean hasCooldown() {
return Boolean.valueOf(cooldown > 0);
}
/**
* Checks if the chat channel has a permission set.
*
* @return {@link Boolean#TRUE} if the permission does not equal
* {@link ChatChannel#NO_PERMISSIONS}, {@link Boolean#FALSE} otherwise.
*/
public Boolean hasPermission() {
return Boolean.valueOf(!permission.equalsIgnoreCase(NO_PERMISSIONS));
}
/**
* Checks if the chat channel has a speak permission set.
*
* @return true if the speak permission does not equal
* {@link ChatChannel#NO_PERMISSIONS}, false otherwise.
*/
public boolean hasSpeakPermission() {
return !speakPermission.equalsIgnoreCase(NO_PERMISSIONS);
}
/**
* Get the speak permissions node for the chat channel.
*
* @return {@link String}
*/
public String getSpeakPermission() {
return speakPermission;
}
/**
* Checks if the chat channel has the filter enabled.
*
* @return {@link Boolean#TRUE} if the chat channel has the filter enabled,
* {@link Boolean#FALSE} otherwise.
*/
public Boolean isFiltered() {
return Boolean.valueOf(filter);
}
/**
* Compares the chat channel by name to determine equality.
*
* @param channel
* Object to compare for equality.
* @return true if the objects are equal, false otherwise.
*/
@Override
public boolean equals(Object channel) {
return channel instanceof ChatChannel && this.name.equals(((ChatChannel) channel).getName());
} }
} }

View File

@ -1,118 +1,34 @@
package venture.Aust1n46.chat.model; package venture.Aust1n46.chat.model;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import lombok.Builder;
import lombok.Builder.Default;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
@Getter
@Setter
@ToString
@Builder
public class SynchronizedVentureChatPlayer { public class SynchronizedVentureChatPlayer {
private UUID uuid; private UUID uuid;
private Set<String> listening; @Default
private HashMap<String, MuteContainer> mutes; private Set<String> listening = new HashSet<>();
private Set<UUID> ignores; @Default
private int messagePackets; private HashMap<String, MuteContainer> mutes = new HashMap<>();
private List<String> messageData = new ArrayList<String>(); @Default
private boolean spy; private Set<UUID> ignores = new HashSet<>();
private boolean messageToggle; @Default
private List<String> messageData = new ArrayList<>();
public SynchronizedVentureChatPlayer(UUID uuid, Set<String> listening, HashMap<String, MuteContainer> mutes, Set<UUID> ignores, boolean spy, boolean messageToggle) { @Default
this.uuid = uuid; private boolean messageToggleEnabled = true;
this.listening = listening; private boolean spy;
this.mutes = mutes; private int messagePackets;
this.ignores = ignores; }
this.spy = spy;
this.messageToggle = messageToggle;
}
public SynchronizedVentureChatPlayer(UUID uuid) {
this.uuid = uuid;
listening = new HashSet<String>();
mutes = new HashMap<String, MuteContainer>();
ignores = new HashSet<UUID>();
spy = false;
messageToggle = true;
}
public List<String> getMessageData() {
return this.messageData;
}
public void addData(String s) {
this.messageData.add(s);
}
public void clearMessageData() {
this.messageData.clear();
}
public int getMessagePackets() {
return this.messagePackets;
}
public void incrementMessagePackets() {
this.messagePackets++;
}
public void clearMessagePackets() {
this.messagePackets = 0;
}
public void addIgnore(SynchronizedVentureChatPlayer smcp) {
this.ignores.add(smcp.getUUID());
}
public void removeIgnore(SynchronizedVentureChatPlayer smcp) {
this.ignores.remove(smcp.getUUID());
}
public Set<UUID> getIgnores() {
return this.ignores;
}
public void addMute(String channel, long time, String reason) {
mutes.put(channel, new MuteContainer(channel, time, reason));
}
public void clearMutes() {
this.mutes.clear();
}
public Collection<MuteContainer> getMutes() {
return this.mutes.values();
}
public void addListening(String channel) {
this.listening.add(channel);
}
public void removeListening(String channel) {
this.listening.remove(channel);
}
public Set<String> getListening() {
return this.listening;
}
public UUID getUUID() {
return this.uuid;
}
public boolean isSpy() {
return this.spy;
}
public void setSpy(boolean spy) {
this.spy = spy;
}
public boolean getMessageToggle() {
return this.messageToggle;
}
public void setMessageToggle(boolean messageToggle) {
this.messageToggle = messageToggle;
}
}

View File

@ -6,31 +6,31 @@ import java.util.UUID;
import lombok.Getter; import lombok.Getter;
public class TemporaryDataInstance { public class TemporaryDataInstance {
private final UUID uuid;
@Getter @Getter
private int messagePackets; private int messagePackets;
private final UUID uuid;
private static final HashMap<UUID, TemporaryDataInstance> temporaryDataInstances = new HashMap<UUID, TemporaryDataInstance>(); private static final HashMap<UUID, TemporaryDataInstance> TEMPORARY_DATA_INSTANCES = new HashMap<>();
private TemporaryDataInstance(UUID uuid) { private TemporaryDataInstance(final UUID uuid) {
this.uuid = uuid; this.uuid = uuid;
} }
public static UUID createTemporaryDataInstance() { public static UUID createTemporaryDataInstance() {
UUID uuid = UUID.randomUUID(); final UUID uuid = UUID.randomUUID();
temporaryDataInstances.put(uuid, new TemporaryDataInstance(uuid)); TEMPORARY_DATA_INSTANCES.put(uuid, new TemporaryDataInstance(uuid));
return uuid; return uuid;
} }
public static TemporaryDataInstance getTemporaryDataInstance(UUID uuid) { public static TemporaryDataInstance getTemporaryDataInstance(final UUID uuid) {
return temporaryDataInstances.get(uuid); return TEMPORARY_DATA_INSTANCES.get(uuid);
} }
public void incrementMessagePackets() { public void incrementMessagePackets() {
this.messagePackets++; messagePackets++;
} }
public void destroyInstance() { public void destroyInstance() {
temporaryDataInstances.remove(uuid); TEMPORARY_DATA_INSTANCES.remove(uuid);
} }
} }

View File

@ -48,7 +48,7 @@ public class VentureChatPlayer {
private boolean editing; private boolean editing;
private int editHash; private int editHash;
@Default @Default
private boolean filter = true; private boolean filterEnabled = true;
@Default @Default
private boolean notifications = true; private boolean notifications = true;
@Default @Default

View File

@ -52,7 +52,7 @@ public class VentureChatPlaceholders extends PlaceholderExpansion {
case "channel_chatcolor": case "channel_chatcolor":
return currentChannel.getChatColor(); return currentChannel.getChatColor();
case "channel_is_bungee": case "channel_is_bungee":
return currentChannel.getBungee() ? PlaceholderAPIPlugin.booleanTrue() : PlaceholderAPIPlugin.booleanFalse(); return currentChannel.isBungeeEnabled() ? PlaceholderAPIPlugin.booleanTrue() : PlaceholderAPIPlugin.booleanFalse();
case "channel_cooldown": case "channel_cooldown":
return currentChannel.getCooldown() + ""; return currentChannel.getCooldown() + "";
case "channel_distance": case "channel_distance":

View File

@ -6,6 +6,7 @@ import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import com.google.inject.Inject; import com.google.inject.Inject;
@ -25,6 +26,8 @@ import venture.Aust1n46.chat.utilities.FormatUtils;
@Singleton @Singleton
public class ConfigService { public class ConfigService {
private static final String PERMISSION_PREFIX = "venturechat.";
@Inject @Inject
private VentureChat plugin; private VentureChat plugin;
@ -35,31 +38,45 @@ public class ConfigService {
private boolean aliasesRegisteredAsCommands; private boolean aliasesRegisteredAsCommands;
private ChatChannel defaultChatChannel; private ChatChannel defaultChatChannel;
private String defaultColor; private String defaultColor;
@Getter
private boolean ignoreChatEnabled;
@Getter @Getter
private List<Filter> filters; private List<Filter> filters;
public String getValidColor(final String colorRaw) {
if (FormatUtils.isValidColor(colorRaw)) {
return String.valueOf(ChatColor.valueOf(colorRaw.toUpperCase()));
}
if (FormatUtils.isValidHexColor(colorRaw)) {
return FormatUtils.convertHexColorCodeToBukkitColorCode(colorRaw);
}
return FormatUtils.DEFAULT_COLOR_CODE;
}
@Inject @Inject
public void postConstruct() { public void postConstruct() {
aliasesRegisteredAsCommands = true; aliasesRegisteredAsCommands = true;
ConfigurationSection cs = plugin.getConfig().getConfigurationSection("channels"); ConfigurationSection cs = plugin.getConfig().getConfigurationSection("channels");
for (String key : cs.getKeys(false)) { for (final String key : cs.getKeys(false)) {
String color = cs.getString(key + ".color", "white"); final String colorRaw = cs.getString(key + ".color", "white");
String chatColor = cs.getString(key + ".chatcolor", "white"); final String chatColorRaw = cs.getString(key + ".chatcolor", "white");
String name = key; final String name = key;
String permission = cs.getString(key + ".permissions", "None"); final String permission = PERMISSION_PREFIX + cs.getString(key + ".permissions", "None");
String speakPermission = cs.getString(key + ".speak_permissions", "None"); final String speakPermission = PERMISSION_PREFIX + cs.getString(key + ".speak_permissions", "None");
boolean mutable = cs.getBoolean(key + ".mutable", false); final boolean mutable = cs.getBoolean(key + ".mutable", false);
boolean filter = cs.getBoolean(key + ".filter", true); final boolean filter = cs.getBoolean(key + ".filter", true);
boolean bungee = cs.getBoolean(key + ".bungeecord", false); final boolean bungee = cs.getBoolean(key + ".bungeecord", false);
String format = cs.getString(key + ".format", "Default"); final String format = cs.getString(key + ".format", "Default");
boolean defaultChannel = cs.getBoolean(key + ".default", false); final boolean defaultChannel = cs.getBoolean(key + ".default", false);
String alias = cs.getString(key + ".alias", "None"); final String alias = cs.getString(key + ".alias", "None");
double distance = cs.getDouble(key + ".distance", (double) 0); final double distance = cs.getDouble(key + ".distance", (double) 0);
int cooldown = cs.getInt(key + ".cooldown", 0); final int cooldown = cs.getInt(key + ".cooldown", 0);
boolean autojoin = cs.getBoolean(key + ".autojoin", false); final boolean autojoin = cs.getBoolean(key + ".autojoin", false);
String prefix = cs.getString(key + ".channel_prefix"); final String prefix = cs.getString(key + ".channel_prefix");
ChatChannel chatChannel = new ChatChannel(name, color, chatColor, permission, speakPermission, mutable, filter, defaultChannel, alias, distance, autojoin, bungee, final String color = getValidColor(colorRaw);
final String chatColor = chatColorRaw.equalsIgnoreCase("None") ? "None" : getValidColor(chatColorRaw);
final ChatChannel chatChannel = new ChatChannel(name, color, colorRaw, chatColor, chatColorRaw, permission, speakPermission, mutable, filter, defaultChannel, alias, distance, autojoin, bungee,
cooldown, prefix, format); cooldown, prefix, format);
chatChannels.put(name.toLowerCase(), chatChannel); chatChannels.put(name.toLowerCase(), chatChannel);
chatChannels.put(alias.toLowerCase(), chatChannel); chatChannels.put(alias.toLowerCase(), chatChannel);
@ -71,7 +88,7 @@ public class ConfigService {
// Error handling for missing default channel in the config. // Error handling for missing default channel in the config.
if (defaultChatChannel == null) { if (defaultChatChannel == null) {
plugin.getServer().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]", defaultChatChannel = new ChatChannel("MissingDefault", "red", "RED", "red", "RED", ChatChannel.NO_PERMISSIONS, ChatChannel.NO_PERMISSIONS, false, true, true, "md", 0, true, false, 0, "&f[&cMissingDefault&f]",
"{venturechat_channel_prefix} {vault_prefix}{player_displayname}&c:"); "{venturechat_channel_prefix} {vault_prefix}{player_displayname}&c:");
defaultColor = defaultChatChannel.getColor(); defaultColor = defaultChatChannel.getColor();
chatChannels.put("missingdefault", defaultChatChannel); chatChannels.put("missingdefault", defaultChatChannel);
@ -124,6 +141,8 @@ public class ConfigService {
.map(x -> x.split(",")) .map(x -> x.split(","))
.map(x -> new Filter(x[0], x[1])) .map(x -> new Filter(x[0], x[1]))
.toList(); .toList();
ignoreChatEnabled = plugin.getConfig().getBoolean("ignorechat", false);
} }
public boolean areAliasesRegisteredAsCommands() { public boolean areAliasesRegisteredAsCommands() {
@ -164,9 +183,9 @@ public class ConfigService {
if (ventureChatPlayer.isOnline()) { if (ventureChatPlayer.isOnline()) {
if (isChannel(channel)) { if (isChannel(channel)) {
ChatChannel chatChannel = getChannel(channel); ChatChannel chatChannel = getChannel(channel);
if (chatChannel.hasPermission()) { if (chatChannel.isPermissionRequired()) {
if (!ventureChatPlayer.getPlayer().hasPermission(chatChannel.getPermission())) { if (!ventureChatPlayer.getPlayer().hasPermission(chatChannel.getPermission())) {
if (ventureChatPlayer.getCurrentChannel().equals(chatChannel)) { if (ventureChatPlayer.getCurrentChannel().getName().equals(channel)) {
ventureChatPlayer.setCurrentChannel(getDefaultChannel()); ventureChatPlayer.setCurrentChannel(getDefaultChannel());
} }
ventureChatPlayer.getListening().remove(channel); ventureChatPlayer.getListening().remove(channel);
@ -237,7 +256,7 @@ public class ConfigService {
public List<ChatChannel> getAutojoinList() { public List<ChatChannel> getAutojoinList() {
List<ChatChannel> joinlist = new ArrayList<ChatChannel>(); List<ChatChannel> joinlist = new ArrayList<ChatChannel>();
for (ChatChannel c : chatChannels.values()) { for (ChatChannel c : chatChannels.values()) {
if (c.getAutojoin()) { if (c.isAutoJoinEnabled()) {
joinlist.add(c); joinlist.add(c);
} }
} }

View File

@ -9,6 +9,7 @@ import static venture.Aust1n46.chat.utilities.FormatUtils.HEX_COLOR_CODE_PREFIX;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -437,7 +438,7 @@ public class FormatService {
return s.replace("\\", "\\\\").replace("\"", "\\\""); return s.replace("\\", "\\\\").replace("\"", "\\\"");
} }
public String formatModerationGUI(String json, Player player, String sender, String channelName, int hash) { private String formatModerationGUI(String json, Player player, String sender, String channelName, int hash) {
if (player.hasPermission("venturechat.gui")) { if (player.hasPermission("venturechat.gui")) {
json = json.substring(0, json.length() - 1); json = json.substring(0, json.length() - 1);
json += "," + convertToJsonColors(FormatUtils.FormatStringAll(plugin.getConfig().getString("guiicon")), json += "," + convertToJsonColors(FormatUtils.FormatStringAll(plugin.getConfig().getString("guiicon")),
@ -502,6 +503,27 @@ public class FormatService {
} }
} }
public void createAndSendChatMessage(final String json, final String channelName, final int hash, final Set<Player> recipients, final String sender) {
for (final Player player : recipients) {
final String finalJson = formatModerationGUI(json, player, sender, channelName, hash);
final PacketContainer packet = createPacketPlayOutChat(finalJson);
sendPacketPlayOutChat(player, packet);
}
}
public void createAndSendExternalChatMessage(final String message, final String channelName, final String sender) {
final String json = convertPlainTextToJson(message, true);
final int hash = FormatUtils.stripColor(message).hashCode();
playerApiService.getOnlineMineverseChatPlayers()
.stream()
.filter(vcp -> configService.isListening(vcp, channelName))
.forEach(vcp -> {
final String finalJSON = formatModerationGUI(json, vcp.getPlayer(), sender, channelName, hash);
final PacketContainer packet = createPacketPlayOutChat(finalJSON);
sendPacketPlayOutChat(vcp.getPlayer(), packet);
});
}
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public String toColoredText(Object o, Class<?> c) { public String toColoredText(Object o, Class<?> c) {
if (versionService.is1_7()) { if (versionService.is1_7()) {

View File

@ -13,7 +13,7 @@ public class ProxyPlayerApiService {
private final HashMap<UUID, SynchronizedVentureChatPlayer> proxyPlayerMap = new HashMap<>(); private final HashMap<UUID, SynchronizedVentureChatPlayer> proxyPlayerMap = new HashMap<>();
public void addSynchronizedMineverseChatPlayerToMap(SynchronizedVentureChatPlayer smcp) { public void addSynchronizedMineverseChatPlayerToMap(SynchronizedVentureChatPlayer smcp) {
proxyPlayerMap.put(smcp.getUUID(), smcp); proxyPlayerMap.put(smcp.getUuid(), smcp);
} }
public void clearProxyPlayerMap() { public void clearProxyPlayerMap() {