Skip to content

Commit

Permalink
Merge pull request #72 from CallVDois/add-hex-colors
Browse files Browse the repository at this point in the history
Add hex colors
  • Loading branch information
needkg authored Jan 6, 2025
2 parents d4c2c4d + a4fd9a9 commit 1850e13
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
26 changes: 25 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,28 @@ dependency-reduced-pom.xml
.idea/

#vscode
.vscode
.vscode

# Servidor de desenvolvimento
*.bat
*.sh
server/
*.jar
*.log
eula.txt
logs/
crash-reports/
world/
world_nether/
world_the_end/
plugins/
banned-ips.json
banned-players.json
ops.json
usercache.json
whitelist.json
spigot.yml
bukkit.yml
commands.yml
permissions.yml
help.yml
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<groupId>org.callv2</groupId>
<artifactId>DayNightPvP</artifactId>
<name>DayNightPvP</name>
<version>1.2.7.3</version>
<version>1.2.8.0</version>
<packaging>jar</packaging>

<properties>
Expand All @@ -35,7 +35,7 @@
<artifactId>maven-jar-plugin</artifactId>
<version>3.4.2</version>
<configuration>
<outputDirectory>C:\Users\Claudinei-TI\Desktop\Debug\plugins</outputDirectory>
<outputDirectory>C:\Users\ADM\Desktop\Debug\plugins</outputDirectory>
</configuration>
</plugin>

Expand Down
22 changes: 21 additions & 1 deletion src/main/java/org/callv2/daynightpvp/files/LangFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import org.callv2.daynightpvp.utils.ConsoleUtils;

import java.io.File;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class LangFile {

Expand Down Expand Up @@ -62,7 +64,25 @@ private void loadFileContent() {
private String formatMessage(String path) {
String text = fileContent.getString(path);
if (text != null) {
return ChatColor.translateAlternateColorCodes('&', text);
// Regex para encontrar códigos hexadecimais no formato <#RRGGBB>
Pattern hexPattern = Pattern.compile("<#([A-Fa-f0-9]{6})>");
Matcher matcher = hexPattern.matcher(text);
StringBuffer buffer = new StringBuffer();

// Substitui cada código hexadecimal encontrado pelo formato §x§R§R§G§G§B§B
while (matcher.find()) {
String hexCode = matcher.group(1);
StringBuilder hexColor = new StringBuilder("§x");
for (char c : hexCode.toCharArray()) {
hexColor.append('§').append(c);
}
matcher.appendReplacement(buffer, hexColor.toString());
}
matcher.appendTail(buffer);

// Substitui os códigos '&' por '§'
text = ChatColor.translateAlternateColorCodes('&', buffer.toString());
return text;
}
return "Invalid message syntax";
}
Expand Down

0 comments on commit 1850e13

Please sign in to comment.