Some changes to the Quality StringParser

This commit is contained in:
Sn0wStorm
2020-11-09 16:14:20 +01:00
parent 9553aa9fce
commit 390f7fe765
4 changed files with 45 additions and 78 deletions
+31 -50
View File
@@ -2,57 +2,38 @@ package com.dre.brewery.utility;
import com.dre.brewery.P;
public interface StringParser {
public class StringParser {
public Object parse(String line);
public static StringParser cmdParser = new StringParser() {
@Override
public Object parse(String line) {
line = P.p.color(line);
int plus = 0;
if (line.startsWith("+++")) {
plus = 3;
line = line.substring(3);
} else if (line.startsWith("++")) {
plus = 2;
line = line.substring(2);
} else if (line.startsWith("+")) {
plus = 1;
line = line.substring(1);
}
if (line.startsWith(" ")) {
line = line.substring(1);
}
if (line.startsWith("/")) {
line = line.substring(1);
}
return new Tuple<Integer,String>(plus, line);
public static Tuple<Integer, String> parseQuality(String line, ParseType type) {
line = P.p.color(line);
int plus = 0;
if (line.startsWith("+++")) {
plus = 3;
line = line.substring(3);
} else if (line.startsWith("++")) {
plus = 2;
line = line.substring(2);
} else if (line.startsWith("+")) {
plus = 1;
line = line.substring(1);
}
};
public static StringParser loreParser = new StringParser() {
@Override
public Object parse(String line) {
line = P.p.color(line);
int plus = 0;
if (line.startsWith("+++")) {
plus = 3;
line = line.substring(3);
} else if (line.startsWith("++")) {
plus = 2;
line = line.substring(2);
} else if (line.startsWith("+")) {
plus = 1;
line = line.substring(1);
}
if (line.startsWith(" ")) {
line = line.substring(1);
}
if (!line.startsWith("§")) {
line = "§9" + line;
}
return new Tuple<Integer,String>(plus, line);
if (line.startsWith(" ")) {
line = line.substring(1);
}
};
if (type == ParseType.CMD && line.startsWith("/")) {
line = line.substring(1);
}
if (type == ParseType.LORE && !line.startsWith("§")) {
line = "§9" + line;
}
return new Tuple<Integer,String>(plus, line);
}
public enum ParseType {
LORE,
CMD,
OTHER
}
}