Skip to content

Commit 45bd8de

Browse files
authored
UltraStaffChat BungeeCord - Version 5.1.0
* Updated UpdateLib * Added on/off configuration * Added markdown support in staff chat messages
2 parents 8348a54 + fb29dd2 commit 45bd8de

8 files changed

Lines changed: 196 additions & 35 deletions

File tree

pom.xml

Lines changed: 4 additions & 4 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.0.1</version>
27+
<version>5.1.0</version>
2828
<packaging>jar</packaging>
2929

3030
<name>UltraStaffChat</name>
@@ -86,8 +86,8 @@
8686
<url>https://oss.sonatype.org/content/groups/public/</url>
8787
</repository>
8888
<repository>
89-
<id>hypera-snapshots</id>
90-
<url>https://repo.hypera.dev/snapshots/</url>
89+
<id>hypera-releases</id>
90+
<url>https://repo.hypera.dev/releases/</url>
9191
</repository>
9292
</repositories>
9393

@@ -105,7 +105,7 @@
105105
<dependency>
106106
<groupId>dev.hypera</groupId>
107107
<artifactId>UpdateLib</artifactId>
108-
<version>2.1.1-SNAPSHOT</version>
108+
<version>2.1.2</version>
109109
</dependency>
110110

111111
<!-- Reflections for automatic registry -->

src/main/java/dev/hypera/ultrastaffchat/commands/impl/MuteStaffChatCommand.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,21 @@ public void execute(CommandSender sender, String[] args) {
5151
if(args.length == 0) {
5252
boolean toggled = StaffChat.toggleStaffChatMute();
5353
if(toggled) {
54-
audience.sendMessage(Common.adventurise(UltraStaffChat.getConfig().getString("mute-staffchat-message").replaceAll("\\{mute}", "&cmuted")));
54+
audience.sendMessage(Common.adventurise(UltraStaffChat.getConfig().getString("mute-staffchat-message-on")));
5555
} else
56-
audience.sendMessage(Common.adventurise(UltraStaffChat.getConfig().getString("mute-staffchat-message").replaceAll("\\{mute}", "&aunmuted")));
56+
audience.sendMessage(Common.adventurise(UltraStaffChat.getConfig().getString("mute-staffchat-message-off")));
5757
return;
5858
}
5959

6060
if(args[0].matches("(?i:(off|false|disable(d)?|unmute(d)?))")) {
6161
StaffChat.unmuteStaffChat();
62-
audience.sendMessage(Common.adventurise(UltraStaffChat.getConfig().getString("mute-staffchat-message").replaceAll("\\{mute}", "&aunmuted")));
62+
audience.sendMessage(Common.adventurise(UltraStaffChat.getConfig().getString("mute-staffchat-message-off")));
6363
return;
6464
}
6565

6666
if(args[0].matches("(?i:(on|true|enable(d)?|mute(d)?))")) {
6767
StaffChat.muteStaffChat();
68-
audience.sendMessage(Common.adventurise(UltraStaffChat.getConfig().getString("mute-staffchat-message").replaceAll("\\{mute}", "&cmuted")));
68+
audience.sendMessage(Common.adventurise(UltraStaffChat.getConfig().getString("mute-staffchat-message-on")));
6969
return;
7070
}
7171

src/main/java/dev/hypera/ultrastaffchat/commands/impl/StaffChatMuteCommand.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,21 @@ public void execute(CommandSender sender, String[] args) {
5656
if(args.length == 0) {
5757
boolean toggled = StaffChat.toggleMessages(p);
5858
if(toggled) {
59-
audience.sendMessage(Common.adventurise(UltraStaffChat.getConfig().getString("mute-message").replaceAll("\\{mute}", "&cmuted")));
59+
audience.sendMessage(Common.adventurise(UltraStaffChat.getConfig().getString("mute-message-on")));
6060
} else
61-
audience.sendMessage(Common.adventurise(UltraStaffChat.getConfig().getString("mute-message").replaceAll("\\{mute}", "&aunmuted")));
61+
audience.sendMessage(Common.adventurise(UltraStaffChat.getConfig().getString("mute-message-off")));
6262
return;
6363
}
6464

65-
if(args[0].matches("(?i:(off|false|mute(d)?|disable(d)?))")) {
65+
if(args[0].matches("(?i:(off|false|disable(d)?|unmute(d)?))")) {
6666
StaffChat.enableMessages(p);
67-
audience.sendMessage(Common.adventurise(UltraStaffChat.getConfig().getString("mute-message").replaceAll("\\{mute}", "&cmuted")));
67+
audience.sendMessage(Common.adventurise(UltraStaffChat.getConfig().getString("mute-message-off")));
6868
return;
6969
}
7070

71-
if(args[0].matches("(?i:(on|true|unmute(d)?|enable(d)?))")) {
71+
if(args[0].matches("(?i:(on|true|enable(d)?|mute(d)?))")) {
7272
StaffChat.disableMessages(p);
73-
audience.sendMessage(Common.adventurise(UltraStaffChat.getConfig().getString("mute-message").replaceAll("\\{mute}", "&aunmuted")));
73+
audience.sendMessage(Common.adventurise(UltraStaffChat.getConfig().getString("mute-message-on")));
7474
return;
7575
}
7676

src/main/java/dev/hypera/ultrastaffchat/commands/impl/StaffChatToggleCommand.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,21 @@ public void execute(CommandSender sender, String[] args) {
5656
if(args.length == 0) {
5757
boolean toggled = StaffChat.toggleChatStaffChat(p);
5858
if(toggled) {
59-
audience.sendMessage(Common.adventurise(UltraStaffChat.getConfig().getString("toggle-message").replaceAll("\\{toggle}", "&aon")));
59+
audience.sendMessage(Common.adventurise(UltraStaffChat.getConfig().getString("toggle-message-on")));
6060
} else
61-
audience.sendMessage(Common.adventurise(UltraStaffChat.getConfig().getString("toggle-message").replaceAll("\\{toggle}", "&coff")));
61+
audience.sendMessage(Common.adventurise(UltraStaffChat.getConfig().getString("toggle-message-off")));
6262
return;
6363
}
6464

6565
if(args[0].matches("(?i:(off|false|disable(d)?))")) {
6666
StaffChat.disableChatStaffChat(p);
67-
audience.sendMessage(Common.adventurise(UltraStaffChat.getConfig().getString("toggle-message").replaceAll("\\{toggle}", "&coff")));
67+
audience.sendMessage(Common.adventurise(UltraStaffChat.getConfig().getString("toggle-message-off")));
6868
return;
6969
}
7070

7171
if(args[0].matches("(?i:(on|true|enable(d)?))")) {
7272
StaffChat.enableChatStaffChat(p);
73-
audience.sendMessage(Common.adventurise(UltraStaffChat.getConfig().getString("toggle-message").replaceAll("\\{toggle}", "&aon")));
73+
audience.sendMessage(Common.adventurise(UltraStaffChat.getConfig().getString("toggle-message-on")));
7474
return;
7575
}
7676

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,9 @@
1919
package dev.hypera.ultrastaffchat.managers;
2020

2121
import dev.hypera.ultrastaffchat.UltraStaffChat;
22-
import dev.hypera.ultrastaffchat.events.staff.StaffChatEvent;
23-
import dev.hypera.ultrastaffchat.events.staff.StaffJoinEvent;
24-
import dev.hypera.ultrastaffchat.events.staff.StaffLeaveEvent;
25-
import dev.hypera.ultrastaffchat.events.staff.StaffSwitchServerEvent;
26-
import dev.hypera.ultrastaffchat.events.staff.StaffToggleAFKEvent;
22+
import dev.hypera.ultrastaffchat.events.staff.*;
2723
import dev.hypera.ultrastaffchat.utils.Discord;
24+
import dev.hypera.ultrastaffchat.utils.MD_;
2825
import dev.hypera.ultrastaffchat.utils.StaffChat;
2926
import net.kyori.adventure.audience.Audience;
3027
import net.md_5.bungee.api.CommandSender;
@@ -36,7 +33,8 @@
3633

3734
public class StaffChatManager {
3835

39-
public static void broadcastMessage(CommandSender sender, String message) {
36+
public static void broadcastMessage(CommandSender sender, String m) {
37+
String message = (sender.hasPermission(UltraStaffChat.getConfig().getString("permission-chat-format")) ? MD_.parseMarkdown(m) : m);
4038
UltraStaffChat.getInstance().getAdventure().filter(person -> {
4139
if(!person.hasPermission(messageRaw("permission-read")))
4240
return false;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class Common {
4040

4141
private static final int bStatsId = 5040;
4242
private static final long resourceId = 68956;
43-
private static final int configVersion = 36;
43+
private static final int configVersion = 37;
4444
private static final String[] contributors = new String[] { "Joshua Sing", "Christian F", "SLLCoding", "Hunter Y" };
4545

4646
/**
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
/*
2+
* MIT License
3+
*
4+
* Copyright (c) 2018 Aeternum Network
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
package dev.hypera.ultrastaffchat.utils;
26+
27+
import net.md_5.bungee.api.ChatColor;
28+
import net.md_5.bungee.api.plugin.Listener;
29+
30+
import java.util.ArrayList;
31+
import java.util.List;
32+
import java.util.regex.Matcher;
33+
import java.util.regex.Pattern;
34+
35+
public class MD_ implements Listener {
36+
37+
public static String parseMarkdown(String message) {
38+
String translated = message;
39+
40+
translated = replaceWith(translated, "(?<!\\\\)\\*\\*", ChatColor.COLOR_CHAR + "z", ChatColor.COLOR_CHAR + "Z");
41+
translated = replaceWith(translated, "(?<!\\\\)\\*", ChatColor.COLOR_CHAR + "x", ChatColor.COLOR_CHAR + "X");
42+
translated = replaceWith(translated, "(?<!\\\\)__", ChatColor.COLOR_CHAR + "v", ChatColor.COLOR_CHAR + "V");
43+
translated = replaceWith(translated, "(?<!\\\\)_", ChatColor.COLOR_CHAR + "q", ChatColor.COLOR_CHAR + "Q");
44+
translated = replaceWith(translated, "(?<!\\\\)~~", ChatColor.COLOR_CHAR + "m", ChatColor.COLOR_CHAR + "M");
45+
translated = replaceWith(translated, "(?<!\\\\)~", ChatColor.COLOR_CHAR + "w", ChatColor.COLOR_CHAR + "W");
46+
47+
translated = translated.replace("\\*", "*").replace("\\_", "_").replace("\\~", "~");
48+
49+
return parseParts(translated).toString();
50+
}
51+
52+
private static StringBuilder parseParts(String translated) {
53+
String partForPart = (" " + translated);
54+
String[] parts = partForPart.split("" + ChatColor.COLOR_CHAR);
55+
StringBuilder builder = new StringBuilder();
56+
for (String part : parts) {
57+
if (part.isEmpty()) {
58+
continue;
59+
}
60+
parsePart(part, builder);
61+
}
62+
return builder;
63+
}
64+
65+
private static void parsePart(String part, StringBuilder builder) {
66+
char colorCharacter = part.charAt(0);
67+
ChatColor color = ChatColor.getByChar(colorCharacter);
68+
69+
String colors = getLastColors(builder.toString());
70+
if (color != null) {
71+
StringBuilder colorBuilder = new StringBuilder();
72+
for (String cc : colors.split(ChatColor.COLOR_CHAR + "")) {
73+
if (cc.isEmpty()) {
74+
continue;
75+
}
76+
if (isFormat(ChatColor.getByChar(cc.charAt(0)))) {
77+
colorBuilder.append(ChatColor.COLOR_CHAR + cc);
78+
}
79+
}
80+
builder.append(color + colorBuilder.toString());
81+
} else {
82+
colors = parseColours(colorCharacter, builder, colors);
83+
}
84+
if (part.length() > 1) {
85+
builder.append(part.substring(1));
86+
}
87+
}
88+
89+
private static String parseColours(char colorCharacter, StringBuilder builder, String c) {
90+
String colors = c;
91+
if (colorCharacter == 'z') builder.append(ChatColor.BOLD);
92+
else if (colorCharacter == 'x') builder.append(ChatColor.ITALIC);
93+
else if (colorCharacter == 'v') builder.append(ChatColor.UNDERLINE);
94+
else if (colorCharacter == 'q') builder.append(ChatColor.ITALIC);
95+
else if (colorCharacter == 'm') builder.append(ChatColor.STRIKETHROUGH);
96+
else if (colorCharacter == 'w') builder.append(ChatColor.MAGIC);
97+
else if (colorCharacter == 'Z') colors = colors.replace(ChatColor.BOLD.toString(), "");
98+
else if (colorCharacter == 'X') colors = colors.replace(ChatColor.ITALIC.toString(), "");
99+
else if (colorCharacter == 'V') colors = colors.replace(ChatColor.UNDERLINE.toString(), "");
100+
else if (colorCharacter == 'Q') colors = colors.replace(ChatColor.ITALIC.toString(), "");
101+
else if (colorCharacter == 'M') colors = colors.replace(ChatColor.STRIKETHROUGH.toString(), "");
102+
else if (colorCharacter == 'W') colors = colors.replace(ChatColor.MAGIC.toString(), "");
103+
if (Character.isUpperCase(colorCharacter)) builder.append(ChatColor.RESET + colors);
104+
return colors;
105+
}
106+
107+
private static String replaceWith(String message, String quot, String pre, String suf) {
108+
String part = message;
109+
for (String str : getMatches(message, quot + "(.+?)" + quot)) {
110+
part = part.replaceFirst(quot + Pattern.quote(str) + quot, pre + str + suf);
111+
}
112+
return part;
113+
}
114+
115+
public static List<String> getMatches(String string, String regex) {
116+
Pattern pattern = Pattern.compile(regex);
117+
Matcher matcher = pattern.matcher(string);
118+
List<String> matches = new ArrayList<String>();
119+
while (matcher.find()) {
120+
matches.add(matcher.group(1));
121+
}
122+
return matches;
123+
}
124+
125+
private static boolean isFormat(ChatColor color) {
126+
return color == ChatColor.MAGIC || color == ChatColor.BOLD || color == ChatColor.STRIKETHROUGH || color == ChatColor.ITALIC || color == ChatColor.UNDERLINE;
127+
}
128+
129+
private static String getLastColors(String input) {
130+
String result = "";
131+
int length = input.length();
132+
133+
// Search backwards from the end as it is faster
134+
for (int index = length - 1; index > -1; index--) {
135+
char section = input.charAt(index);
136+
if (section == ChatColor.COLOR_CHAR && index < length - 1) {
137+
char c = input.charAt(index + 1);
138+
ChatColor color = ChatColor.getByChar(c);
139+
140+
if (color != null) {
141+
result = color.toString() + result;
142+
143+
// Once we find a color or reset we can stop searching
144+
if (!isFormat(color) || color.equals(ChatColor.RESET)) {
145+
break;
146+
}
147+
}
148+
}
149+
}
150+
151+
return result;
152+
}
153+
154+
}

src/main/resources/config.yml

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,11 @@ staffchat-prefix: "#"
242242
# Toggle | Enabled
243243
toggle-enabled: true
244244

245-
# Toggle | Message
246-
# - Placeholders: &aOn/&cOff - {toggle}
247-
toggle-message: "&8[&4&lStaffChat&8] &cStaffChat Toggled {toggle}&c!"
245+
# Toggle On | Message
246+
toggle-message-on: "&8[&4&lStaffChat&8] &cStaffChat Toggled &aOn&c!"
247+
248+
# Toggle Off | Message
249+
toggle-message-off: "&8[&4&lStaffChat&8] &cStaffChat Toggled &cOff&c!"
248250

249251
# Toggle | Usage
250252
toggle-usage: "&cUsage: /sctoggle <state>"
@@ -255,9 +257,11 @@ toggle-usage: "&cUsage: /sctoggle <state>"
255257
# Mute | Enabled
256258
mute-enabled: true
257259

258-
# Mute | Message
259-
# - Placeholders: &cMuted/&aUnmuted - {mute}
260-
mute-message: "&8[&4&lStaffChat&8] &cStaffChat {mute}&c!"
260+
# Mute On | Message
261+
mute-message-on: "&8[&4&lStaffChat&8] &cStaffChat &cMuted&c!"
262+
263+
# Mute Off | Message
264+
mute-message-off: "&8[&4&lStaffChat&8] &cStaffChat &aUnmuted&c!"
261265

262266
# Mute | Usage
263267
mute-usage: "&cUsage: /scmute <state>"
@@ -267,9 +271,11 @@ mute-usage: "&cUsage: /scmute <state>"
267271
# Mute | Enabled
268272
mute-staffchat-enabled: true
269273

270-
# Mute | Message
271-
# - Placeholders: &cMuted/&aUnmuted - {mute}
272-
mute-staffchat-message: "&8[&4&lStaffChat&8] &cStaffChat has been {mute}&c!"
274+
# Mute On | Message
275+
mute-staffchat-message-on: "&8[&4&lStaffChat&8] &cStaffChat has been &cMuted&c!"
276+
277+
# Mute Off | Message
278+
mute-staffchat-message-off: "&8[&4&lStaffChat&8] &cStaffChat has been &aUnmuted&c!"
273279

274280
# Mute | Usage
275281
mute-staffchat-usage: "&cUsage: /mutesc <state>"
@@ -391,6 +397,9 @@ permission-list: "staffchat.list"
391397
# Permission | Staff (Permission needed to display on Staff List)
392398
permission-staff: "staffchat.staff"
393399

400+
# Permission | Chat Formatting
401+
permission-chat-format: "staffchat.format"
402+
394403
# Permission | Update Notification
395404
permission-update: "ultrastaffchat.update"
396405

@@ -406,4 +415,4 @@ permission-debug: "ultrastaffchat.debug"
406415

407416
# System | Configuration Version
408417
# Used for Internal purposes - Don't edit!
409-
version: 36
418+
version: 37

0 commit comments

Comments
 (0)