Skip to content

Commit

Permalink
feat PM short channel name (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zickles authored Jul 19, 2024
1 parent 9ee12d5 commit 9ff12e8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/main/java/org/polyfrost/hytils/config/HytilsConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,13 @@ public class HytilsConfig extends Config {
)
public static boolean shortChannelNames;

@Switch(
name = "Short Private Message Channel Names",
description = "Abbreviate private message channel names.\n§eExample: §dTo and §dFrom §e-> PM",
category = "Chat", subcategory = "Visual"
)
public static boolean pmShortChannelNames;

@Switch(
name = "Party Chat Swapper",
description = "Automatically change to and out of a party channel when joining/leaving a party.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,18 @@ public void onMessageReceived(@NotNull ClientChatReceivedEvent event) {
}
}

if (HytilsConfig.pmShortChannelNames) {
Matcher privateMessageToMatcher = language.chatRestylerPrivateMessageToPatternRegex.matcher(message);
Matcher privateMessageFromMatcher = language.chatRestylerPrivateMessageFromPatternRegex.matcher(message);
if (privateMessageToMatcher.find()) {
event.message = shortenChannelName(event.message, language.chatRestylerPrivateMessageToPatternRegex.pattern(),
"§d" + "PM >", true);
} else if (privateMessageFromMatcher.find()) {
event.message = shortenChannelName(event.message, language.chatRestylerPrivateMessageFromPatternRegex.pattern(),
"§5" + "PM <", true);
}
}

if (HytilsConfig.coloredStatuses) {
Matcher statusMatcher = getLanguage().chatRestylerStatusPatternRegex.matcher(event.message.getFormattedText().trim());
if (statusMatcher.matches()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ public class LanguageData {
private String chatRestylerFriendPattern = "^((?:\u00a7r)?\u00a7\\w)(Friend >)";
private String chatRestylerOfficerPattern = "^((?:\u00a7r)?\u00a7\\w)(Officer >)";
private String chatRestylerStatusPattern = "^(?<type>(?:\u00a7aFriend|\u00a7a\u00a7aF|\u00a72Guild|\u00a72\u00a72G)) > (\u00a7r|\u00a7r\u00a7r){1,2}(?<player>\u00a7[\\da-f]\\w{1,16}) \u00a7r\u00a7e(?<status>(?:joined|left))\\.\u00a7r$";
private String chatRestylerPrivateMessageToPattern = "^((?:\u00a7r)?\u00a7\\w)(To)";
private String chatRestylerPrivateMessageFromPattern = "^((?:\u00a7r)?\u00a7\\w)(From)";

private String autoChatSwapperPartyStatus = "^(?:You have been kicked from the party by (?:\\[.+] )?\\w{1,16}|(?:\\[.+] )?\\w{1,16} has disbanded the party!|You left the party.)$";
private String autoChatSwapperPartyStatus2 = "^(?:You have joined (?:\\[.+] )?(?:.*)|Party Members(?:\\[.+] )?\\w{1,100}|(?:\\[.+] )?\\w{1,100} joined the(?:.*) party(?:.*))$";
Expand Down Expand Up @@ -157,6 +159,8 @@ public class LanguageData {
public Pattern chatRestylerFriendPatternRegex;
public Pattern chatRestylerOfficerPatternRegex;
public Pattern chatRestylerStatusPatternRegex;
public Pattern chatRestylerPrivateMessageToPatternRegex;
public Pattern chatRestylerPrivateMessageFromPatternRegex;

public Pattern autoChatSwapperPartyStatusRegex;
public Pattern autoChatSwapperPartyStatusRegex2;
Expand Down Expand Up @@ -223,6 +227,8 @@ public void initialize() {
chatRestylerFriendPatternRegex = Pattern.compile(chatRestylerFriendPattern);
chatRestylerOfficerPatternRegex = Pattern.compile(chatRestylerOfficerPattern);
chatRestylerStatusPatternRegex = Pattern.compile(chatRestylerStatusPattern);
chatRestylerPrivateMessageToPatternRegex = Pattern.compile(chatRestylerPrivateMessageToPattern);
chatRestylerPrivateMessageFromPatternRegex = Pattern.compile(chatRestylerPrivateMessageFromPattern);

autoChatSwapperPartyStatusRegex = Pattern.compile(autoChatSwapperPartyStatus);
autoChatSwapperPartyStatusRegex2 = Pattern.compile(autoChatSwapperPartyStatus2);
Expand Down

0 comments on commit 9ff12e8

Please sign in to comment.