Skip to content

Commit 62c031a

Browse files
committed
feat: add channel relay and MiniMessage controls
1 parent 3fdb6d9 commit 62c031a

9 files changed

Lines changed: 70 additions & 52 deletions

File tree

api/src/main/java/com/bitaspire/sir/channel/ChatChannel.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ public interface ChatChannel extends PermissibleUnit {
2424
*/
2525
boolean isGlobal();
2626

27+
/**
28+
* Returns whether messages from this channel should be relayed through the Discord module.
29+
*
30+
* @return {@code true} if Discord relay is enabled for this channel.
31+
*/
32+
default boolean relayToDiscord() {
33+
return false;
34+
}
35+
2736
/**
2837
* Returns whether this channel is local (radius-based), i.e., not global.
2938
*

api/src/main/java/com/bitaspire/sir/channel/Style.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,15 @@ public interface Style {
6666
*/
6767
boolean allowsRgbColors();
6868

69+
/**
70+
* Returns whether players may use MiniMessage tags.
71+
*
72+
* @return {@code true} if MiniMessage tags are allowed.
73+
*/
74+
default boolean allowsMiniMessage() {
75+
return false;
76+
}
77+
6978
/**
7079
* Returns the click action attached to messages in this channel, if any.
7180
*

module/channels/src/main/java/com/bitaspire/sir/module/channel/Factory.java

Lines changed: 31 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,9 @@
99
import com.bitaspire.sir.channel.Logging;
1010
import com.bitaspire.sir.channel.Style;
1111
import com.bitaspire.sir.module.channel.channel.Resolver;
12-
import com.bitaspire.sir.user.ColorData;
1312
import com.bitaspire.sir.user.SIRUser;
14-
import lombok.AccessLevel;
15-
import lombok.Getter;
16-
import lombok.RequiredArgsConstructor;
17-
import lombok.Setter;
13+
import lombok.*;
14+
import lombok.experimental.Accessors;
1815
import lombok.experimental.UtilityClass;
1916
import me.croabeast.common.CollectionBuilder;
2017
import me.croabeast.common.applier.StringApplier;
@@ -59,6 +56,8 @@ abstract class BaseChannel implements ChatChannel {
5956

6057
private final String permission;
6158
private final int priority;
59+
@Accessors(fluent = true)
60+
private final boolean relayToDiscord;
6261

6362
private final Access access;
6463
private final Audience audience;
@@ -85,6 +84,7 @@ abstract class BaseChannel implements ChatChannel {
8584
"priority", ChatChannel::getPriority,
8685
permission.matches("(?i)DEFAULT") ? 0 : 1
8786
);
87+
relayToDiscord = fromParent("relay-to-discord", ChatChannel::relayToDiscord, false);
8888

8989
access = new AccessImpl(
9090
fromParent("access.default", c -> c.getAccess().isDefault(), false),
@@ -110,6 +110,7 @@ abstract class BaseChannel implements ChatChannel {
110110
fromParent("color-options.normal", c -> c.getStyle().allowsNormalColors(), false),
111111
fromParent("color-options.special", c -> c.getStyle().allowsSpecialColors(), false),
112112
fromParent("color-options.rgb", c -> c.getStyle().allowsRgbColors(), false),
113+
fromParent("color-options.mini-message", c -> c.getStyle().allowsMiniMessage(), false),
113114
clickAction(),
114115
fromList("hover", c -> c.getStyle().getHover()),
115116
fromParent("format", c -> c.getStyle().getFormat(), DEFAULT_FORMAT).trim()
@@ -118,7 +119,8 @@ abstract class BaseChannel implements ChatChannel {
118119
checker = new ColorChecker(
119120
style.allowsNormalColors(),
120121
style.allowsSpecialColors(),
121-
style.allowsRgbColors()
122+
style.allowsRgbColors(),
123+
style.allowsMiniMessage()
122124
);
123125

124126
logging = new LoggingImpl(
@@ -127,12 +129,6 @@ abstract class BaseChannel implements ChatChannel {
127129
);
128130
}
129131

130-
@NotNull
131-
@Override
132-
public String getName() {
133-
return name;
134-
}
135-
136132
private boolean useParents(String path) {
137133
return !section.isSet(path) && parent != null;
138134
}
@@ -282,18 +278,12 @@ public String[] getChatValues(SIRUser user, String message) {
282278

283279
@NotNull
284280
private String chatColorStart(@Nullable SIRUser user) {
285-
if (user == null) return "";
286-
287-
ColorData data = user.getColorData();
288-
return data == null ? "" : StringUtils.defaultString(data.getStart());
281+
return user == null ? "" : StringUtils.defaultString(user.getColorData().getStart());
289282
}
290283

291284
@NotNull
292285
private String chatColorEnd(@Nullable SIRUser user) {
293-
if (user == null) return "";
294-
295-
ColorData data = user.getColorData();
296-
return data == null ? "" : StringUtils.defaultString(data.getEnd());
286+
return user == null ? "" : StringUtils.defaultString(user.getColorData().getEnd());
297287
}
298288

299289
private boolean hasPermission(SIRUser user, String permission) {
@@ -340,12 +330,13 @@ public String toString() {
340330
return "BaseChannel{path=" + section.getCurrentPath() +
341331
", permission='" + permission + '\'' +
342332
", priority=" + priority + ", global=" + global +
333+
", relayToDiscord=" + relayToDiscord +
343334
", format='" + style.getFormat() + '\'' + '}';
344335
}
345336
}
346337

347-
@Getter
348338
@RequiredArgsConstructor
339+
@Getter
349340
class AccessImpl implements Access {
350341

351342
private final boolean defaultAccess;
@@ -372,8 +363,8 @@ public String toString() {
372363
}
373364
}
374365

375-
@Getter
376366
@RequiredArgsConstructor
367+
@Getter
377368
class AudienceImpl implements Audience {
378369

379370
private final int radius;
@@ -399,8 +390,8 @@ public String toString() {
399390
}
400391
}
401392

402-
@Getter
403393
@RequiredArgsConstructor
394+
@Getter
404395
class ClickImpl implements Click {
405396

406397
private final ChatComponent.Click action;
@@ -424,6 +415,7 @@ public String toString() {
424415
}
425416
}
426417

418+
@AllArgsConstructor
427419
@Getter
428420
class StyleImpl implements Style {
429421

@@ -434,36 +426,13 @@ class StyleImpl implements Style {
434426
private final boolean normalColors;
435427
private final boolean specialColors;
436428
private final boolean rgbColors;
429+
private final boolean miniMessage;
437430
private final Click click;
438431
private final List<String> hover;
439432

440433
@Setter
441434
private String format;
442435

443-
private StyleImpl(
444-
String tag,
445-
String prefix,
446-
String suffix,
447-
String color,
448-
boolean normalColors,
449-
boolean specialColors,
450-
boolean rgbColors,
451-
Click click,
452-
List<String> hover,
453-
String format
454-
) {
455-
this.tag = tag;
456-
this.prefix = prefix;
457-
this.suffix = suffix;
458-
this.color = color;
459-
this.normalColors = normalColors;
460-
this.specialColors = specialColors;
461-
this.rgbColors = rgbColors;
462-
this.click = click;
463-
this.hover = hover;
464-
this.format = format;
465-
}
466-
467436
@Override
468437
public boolean allowsNormalColors() {
469438
return normalColors;
@@ -479,6 +448,11 @@ public boolean allowsRgbColors() {
479448
return rgbColors;
480449
}
481450

451+
@Override
452+
public boolean allowsMiniMessage() {
453+
return miniMessage;
454+
}
455+
482456
@Override
483457
public String toString() {
484458
return "Style{tag='" + tag + '\'' +
@@ -488,12 +462,13 @@ public String toString() {
488462
", normal=" + normalColors +
489463
", special=" + specialColors +
490464
", rgb=" + rgbColors +
465+
", miniMessage=" + miniMessage +
491466
", format='" + format + '\'' + '}';
492467
}
493468
}
494469

495-
@Getter
496470
@RequiredArgsConstructor
471+
@Getter
497472
class LoggingImpl implements Logging {
498473

499474
private final boolean enabled;
@@ -509,7 +484,7 @@ public String toString() {
509484
class ColorChecker {
510485

511486
static final String PERM = "sir.color.chat.";
512-
final boolean normal, special, rgb;
487+
final boolean normal, special, rgb, miniMessage;
513488

514489
boolean notColor(Player player, String perm) {
515490
boolean allowed;
@@ -520,6 +495,9 @@ boolean notColor(Player player, String perm) {
520495
case "rgb":
521496
allowed = rgb;
522497
break;
498+
case "mini-message":
499+
allowed = miniMessage;
500+
break;
523501
case "normal":
524502
default:
525503
allowed = normal;
@@ -538,13 +516,16 @@ String check(Player player, String string) {
538516
applier.apply(PrismaticAPI::stripRGB);
539517
if (notColor(player, "special"))
540518
applier.apply(PrismaticAPI::stripSpecial);
519+
if (notColor(player, "mini-message"))
520+
applier.apply(PrismaticAPI::stripMiniMessage);
541521

542522
return applier.toString();
543523
}
544524

545525
@Override
546526
public String toString() {
547-
return "ColorChecker{normal=" + normal + ", special=" + special + ", rgb=" + rgb + '}';
527+
return "ColorChecker{normal=" + normal + ", special=" + special +
528+
", rgb=" + rgb + ", miniMessage=" + miniMessage + '}';
548529
}
549530
}
550531
}

module/channels/src/main/java/com/bitaspire/sir/module/channel/Listener.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ private boolean isVisibleBlank(String message) {
4747

4848
String stripped = RGB_HEX_CODE.matcher(message).replaceAll("");
4949
stripped = PrismaticAPI.stripAll(stripped);
50-
stripped = ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', stripped));
50+
stripped = ChatColor.stripColor(PrismaticAPI.colorize(stripped));
5151

5252
return StringUtils.isBlank(stripped);
5353
}
@@ -163,7 +163,7 @@ private void onSIRChat(ChatEvent event) {
163163
String message = event.getMessage();
164164

165165
ModuleManager manager = main.getApi().getModuleManager();
166-
if (manager.isEnabled("Discord")) {
166+
if (channel.relayToDiscord() && manager.isEnabled("Discord")) {
167167
String m = lib.getPlaceholderManager().replace(player, message);
168168
String name = event.isGlobal() ? "global-chat" : channel.getName();
169169

module/channels/src/main/java/com/bitaspire/sir/module/channel/channel/Exporter.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ private void writeSection(@NotNull ConfigurationSection source, @NotNull Configu
5353
setIfPresent(source, target, "enabled");
5454
setIfPresent(source, target, "description");
5555
setIfPresent(source, target, "priority");
56+
setIfPresent(source, target, "relay-to-discord");
5657
setIfPresent(source, target, "permission");
5758
setIfPresent(source, target, "group");
5859
setIfPresent(source, target, "inherits");
@@ -111,6 +112,7 @@ private void writeStyle(@NotNull ConfigurationSection source, @NotNull Configura
111112
colors.set("normal", source.getBoolean("color-options.normal", false));
112113
colors.set("special", source.getBoolean("color-options.special", false));
113114
colors.set("rgb", source.getBoolean("color-options.rgb", false));
115+
colors.set("mini-message", source.getBoolean("color-options.mini-message", false));
114116

115117
writeClick(source, style);
116118
}

module/channels/src/main/java/com/bitaspire/sir/module/channel/channel/ModernParser.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ private void apply(@Nullable ConfigurationSection source, @NotNull Configuration
126126
copy(source, target, "description");
127127
copy(source, target, "priority");
128128
copy(source, target, "global");
129+
copy(source, target, "relay-to-discord");
129130
copy(source, target, "permission");
130131
copy(source, target, "group");
131132

@@ -148,6 +149,7 @@ private void apply(@Nullable ConfigurationSection source, @NotNull Configuration
148149
copy(source, target, "style.colors.normal", "color-options.normal");
149150
copy(source, target, "style.colors.special", "color-options.special");
150151
copy(source, target, "style.colors.rgb", "color-options.rgb");
152+
copy(source, target, "style.colors.mini-message", "color-options.mini-message");
151153
copy(source, target, "style.hover", "hover");
152154
copy(source, target, "style.format", "format");
153155
copy(source, target, "style.click.action", "click.action");
@@ -186,6 +188,7 @@ private void finalize(@NotNull ConfigurationSection target, boolean defaults) {
186188
Resolver.setIfAbsent(target, "access.strip-prefix", true);
187189
Resolver.setIfAbsent(target, "logging.enabled", false);
188190
Resolver.setIfAbsent(target, "access.default", defaults);
191+
Resolver.setIfAbsent(target, "relay-to-discord", false);
189192

190193
int radius = Math.max(0, target.getInt("radius", 0));
191194
target.set("radius", radius);

module/channels/src/main/java/com/bitaspire/sir/module/channel/channel/Resolver.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ public void promoteModernAliases(@NotNull ConfigurationSection section) {
9595
alias(section, "color-options.normal", "style.colors.normal");
9696
alias(section, "color-options.special", "style.colors.special");
9797
alias(section, "color-options.rgb", "style.colors.rgb");
98+
alias(section, "color-options.mini-message", "style.colors.mini-message");
9899
alias(section, "hover", "style.hover");
99100
alias(section, "format", "style.format");
100101
alias(section, "click.action", "style.click.action");

module/channels/src/main/resources/channels.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ default-channel:
4444
special: false
4545
# Allows RGB or hex colors when supported by the server.
4646
rgb: false
47+
# Allows MiniMessage tags in player messages.
48+
mini-message: false
4749
# Channel color used by {color}. If unset, {color} falls back to the sender's chat color.
4850
default: '&f'
4951
# Final chat line. Common placeholders: {tag}, {player}, {color}, {chat-color}, {color-start}, {color-end}, and {message}.
@@ -52,6 +54,9 @@ default-channel:
5254
logging:
5355
# If false, SIR uses the legacy/global chat logger behavior.
5456
enabled: false
57+
# If true, messages from this channel are relayed through the Discord module.
58+
# This is independent of radius/global delivery; keep false for staff/private channels.
59+
relay-to-discord: false
5560

5661
# Additional named channels. Each child key is the channel ID used by commands and user settings.
5762
channels:
@@ -77,6 +82,8 @@ channels:
7782
hover:
7883
- '&7Message sent to the whole server.'
7984
format: '{tag} &7{player}&8: {color}{message}'
85+
# Enable this only if this channel should be sent to Discord.
86+
relay-to-discord: false
8087

8188
# Staff-only channel example.
8289
staff:
@@ -98,6 +105,7 @@ channels:
98105
normal: true
99106
special: true
100107
rgb: true
108+
mini-message: false
101109
default: '&c'
102110
hover:
103111
- '&7Only visible to staff.'
@@ -106,6 +114,8 @@ channels:
106114
enabled: true
107115
# Format used by the channel-specific logger.
108116
format: '&7[Staff] {player}: {message}'
117+
# Keep false to avoid sending staff chat to Discord.
118+
relay-to-discord: false
109119

110120
# Local member channel example with distance and permission filters.
111121
member-local:
@@ -124,6 +134,7 @@ channels:
124134
prefix: '&6Member'
125135
colors:
126136
normal: true
137+
mini-message: false
127138
default: '&f'
128139
format: '{tag} {prefix} &7{player}&8: {color}{message}'
129140

plugin/src/main/java/com/bitaspire/sir/MigrationService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,8 @@ private void migrateLegacySirChannelSection(
420420
target.set("style.colors.special", source.getBoolean("color-options.special", false));
421421
if (defaults || source.isSet("color-options.rgb"))
422422
target.set("style.colors.rgb", source.getBoolean("color-options.rgb", false));
423+
if (defaults || source.isSet("color-options.mini-message"))
424+
target.set("style.colors.mini-message", source.getBoolean("color-options.mini-message", false));
423425

424426
List<String> hover = source.getStringList("hover");
425427
if (!hover.isEmpty())

0 commit comments

Comments
 (0)