Skip to content

Commit c594150

Browse files
committed
Make Votifier channel configurable
1 parent 451faae commit c594150

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

src/main/java/nl/hauntedmc/serverfeatures/features/votifier/Votifier.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
public class Votifier extends BukkitBaseFeature<Meta> {
1515

16-
private static final String CHANNEL = "vote"; // must match proxy publisher
16+
private static final String DEFAULT_CHANNEL = "proxy.votifier.vote";
1717
private static final String CONNECTION = "hauntedmc";
1818

1919
private EventBusHandler eventBusHandler;
@@ -26,6 +26,7 @@ public Votifier(ServerFeatures plugin) {
2626
public ConfigMap getDefaultConfig() {
2727
ConfigMap cfg = new ConfigMap();
2828
cfg.put("enabled", false);
29+
cfg.put("channel", DEFAULT_CHANNEL);
2930
return cfg;
3031
}
3132

@@ -47,9 +48,15 @@ public void initialize() {
4748
throw new IllegalStateException("Redis messaging provider is not available for feature '" + getFeatureName() + "'.");
4849
}
4950

50-
// Subscribe to the vote channel
51+
String configuredChannel = getConfigHandler().get("channel", String.class, DEFAULT_CHANNEL);
52+
String channel = resolveChannel(configuredChannel);
53+
54+
if (configuredChannel == null || configuredChannel.isBlank()) {
55+
getLogger().warning("Configured Votifier channel is blank; falling back to \"" + DEFAULT_CHANNEL + "\".");
56+
}
57+
5158
this.eventBusHandler = new EventBusHandler(this, redisBus.get());
52-
this.eventBusHandler.subscribe(CHANNEL);
59+
this.eventBusHandler.subscribe(channel);
5360
}
5461

5562
@Override
@@ -59,4 +66,13 @@ public void disable() {
5966
eventBusHandler = null;
6067
}
6168
}
69+
70+
static String resolveChannel(String configuredChannel) {
71+
if (configuredChannel == null) {
72+
return DEFAULT_CHANNEL;
73+
}
74+
75+
String channel = configuredChannel.trim();
76+
return channel.isEmpty() ? DEFAULT_CHANNEL : channel;
77+
}
6278
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package nl.hauntedmc.serverfeatures.features.votifier;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import static org.junit.jupiter.api.Assertions.assertEquals;
6+
7+
class VotifierTest {
8+
9+
@Test
10+
void resolveChannelFallsBackToDefaultWhenMissing() {
11+
assertEquals("proxy.votifier.vote", Votifier.resolveChannel(null));
12+
assertEquals("proxy.votifier.vote", Votifier.resolveChannel(""));
13+
assertEquals("proxy.votifier.vote", Votifier.resolveChannel(" "));
14+
}
15+
16+
@Test
17+
void resolveChannelUsesTrimmedConfiguredValue() {
18+
assertEquals("proxy.custom.vote", Votifier.resolveChannel(" proxy.custom.vote "));
19+
}
20+
}

0 commit comments

Comments
 (0)