Skip to content

Commit 8cc27e0

Browse files
authored
Merge pull request #20 from HyperaOfficial/development
Release v5.1.2
2 parents 07c058d + fe4518d commit 8cc27e0

6 files changed

Lines changed: 29 additions & 19 deletions

File tree

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
<groupId>dev.hypera</groupId>
2626
<artifactId>UltraStaffChat</artifactId>
27-
<version>5.1.1</version>
27+
<version>5.1.2</version>
2828
<packaging>jar</packaging>
2929

3030
<name>UltraStaffChat</name>
@@ -119,12 +119,12 @@
119119
<dependency>
120120
<groupId>net.kyori</groupId>
121121
<artifactId>adventure-api</artifactId>
122-
<version>4.8.1</version>
122+
<version>4.9.1</version>
123123
</dependency>
124124
<dependency>
125125
<groupId>net.kyori</groupId>
126126
<artifactId>adventure-platform-bungeecord</artifactId>
127-
<version>4.0.0-SNAPSHOT</version>
127+
<version>4.0.0</version>
128128
</dependency>
129129

130130
<!-- bStats -->

src/main/java/dev/hypera/ultrastaffchat/listeners/impl/ChatListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public void onChat(ChatEvent e) {
5252

5353
if(p.hasPermission(UltraStaffChat.getConfig().getString("permission-talk"))) {
5454
String prefix = UltraStaffChat.getConfig().getString("staffchat-prefix");
55-
if(!prefix.equals("") && e.getMessage().startsWith(prefix)) {
55+
if(!prefix.equals("") && e.getMessage().startsWith(prefix) && e.getMessage().replaceFirst(prefix, "").length() > 0) {
5656
e.setCancelled(true);
5757
if(StaffChat.staffChatIsMuted()) {
5858
if(!((ProxiedPlayer) e.getSender()).hasPermission(UltraStaffChat.getConfig().getString("permission-bypass"))) {

src/main/java/dev/hypera/ultrastaffchat/managers/StaffChatManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public static void broadcastMessage(CommandSender sender, String m) {
4444
ProxyServer.getInstance().getPluginManager().callEvent(staffChatEvent);
4545
return !staffChatEvent.isCancelled();
4646
}).sendMessage(adventurise(messageRaw("staffchat-format").replace("{player}", getName(sender)).replace("{server}", getServerSafe(sender)).replace("{message}", message)));
47-
Discord.broadcastDiscordStaffChatMessage(sender, message);
47+
Discord.broadcastDiscordStaffChatMessage(sender, m);
4848
}
4949

5050
public static void broadcastAFK(ProxiedPlayer player, boolean afk) {

src/main/java/dev/hypera/ultrastaffchat/utils/Common.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class Common {
4141
private static final int bStatsId = 5040;
4242
private static final long resourceId = 68956;
4343
private static final int configVersion = 37;
44-
private static final String[] contributors = new String[] { "Joshua Sing", "Christian F", "SLLCoding", "Hunter Y" };
44+
private static final String[] contributors = new String[] { "Joshua Sing", "Christian F", "SLLCoding" };
4545

4646
/**
4747
* Logs messages to console.

src/main/java/dev/hypera/ultrastaffchat/utils/Discord.java

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import dev.hypera.ultrastaffchat.UltraStaffChat;
2222
import dev.hypera.ultrastaffchat.utils.DiscordWebhook.EmbedObject;
23+
import net.md_5.bungee.api.ChatColor;
2324
import net.md_5.bungee.api.CommandSender;
2425
import net.md_5.bungee.api.ProxyServer;
2526
import net.md_5.bungee.api.connection.ProxiedPlayer;
@@ -83,7 +84,7 @@ public static void broadcastDiscordJoin(ProxiedPlayer p) {
8384
ProxyServer.getInstance().getScheduler().runAsync(UltraStaffChat.getInstance(), () -> {
8485
try {
8586
DiscordWebhook hook = getHook();
86-
if(UltraStaffChat.getConfig().getBoolean("discord-embed").equals(false)) {
87+
if(!UltraStaffChat.getConfig().getBoolean("discord-embed")) {
8788
Configuration textFormat = UltraStaffChat.getConfig().getConfiguration().getSection("discord-join-format");
8889
hook.setContent(join_leavePlaceholders(textFormat.getString("text"), p));
8990
hook.execute();
@@ -118,7 +119,7 @@ public static void broadcastDiscordLeave(ProxiedPlayer p) {
118119
try {
119120
DiscordWebhook hook = getHook();
120121

121-
if(UltraStaffChat.getConfig().getBoolean("discord-embed").equals(false)) {
122+
if(!UltraStaffChat.getConfig().getBoolean("discord-embed")) {
122123
Configuration textFormat = UltraStaffChat.getConfig().getConfiguration().getSection("discord-leave-format");
123124
hook.setContent(join_leavePlaceholders(textFormat.getString("text"), p));
124125
hook.execute();
@@ -153,7 +154,7 @@ public static void broadcastDiscordSwitch(ProxiedPlayer p, String from, String t
153154
try {
154155
DiscordWebhook hook = getHook();
155156

156-
if(UltraStaffChat.getConfig().getBoolean("discord-embed").equals(false)) {
157+
if(!UltraStaffChat.getConfig().getBoolean("discord-embed")) {
157158
Configuration textFormat = UltraStaffChat.getConfig().getConfiguration().getSection("discord-switch-format");
158159
hook.setContent(switchPlaceholders(textFormat.getString("text"), p, from, to));
159160
try {
@@ -192,7 +193,7 @@ public static void broadcastDiscordStaffChatMessage(CommandSender s, String mess
192193
try {
193194
DiscordWebhook hook = getHook();
194195

195-
if(UltraStaffChat.getConfig().getBoolean("discord-embed").equals(false)) {
196+
if(!UltraStaffChat.getConfig().getBoolean("discord-embed")) {
196197
Configuration textFormat = UltraStaffChat.getConfig().getConfiguration().getSection("discord-format");
197198
hook.setContent(messagePlaceholders(textFormat.getString("text"), s, message));
198199
try {
@@ -231,9 +232,9 @@ public static void broadcastDiscordAFKEnable(ProxiedPlayer p) {
231232
try {
232233
DiscordWebhook hook = getHook();
233234

234-
if(UltraStaffChat.getConfig().getBoolean("discord-embed").equals(false)) {
235+
if(!UltraStaffChat.getConfig().getBoolean("discord-embed")) {
235236
Configuration textFormat = UltraStaffChat.getConfig().getConfiguration().getSection("discord-afk-enable-format");
236-
hook.setContent(join_leavePlaceholders(textFormat.getString("text"), p));
237+
hook.setContent(afkPlaceholders(textFormat.getString("text"), p));
237238
hook.execute();
238239
return;
239240
}
@@ -266,9 +267,9 @@ public static void broadcastDiscordAFKDisable(ProxiedPlayer p) {
266267
try {
267268
DiscordWebhook hook = getHook();
268269

269-
if(UltraStaffChat.getConfig().getBoolean("discord-embed").equals(false)) {
270+
if(!UltraStaffChat.getConfig().getBoolean("discord-embed")) {
270271
Configuration textFormat = UltraStaffChat.getConfig().getConfiguration().getSection("discord-afk-disable-format");
271-
hook.setContent(join_leavePlaceholders(textFormat.getString("text"), p));
272+
hook.setContent(afkPlaceholders(textFormat.getString("text"), p));
272273
hook.execute();
273274
return;
274275
}
@@ -295,19 +296,19 @@ public static void broadcastDiscordAFKDisable(ProxiedPlayer p) {
295296
}
296297

297298
private static String messagePlaceholders(String string, CommandSender s, String m) {
298-
return string.replaceAll("\\{message}", m).replaceAll("\\{player}", Common.getDisplayNameSafe(s)).replaceAll("\\{server}", Common.getServerSafe(s));
299+
return escape(string.replaceAll("\\{message}", stripColor(m)).replaceAll("\\{player}", Common.getDisplayNameSafe(s)).replaceAll("\\{server}", Common.getServerSafe(s)));
299300
}
300301

301302
private static String join_leavePlaceholders(String string, ProxiedPlayer p) {
302-
return string.replaceAll("\\{player}", Common.getDisplayNameSafe(p)).replaceAll("\\{server}", Common.getServerSafe(p));
303+
return escape(string.replaceAll("\\{player}", Common.getDisplayNameSafe(p)).replaceAll("\\{server}", Common.getServerSafe(p)));
303304
}
304305

305306
private static String switchPlaceholders(String string, ProxiedPlayer p, String from, String to) {
306-
return string.replaceAll("\\{player}", Common.getDisplayNameSafe(p)).replaceAll("\\{to}", to).replaceAll("\\{from}", from);
307+
return escape(string.replaceAll("\\{player}", Common.getDisplayNameSafe(p)).replaceAll("\\{to}", to).replaceAll("\\{from}", from));
307308
}
308309

309310
private static String afkPlaceholders(String string, ProxiedPlayer p) {
310-
return string.replaceAll("\\{player}", Common.getDisplayNameSafe(p));
311+
return escape(string.replaceAll("\\{player}", Common.getDisplayNameSafe(p)));
311312
}
312313

313314
private static DiscordWebhook getHook() {
@@ -321,4 +322,12 @@ private static DiscordWebhook.EmbedObject createEmbed() {
321322
return new DiscordWebhook.EmbedObject().setFooter(footer, footerUrl);
322323
}
323324

325+
private static String escape(String input) {
326+
return input.replaceAll("\"", "\\\\\"");
327+
}
328+
329+
private static String stripColor(String input) {
330+
return input.replaceAll("(?i)[§&][0-9A-FK-ORX]", "");
331+
}
332+
324333
}

src/main/java/dev/hypera/ultrastaffchat/utils/DiscordWebhook.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44
package dev.hypera.ultrastaffchat.utils;
55

6+
import java.nio.charset.StandardCharsets;
67
import javax.net.ssl.HttpsURLConnection;
78
import java.awt.Color;
89
import java.io.IOException;
@@ -151,7 +152,7 @@ public void execute() throws IOException {
151152
connection.setRequestMethod("POST");
152153

153154
OutputStream stream = connection.getOutputStream();
154-
stream.write(json.toString().getBytes());
155+
stream.write(json.toString().getBytes(StandardCharsets.UTF_8));
155156
stream.flush();
156157
stream.close();
157158

0 commit comments

Comments
 (0)