T2CodeLib/src/main/java/net/t2code/lib/Spigot/Lib/replace/Replace.java

146 lines
7.5 KiB
Java

package net.t2code.lib.Spigot.Lib.replace;
import me.clip.placeholderapi.PlaceholderAPI;
import net.t2code.lib.Spigot.Lib.messages.send;
import net.t2code.lib.Spigot.system.T2CodeMain;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class Replace {
public static String replace(String prefix, String Text) {
return replaceLegacyColor(Text).replace("[prefix]", prefix).replace("[ue]", "ü")
.replace("[UE]", "Ü").replace("[oe]", "ö").replace("[OE]", "Ö")
.replace("[ae]", "ä").replace("[AE]", "Ä").replace("[nl]", "\n");
}
public static String replace(String prefix, Player player, String Text) {
return replaceLegacyColor(PlaceholderAPI.setPlaceholders(player, Text.replace("[prefix]", prefix)
.replace("[ue]", "ü").replace("[UE]", "Ü").replace("[oe]", "ö")
.replace("[OE]", "Ö").replace("[ae]", "ä").replace("[AE]", "Ä")
.replace("[nl]", "\n")));
}
public static List<String> replace(String prefix, List<String> Text) {
List<String> output = new ArrayList<>();
for (String input : Text) {
output.add(replaceLegacyColor(input).replace("[prefix]", prefix)
.replace("[ue]", "ü").replace("[UE]", "Ü").replace("[oe]", "ö")
.replace("[OE]", "Ö").replace("[ae]", "ä").replace("[AE]", "Ä")
.replace("[nl]", "\n"));
}
return output;
}
public static List<String> replace(String prefix, Player player, List<String> Text) {
List<String> output = new ArrayList();
if (player == null) {
return Collections.singletonList("player is null");
}
if (Text == null) {
return Collections.singletonList("Text is null");
}
for (String input : Text) {
output.add(PlaceholderAPI.setPlaceholders(player, replaceLegacyColor(input).replace("[prefix]", prefix)
.replace("[ue]", "ü").replace("[UE]", "Ü").replace("[oe]", "ö")
.replace("[OE]", "Ö").replace("[ae]", "ä").replace("[AE]", "Ä")
.replace("[nl]", "\n")));
}
return output;
}
public static List<String> replacePrice(String prefix, List<String> Text, String price) {
List<String> rp = new ArrayList();
for (String s : Text) {
rp.add(replaceLegacyColor(s).replace("[prefix]", prefix)
.replace("[ue]", "ü").replace("[UE]", "Ü").replace("[oe]", "ö")
.replace("[OE]", "Ö").replace("[ae]", "ä").replace("[AE]", "Ä")
.replace("[nl]", "\n").replace("[price]", String.valueOf(price)));
}
return rp;
}
public static String removeColorCode(String value) {
return value.replace("&0", "").replace("&1", "").replace("&2", "").replace("&3", "")
.replace("&4", "").replace("&5", "").replace("&6", "").replace("&7", "")
.replace("&8", "").replace("&9", "").replace("&a", "").replace("&b", "")
.replace("&c", "").replace("&d", "").replace("&e", "").replace("&f", "")
.replace("&k", "").replace("&l", "").replace("&m", "").replace("&n", "")
.replace("&o", "").replace("&r", "");
// String text = value.replace("&", "§");
// while (text.contains("§")) {
// int stelle = text.indexOf("§");
// if (text.length() >= stelle + 2) {
// text = text.substring(0, stelle) + text.substring(stelle + 2);
// } else {
// text = text.substring(0, stelle) + text.substring(stelle + 1);
// }
// }
// return (text);
}
public static List<String> replacePrice(String prefix, Player player, List<String> Text, String price) {
List<String> rp = new ArrayList();
for (String s : Text) {
rp.add(replaceLegacyColor(PlaceholderAPI.setPlaceholders(player, s.replace("[prefix]", prefix)
.replace("[ue]", "ü").replace("[UE]", "Ü").replace("[oe]", "ö")
.replace("[OE]", "Ö").replace("[ae]", "ä").replace("[AE]", "Ä").replace("[nl]", "\n")
.replace("[price]", String.valueOf(price)))));
}
return rp;
}
public static String replacePrice(String prefix, String Text, String price) {
return replaceLegacyColor(Text).replace("[prefix]", prefix)
.replace("&o", "§o").replace("&r", "§r").replace("[ue]", "ü")
.replace("[UE]", "Ü").replace("[oe]", "ö").replace("[OE]", "Ö")
.replace("[ae]", "ä").replace("[AE]", "Ä").replace("[price]", String.valueOf(price))
.replace("[nl]", "\n");
}
public static String replacePrice(String prefix, Player player, String Text, String price) {
return replaceLegacyColor(PlaceholderAPI.setPlaceholders(player, Text.replace("[prefix]", prefix)
.replace("[ue]", "ü").replace("[UE]", "Ü").replace("[oe]", "ö")
.replace("[OE]", "Ö").replace("[ae]", "ä").replace("[AE]", "Ä")
.replace("[price]", String.valueOf(price)).replace("[nl]", "\n")));
}
public static String replaceLegacyColor(String text) {
return text.replace("&0", "§0").replace("&1", "§1").replace("&2", "§2").replace("&3", "§3")
.replace("&4", "§4").replace("&5", "§5").replace("&6", "§6").replace("&7", "§7")
.replace("&8", "§8").replace("&9", "§9").replace("&a", "§a").replace("&b", "§b")
.replace("&c", "§c").replace("&d", "§d").replace("&e", "§e").replace("&f", "§f")
.replace("&k", "§k").replace("&l", "§l").replace("&m", "§m").replace("&n", "§n")
.replace("&o", "§o").replace("&r", "§r");
}
public static String convertColorCode(String text) {
return text.replace("&0", "<black>").replace("§0", "<black>")
.replace("&1", "<dark_blue>").replace("§1", "<dark_blue>")
.replace("&2", "<dark_green>").replace("§2", "<dark_green>")
.replace("&3", "<dark_aqua>").replace("§3", "<dark_aqua>")
.replace("&4", "<dark_red>").replace("§4", "<dark_red>")
.replace("&5", "<dark_purple>").replace("§5", "<dark_purple>")
.replace("&6", "<gold>").replace("§6", "<gold>")
.replace("&7", "<gray>").replace("§7", "<gray>")
.replace("&8", "<dark_gray>").replace("§8", "<dark_gray>")
.replace("&9", "<blue>").replace("§9", "<blue>")
.replace("&a", "<green>").replace("§a", "<green>")
.replace("&b", "<aqua>").replace("§b", "<aqua>")
.replace("&c", "<red>").replace("§c", "<red>")
.replace("&d", "<light_purple>").replace("§d", "<light_purple>")
.replace("&e", "<yellow>").replace("§e", "<yellow>")
.replace("&f", "<white>").replace("§f", "<white>")
.replace("&k", "<obfuscated>").replace("§k", "<obfuscated>")
.replace("&l", "<bold>").replace("§l", "<bold>")
.replace("&m", "<strikethrough>").replace("§m", "<strikethrough>")
.replace("&n", "<underlined>").replace("§n", "<underlined>")
.replace("&o", "<italic>").replace("§o", "<italic>")
.replace("&r", "<reset>").replace("§r", "<reset>");
}
}