Skip to content

Commit

Permalink
Temporary Fallback to the old FormatParser
Browse files Browse the repository at this point in the history
Awaiting help from contributors
  • Loading branch information
xSehrMotiviert committed Apr 29, 2022
1 parent 565f43a commit 1149bb5
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>eu.prellberg.nick</groupId>
<artifactId>velocityplus</artifactId>
<version>1.1.2</version>
<version>1.1.3</version>

<properties>
<maven.compiler.source>17</maven.compiler.source>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;

@Plugin(id = "velocityplus", name = "VelocityPlus", version = "1.1.2", authors = {"Nick Prellberg"}, url = "https://github.com/xsehrmotiviert/velocityplus")
@Plugin(id = "velocityplus", name = "VelocityPlus", version = "1.1.3", authors = {"Nick Prellberg"}, url = "https://github.com/xsehrmotiviert/velocityplus")
public class VelocityPlus {

private final ProxyServer server;
Expand Down Expand Up @@ -66,7 +66,7 @@ public void onProxyInitialize(ProxyInitializeEvent event) {
/$$ | $$ \s
| $$$$$$/ \s
\\______/ \s
Version: 1.1.2""");
Version: 1.1.3""");

new SendCommand(server, this, logger);
new KickallCommand(server, this, logger);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import java.util.HashMap;
import java.util.concurrent.atomic.AtomicReference;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class FormatParser {

HashMap<String, String> legacyCodes = new HashMap<>() {{
/*HashMap<String, String> legacyCodes = new HashMap<>() {{
put("0", "<black>");
put("1", "<dark_blue>");
put("2", "<dark_green>");
Expand Down Expand Up @@ -39,5 +41,67 @@ public String parse(String string) {
});
return newString.get();
}*/

public String parse(String string) {
Pattern patternAmpersand = Pattern.compile("&[0-9a-fk-or]", Pattern.CASE_INSENSITIVE);
Pattern patternParagraph = Pattern.compile("§[0-9a-fk-or]", Pattern.CASE_INSENSITIVE);

Matcher matcherAmpersand = patternAmpersand.matcher(string);
Matcher matcherParagraph = patternParagraph.matcher(string);

boolean matchAFound = matcherAmpersand.find();
boolean matchPFound = matcherParagraph.find();

if (matchAFound) {
string = string.replaceAll("&0", "<black>");
string = string.replaceAll("&1", "<dark_blue>");
string = string.replaceAll("&2", "<dark_green>");
string = string.replaceAll("&3", "<dark_aqua>");
string = string.replaceAll("&4", "<dark_red>");
string = string.replaceAll("&5", "<dark_purple>");
string = string.replaceAll("&6", "<gold>");
string = string.replaceAll("&7", "<gray>");
string = string.replaceAll("&8", "<dark_gray>");
string = string.replaceAll("&9", "<blue>");
string = string.replaceAll("&a", "<green>");
string = string.replaceAll("&b", "<aqua>");
string = string.replaceAll("&c", "<red>");
string = string.replaceAll("&d", "<light_purple>");
string = string.replaceAll("&e", "<yellow>");
string = string.replaceAll("&f", "<white>");
string = string.replaceAll("&k", "<obf>");
string = string.replaceAll("&l", "<b>");
string = string.replaceAll("&m", "<st>");
string = string.replaceAll("&n", "<u>");
string = string.replaceAll("&o", "<i>");
string = string.replaceAll("&r", "<reset>");
}

if (matchPFound) {
string = string.replaceAll("§0", "<black>");
string = string.replaceAll("§1", "<dark_blue>");
string = string.replaceAll("§2", "<dark_green>");
string = string.replaceAll("§3", "<dark_aqua>");
string = string.replaceAll("§4", "<dark_red>");
string = string.replaceAll("§5", "<dark_purple>");
string = string.replaceAll("§6", "<gold>");
string = string.replaceAll("§7", "<gray>");
string = string.replaceAll("§8", "<dark_gray>");
string = string.replaceAll("§9", "<blue>");
string = string.replaceAll("§a", "<green>");
string = string.replaceAll("§b", "<aqua>");
string = string.replaceAll("§c", "<red>");
string = string.replaceAll("§d", "<light_purple>");
string = string.replaceAll("§e", "<yellow>");
string = string.replaceAll("§f", "<white>");
string = string.replaceAll("§k", "<obf>");
string = string.replaceAll("§l", "<b>");
string = string.replaceAll("§m", "<st>");
string = string.replaceAll("§n", "<u>");
string = string.replaceAll("§o", "<i>");
string = string.replaceAll("§r", "<reset>");
}
return string;
}
}

0 comments on commit 1149bb5

Please sign in to comment.