Skip to content

Commit 87369a2

Browse files
authored
Merge pull request #9 from Iridium-Development/feature/color-stripping
Add color stripping method
2 parents c794546 + 2c39773 commit 87369a2

3 files changed

Lines changed: 40 additions & 2 deletions

File tree

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
# Project exclude paths
22
.idea/
3-
.gradle/
4-
build/
3+
target/

IridiumColorAPI.iml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
3+
<component name="FacetManager">
4+
<facet type="minecraft" name="Minecraft">
5+
<configuration>
6+
<autoDetectTypes>
7+
<platformType>SPIGOT</platformType>
8+
<platformType>MCP</platformType>
9+
</autoDetectTypes>
10+
</configuration>
11+
</facet>
12+
</component>
13+
<component name="McpModuleSettings">
14+
<option name="srgType" value="SRG" />
15+
</component>
16+
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
17+
<output url="file://$MODULE_DIR$/target/classes" />
18+
<output-test url="file://$MODULE_DIR$/target/test-classes" />
19+
<content url="file://$MODULE_DIR$">
20+
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
21+
<excludeFolder url="file://$MODULE_DIR$/target" />
22+
</content>
23+
<orderEntry type="inheritedJdk" />
24+
<orderEntry type="sourceFolder" forTests="false" />
25+
<orderEntry type="library" scope="PROVIDED" name="Maven: org.spigotmc:spigot:1.17.1-R0.1-SNAPSHOT" level="project" />
26+
</component>
27+
</module>

src/main/java/com/iridium/iridiumcolorapi/IridiumColorAPI.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,18 @@ public static ChatColor getColor(@Nonnull String string) {
168168
return SUPPORTS_RGB ? ChatColor.of(new Color(Integer.parseInt(string, 16))) : getClosestColor(new Color(Integer.parseInt(string, 16)));
169169
}
170170

171+
/**
172+
* Removes all color codes from the provided String, including IridiumColorAPI patterns.
173+
*
174+
* @param string The String which should be stripped
175+
* @return The stripped string without color codes
176+
* @since 1.0.5
177+
*/
178+
@Nonnull
179+
public static String stripColorFormatting(@Nonnull String string) {
180+
return string.replaceAll("[&§][a-f0-9lnokm]|<[/]?\\w{5,8}(:[0-9A-F]{6})?>", "");
181+
}
182+
171183
/**
172184
* Returns a rainbow array of chat colors.
173185
*

0 commit comments

Comments
 (0)