Add method to remove string at start
A new method `removeStringAtStart` has been added to the `ModifiableString` class. It replaces the starting string in a given text. Also, a condition has been modified in the `ChatListener` class to invoke this new method when the input string starts with the `APRIL_FOOLS_RESET` string. Additional unit tests were created to validate these changes.
This commit is contained in:
@@ -61,4 +61,8 @@ public class ModifiableString {
|
||||
return list;
|
||||
}));
|
||||
}
|
||||
|
||||
public void removeStringAtStart(String s) {
|
||||
text = text.replaceText(TextReplacementConfig.builder().match("^" + s).replacement("").build());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import com.alttd.chat.config.Config;
|
||||
import com.alttd.chat.objects.ModifiableString;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
@@ -20,6 +21,31 @@ public class ReverseTest {
|
||||
assertEquals(expectedOutput, modifiableString.string());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveKeyword() {
|
||||
String input = "Hello how are you doing today?";
|
||||
MiniMessage miniMessage = MiniMessage.miniMessage();
|
||||
|
||||
ModifiableString modifiableString = new ModifiableString(miniMessage.deserialize(Config.APRIL_FOOLS_RESET + " " + input));
|
||||
modifiableString.removeStringAtStart(Config.APRIL_FOOLS_RESET + " ");
|
||||
|
||||
assertEquals(input, modifiableString.string());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveKeywordWithTags() {
|
||||
MiniMessage miniMessage = MiniMessage.miniMessage();
|
||||
String input = "<blue>" + Config.APRIL_FOOLS_RESET + " <red>Hello how are</red> you <blue>doing today</blue>?</blue>";
|
||||
String expectedOutput = "Hello how are you doing today?";
|
||||
Component deserialize = miniMessage.deserialize(input);
|
||||
|
||||
ModifiableString modifiableString = new ModifiableString(deserialize);
|
||||
modifiableString.removeStringAtStart(Config.APRIL_FOOLS_RESET + " ");
|
||||
|
||||
assertEquals(expectedOutput, modifiableString.string());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testReverseStringWithTags() {
|
||||
String input = "<red>Hello how are</red> you <blue>doing today</blue>?";
|
||||
|
||||
Reference in New Issue
Block a user