Skip to content

Commit

Permalink
UltraStaffChat BungeeCord - Version 5.1.0
Browse files Browse the repository at this point in the history
* Updated UpdateLib
* Added on/off configuration
* Added markdown support in staff chat messages
  • Loading branch information
LooFifteen authored May 9, 2021
2 parents 8348a54 + fb29dd2 commit 45bd8de
Show file tree
Hide file tree
Showing 8 changed files with 196 additions and 35 deletions.
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

<groupId>dev.hypera</groupId>
<artifactId>UltraStaffChat</artifactId>
<version>5.0.1</version>
<version>5.1.0</version>
<packaging>jar</packaging>

<name>UltraStaffChat</name>
Expand Down Expand Up @@ -86,8 +86,8 @@
<url>https://oss.sonatype.org/content/groups/public/</url>
</repository>
<repository>
<id>hypera-snapshots</id>
<url>https://repo.hypera.dev/snapshots/</url>
<id>hypera-releases</id>
<url>https://repo.hypera.dev/releases/</url>
</repository>
</repositories>

Expand All @@ -105,7 +105,7 @@
<dependency>
<groupId>dev.hypera</groupId>
<artifactId>UpdateLib</artifactId>
<version>2.1.1-SNAPSHOT</version>
<version>2.1.2</version>
</dependency>

<!-- Reflections for automatic registry -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,21 @@ public void execute(CommandSender sender, String[] args) {
if(args.length == 0) {
boolean toggled = StaffChat.toggleStaffChatMute();
if(toggled) {
audience.sendMessage(Common.adventurise(UltraStaffChat.getConfig().getString("mute-staffchat-message").replaceAll("\\{mute}", "&cmuted")));
audience.sendMessage(Common.adventurise(UltraStaffChat.getConfig().getString("mute-staffchat-message-on")));
} else
audience.sendMessage(Common.adventurise(UltraStaffChat.getConfig().getString("mute-staffchat-message").replaceAll("\\{mute}", "&aunmuted")));
audience.sendMessage(Common.adventurise(UltraStaffChat.getConfig().getString("mute-staffchat-message-off")));
return;
}

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,21 @@ public void execute(CommandSender sender, String[] args) {
if(args.length == 0) {
boolean toggled = StaffChat.toggleMessages(p);
if(toggled) {
audience.sendMessage(Common.adventurise(UltraStaffChat.getConfig().getString("mute-message").replaceAll("\\{mute}", "&cmuted")));
audience.sendMessage(Common.adventurise(UltraStaffChat.getConfig().getString("mute-message-on")));
} else
audience.sendMessage(Common.adventurise(UltraStaffChat.getConfig().getString("mute-message").replaceAll("\\{mute}", "&aunmuted")));
audience.sendMessage(Common.adventurise(UltraStaffChat.getConfig().getString("mute-message-off")));
return;
}

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,21 @@ public void execute(CommandSender sender, String[] args) {
if(args.length == 0) {
boolean toggled = StaffChat.toggleChatStaffChat(p);
if(toggled) {
audience.sendMessage(Common.adventurise(UltraStaffChat.getConfig().getString("toggle-message").replaceAll("\\{toggle}", "&aon")));
audience.sendMessage(Common.adventurise(UltraStaffChat.getConfig().getString("toggle-message-on")));
} else
audience.sendMessage(Common.adventurise(UltraStaffChat.getConfig().getString("toggle-message").replaceAll("\\{toggle}", "&coff")));
audience.sendMessage(Common.adventurise(UltraStaffChat.getConfig().getString("toggle-message-off")));
return;
}

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,9 @@
package dev.hypera.ultrastaffchat.managers;

import dev.hypera.ultrastaffchat.UltraStaffChat;
import dev.hypera.ultrastaffchat.events.staff.StaffChatEvent;
import dev.hypera.ultrastaffchat.events.staff.StaffJoinEvent;
import dev.hypera.ultrastaffchat.events.staff.StaffLeaveEvent;
import dev.hypera.ultrastaffchat.events.staff.StaffSwitchServerEvent;
import dev.hypera.ultrastaffchat.events.staff.StaffToggleAFKEvent;
import dev.hypera.ultrastaffchat.events.staff.*;
import dev.hypera.ultrastaffchat.utils.Discord;
import dev.hypera.ultrastaffchat.utils.MD_;
import dev.hypera.ultrastaffchat.utils.StaffChat;
import net.kyori.adventure.audience.Audience;
import net.md_5.bungee.api.CommandSender;
Expand All @@ -36,7 +33,8 @@

public class StaffChatManager {

public static void broadcastMessage(CommandSender sender, String message) {
public static void broadcastMessage(CommandSender sender, String m) {
String message = (sender.hasPermission(UltraStaffChat.getConfig().getString("permission-chat-format")) ? MD_.parseMarkdown(m) : m);
UltraStaffChat.getInstance().getAdventure().filter(person -> {
if(!person.hasPermission(messageRaw("permission-read")))
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/dev/hypera/ultrastaffchat/utils/Common.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class Common {

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

/**
Expand Down
154 changes: 154 additions & 0 deletions src/main/java/dev/hypera/ultrastaffchat/utils/MD_.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
/*
* MIT License
*
* Copyright (c) 2018 Aeternum Network
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package dev.hypera.ultrastaffchat.utils;

import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.plugin.Listener;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class MD_ implements Listener {

public static String parseMarkdown(String message) {
String translated = message;

translated = replaceWith(translated, "(?<!\\\\)\\*\\*", ChatColor.COLOR_CHAR + "z", ChatColor.COLOR_CHAR + "Z");
translated = replaceWith(translated, "(?<!\\\\)\\*", ChatColor.COLOR_CHAR + "x", ChatColor.COLOR_CHAR + "X");
translated = replaceWith(translated, "(?<!\\\\)__", ChatColor.COLOR_CHAR + "v", ChatColor.COLOR_CHAR + "V");
translated = replaceWith(translated, "(?<!\\\\)_", ChatColor.COLOR_CHAR + "q", ChatColor.COLOR_CHAR + "Q");
translated = replaceWith(translated, "(?<!\\\\)~~", ChatColor.COLOR_CHAR + "m", ChatColor.COLOR_CHAR + "M");
translated = replaceWith(translated, "(?<!\\\\)~", ChatColor.COLOR_CHAR + "w", ChatColor.COLOR_CHAR + "W");

translated = translated.replace("\\*", "*").replace("\\_", "_").replace("\\~", "~");

return parseParts(translated).toString();
}

private static StringBuilder parseParts(String translated) {
String partForPart = (" " + translated);
String[] parts = partForPart.split("" + ChatColor.COLOR_CHAR);
StringBuilder builder = new StringBuilder();
for (String part : parts) {
if (part.isEmpty()) {
continue;
}
parsePart(part, builder);
}
return builder;
}

private static void parsePart(String part, StringBuilder builder) {
char colorCharacter = part.charAt(0);
ChatColor color = ChatColor.getByChar(colorCharacter);

String colors = getLastColors(builder.toString());
if (color != null) {
StringBuilder colorBuilder = new StringBuilder();
for (String cc : colors.split(ChatColor.COLOR_CHAR + "")) {
if (cc.isEmpty()) {
continue;
}
if (isFormat(ChatColor.getByChar(cc.charAt(0)))) {
colorBuilder.append(ChatColor.COLOR_CHAR + cc);
}
}
builder.append(color + colorBuilder.toString());
} else {
colors = parseColours(colorCharacter, builder, colors);
}
if (part.length() > 1) {
builder.append(part.substring(1));
}
}

private static String parseColours(char colorCharacter, StringBuilder builder, String c) {
String colors = c;
if (colorCharacter == 'z') builder.append(ChatColor.BOLD);
else if (colorCharacter == 'x') builder.append(ChatColor.ITALIC);
else if (colorCharacter == 'v') builder.append(ChatColor.UNDERLINE);
else if (colorCharacter == 'q') builder.append(ChatColor.ITALIC);
else if (colorCharacter == 'm') builder.append(ChatColor.STRIKETHROUGH);
else if (colorCharacter == 'w') builder.append(ChatColor.MAGIC);
else if (colorCharacter == 'Z') colors = colors.replace(ChatColor.BOLD.toString(), "");
else if (colorCharacter == 'X') colors = colors.replace(ChatColor.ITALIC.toString(), "");
else if (colorCharacter == 'V') colors = colors.replace(ChatColor.UNDERLINE.toString(), "");
else if (colorCharacter == 'Q') colors = colors.replace(ChatColor.ITALIC.toString(), "");
else if (colorCharacter == 'M') colors = colors.replace(ChatColor.STRIKETHROUGH.toString(), "");
else if (colorCharacter == 'W') colors = colors.replace(ChatColor.MAGIC.toString(), "");
if (Character.isUpperCase(colorCharacter)) builder.append(ChatColor.RESET + colors);
return colors;
}

private static String replaceWith(String message, String quot, String pre, String suf) {
String part = message;
for (String str : getMatches(message, quot + "(.+?)" + quot)) {
part = part.replaceFirst(quot + Pattern.quote(str) + quot, pre + str + suf);
}
return part;
}

public static List<String> getMatches(String string, String regex) {
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(string);
List<String> matches = new ArrayList<String>();
while (matcher.find()) {
matches.add(matcher.group(1));
}
return matches;
}

private static boolean isFormat(ChatColor color) {
return color == ChatColor.MAGIC || color == ChatColor.BOLD || color == ChatColor.STRIKETHROUGH || color == ChatColor.ITALIC || color == ChatColor.UNDERLINE;
}

private static String getLastColors(String input) {
String result = "";
int length = input.length();

// Search backwards from the end as it is faster
for (int index = length - 1; index > -1; index--) {
char section = input.charAt(index);
if (section == ChatColor.COLOR_CHAR && index < length - 1) {
char c = input.charAt(index + 1);
ChatColor color = ChatColor.getByChar(c);

if (color != null) {
result = color.toString() + result;

// Once we find a color or reset we can stop searching
if (!isFormat(color) || color.equals(ChatColor.RESET)) {
break;
}
}
}
}

return result;
}

}
29 changes: 19 additions & 10 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,11 @@ staffchat-prefix: "#"
# Toggle | Enabled
toggle-enabled: true

# Toggle | Message
# - Placeholders: &aOn/&cOff - {toggle}
toggle-message: "&8[&4&lStaffChat&8] &cStaffChat Toggled {toggle}&c!"
# Toggle On | Message
toggle-message-on: "&8[&4&lStaffChat&8] &cStaffChat Toggled &aOn&c!"

# Toggle Off | Message
toggle-message-off: "&8[&4&lStaffChat&8] &cStaffChat Toggled &cOff&c!"

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

# Mute | Message
# - Placeholders: &cMuted/&aUnmuted - {mute}
mute-message: "&8[&4&lStaffChat&8] &cStaffChat {mute}&c!"
# Mute On | Message
mute-message-on: "&8[&4&lStaffChat&8] &cStaffChat &cMuted&c!"

# Mute Off | Message
mute-message-off: "&8[&4&lStaffChat&8] &cStaffChat &aUnmuted&c!"

# Mute | Usage
mute-usage: "&cUsage: /scmute <state>"
Expand All @@ -267,9 +271,11 @@ mute-usage: "&cUsage: /scmute <state>"
# Mute | Enabled
mute-staffchat-enabled: true

# Mute | Message
# - Placeholders: &cMuted/&aUnmuted - {mute}
mute-staffchat-message: "&8[&4&lStaffChat&8] &cStaffChat has been {mute}&c!"
# Mute On | Message
mute-staffchat-message-on: "&8[&4&lStaffChat&8] &cStaffChat has been &cMuted&c!"

# Mute Off | Message
mute-staffchat-message-off: "&8[&4&lStaffChat&8] &cStaffChat has been &aUnmuted&c!"

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

# Permission | Chat Formatting
permission-chat-format: "staffchat.format"

# Permission | Update Notification
permission-update: "ultrastaffchat.update"

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

# System | Configuration Version
# Used for Internal purposes - Don't edit!
version: 36
version: 37

0 comments on commit 45bd8de

Please sign in to comment.