Skip to content

Commit 01f8cd4

Browse files
committed
Added HEX support
1 parent 3055e6b commit 01f8cd4

File tree

5 files changed

+55
-6
lines changed

5 files changed

+55
-6
lines changed

build.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ dependencies {
6767
implementation("com.github.cryptomorin:XSeries:8.6.0")
6868
implementation("net.kyori:adventure-api:4.9.3")
6969
implementation("net.kyori:adventure-text-serializer-legacy:4.9.3")
70+
implementation("com.github.harry0198:HexiTextLib:9a9ce45ec1") {
71+
exclude module: "annotations"
72+
}
73+
7074
slim("mysql:mysql-connector-java:8.0.27")
7175
slim("commons-io:commons-io:2.11.0")
7276
}
@@ -88,6 +92,7 @@ shadowJar {
8892
relocate("net.kyori.examination", "${libsBase}examination")
8993
relocate("com.cryptomorin.xseries", "${libsBase}xseries")
9094
relocate("io.github.slimjar", "${libsBase}slimjar")
95+
relocate("com.haroldstudios.hexitextlib", "${libsBase}.hex")
9196

9297
archiveFileName = "${project.name}-${project.version}.jar"
9398
}

src/main/java/me/lorenzo0111/rocketplaceholders/creator/Placeholder.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import me.lorenzo0111.rocketplaceholders.creator.conditions.ConditionNode;
2929
import me.lorenzo0111.rocketplaceholders.exceptions.InvalidConditionException;
3030
import me.lorenzo0111.rocketplaceholders.storage.PlaceholderSettings;
31+
import me.lorenzo0111.rocketplaceholders.utilities.HexParser;
3132
import me.lorenzo0111.rocketplaceholders.utilities.JavaScriptParser;
3233
import org.bukkit.ChatColor;
3334
import org.bukkit.configuration.file.FileConfiguration;
@@ -72,7 +73,7 @@ public Placeholder(@NotNull String identifier, JavaPlugin owner, @NotNull String
7273
if (text.contains("%rp_")) {
7374
this.text = ChatColor.translateAlternateColorCodes('&', "&cError! You can't use rp placeholders in the text.");
7475
} else {
75-
this.text = ChatColor.translateAlternateColorCodes('&', text);
76+
this.text = HexParser.text(text);
7677
}
7778

7879
this.conditionNodes = nodes;
@@ -95,7 +96,7 @@ public Placeholder(@NotNull String identifier, JavaPlugin owner, @NotNull String
9596
if (text.contains("%rp_")) {
9697
this.text = ChatColor.translateAlternateColorCodes('&', "&cError! You can't use rp placeholders in the text.");
9798
} else {
98-
this.text = ChatColor.translateAlternateColorCodes('&', text);
99+
this.text = HexParser.text(text);
99100
}
100101
this.owner = owner;
101102
}

src/main/java/me/lorenzo0111/rocketplaceholders/creator/conditions/Requirements.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
import me.lorenzo0111.rocketplaceholders.creator.conditions.types.*;
2828
import me.lorenzo0111.rocketplaceholders.exceptions.InvalidConditionException;
29+
import me.lorenzo0111.rocketplaceholders.utilities.HexParser;
2930
import org.bukkit.Bukkit;
3031
import org.bukkit.ChatColor;
3132
import org.bukkit.Material;
@@ -150,7 +151,7 @@ private static String translateColors(String text) {
150151
return null;
151152
}
152153

153-
return ChatColor.translateAlternateColorCodes('&', text);
154+
return HexParser.text(text);
154155
}
155156

156157
/**
@@ -166,7 +167,7 @@ private static List<String> translateColors(List<String> text) {
166167
List<String> translated = new ArrayList<>();
167168

168169
for (String string : text) {
169-
translated.add(ChatColor.translateAlternateColorCodes('&', string));
170+
translated.add(HexParser.text(string));
170171
}
171172

172173
return translated;

src/main/java/me/lorenzo0111/rocketplaceholders/storage/ConfigManager.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import me.lorenzo0111.rocketplaceholders.creator.conditions.Requirements;
3232
import me.lorenzo0111.rocketplaceholders.exceptions.InvalidConditionException;
3333
import me.lorenzo0111.rocketplaceholders.legacy.LegacyMover;
34+
import me.lorenzo0111.rocketplaceholders.utilities.HexParser;
3435
import org.apache.commons.io.FilenameUtils;
3536
import org.bukkit.ChatColor;
3637
import org.bukkit.configuration.ConfigurationSection;
@@ -94,7 +95,7 @@ public void registerPlaceholders() throws IOException, InvalidConditionException
9495
nodes = new ArrayList<>(scanConditions(conditions));
9596
}
9697

97-
storageManager.getInternalPlaceholders().build(FilenameUtils.getBaseName(file.getName()), config.getString("placeholder", "null"), ChatColor.translateAlternateColorCodes('&', config.getString("text", "")),nodes,parseJS);
98+
storageManager.getInternalPlaceholders().build(FilenameUtils.getBaseName(file.getName()), config.getString("placeholder", "null"), HexParser.text(config.getString("text", "")),nodes,parseJS);
9899
}
99100

100101
plugin.getLogger().info("Loaded " + storageManager.getInternalPlaceholders().getMap().size() + " placeholders!");
@@ -139,7 +140,7 @@ public void reload(@Nullable String oldIdentifier, @NotNull Placeholder placehol
139140
storageManager.getInternalPlaceholders()
140141
.getMap()
141142
.remove(oldIdentifier == null ? placeholder.getIdentifier() : oldIdentifier);
142-
storageManager.getInternalPlaceholders().build(placeholder.getFile().getName(), config.getString("placeholder", "null"), ChatColor.translateAlternateColorCodes('&', config.getString("text", "")),nodes.isEmpty() ? null : nodes,parseJS);
143+
storageManager.getInternalPlaceholders().build(placeholder.getFile().getName(), config.getString("placeholder", "null"), HexParser.text(config.getString("text", "")),nodes.isEmpty() ? null : nodes,parseJS);
143144
}
144145
}
145146

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* This file is part of RocketPlaceholders, licensed under the MIT License.
3+
*
4+
* Copyright (c) Lorenzo0111
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
package me.lorenzo0111.rocketplaceholders.utilities;
26+
27+
import com.haroldstudios.hexitextlib.HexResolver;
28+
import org.jetbrains.annotations.NotNull;
29+
30+
import java.util.regex.Pattern;
31+
32+
public class HexParser {
33+
private static final Pattern PATTERN = Pattern.compile("&(#[a-fA-F0-9]{6})");
34+
35+
private HexParser() {}
36+
37+
public static @NotNull String text(@NotNull String text) {
38+
return HexResolver.parseHexString(text, PATTERN);
39+
}
40+
41+
}

0 commit comments

Comments
 (0)