Skip to content

Commit f390d98

Browse files
committed
README.md edit, ColorAPI add (v0.1)
1 parent 9ebf513 commit f390d98

File tree

6 files changed

+273
-9
lines changed

6 files changed

+273
-9
lines changed

README.md

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# ForestPlug
1+
# ForestPlug v0.1
22

33
![badge](https://img.shields.io/github/downloads/ForestTechMC/ForestPlug/total)
44
![badge](https://img.shields.io/github/last-commit/ForestTechMC/ForestPlug)
@@ -9,17 +9,38 @@
99

1010
## Table of contents
1111

12+
* [Why our Plug](#why-our-plug)
1213
* [Info](#info)
13-
* [Config](#config)
14+
* [Modules](#modules)
15+
* [Addon list](#addon-list)
1416
* [Dev APIs](#dev-apis)
1517
* [Dev addons](#dev-addons)
1618
* [License](#license)
1719

20+
## Why our plug
21+
You maybe now ask "Why i need this plugin?"
22+
- We want to make developing in Java Spigot/Bungee easier to understand, <br>
23+
and showing some ways how to do some things like APIs.
24+
- If you have some developer team, <br>
25+
and you need have one plugin for all things, you can use this as main, and have addons in custom addon folder
26+
1827

1928
## Info
29+
Project is in the initial development phase, it has not been sufficiently tested yet, use at your own risk!
30+
31+
## Modules
32+
Parts of our API we imported into core part, and everyone who connect to our API can use it with addon API
33+
34+
## Addon list
35+
- If you want to get to this list with your addon, contact us on Discord server
36+
<br></br>
37+
[`TODO`](https://github.com/ForestTechMC)
2038

21-
More info soon....
39+
## Dev APIs
40+
Soon...
2241

42+
## Dev addons
43+
Soon...
2344

2445
## License
2546
ForestPlug is licensed under the permissive MIT license. Please see [`LICENSE.txt`](https://github.com/ForestTechMC/ForestPlug/blob/master/LICENSE.txt) for more information.

src/main/java/cz/forestTech/addons/AddonManager.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ public AddonManager() {
2020
plugin = Spigot.getInstance();
2121
addonsList = new ArrayList<>();
2222
loadAddons();
23-
2423
}
2524

2625
public void loadAddons() {

src/main/java/cz/forestTech/addons/ForestAddon.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ public ForestAddon(Plugin plugin) {
1111
}
1212

1313
public abstract String name();
14-
public abstract Plugin plugin();
1514
public abstract String author();
15+
public abstract String version();
16+
public abstract Plugin plugin();
1617
public abstract String describe();
1718

1819
}

src/main/java/cz/forestTech/apis/PlaceHolderAPI.java

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 242 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,242 @@
1+
package cz.forestTech.colors;
2+
3+
4+
import net.md_5.bungee.api.ChatColor;
5+
6+
import java.awt.*;
7+
import java.util.Arrays;
8+
9+
import java.util.List;
10+
import java.util.regex.Matcher;
11+
import java.util.regex.Pattern;
12+
13+
public class ColorAPI {
14+
15+
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");
16+
private static final List<String> specialChars = Arrays.asList("&l", "&n", "&o", "&k", "&m", "§l", "§n", "§o", "§k", "§m");
17+
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})<\\}");
19+
private static final Pattern patternOneFromTwo = Pattern.compile("\\{#([0-9A-Fa-f]{6})<>\\}");
20+
private static Matcher matcher;
21+
22+
/**
23+
*
24+
* Here we can select the type of colorize,
25+
* soo if we only want RGB we do ColorizeType.RGB into input
26+
*
27+
* @param input message
28+
* @param type ColorizeType enum, for better selecting type
29+
* @return colored output, or null type
30+
*/
31+
public static String colorizeType(ColorizeType type, String input) {
32+
return switch (type) {
33+
case GRADIENT -> colorizeGradient(input);
34+
case RGB -> colorizeRGB(input);
35+
case CLASSIC -> colorizeClassic(input);
36+
};
37+
}
38+
39+
/**
40+
*
41+
* This method clear whole string
42+
*
43+
* @return string without patterns, legacy colors, and special chars
44+
*/
45+
public static String clear(String input) {
46+
input = removePatterns(input);
47+
input = removeLegacyColors(input);
48+
input = removeSpecialChars(input);
49+
return input;
50+
}
51+
52+
/**
53+
*
54+
* In this method we remove specialChars like "&n", "&r"...
55+
* Example:
56+
* "&kForestTech ❤" -> "ForestTech ❤"
57+
*
58+
* @param input message
59+
* @return output
60+
*/
61+
public static String removeSpecialChars(String input) {
62+
for (String chars : specialChars) {
63+
if (!input.contains(chars)) {
64+
continue;
65+
}
66+
input = input.replaceAll(chars, "");
67+
}
68+
69+
return input;
70+
}
71+
72+
/**
73+
*
74+
* In this method we remove legacyColors like "&2", "&c"...
75+
* Example:
76+
* "&2ForestTech ❤" -> "ForestTech ❤"
77+
*
78+
* @param input message
79+
* @return output
80+
*/
81+
public static String removeLegacyColors(String input) {
82+
for (String color : legacyColors) {
83+
if (!input.contains(color)) {
84+
continue;
85+
}
86+
input = input.replaceAll(color, "");
87+
}
88+
return input;
89+
}
90+
91+
/**
92+
*
93+
* If we want to remove patterns from message we can use this
94+
* Example:
95+
* "{#00e64e}ForestTech ❤" -> "ForestTech ❤"
96+
*
97+
* @param input message with patterns
98+
* @return string without patterns
99+
*/
100+
public static String removePatterns(String input) {
101+
input = input.replaceAll("\\{#([0-9A-Fa-f]{6})>\\}", "");
102+
input = input.replaceAll("\\{#([0-9A-Fa-f]{6})<\\}", "");
103+
input = input.replaceAll("\\{#([0-9A-Fa-f]{6})\\}", "");
104+
return input;
105+
}
106+
107+
/**
108+
*
109+
* Universal colorize method for add colors into message
110+
*
111+
* @param input message
112+
* @return colored message
113+
*/
114+
public static String colorize(String input) {
115+
input = colorizeGradient(input);
116+
input = colorizeRGB(input);
117+
return input;
118+
}
119+
120+
/**
121+
*
122+
* Method for normal translate colors from spigot
123+
*
124+
*/
125+
public static String colorizeClassic(String input) {
126+
input = ChatColor.translateAlternateColorCodes('&', input);
127+
return input;
128+
}
129+
130+
/**
131+
*
132+
* Here we can call for gradient colorize
133+
*
134+
* Group 1 = First gradient
135+
* Group 3 = Second gradient
136+
* Group 2 = content
137+
*
138+
* @param input message
139+
* @return colored output with gradient
140+
*/
141+
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+
152+
matcher = patternGrad.matcher(input);
153+
while (matcher.find()) {
154+
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))));
155+
}
156+
return ChatColor.translateAlternateColorCodes('&', input);
157+
}
158+
159+
/**
160+
*
161+
* This method only do normal RGB without gradient
162+
*
163+
* @param input message
164+
* @return colored rgb output
165+
*/
166+
public static String colorizeRGB(String input) {
167+
matcher = patternNormal.matcher(input);
168+
String color;
169+
while (matcher.find()) {
170+
color = matcher.group(1);
171+
if (color == null) {
172+
color = matcher.group(2);
173+
}
174+
input = input.replace(matcher.group(), getColor(color) + "");
175+
}
176+
return input;
177+
}
178+
179+
/**
180+
*
181+
* Color method for gradient for example this take
182+
* the first one gradient, and second one, and do gradient in the message
183+
*
184+
* @param input whole message
185+
* @param first first gradient
186+
* @param second second gradient
187+
*/
188+
public static String color(String input, Color first, Color second) {
189+
ChatColor[] colors = createGradient(first, second, removeSpecialChars(input).length());
190+
return apply(input, colors);
191+
}
192+
193+
private static String apply(String input, ChatColor[] colors) {
194+
StringBuilder specialColors = new StringBuilder();
195+
StringBuilder stringBuilder = new StringBuilder();
196+
String[] characters = input.split("");
197+
int outIndex = 0;
198+
199+
for (int i = 0; i < characters.length; i++) {
200+
if (!characters[i].equals("&") && !characters[i].equals("§")) {
201+
stringBuilder.append(colors[outIndex++]).append(specialColors).append(characters[i]);
202+
continue;
203+
}
204+
if (i + 1 >= characters.length) {
205+
stringBuilder.append(colors[outIndex++]).append(specialColors).append(characters[i]);
206+
continue;
207+
}
208+
if (characters[i + 1].equals("r")) {
209+
specialColors.setLength(0);
210+
} else {
211+
specialColors.append(characters[i]);
212+
specialColors.append(characters[i + 1]);
213+
}
214+
i++;
215+
}
216+
return stringBuilder.toString();
217+
}
218+
219+
/**
220+
*
221+
* @return colors for string
222+
*
223+
*/
224+
private static ChatColor[] createGradient(Color first, Color second, int amount) {
225+
ChatColor[] colors = new ChatColor[amount];
226+
int amountR = Math.abs(first.getRed() - second.getRed()) / (amount - 1);
227+
int amountG = Math.abs(first.getGreen() - second.getGreen()) / (amount - 1);
228+
int amountB = Math.abs(first.getBlue() - second.getBlue()) / (amount - 1);
229+
int[] colorDir = new int[]{first.getRed() < second.getRed() ? +1 : -1, first.getGreen() < second.getGreen() ? +1 : -1, first.getBlue() < second.getBlue() ? +1 : -1};
230+
231+
for (int i = 0; i < amount; i++) {
232+
Color color = new Color(first.getRed() + ((amountR * i) * colorDir[0]), first.getGreen() + ((amountG * i) * colorDir[1]), first.getBlue() + ((amountB * i) * colorDir[2]));
233+
colors[i] = ChatColor.of(color);
234+
}
235+
return colors;
236+
}
237+
238+
public static ChatColor getColor(String matcher) {
239+
return ChatColor.of(new Color(Integer.parseInt(matcher, 16)));
240+
}
241+
242+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package cz.forestTech.colors;
2+
3+
public enum ColorizeType {
4+
GRADIENT, RGB, CLASSIC
5+
}

0 commit comments

Comments
 (0)