7 Commits

Author SHA1 Message Date
Aust1n46
b9e19e2441 Update for 1.21.8 (#149)
* implement json format changes for 1.21.5

update deps, update message sound and safety wrap it

* imports
2025-08-20 01:14:29 -05:00
Aust1n46
d964918a7b Cancel/handle plugin message events to/from client (#133)
* Cancel/handle plugin message events to/from client

* spacing
2025-02-20 00:37:16 -06:00
Aust1n46
05762e0bc7 Bugfix use 1.20.4 json boolean type for urls 2024-01-06 19:56:34 -06:00
Aust1n46
d87c255059 Support 1.20.4 2024-01-05 17:34:16 -06:00
Aust1n46
0dfd13f2de ISSUE-80 Update server dependencies to 1.20 vers (#81) 2023-06-08 00:36:38 -05:00
Aust1n46
47fbbe23bc Allow ignore bypass for bungeecord messaging (#66) 2023-02-09 19:09:05 -06:00
Aust1n46
314fe96e1d Update detection of velocity enabled on paper (#64) 2023-02-09 18:39:07 -06:00
8 changed files with 164 additions and 78 deletions

56
pom.xml
View File

@@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>mineverse.Aust1n46.chat</groupId> <groupId>mineverse.Aust1n46.chat</groupId>
<artifactId>VentureChat</artifactId> <artifactId>VentureChat</artifactId>
<version>3.4.5</version> <version>3.8.0</version>
<url>https://bitbucket.org/Aust1n46/venturechat/src/master</url> <url>https://bitbucket.org/Aust1n46/venturechat/src/master</url>
<scm> <scm>
<url>https://bitbucket.org/Aust1n46/venturechat/src/master</url> <url>https://bitbucket.org/Aust1n46/venturechat/src/master</url>
@@ -30,10 +30,10 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version> <version>3.11.0</version>
<configuration> <configuration>
<source>1.8</source> <source>17</source>
<target>1.8</target> <target>17</target>
</configuration> </configuration>
</plugin> </plugin>
<plugin> <plugin>
@@ -56,7 +56,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId> <artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version> <version>3.4.1</version>
<configuration> <configuration>
<relocations> <relocations>
<relocation> <relocation>
@@ -91,22 +91,10 @@
<id>jitpack.io</id> <id>jitpack.io</id>
<url>https://jitpack.io</url> <url>https://jitpack.io</url>
</repository> </repository>
<repository>
<id>placeholderapi</id>
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
</repository>
<repository> <repository>
<id>dmulloy2-repo</id> <id>dmulloy2-repo</id>
<url>https://repo.dmulloy2.net/repository/public/</url> <url>https://repo.dmulloy2.net/repository/public/</url>
</repository> </repository>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>bungeecord-repo</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</repository>
<repository> <repository>
<id>essentialsx-repo</id> <id>essentialsx-repo</id>
<url>https://repo.essentialsx.net/releases/</url> <url>https://repo.essentialsx.net/releases/</url>
@@ -117,14 +105,14 @@
</repository> </repository>
<repository> <repository>
<id>papermc</id> <id>papermc</id>
<url>https://papermc.io/repo/repository/maven-public/</url> <url>https://repo.papermc.io/repository/maven-public/</url>
</repository> </repository>
</repositories> </repositories>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>io.papermc.paper</groupId> <groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId> <artifactId>paper-api</artifactId>
<version>1.17.1-R0.1-SNAPSHOT</version> <version>1.21.8-R0.1-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
@@ -134,10 +122,9 @@
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>me.clip</groupId> <groupId>com.github.placeholderapi</groupId>
<artifactId>placeholderapi</artifactId> <artifactId>placeholderapi</artifactId>
<version>2.10.9</version> <version>2.11.6</version>
<scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.github.MilkBowl</groupId> <groupId>com.github.MilkBowl</groupId>
@@ -152,9 +139,9 @@
</exclusions> </exclusions>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.comphenix.protocol</groupId> <groupId>net.dmulloy2</groupId>
<artifactId>ProtocolLib</artifactId> <artifactId>ProtocolLib</artifactId>
<version>5.0.0-SNAPSHOT</version> <version>5.4.0</version>
</dependency> </dependency>
<!--These are long depreciated. I would've removed them, but that is outside the scope of what I want to do here. <!--These are long depreciated. I would've removed them, but that is outside the scope of what I want to do here.
I am using the latest builds of these plugins to be published to SpigotMC.--> I am using the latest builds of these plugins to be published to SpigotMC.-->
@@ -204,23 +191,34 @@
<dependency> <dependency>
<groupId>net.md-5</groupId> <groupId>net.md-5</groupId>
<artifactId>bungeecord-api</artifactId> <artifactId>bungeecord-api</artifactId>
<version>1.13-SNAPSHOT</version> <version>1.20-R0.1-SNAPSHOT</version>
<type>jar</type> <type>jar</type>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>net.md-5</groupId> <groupId>net.md-5</groupId>
<artifactId>bungeecord-api</artifactId> <artifactId>bungeecord-api</artifactId>
<version>1.13-SNAPSHOT</version> <version>1.20-R0.1-SNAPSHOT</version>
<type>javadoc</type> <type>javadoc</type>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.spigotmc</groupId> <groupId>net.kyori</groupId>
<artifactId>spigot-api</artifactId> <artifactId>adventure-api</artifactId>
<version>1.19-R0.1-SNAPSHOT</version> <version>4.24.0</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-platform-bukkit</artifactId>
<version>4.4.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>

View File

@@ -79,6 +79,17 @@ public class MineverseChat extends JavaPlugin implements PluginMessageListener {
private static Permission permission = null; private static Permission permission = null;
private static Chat chat = null; private static Chat chat = null;
// TODO: This won't be so poorly done in the 4.0.0 branch I promise...
public static boolean isConnectedToProxy() {
try {
final MineverseChat plugin = MineverseChat.getInstance();
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 (final NoSuchMethodError ignored) {} // Thrown if server isn't Paper.
return false;
}
@Override @Override
public void onEnable() { public void onEnable() {
ccInfo = new ChatChannelInfo(); ccInfo = new ChatChannelInfo();
@@ -126,9 +137,11 @@ public class MineverseChat extends JavaPlugin implements PluginMessageListener {
Bukkit.getConsoleSender().sendMessage(Format.FormatStringAll("&8[&eVentureChat&8]&e - Registering Listeners")); Bukkit.getConsoleSender().sendMessage(Format.FormatStringAll("&8[&eVentureChat&8]&e - Registering Listeners"));
Bukkit.getConsoleSender().sendMessage(Format.FormatStringAll("&8[&eVentureChat&8]&e - Attaching to Executors")); Bukkit.getConsoleSender().sendMessage(Format.FormatStringAll("&8[&eVentureChat&8]&e - Attaching to Executors"));
if (MineverseChat.isConnectedToProxy()) {
Bukkit.getConsoleSender().sendMessage(Format.FormatStringAll("&8[&eVentureChat&8]&e - Establishing BungeeCord")); Bukkit.getConsoleSender().sendMessage(Format.FormatStringAll("&8[&eVentureChat&8]&e - Establishing BungeeCord"));
Bukkit.getMessenger().registerOutgoingPluginChannel(this, PLUGIN_MESSAGING_CHANNEL); Bukkit.getMessenger().registerOutgoingPluginChannel(this, PLUGIN_MESSAGING_CHANNEL);
Bukkit.getMessenger().registerIncomingPluginChannel(this, PLUGIN_MESSAGING_CHANNEL, this); Bukkit.getMessenger().registerIncomingPluginChannel(this, PLUGIN_MESSAGING_CHANNEL, this);
}
PluginManager pluginManager = getServer().getPluginManager(); PluginManager pluginManager = getServer().getPluginManager();
if(pluginManager.isPluginEnabled("Towny")) { if(pluginManager.isPluginEnabled("Towny")) {
@@ -363,6 +376,9 @@ public class MineverseChat extends JavaPlugin implements PluginMessageListener {
@Override @Override
public void onPluginMessageReceived(String channel, Player player, byte[] inputStream) { public void onPluginMessageReceived(String channel, Player player, byte[] inputStream) {
if (!MineverseChat.isConnectedToProxy()) {
return;
}
if(!channel.equals(PLUGIN_MESSAGING_CHANNEL)) { if(!channel.equals(PLUGIN_MESSAGING_CHANNEL)) {
return; return;
} }
@@ -605,6 +621,15 @@ public class MineverseChat extends JavaPlugin implements PluginMessageListener {
sendPluginMessage(stream); sendPluginMessage(stream);
return; 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("Ignore");
out.writeUTF("Echo"); out.writeUTF("Echo");
out.writeUTF(server); out.writeUTF(server);
@@ -640,6 +665,12 @@ public class MineverseChat extends JavaPlugin implements PluginMessageListener {
.replace("{player}", receiverName)); .replace("{player}", receiverName));
synchronize(p, true); synchronize(p, true);
} }
if(identifier.equals("Bypass")) {
String receiver = msgin.readUTF();
UUID sender = UUID.fromString(msgin.readUTF());
MineverseChatPlayer p = MineverseChatAPI.getOnlineMineverseChatPlayer(sender);
p.getPlayer().sendMessage(LocalizedMessage.IGNORE_PLAYER_CANT.toString().replace("{player}", receiver));
}
} }
if(subchannel.equals("Mute")) { if(subchannel.equals("Mute")) {
String identifier = msgin.readUTF(); String identifier = msgin.readUTF();

View File

@@ -73,8 +73,7 @@ public class LoginListener implements Listener {
} }
} }
try { if (MineverseChat.isConnectedToProxy()) {
if(plugin.getServer().spigot().getConfig().getBoolean("settings.bungeecord") || plugin.getServer().spigot().getPaperConfig().getBoolean("settings.velocity-support.enabled")) {
long delayInTicks = 20L; long delayInTicks = 20L;
final MineverseChatPlayer sync = mcp; final MineverseChatPlayer sync = mcp;
plugin.getServer().getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() { plugin.getServer().getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() {
@@ -84,8 +83,4 @@ public class LoginListener implements Listener {
}, delayInTicks); }, delayInTicks);
} }
} }
catch(NoSuchMethodError exception) { // Thrown if server isn't Paper.
// Do nothing
}
}
} }

View File

@@ -105,6 +105,9 @@ public class VentureChatBungee extends Plugin implements Listener, VentureChatPr
if(!event.getTag().equals(VentureChatProxy.PLUGIN_MESSAGING_CHANNEL_STRING) && !event.getTag().contains("viaversion:")) { if(!event.getTag().equals(VentureChatProxy.PLUGIN_MESSAGING_CHANNEL_STRING) && !event.getTag().contains("viaversion:")) {
return; return;
} }
// Critical to prevent client from sending or receiving messages
event.setCancelled(true);
if(!(event.getSender() instanceof Server)) { if(!(event.getSender() instanceof Server)) {
return; return;
} }

View File

@@ -205,6 +205,18 @@ public class VentureChatProxy {
source.sendPluginMessage(server, outstream.toByteArray()); 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")) { if(subchannel.equals("Mute")) {
String identifier = in.readUTF(); String identifier = in.readUTF();

View File

@@ -134,12 +134,14 @@ public class VentureChatVelocity implements VentureChatProxySource {
if(!channelIdentifierId.equals(VentureChatProxy.PLUGIN_MESSAGING_CHANNEL_STRING) && !channelIdentifierId.contains("viaversion:")) { if(!channelIdentifierId.equals(VentureChatProxy.PLUGIN_MESSAGING_CHANNEL_STRING) && !channelIdentifierId.contains("viaversion:")) {
return; return;
} }
// Critical to prevent client from sending or receiving messages
event.setResult(ForwardResult.handled());
if(!(event.getSource() instanceof ServerConnection)) { if(!(event.getSource() instanceof ServerConnection)) {
return; return;
} }
String serverName = ((ServerConnection) event.getSource()).getServerInfo().getName(); String serverName = ((ServerConnection) event.getSource()).getServerInfo().getName();
VentureChatProxy.onPluginMessage(event.getData(), serverName, this); VentureChatProxy.onPluginMessage(event.getData(), serverName, this);
event.setResult(ForwardResult.handled());
} }
@Override @Override

View File

@@ -3,13 +3,12 @@ package mineverse.Aust1n46.chat.utilities;
import static mineverse.Aust1n46.chat.MineverseChat.getInstance; import static mineverse.Aust1n46.chat.MineverseChat.getInstance;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.StringTokenizer; import java.util.StringTokenizer;
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 mineverse.Aust1n46.chat.MineverseChat;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@@ -134,14 +133,14 @@ public class Format {
} else { } else {
final String clickText = escapeJsonChars(Format.FormatStringAll( final String clickText = escapeJsonChars(Format.FormatStringAll(
PlaceholderAPI.setBracketPlaceholders(icp.getPlayer(), jsonAttribute.getClickText()))); PlaceholderAPI.setBracketPlaceholders(icp.getPlayer(), jsonAttribute.getClickText())));
actionJson = ",\"clickEvent\":{\"action\":\"" + jsonAttribute.getClickAction().toString() + "\",\"value\":\"" + clickText actionJson = ",\"click_event\":{\"action\":\"" + jsonAttribute.getClickAction().toString() + "\",\"command\":\"" + clickText
+ "\"}"; + "\"}";
} }
final String hoverJson; final String hoverJson;
if (hoverText.isEmpty()) { if (hoverText.isEmpty()) {
hoverJson = StringUtils.EMPTY; hoverJson = StringUtils.EMPTY;
} else { } else {
hoverJson = ",\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[" hoverJson = ",\"hover_event\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":["
+ convertToJsonColors(hoverText) + "]}}"; + convertToJsonColors(hoverText) + "]}}";
} }
temp += convertToJsonColors(lastCode + formattedPlaceholder, actionJson + hoverJson) + ","; temp += convertToJsonColors(lastCode + formattedPlaceholder, actionJson + hoverJson) + ",";
@@ -190,10 +189,10 @@ public class Format {
if (ChatColor.stripColor(link).contains("https://")) if (ChatColor.stripColor(link).contains("https://"))
https = "s"; https = "s";
temp += convertToJsonColors(lastCode + link, temp += convertToJsonColors(lastCode + link,
",\"underlined\":\"" + underlineURLs() ",\"underlined\":" + underlineURLs()
+ "\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"http" + https + "://" + ",\"click_event\":{\"action\":\"open_url\",\"url\":\"http" + https + "://"
+ ChatColor.stripColor(link.replace("http://", "").replace("https://", "")) + ChatColor.stripColor(link.replace("http://", "").replace("https://", ""))
+ "\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[" + "\"},\"hover_event\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":["
+ convertToJsonColors(lastCode + link) + "]}}") + convertToJsonColors(lastCode + link) + "]}}")
+ ","; + ",";
lastCode = getLastCode(lastCode + link); lastCode = getLastCode(lastCode + link);
@@ -343,15 +342,35 @@ public class Format {
underlined = false; underlined = false;
} }
if (bold) if (bold)
if (VersionHandler.isAtLeast_1_20_4()) {
modifier += ",\"bold\":true";
} else {
modifier += ",\"bold\":\"true\""; modifier += ",\"bold\":\"true\"";
}
if (obfuscated) if (obfuscated)
if (VersionHandler.isAtLeast_1_20_4()) {
modifier += ",\"obfuscated\":true";
} else {
modifier += ",\"obfuscated\":\"true\""; modifier += ",\"obfuscated\":\"true\"";
}
if (italic) if (italic)
if (VersionHandler.isAtLeast_1_20_4()) {
modifier += ",\"italic\":true";
} else {
modifier += ",\"italic\":\"true\""; modifier += ",\"italic\":\"true\"";
}
if (underlined) if (underlined)
if (VersionHandler.isAtLeast_1_20_4()) {
modifier += ",\"underlined\":true";
} else {
modifier += ",\"underlined\":\"true\""; modifier += ",\"underlined\":\"true\"";
}
if (strikethrough) if (strikethrough)
if (VersionHandler.isAtLeast_1_20_4()) {
modifier += ",\"strikethrough\":true";
} else {
modifier += ",\"strikethrough\":\"true\""; modifier += ",\"strikethrough\":\"true\"";
}
remaining = remaining.substring(colorLength); remaining = remaining.substring(colorLength);
colorLength = LEGACY_COLOR_CODE_LENGTH; colorLength = LEGACY_COLOR_CODE_LENGTH;
indexNextColor = remaining.indexOf(BUKKIT_COLOR_CODE_PREFIX); indexNextColor = remaining.indexOf(BUKKIT_COLOR_CODE_PREFIX);
@@ -435,9 +454,9 @@ public class Format {
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 += "," + Format.convertToJsonColors(Format.FormatStringAll(getInstance().getConfig().getString("guiicon")), json += "," + Format.convertToJsonColors(Format.FormatStringAll(getInstance().getConfig().getString("guiicon")),
",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/vchatgui " + sender + " " + channelName ",\"click_event\":{\"action\":\"run_command\",\"command\":\"/vchatgui " + sender + " " + channelName
+ " " + hash + " " + hash
+ "\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[" + "\"},\"hover_event\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":["
+ Format.convertToJsonColors( + Format.convertToJsonColors(
Format.FormatStringAll(getInstance().getConfig().getString("guitext"))) Format.FormatStringAll(getInstance().getConfig().getString("guitext")))
+ "]}}") + "]}}")
@@ -448,16 +467,20 @@ public class Format {
public static PacketContainer createPacketPlayOutChat(String json) { public static PacketContainer createPacketPlayOutChat(String json) {
final PacketContainer container; final PacketContainer container;
if (VersionHandler.isAbove_1_19()) { if (VersionHandler.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 (VersionHandler.isAbove_1_19()) { // 1.19.1 -> 1.20.3
container = new PacketContainer(PacketType.Play.Server.SYSTEM_CHAT); container = new PacketContainer(PacketType.Play.Server.SYSTEM_CHAT);
container.getStrings().write(0, json); container.getStrings().write(0, json);
container.getBooleans().write(0, false); container.getBooleans().write(0, false);
} else if (VersionHandler.isUnder_1_19()) { } else if (VersionHandler.isUnder_1_19()) { // 1.7 -> 1.19
WrappedChatComponent component = WrappedChatComponent.fromJson(json); WrappedChatComponent component = WrappedChatComponent.fromJson(json);
container = new PacketContainer(PacketType.Play.Server.CHAT); container = new PacketContainer(PacketType.Play.Server.CHAT);
container.getModifier().writeDefaults(); container.getModifier().writeDefaults();
container.getChatComponents().write(0, component); container.getChatComponents().write(0, component);
} else { } else { // 1.19
container = new PacketContainer(PacketType.Play.Server.SYSTEM_CHAT); container = new PacketContainer(PacketType.Play.Server.SYSTEM_CHAT);
container.getStrings().write(0, json); container.getStrings().write(0, json);
container.getIntegers().write(0, 1); container.getIntegers().write(0, 1);
@@ -467,15 +490,19 @@ public class Format {
public static PacketContainer createPacketPlayOutChat(WrappedChatComponent component) { public static PacketContainer createPacketPlayOutChat(WrappedChatComponent component) {
final PacketContainer container; final PacketContainer container;
if (VersionHandler.isAbove_1_19()) { if (VersionHandler.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 (VersionHandler.isAbove_1_19()) { // 1.19.1 -> 1.20.3
container = new PacketContainer(PacketType.Play.Server.SYSTEM_CHAT); container = new PacketContainer(PacketType.Play.Server.SYSTEM_CHAT);
container.getStrings().write(0, component.getJson()); container.getStrings().write(0, component.getJson());
container.getBooleans().write(0, false); container.getBooleans().write(0, false);
} else if (VersionHandler.isUnder_1_19()) { } else if (VersionHandler.isUnder_1_19()) { // 1.7 -> 1.19
container = new PacketContainer(PacketType.Play.Server.CHAT); container = new PacketContainer(PacketType.Play.Server.CHAT);
container.getModifier().writeDefaults(); container.getModifier().writeDefaults();
container.getChatComponents().write(0, component); container.getChatComponents().write(0, component);
} else { } else { // 1.19
container = new PacketContainer(PacketType.Play.Server.SYSTEM_CHAT); container = new PacketContainer(PacketType.Play.Server.SYSTEM_CHAT);
container.getStrings().write(0, component.getJson()); container.getStrings().write(0, component.getJson());
container.getIntegers().write(0, 1); container.getIntegers().write(0, 1);
@@ -783,8 +810,13 @@ public class Format {
.replace(")", "\\)").replace("|", "\\|").replace("+", "\\+").replace("*", "\\*"); .replace(")", "\\)").replace("|", "\\|").replace("+", "\\+").replace("*", "\\*");
} }
public static boolean underlineURLs() { public static String underlineURLs() {
return getInstance().getConfig().getBoolean("underlineurls", true); final boolean configValue = getInstance().getConfig().getBoolean("underlineurls", true);
if (VersionHandler.isAtLeast_1_20_4()) {
return String.valueOf(configValue);
} else {
return "\"" + configValue + "\"";
}
} }
public static String parseTimeStringFromMillis(long millis) { public static String parseTimeStringFromMillis(long millis) {
@@ -927,15 +959,23 @@ public class Format {
public static void playMessageSound(MineverseChatPlayer mcp) { public static void playMessageSound(MineverseChatPlayer mcp) {
Player player = mcp.getPlayer(); Player player = mcp.getPlayer();
String soundName = getInstance().getConfig().getString("message_sound", DEFAULT_MESSAGE_SOUND); String soundName = getInstance().getConfig().getString("message_sound", DEFAULT_MESSAGE_SOUND);
if(!soundName.equalsIgnoreCase("None")) { if (!soundName.equalsIgnoreCase("None")) {
try {
Sound messageSound = getSound(soundName); Sound messageSound = getSound(soundName);
player.playSound(player.getLocation(), messageSound, 1, 0); player.playSound(player.getLocation(), messageSound, 1, 0);
} catch (final Exception e) {
if (MineverseChat.getInstance().getConfig().getString("loglevel", "info").equals("debug")) {
Bukkit.getConsoleSender().sendMessage(Format.FormatStringAll("&8[&eVentureChat&8]&c - Error playing sound, defaulting to none"));
}
}
} }
} }
private static Sound getSound(String soundName) { private static Sound getSound(String soundName) {
if(Arrays.asList(Sound.values()).stream().map(Sound::toString).collect(Collectors.toList()).contains(soundName)) { for (Sound sound : Sound.values()) {
return Sound.valueOf(soundName); if (sound.toString().equalsIgnoreCase(soundName)) {
return sound;
}
} }
Bukkit.getConsoleSender().sendMessage(Format.FormatStringAll("&8[&eVentureChat&8]&c - Message sound invalid!")); Bukkit.getConsoleSender().sendMessage(Format.FormatStringAll("&8[&eVentureChat&8]&c - Message sound invalid!"));
return getDefaultMessageSound(); return getDefaultMessageSound();

View File

@@ -7,6 +7,7 @@ public final class VersionHandler {
public static final MinecraftVersion SERVER_VERSION = MinecraftVersion.getCurrentVersion(); 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 = new MinecraftVersion(1, 19, 0);
private static final MinecraftVersion MC1_19_1 = new MinecraftVersion(1, 19, 1); 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 VersionHandler() { private VersionHandler() {
} }
@@ -74,4 +75,8 @@ public final class VersionHandler {
public static boolean isAbove_1_19() { public static boolean isAbove_1_19() {
return SERVER_VERSION.isAtLeast(MC1_19_1); return SERVER_VERSION.isAtLeast(MC1_19_1);
} }
public static boolean isAtLeast_1_20_4() {
return SERVER_VERSION.isAtLeast(MC1_20_4);
}
} }