diff --git a/pom.xml b/pom.xml index eaf83ef..bfa922d 100644 --- a/pom.xml +++ b/pom.xml @@ -168,7 +168,7 @@ com.comphenix.protocol ProtocolLib - 4.6.0 + 5.0.0-SNAPSHOT @@ -225,21 +225,21 @@ net.md-5 bungeecord-api - 1.13-SNAPSHOT + 1.20-R0.1-SNAPSHOT jar compile net.md-5 bungeecord-api - 1.13-SNAPSHOT + 1.20-R0.1-SNAPSHOT javadoc provided org.spigotmc spigot-api - 1.13-R0.1-SNAPSHOT + 1.20-R0.1-SNAPSHOT provided diff --git a/src/main/java/venture/Aust1n46/chat/controllers/PluginMessageController.java b/src/main/java/venture/Aust1n46/chat/controllers/PluginMessageController.java index d6b80b2..25f1ddb 100644 --- a/src/main/java/venture/Aust1n46/chat/controllers/PluginMessageController.java +++ b/src/main/java/venture/Aust1n46/chat/controllers/PluginMessageController.java @@ -396,6 +396,15 @@ public class PluginMessageController { sendPluginMessage(stream); return; } + if (p.getPlayer().hasPermission("venturechat.ignore.bypass")) { + out.writeUTF("Ignore"); + out.writeUTF("Bypass"); + out.writeUTF(server); + out.writeUTF(receiver); + out.writeUTF(sender.toString()); + sendPluginMessage(stream); + return; + } out.writeUTF("Ignore"); out.writeUTF("Echo"); out.writeUTF(server); @@ -428,6 +437,12 @@ public class PluginMessageController { p.getPlayer().sendMessage(LocalizedMessage.IGNORE_PLAYER_ON.toString().replace("{player}", receiverName)); synchronize(p, true); } + if (identifier.equals("Bypass")) { + String receiver = msgin.readUTF(); + UUID sender = UUID.fromString(msgin.readUTF()); + VentureChatPlayer p = playerApiService.getOnlineMineverseChatPlayer(sender); + p.getPlayer().sendMessage(LocalizedMessage.IGNORE_PLAYER_CANT.toString().replace("{player}", receiver)); + } } if (subchannel.equals("Mute")) { String identifier = msgin.readUTF(); diff --git a/src/main/java/venture/Aust1n46/chat/controllers/proxy/VentureChatProxyController.java b/src/main/java/venture/Aust1n46/chat/controllers/proxy/VentureChatProxyController.java index 5d78d48..c19ec08 100644 --- a/src/main/java/venture/Aust1n46/chat/controllers/proxy/VentureChatProxyController.java +++ b/src/main/java/venture/Aust1n46/chat/controllers/proxy/VentureChatProxyController.java @@ -212,6 +212,18 @@ public class VentureChatProxyController { source.sendPluginMessage(server, outstream.toByteArray()); } } + if (identifier.equals("Bypass")) { + String server = in.readUTF(); + String player = in.readUTF(); + String sender = in.readUTF(); + out.writeUTF("Ignore"); + out.writeUTF("Bypass"); + out.writeUTF(player); + out.writeUTF(sender); + if(!source.getServer(server).isEmpty()) { + source.sendPluginMessage(server, outstream.toByteArray()); + } + } } if(subchannel.equals("Mute")) { String identifier = in.readUTF(); diff --git a/src/main/java/venture/Aust1n46/chat/initiators/application/VentureChat.java b/src/main/java/venture/Aust1n46/chat/initiators/application/VentureChat.java index a20aeca..3459b46 100644 --- a/src/main/java/venture/Aust1n46/chat/initiators/application/VentureChat.java +++ b/src/main/java/venture/Aust1n46/chat/initiators/application/VentureChat.java @@ -22,7 +22,7 @@ import venture.Aust1n46.chat.controllers.VentureChatSpigotFlatFileController; import venture.Aust1n46.chat.guice.VentureChatPluginModule; import venture.Aust1n46.chat.initiators.listeners.ChatListener; import venture.Aust1n46.chat.initiators.listeners.LoginListener; -import venture.Aust1n46.chat.initiators.listeners.PacketListener; +import venture.Aust1n46.chat.initiators.listeners.PacketListenerLegacyChat; import venture.Aust1n46.chat.initiators.listeners.PreProcessCommandListener; import venture.Aust1n46.chat.initiators.listeners.SignListener; import venture.Aust1n46.chat.initiators.schedulers.UnmuteScheduler; @@ -30,6 +30,7 @@ import venture.Aust1n46.chat.localization.Localization; import venture.Aust1n46.chat.placeholderapi.VentureChatPlaceholders; import venture.Aust1n46.chat.service.VentureChatPlayerApiService; import venture.Aust1n46.chat.utilities.FormatUtils; +import venture.Aust1n46.chat.xcut.VersionService; /** * VentureChat Minecraft plugin for servers running Spigot or Paper software. @@ -47,7 +48,7 @@ public class VentureChat extends JavaPlugin implements PluginMessageListener { @Inject private PreProcessCommandListener commandListener; @Inject - private PacketListener packetListener; + private PacketListenerLegacyChat packetListener; @Inject private VentureChatPlaceholders ventureChatPlaceholders; @Inject @@ -56,6 +57,8 @@ public class VentureChat extends JavaPlugin implements PluginMessageListener { private VentureChatPlayerApiService playerApiService; @Inject private PluginMessageController pluginMessageController; + @Inject + private VersionService versionService; private Permission permission = null; @@ -157,7 +160,9 @@ public class VentureChat extends JavaPlugin implements PluginMessageListener { pluginManager.registerEvents(signListener, this); pluginManager.registerEvents(commandListener, this); pluginManager.registerEvents(loginListener, this); - ProtocolLibrary.getProtocolManager().addPacketListener(packetListener); + if (versionService.isUnder_1_19()) { + ProtocolLibrary.getProtocolManager().addPacketListener(packetListener); + } } private boolean setupPermissions() { diff --git a/src/main/java/venture/Aust1n46/chat/initiators/listeners/PacketListener.java b/src/main/java/venture/Aust1n46/chat/initiators/listeners/PacketListenerLegacyChat.java similarity index 93% rename from src/main/java/venture/Aust1n46/chat/initiators/listeners/PacketListener.java rename to src/main/java/venture/Aust1n46/chat/initiators/listeners/PacketListenerLegacyChat.java index 5fc6a28..56efb77 100644 --- a/src/main/java/venture/Aust1n46/chat/initiators/listeners/PacketListener.java +++ b/src/main/java/venture/Aust1n46/chat/initiators/listeners/PacketListenerLegacyChat.java @@ -17,7 +17,7 @@ import venture.Aust1n46.chat.service.VentureChatPlayerApiService; import venture.Aust1n46.chat.xcut.VersionService; @Singleton -public class PacketListener extends PacketAdapter { +public class PacketListenerLegacyChat extends PacketAdapter { @Inject private VentureChatFormatService formatter; @Inject @@ -26,13 +26,13 @@ public class PacketListener extends PacketAdapter { private VersionService versionService; @Inject - public PacketListener(final VentureChat plugin) { + public PacketListenerLegacyChat(final VentureChat plugin) { super(plugin, ListenerPriority.MONITOR, new PacketType[] { PacketType.Play.Server.CHAT }); } @Override public void onPacketSending(PacketEvent event) { - if (event.isCancelled() || event.getPacketType() != PacketType.Play.Server.CHAT) { + if (event.isCancelled()) { return; } diff --git a/src/main/java/venture/Aust1n46/chat/model/ClickAction.java b/src/main/java/venture/Aust1n46/chat/model/ClickAction.java new file mode 100644 index 0000000..6fe74a6 --- /dev/null +++ b/src/main/java/venture/Aust1n46/chat/model/ClickAction.java @@ -0,0 +1,16 @@ +package venture.Aust1n46.chat.model; + +public enum ClickAction { + SUGGEST_COMMAND, RUN_COMMAND, OPEN_URL, NONE; + + private final String jsonValue; + + ClickAction() { + jsonValue = name().toLowerCase(); + } + + @Override + public String toString() { + return jsonValue; + } +} diff --git a/src/main/java/venture/Aust1n46/chat/model/JsonAttribute.java b/src/main/java/venture/Aust1n46/chat/model/JsonAttribute.java index 447c779..b115d05 100644 --- a/src/main/java/venture/Aust1n46/chat/model/JsonAttribute.java +++ b/src/main/java/venture/Aust1n46/chat/model/JsonAttribute.java @@ -8,10 +8,10 @@ import lombok.Getter; public class JsonAttribute { private String name; private List hoverText; - private String clickAction; + private ClickAction clickAction; private String clickText; - public JsonAttribute(String name, List hoverText, String clickAction, String clickText) { + public JsonAttribute(String name, List hoverText, ClickAction clickAction, String clickText) { this.name = name; this.hoverText = hoverText; this.clickAction = clickAction; diff --git a/src/main/java/venture/Aust1n46/chat/service/ConfigService.java b/src/main/java/venture/Aust1n46/chat/service/ConfigService.java index db64598..84b6126 100644 --- a/src/main/java/venture/Aust1n46/chat/service/ConfigService.java +++ b/src/main/java/venture/Aust1n46/chat/service/ConfigService.java @@ -14,6 +14,7 @@ import com.google.inject.Singleton; import venture.Aust1n46.chat.initiators.application.VentureChat; import venture.Aust1n46.chat.model.Alias; import venture.Aust1n46.chat.model.ChatChannel; +import venture.Aust1n46.chat.model.ClickAction; import venture.Aust1n46.chat.model.GuiSlot; import venture.Aust1n46.chat.model.JsonAttribute; import venture.Aust1n46.chat.model.JsonFormat; @@ -81,8 +82,9 @@ public class ConfigService { if (jsonAttributeSection != null) { for (String attribute : jsonAttributeSection.getKeys(false)) { List hoverText = jsonAttributeSection.getStringList(attribute + ".hover_text"); - String clickAction = jsonAttributeSection.getString(attribute + ".click_action", ""); String clickText = jsonAttributeSection.getString(attribute + ".click_text", ""); + String clickActionText = jsonAttributeSection.getString(attribute + ".click_action", "none"); + ClickAction clickAction = ClickAction.valueOf(clickActionText.toUpperCase()); jsonAttributes.add(new JsonAttribute(attribute, hoverText, clickAction, clickText)); } } @@ -215,8 +217,11 @@ public class ConfigService { public boolean isProxyEnabled() { try { - return plugin.getServer().spigot().getConfig().getBoolean("settings.bungeecord") - || plugin.getServer().spigot().getPaperConfig().getBoolean("settings.velocity-support.enabled"); +// return plugin.getServer().spigot().getConfig().getBoolean("settings.bungeecord") +// || plugin.getServer().spigot().getPaperConfig().getBoolean("settings.velocity-support.enabled"); + return (plugin.getServer().spigot().getConfig().getBoolean("settings.bungeecord") + || plugin.getServer().spigot().getPaperConfig().getBoolean("settings.velocity-support.enabled") + || plugin.getServer().spigot().getPaperConfig().getBoolean("proxies.velocity.enabled")); } catch (NoSuchMethodError exception) { // Thrown if server isn't Paper. return false; } diff --git a/src/main/java/venture/Aust1n46/chat/service/VentureChatFormatService.java b/src/main/java/venture/Aust1n46/chat/service/VentureChatFormatService.java index 5ecddbd..9b008ab 100644 --- a/src/main/java/venture/Aust1n46/chat/service/VentureChatFormatService.java +++ b/src/main/java/venture/Aust1n46/chat/service/VentureChatFormatService.java @@ -14,6 +14,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; +import org.apache.commons.lang.StringUtils; import org.bukkit.ChatColor; import org.bukkit.Sound; import org.bukkit.entity.Player; @@ -28,6 +29,7 @@ import com.google.inject.Singleton; import me.clip.placeholderapi.PlaceholderAPI; import venture.Aust1n46.chat.initiators.application.VentureChat; +import venture.Aust1n46.chat.model.ClickAction; import venture.Aust1n46.chat.model.JsonAttribute; import venture.Aust1n46.chat.model.JsonFormat; import venture.Aust1n46.chat.model.VentureChatPlayer; @@ -65,10 +67,10 @@ public class VentureChatFormatService { */ public String convertToJson(VentureChatPlayer sender, String format, String chat) { JsonFormat JSONformat = configService.getJsonFormat(sender.getJsonFormat()); - String f = escapeJsonChars(format); +// String f = escapeJsonChars(format); String c = escapeJsonChars(chat); String json = "[\"\",{\"text\":\"\",\"extra\":["; - json += convertPlaceholders(f, JSONformat, sender); + json += convertPlaceholders(format, JSONformat, sender); json += "]}"; json += "," + convertLinks(c); json += "]"; @@ -108,26 +110,59 @@ public class VentureChatFormatService { indexStart = matcher.start(); indexEnd = matcher.end(); placeholder = remaining.substring(indexStart, indexEnd); - formattedPlaceholder = FormatUtils.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(icp.getPlayer(), placeholder)); - temp += convertToJsonColors(lastCode + remaining.substring(0, indexStart)) + ","; + formattedPlaceholder = escapeJsonChars(FormatUtils.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(icp.getPlayer(), placeholder))); + temp += convertToJsonColors(escapeJsonChars(lastCode + remaining.substring(0, indexStart))) + ","; lastCode = getLastCode(lastCode + remaining.substring(0, indexStart)); - String action = ""; - String text = ""; - String hover = ""; +// String action = ""; +// String text = ""; +// String hover = ""; + boolean placeholderHasJsonAttribute = false; for (JsonAttribute jsonAttribute : format.getJsonAttributes()) { if (placeholder.contains(jsonAttribute.getName().replace("{", "").replace("}", ""))) { - action = jsonAttribute.getClickAction(); - text = FormatUtils.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(icp.getPlayer(), jsonAttribute.getClickText())); +// action = jsonAttribute.getClickAction(); +// text = FormatUtils.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(icp.getPlayer(), jsonAttribute.getClickText())); + final StringBuilder hover = new StringBuilder(); for (String st : jsonAttribute.getHoverText()) { - hover += FormatUtils.FormatStringAll(st) + "\n"; +// hover += FormatUtils.FormatStringAll(st) + "\n"; + hover.append(FormatUtils.FormatStringAll(st) + "\n"); } + final String hoverText; + if(!hover.isEmpty()) { + hoverText = escapeJsonChars(FormatUtils.FormatStringAll( + PlaceholderAPI.setBracketPlaceholders(icp.getPlayer(), hover.substring(0, hover.length() - 1)))); + } else { + hoverText = StringUtils.EMPTY; + } + final ClickAction clickAction = jsonAttribute.getClickAction(); + final String actionJson; + if (clickAction == ClickAction.NONE) { + actionJson = StringUtils.EMPTY; + } else { + final String clickText = escapeJsonChars(FormatUtils.FormatStringAll( + PlaceholderAPI.setBracketPlaceholders(icp.getPlayer(), jsonAttribute.getClickText()))); + actionJson = ",\"clickEvent\":{\"action\":\"" + jsonAttribute.getClickAction().toString() + "\",\"value\":\"" + clickText + + "\"}"; + } + final String hoverJson; + if (hoverText.isEmpty()) { + hoverJson = StringUtils.EMPTY; + } else { + hoverJson = ",\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[" + + convertToJsonColors(hoverText) + "]}}"; + } + temp += convertToJsonColors(lastCode + formattedPlaceholder, actionJson + hoverJson) + ","; + placeholderHasJsonAttribute = true; + break; } } - if (!hover.isEmpty()) { - hover = FormatUtils.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(icp.getPlayer(), hover.substring(0, hover.length() - 1))); +// if (!hover.isEmpty()) { +// hover = FormatUtils.FormatStringAll(PlaceholderAPI.setBracketPlaceholders(icp.getPlayer(), hover.substring(0, hover.length() - 1))); +// } + if (!placeholderHasJsonAttribute) { + temp += convertToJsonColors(lastCode + formattedPlaceholder) + ","; } - temp += convertToJsonColors(lastCode + formattedPlaceholder, ",\"clickEvent\":{\"action\":\"" + action + "\",\"value\":\"" + text - + "\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[" + convertToJsonColors(hover) + "]}}") + ","; +// temp += convertToJsonColors(lastCode + formattedPlaceholder, ",\"clickEvent\":{\"action\":\"" + action + "\",\"value\":\"" + text +// + "\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[" + convertToJsonColors(hover) + "]}}") + ","; lastCode = getLastCode(lastCode + formattedPlaceholder); remaining = remaining.substring(indexEnd); } else { @@ -165,7 +200,7 @@ public class VentureChatFormatService { if (ChatColor.stripColor(link).contains("https://")) https = "s"; temp += convertToJsonColors(lastCode + link, - ",\"underlined\":\"" + underlineURLs() + "\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"http" + https + "://" + ",\"underlined\":" + underlineURLs() + ",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"http" + https + "://" + ChatColor.stripColor(link.replace("http://", "").replace("https://", "")) + "\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[" + convertToJsonColors(lastCode + link) + "]}}") + ","; @@ -307,15 +342,35 @@ public class VentureChatFormatService { underlined = false; } if (bold) - modifier += ",\"bold\":\"true\""; + if (versionService.isAtLeast_1_20_4()) { + modifier += ",\"bold\":true"; + } else { + modifier += ",\"bold\":\"true\""; + } if (obfuscated) - modifier += ",\"obfuscated\":\"true\""; + if (versionService.isAtLeast_1_20_4()) { + modifier += ",\"obfuscated\":true"; + } else { + modifier += ",\"obfuscated\":\"true\""; + } if (italic) - modifier += ",\"italic\":\"true\""; + if (versionService.isAtLeast_1_20_4()) { + modifier += ",\"italic\":true"; + } else { + modifier += ",\"italic\":\"true\""; + } if (underlined) - modifier += ",\"underlined\":\"true\""; + if (versionService.isAtLeast_1_20_4()) { + modifier += ",\"underlined\":true"; + } else { + modifier += ",\"underlined\":\"true\""; + } if (strikethrough) - modifier += ",\"strikethrough\":\"true\""; + if (versionService.isAtLeast_1_20_4()) { + modifier += ",\"strikethrough\":true"; + } else { + modifier += ",\"strikethrough\":\"true\""; + } remaining = remaining.substring(colorLength); colorLength = LEGACY_COLOR_CODE_LENGTH; indexNextColor = remaining.indexOf(BUKKIT_COLOR_CODE_PREFIX); @@ -407,17 +462,47 @@ public class VentureChatFormatService { } public PacketContainer createPacketPlayOutChat(String json) { - WrappedChatComponent component = WrappedChatComponent.fromJson(json); - PacketContainer container = new PacketContainer(PacketType.Play.Server.CHAT); - container.getModifier().writeDefaults(); - container.getChatComponents().write(0, component); + final PacketContainer container; + if (versionService.isAtLeast_1_20_4()) { // 1.20.4+ + container = new PacketContainer(PacketType.Play.Server.SYSTEM_CHAT); + container.getChatComponents().write(0, WrappedChatComponent.fromJson(json)); + container.getBooleans().write(0, false); + } else if (versionService.isAbove_1_19()) { // 1.19.1 -> 1.20.3 + container = new PacketContainer(PacketType.Play.Server.SYSTEM_CHAT); + container.getStrings().write(0, json); + container.getBooleans().write(0, false); + } else if (versionService.isUnder_1_19()) { // 1.7 -> 1.19 + WrappedChatComponent component = WrappedChatComponent.fromJson(json); + container = new PacketContainer(PacketType.Play.Server.CHAT); + container.getModifier().writeDefaults(); + container.getChatComponents().write(0, component); + } else { // 1.19 + container = new PacketContainer(PacketType.Play.Server.SYSTEM_CHAT); + container.getStrings().write(0, json); + container.getIntegers().write(0, 1); + } return container; } public PacketContainer createPacketPlayOutChat(WrappedChatComponent component) { - PacketContainer container = new PacketContainer(PacketType.Play.Server.CHAT); - container.getModifier().writeDefaults(); - container.getChatComponents().write(0, component); + final PacketContainer container; + if (versionService.isAtLeast_1_20_4()) { // 1.20.4+ + container = new PacketContainer(PacketType.Play.Server.SYSTEM_CHAT); + container.getChatComponents().write(0, component); + container.getBooleans().write(0, false); + } else if (versionService.isAbove_1_19()) { // 1.19.1 -> 1.20.3 + container = new PacketContainer(PacketType.Play.Server.SYSTEM_CHAT); + container.getStrings().write(0, component.getJson()); + container.getBooleans().write(0, false); + } else if (versionService.isUnder_1_19()) { // 1.7 -> 1.19 + container = new PacketContainer(PacketType.Play.Server.CHAT); + container.getModifier().writeDefaults(); + container.getChatComponents().write(0, component); + } else { // 1.19 + container = new PacketContainer(PacketType.Play.Server.SYSTEM_CHAT); + container.getStrings().write(0, component.getJson()); + container.getIntegers().write(0, 1); + } return container; } @@ -578,8 +663,13 @@ public class VentureChatFormatService { return msg; } - public boolean underlineURLs() { - return plugin.getConfig().getBoolean("underlineurls", true); + public String underlineURLs() { + final boolean configValue = plugin.getConfig().getBoolean("underlineurls", true); + if (versionService.isAtLeast_1_20_4()) { + return String.valueOf(configValue); + } else { + return "\"" + configValue + "\""; + } } public void broadcastToServer(String message) { diff --git a/src/main/java/venture/Aust1n46/chat/xcut/VersionService.java b/src/main/java/venture/Aust1n46/chat/xcut/VersionService.java index 95a5ae9..75e99c9 100644 --- a/src/main/java/venture/Aust1n46/chat/xcut/VersionService.java +++ b/src/main/java/venture/Aust1n46/chat/xcut/VersionService.java @@ -6,6 +6,9 @@ import com.google.inject.Singleton; @Singleton public final class VersionService { public static final MinecraftVersion SERVER_VERSION = MinecraftVersion.getCurrentVersion(); + private static final MinecraftVersion MC1_19 = new MinecraftVersion(1, 19, 0); + private static final MinecraftVersion MC1_19_1 = new MinecraftVersion(1, 19, 1); + private static final MinecraftVersion MC1_20_4 = new MinecraftVersion(1, 20, 4); private VersionService() { } @@ -67,22 +70,14 @@ public final class VersionService { } public boolean isUnder_1_19() { - if (SERVER_VERSION.getMajor() < 1) { - return true; - } - return SERVER_VERSION.getMajor() == 1 && SERVER_VERSION.getMinor() < 19; + return !SERVER_VERSION.isAtLeast(MC1_19); } public boolean isAbove_1_19() { - if (SERVER_VERSION.getMajor() < 1) { - return false; - } - if (SERVER_VERSION.getMajor() > 1) { - return true; - } - if (SERVER_VERSION.getMinor() > 19) { - return true; - } - return SERVER_VERSION.getMinor() == 19 && SERVER_VERSION.getBuild() > 0; + return SERVER_VERSION.isAtLeast(MC1_19_1); + } + + public boolean isAtLeast_1_20_4() { + return SERVER_VERSION.isAtLeast(MC1_20_4); } } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 1974c4a..a53e57a 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -136,7 +136,7 @@ messageremovertext: '&c&o' # The name of the group is the permissions node for the format # Example: venturechat.json.Owner is the node for the group Owner # A lower priority overrides a higher priority if a player has more than 1 group -# Possible options for click_name and click_prefix are suggest_command, run_command, and open_url +# Possible options for click_action are suggest_command, run_command, open_url, and none jsonformatting: Default: # This default format is required! Do not delete or rename it! priority: 2147483647 # Integer.MAX_VALUE