Skip to content

Commit 7f858fe

Browse files
committed
Update v1.3
1 parent 3370280 commit 7f858fe

File tree

3 files changed

+26
-13
lines changed

3 files changed

+26
-13
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
[![badge](https://img.shields.io/discord/896466173166747650?label=discord)](https://discord.gg/2PpdrfxhD4)
88
[![badge](https://img.shields.io/github/license/ForestTechMC/ForestColorAPI)](https://github.com/ForestTechMC/ForestColorAPI/blob/master/LICENSE.txt)
99

10-
**[JavaDoc 1.1](https://foresttechmc.github.io/ForestColorAPI/1.1/)**
10+
**[JavaDoc 1.3](https://foresttechmc.github.io/ForestColorAPI/1.3/)**
1111

1212
Small and effective Color API for your plugins.\
1313
Only 1.16+ version of spigot support!
@@ -70,23 +70,23 @@ dependencies {
7070

7171
### Example of patterns
7272

73-
If you want to use gradient you need to use pattern like `{/#b36000}Super gradient!{/#72cc00}`
73+
If you want to use gradient you need to use pattern like `{#b36000>}Super gradient!{#72cc00<}`
7474
For normal RGB `{#72cc00}Super color!`
7575

7676

7777
### Using Color API
7878

7979
```java
8080
// Example of removing chars, legacy colors, and patterns
81-
String cleanMessage = ColorAPI.clear("{/#b36000}Super gradient{/#72cc00} &3Some color");
81+
String cleanMessage = ColorAPI.clear("{#b36000>}Super gradient{#72cc00<} &3Some color");
8282
// Output -> "Super gradient Some color" message without patterns, colors, chars...
8383
// You can use separate methods to clear only some kind of coloring
8484

8585
// Example of universal usage for colorize
86-
player.sendMessage(ColorAPI.colorize("{/#b36000}Super gradient{/#72cc00} {#b36000}Super RGB color"));
86+
player.sendMessage(ColorAPI.colorize("{#b36000>}Super gradient{#72cc00<} {#b36000}Super RGB color"));
8787

8888
// Example of gradient method
89-
player.sendMessage(ColorAPI.colorizeGradient("{/#b36000}Super gradient{/#72cc00}"));
89+
player.sendMessage(ColorAPI.colorizeGradient("{#b36000>}Super gradient{#72cc00<}"));
9090

9191
// Example of RGB method
9292
player.sendMessage(ColorAPI.colorizeRGB("{#b36000}Super RGB color"));

pom.xml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>cz.foresttech</groupId>
88
<artifactId>ForestColorAPI</artifactId>
9-
<version>1.2</version>
9+
<version>1.3</version>
1010

1111
<properties>
1212
<maven.compiler.source>17</maven.compiler.source>
@@ -16,16 +16,18 @@
1616

1717

1818
<repositories>
19-
<repository>
20-
<id>spigot-repo</id>
21-
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
22-
</repository>
2319
<repository>
2420
<id>jitpack.io</id>
2521
<url>https://jitpack.io</url>
2622
</repository>
23+
<repository>
24+
<id>spigot-repo</id>
25+
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
26+
</repository>
2727
</repositories>
2828

29+
30+
2931
<dependencies>
3032
<dependency>
3133
<groupId>net.md-5</groupId>

src/main/java/cz/foresttech/api/ColorAPI.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ public class ColorAPI {
1515
private static final List<String> legacyColors = Arrays.asList("&0", "&1", "&2", "&3", "&4", "&5", "&6", "&7", "&8", "&9", "&a", "&b", "&c", "&d", "&e", "§0", "§1", "§2", "§3", "§4", "§5", "§6", "§7", "§8", "§9", "§a", "§b", "§c", "§d", "§e");
1616
private static final List<String> specialChars = Arrays.asList("&l", "&n", "&o", "&k", "&m", "§l", "§n", "§o", "§k", "§m");
1717
private static final Pattern patternNormal = Pattern.compile("\\{#([0-9A-Fa-f]{6})\\}");
18-
private static final Pattern patternGrad = Pattern.compile("\\{/#([0-9A-Fa-f]{6})\\}(.*?)\\{/#([0-9A-Fa-f]{6})\\}");
18+
private static final Pattern patternGrad = Pattern.compile("\\{#([0-9A-Fa-f]{6})>\\}(.*?)\\{#([0-9A-Fa-f]{6})<\\}");
19+
private static final Pattern patternOneFromTwo = Pattern.compile("\\{#([0-9A-Fa-f]{6})<>\\}");
1920
private static Matcher matcher;
2021

2122
/**
@@ -97,7 +98,8 @@ public static String removeLegacyColors(String input) {
9798
* @return string without patterns
9899
*/
99100
public static String removePatterns(String input) {
100-
input = input.replaceAll("\\{/#([0-9A-Fa-f]{6})\\}", "");
101+
input = input.replaceAll("\\{#([0-9A-Fa-f]{6})>\\}", "");
102+
input = input.replaceAll("\\{#([0-9A-Fa-f]{6})<\\}", "");
101103
input = input.replaceAll("\\{#([0-9A-Fa-f]{6})\\}", "");
102104
return input;
103105
}
@@ -125,7 +127,6 @@ public static String colorizeClassic(String input) {
125127
return input;
126128
}
127129

128-
129130
/**
130131
*
131132
* Here we can call for gradient colorize
@@ -138,6 +139,16 @@ public static String colorizeClassic(String input) {
138139
* @return colored output with gradient
139140
*/
140141
public static String colorizeGradient(String input) {
142+
matcher = patternOneFromTwo.matcher(input);
143+
144+
StringBuffer output = new StringBuffer();
145+
146+
while (matcher.find()) {
147+
String text = matcher.group(1);
148+
matcher.appendReplacement(output, "{#" + text + "<}{#" + text + ">}");
149+
}
150+
input = String.valueOf(output);
151+
141152
matcher = patternGrad.matcher(input);
142153
while (matcher.find()) {
143154
input = input.replace(matcher.group(), color(matcher.group(2), new Color(Integer.parseInt(matcher.group(1), 16)), new Color(Integer.parseInt(matcher.group(3), 16))));

0 commit comments

Comments
 (0)