Skip to content

Commit ef04874

Browse files
committed
fix: migrate pin feature + e2e fixtures to BanManager v8 placeholder syntax
BanManager v8 dropped legacy [token] placeholders in favour of MiniMessage <token> tags, and rejects messages containing legacy & colour codes outright. Without this migration the pin feature silently no-ops and every e2e ban / tempban kick test sees the unsubstituted "<pin>" template (or, after rejection, the bundled defaults that have no pin placeholder at all). - CommonPlayerDeniedListener: detect <pin> via Message.getRawTemplate() (the resolved string is a Component-backed legacy render and never contains the raw template token after v8). Bail when the template has no <pin>. - Bundled common/src/main/resources/messages.yml: rewrite pin.notify / pin.pin / pin.rateLimited in MiniMessage format with <pin>, <expires>, <seconds>. - e2e fixtures (bukkit / bungee / fabric / sponge / velocity): - banmanager-webenhancer/messages.yml: same MiniMessage rewrite. - banmanager/messages.yml: shrink from a full clone of the legacy messages.yml to a minimal MiniMessage override of just ban / tempban / banip / tempbanip kick + disallowed templates so the WebEnhancer pin feature has a <pin> token to substitute. Everything else falls through to BanManager v8's bundled defaults. - Update CommonPlayerDeniedListenerTest to mock getRawTemplate() and add a null-template case.
1 parent 56204f3 commit ef04874

13 files changed

Lines changed: 117 additions & 1954 deletions

File tree

common/src/main/java/me/confuser/banmanager/webenhancer/common/listeners/CommonPlayerDeniedListener.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ public CommonPlayerDeniedListener(WebEnhancerPlugin plugin) {
1313
}
1414

1515
public void handlePin(PlayerData player, Message message) {
16-
if (!message.toString().contains("[pin]")) return;
16+
String template = message.getRawTemplate();
17+
if (template == null || !template.contains("<pin>")) return;
1718

1819
PlayerPinData pin = plugin.getPlayerPinStorage().getValidPin(player);
1920

20-
2121
if (pin != null) {
2222
message.set("pin", String.valueOf(pin.getGeneratedPin()));
2323
}
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
# Message templates use MiniMessage formatting: https://docs.advntr.dev/minimessage/format.html
2+
# Placeholders use angle brackets, e.g. <pin>, <expires>, <seconds>
3+
14
messages:
25
pin:
3-
notify: '&6Your pin expires in [expires]'
4-
pin: '[pin]'
5-
rateLimited: '&cPlease wait [seconds] seconds before generating a new pin'
6+
notify: '<gold>Your pin expires in <expires>'
7+
pin: '<pin>'
8+
rateLimited: '<red>Please wait <seconds> seconds before generating a new pin'

common/src/test/java/me/confuser/banmanager/webenhancer/common/listeners/CommonPlayerDeniedListenerTest.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,11 @@ public void setUp() {
3939

4040
@Test
4141
public void handlePin_replacesPlaceholderWithPin() {
42-
// Setup
4342
when(playerPinStorage.getValidPin(player)).thenReturn(pinData);
4443
when(pinData.getGeneratedPin()).thenReturn(123456);
4544

46-
// Create a mocked message with [pin] placeholder
4745
Message message = mock(Message.class);
48-
when(message.toString()).thenReturn("Your login pin is: [pin]");
46+
when(message.getRawTemplate()).thenReturn("Your login pin is: <pin>");
4947

5048
listener.handlePin(player, message);
5149

@@ -54,9 +52,19 @@ public void handlePin_replacesPlaceholderWithPin() {
5452

5553
@Test
5654
public void handlePin_ignoresMessagesWithoutPlaceholder() {
57-
// Create a mocked message without [pin] placeholder
5855
Message message = mock(Message.class);
59-
when(message.toString()).thenReturn("You have been banned!");
56+
when(message.getRawTemplate()).thenReturn("You have been banned!");
57+
58+
listener.handlePin(player, message);
59+
60+
verify(playerPinStorage, never()).getValidPin(any());
61+
verify(message, never()).set(anyString(), anyString());
62+
}
63+
64+
@Test
65+
public void handlePin_ignoresMessagesWithNullTemplate() {
66+
Message message = mock(Message.class);
67+
when(message.getRawTemplate()).thenReturn(null);
6068

6169
listener.handlePin(player, message);
6270

@@ -66,12 +74,10 @@ public void handlePin_ignoresMessagesWithoutPlaceholder() {
6674

6775
@Test
6876
public void handlePin_handlesNullPinGracefully() {
69-
// Setup - getValidPin returns null
7077
when(playerPinStorage.getValidPin(player)).thenReturn(null);
7178

72-
// Create a mocked message with [pin] placeholder
7379
Message message = mock(Message.class);
74-
when(message.toString()).thenReturn("Your login pin is: [pin]");
80+
when(message.getRawTemplate()).thenReturn("Your login pin is: <pin>");
7581

7682
listener.handlePin(player, message);
7783

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
messages:
22
pin:
3-
notify: '&6Your pin expires in [expires]'
4-
pin: '[pin]'
5-
3+
notify: '<gold>Your pin expires in <expires>'
4+
pin: '<pin>'
5+
rateLimited: '<red>Please wait <seconds> seconds before generating a new pin'

0 commit comments

Comments
 (0)