2022-10-25 13:03:07 +00:00
|
|
|
package net.t2code.t2codelib.SPIGOT.api.messages;
|
2021-11-28 01:13:21 +00:00
|
|
|
|
|
|
|
import me.clip.placeholderapi.PlaceholderAPI;
|
2023-07-08 19:29:30 +00:00
|
|
|
import net.t2code.t2codelib.SPIGOT.api.plugins.T2CpluginCheck;
|
2021-11-28 01:13:21 +00:00
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
2021-12-04 04:27:03 +00:00
|
|
|
import java.util.Collections;
|
2021-11-28 01:13:21 +00:00
|
|
|
import java.util.List;
|
|
|
|
|
2022-10-25 13:03:07 +00:00
|
|
|
public class T2Creplace {
|
2021-11-28 01:13:21 +00:00
|
|
|
|
|
|
|
public static String replace(String prefix, String Text) {
|
2022-07-07 11:43:50 +00:00
|
|
|
|
|
|
|
return replaceLegacyColor(Text).replace("[prefix]", prefix).replace("[ue]", "ü")
|
2021-11-28 01:13:21 +00:00
|
|
|
.replace("[UE]", "Ü").replace("[oe]", "ö").replace("[OE]", "Ö")
|
2022-07-07 11:43:50 +00:00
|
|
|
.replace("[ae]", "ä").replace("[AE]", "Ä").replace("[nl]", "\n");
|
2021-11-28 01:13:21 +00:00
|
|
|
}
|
|
|
|
|
2022-06-18 14:16:26 +00:00
|
|
|
public static String replace(String prefix, Player player, String Text) {
|
2023-07-08 19:29:30 +00:00
|
|
|
String input = Text.replace("[prefix]", prefix)
|
2021-11-28 01:13:21 +00:00
|
|
|
.replace("[ue]", "ü").replace("[UE]", "Ü").replace("[oe]", "ö")
|
2022-06-18 14:16:26 +00:00
|
|
|
.replace("[OE]", "Ö").replace("[ae]", "ä").replace("[AE]", "Ä")
|
2023-07-08 19:29:30 +00:00
|
|
|
.replace("[nl]", "\n");
|
|
|
|
if (T2CpluginCheck.papi()) {
|
|
|
|
return replaceLegacyColor(PlaceholderAPI.setPlaceholders(player, input));
|
|
|
|
} else {
|
|
|
|
return replaceLegacyColor(input);
|
|
|
|
}
|
|
|
|
|
2021-11-28 01:13:21 +00:00
|
|
|
}
|
|
|
|
|
2022-12-28 12:42:55 +00:00
|
|
|
public static Object replaceObject(String prefix, Object object) {
|
|
|
|
if (object instanceof String) {
|
|
|
|
object = replaceLegacyColor((String) object).replace("[prefix]", prefix).replace("[ue]", "ü")
|
|
|
|
.replace("[UE]", "Ü").replace("[oe]", "ö").replace("[OE]", "Ö")
|
|
|
|
.replace("[ae]", "ä").replace("[AE]", "Ä").replace("[nl]", "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((object instanceof List) || (object instanceof ArrayList)) {
|
|
|
|
List<String> in = (List<String>) object;
|
|
|
|
List<String> output = new ArrayList<>();
|
|
|
|
for (String input : in) {
|
|
|
|
output.add(replaceLegacyColor(input).replace("[prefix]", prefix)
|
|
|
|
.replace("[ue]", "ü").replace("[UE]", "Ü").replace("[oe]", "ö")
|
|
|
|
.replace("[OE]", "Ö").replace("[ae]", "ä").replace("[AE]", "Ä")
|
|
|
|
.replace("[nl]", "\n"));
|
|
|
|
}
|
|
|
|
object = output;
|
|
|
|
}
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Object replaceObject(String prefix, Player player, Object object) {
|
|
|
|
if (object instanceof String) {
|
2023-07-08 19:29:30 +00:00
|
|
|
|
|
|
|
if (T2CpluginCheck.papi()) {
|
|
|
|
object = PlaceholderAPI.setPlaceholders(player, replaceLegacyColor((String) object).replace("[prefix]", prefix).replace("[ue]", "ü")
|
|
|
|
.replace("[UE]", "Ü").replace("[oe]", "ö").replace("[OE]", "Ö")
|
|
|
|
.replace("[ae]", "ä").replace("[AE]", "Ä").replace("[nl]", "\n"));
|
|
|
|
} else {
|
|
|
|
object = replaceLegacyColor((String) object).replace("[prefix]", prefix).replace("[ue]", "ü")
|
|
|
|
.replace("[UE]", "Ü").replace("[oe]", "ö").replace("[OE]", "Ö")
|
|
|
|
.replace("[ae]", "ä").replace("[AE]", "Ä").replace("[nl]", "\n");
|
|
|
|
}
|
|
|
|
|
2022-12-28 12:42:55 +00:00
|
|
|
}
|
|
|
|
if (object instanceof List) {
|
|
|
|
List<String> in = (List<String>) object;
|
|
|
|
List<String> output = new ArrayList<>();
|
|
|
|
for (String input : in) {
|
2023-07-08 19:29:30 +00:00
|
|
|
if (T2CpluginCheck.papi()) {
|
|
|
|
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")));
|
|
|
|
} else {
|
|
|
|
output.add(replaceLegacyColor(input).replace("[prefix]", prefix)
|
|
|
|
.replace("[ue]", "ü").replace("[UE]", "Ü").replace("[oe]", "ö")
|
|
|
|
.replace("[OE]", "Ö").replace("[ae]", "ä").replace("[AE]", "Ä")
|
|
|
|
.replace("[nl]", "\n"));
|
|
|
|
}
|
2022-12-28 12:42:55 +00:00
|
|
|
}
|
|
|
|
object = output;
|
|
|
|
}
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
|
2021-11-28 01:13:21 +00:00
|
|
|
public static List<String> replace(String prefix, List<String> Text) {
|
|
|
|
List<String> output = new ArrayList<>();
|
|
|
|
for (String input : Text) {
|
2022-07-07 11:43:50 +00:00
|
|
|
output.add(replaceLegacyColor(input).replace("[prefix]", prefix)
|
2021-11-28 01:13:21 +00:00
|
|
|
.replace("[ue]", "ü").replace("[UE]", "Ü").replace("[oe]", "ö")
|
2022-06-18 14:16:26 +00:00
|
|
|
.replace("[OE]", "Ö").replace("[ae]", "ä").replace("[AE]", "Ä")
|
|
|
|
.replace("[nl]", "\n"));
|
2021-11-28 01:13:21 +00:00
|
|
|
}
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
2022-06-18 14:16:26 +00:00
|
|
|
public static List<String> replace(String prefix, Player player, List<String> Text) {
|
2022-12-28 12:42:55 +00:00
|
|
|
List<String> output = new ArrayList<>();
|
2021-11-28 01:13:21 +00:00
|
|
|
if (player == null) {
|
2021-12-04 04:27:03 +00:00
|
|
|
return Collections.singletonList("player is null");
|
2021-11-28 01:13:21 +00:00
|
|
|
}
|
|
|
|
if (Text == null) {
|
2021-12-04 04:27:03 +00:00
|
|
|
return Collections.singletonList("Text is null");
|
2021-11-28 01:13:21 +00:00
|
|
|
}
|
|
|
|
for (String input : Text) {
|
2023-07-08 19:29:30 +00:00
|
|
|
if (T2CpluginCheck.papi()) {
|
|
|
|
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")));
|
|
|
|
} else {
|
|
|
|
output.add(replaceLegacyColor(input).replace("[prefix]", prefix)
|
|
|
|
.replace("[ue]", "ü").replace("[UE]", "Ü").replace("[oe]", "ö")
|
|
|
|
.replace("[OE]", "Ö").replace("[ae]", "ä").replace("[AE]", "Ä")
|
|
|
|
.replace("[nl]", "\n"));
|
|
|
|
}
|
|
|
|
|
2021-11-28 01:13:21 +00:00
|
|
|
}
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
2022-06-18 14:16:26 +00:00
|
|
|
public static List<String> replacePrice(String prefix, List<String> Text, String price) {
|
2022-12-28 12:42:55 +00:00
|
|
|
List<String> rp = new ArrayList<>();
|
2021-11-28 01:13:21 +00:00
|
|
|
for (String s : Text) {
|
2022-07-07 11:43:50 +00:00
|
|
|
rp.add(replaceLegacyColor(s).replace("[prefix]", prefix)
|
2021-11-28 01:13:21 +00:00
|
|
|
.replace("[ue]", "ü").replace("[UE]", "Ü").replace("[oe]", "ö")
|
2022-06-18 14:16:26 +00:00
|
|
|
.replace("[OE]", "Ö").replace("[ae]", "ä").replace("[AE]", "Ä")
|
|
|
|
.replace("[nl]", "\n").replace("[price]", String.valueOf(price)));
|
2021-11-28 01:13:21 +00:00
|
|
|
}
|
|
|
|
return rp;
|
|
|
|
}
|
|
|
|
|
2022-06-18 14:16:26 +00:00
|
|
|
public static String removeColorCode(String value) {
|
2022-07-07 11:43:50 +00:00
|
|
|
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", "");
|
2021-12-31 04:26:57 +00:00
|
|
|
}
|
|
|
|
|
2022-06-18 14:16:26 +00:00
|
|
|
public static List<String> replacePrice(String prefix, Player player, List<String> Text, String price) {
|
2022-12-28 12:42:55 +00:00
|
|
|
List<String> rp = new ArrayList<>();
|
2021-11-28 01:13:21 +00:00
|
|
|
for (String s : Text) {
|
2023-07-08 19:29:30 +00:00
|
|
|
String input = s.replace("[prefix]", prefix)
|
2021-11-28 01:13:21 +00:00
|
|
|
.replace("[ue]", "ü").replace("[UE]", "Ü").replace("[oe]", "ö")
|
2022-06-18 14:16:26 +00:00
|
|
|
.replace("[OE]", "Ö").replace("[ae]", "ä").replace("[AE]", "Ä").replace("[nl]", "\n")
|
2023-07-08 19:29:30 +00:00
|
|
|
.replace("[price]", String.valueOf(price));
|
|
|
|
if (T2CpluginCheck.papi()) {
|
|
|
|
rp.add(replaceLegacyColor(PlaceholderAPI.setPlaceholders(player, input)));
|
|
|
|
} else {
|
|
|
|
rp.add(replaceLegacyColor(input));
|
|
|
|
}
|
2021-11-28 01:13:21 +00:00
|
|
|
}
|
|
|
|
return rp;
|
|
|
|
}
|
2022-06-18 14:16:26 +00:00
|
|
|
|
2021-11-28 01:13:21 +00:00
|
|
|
public static String replacePrice(String prefix, String Text, String price) {
|
2022-07-07 11:43:50 +00:00
|
|
|
return replaceLegacyColor(Text).replace("[prefix]", prefix)
|
|
|
|
.replace("&o", "§o").replace("&r", "§r").replace("[ue]", "ü")
|
2021-11-28 01:13:21 +00:00
|
|
|
.replace("[UE]", "Ü").replace("[oe]", "ö").replace("[OE]", "Ö")
|
2022-06-18 14:16:26 +00:00
|
|
|
.replace("[ae]", "ä").replace("[AE]", "Ä").replace("[price]", String.valueOf(price))
|
|
|
|
.replace("[nl]", "\n");
|
2021-11-28 01:13:21 +00:00
|
|
|
}
|
|
|
|
|
2022-06-18 14:16:26 +00:00
|
|
|
public static String replacePrice(String prefix, Player player, String Text, String price) {
|
2023-07-08 19:29:30 +00:00
|
|
|
String input = Text.replace("[prefix]", prefix)
|
2021-11-28 01:13:21 +00:00
|
|
|
.replace("[ue]", "ü").replace("[UE]", "Ü").replace("[oe]", "ö")
|
|
|
|
.replace("[OE]", "Ö").replace("[ae]", "ä").replace("[AE]", "Ä")
|
2023-07-08 19:29:30 +00:00
|
|
|
.replace("[price]", String.valueOf(price)).replace("[nl]", "\n");
|
|
|
|
if (T2CpluginCheck.papi()) {
|
|
|
|
return replaceLegacyColor(PlaceholderAPI.setPlaceholders(player, input));
|
|
|
|
} else {
|
|
|
|
return replaceLegacyColor(input);
|
|
|
|
}
|
|
|
|
|
2022-07-07 11:43:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
2022-07-08 17:06:22 +00:00
|
|
|
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>");
|
2021-11-28 01:13:21 +00:00
|
|
|
}
|
2023-07-08 17:42:48 +00:00
|
|
|
|
2023-07-08 19:29:30 +00:00
|
|
|
public static Object replace(Object object, String placeholder, String replacement) {
|
2023-07-08 17:42:48 +00:00
|
|
|
if (object instanceof String) {
|
|
|
|
object = ((String) object).replace(placeholder, replacement);
|
|
|
|
}
|
|
|
|
if ((object instanceof List) || (object instanceof ArrayList)) {
|
|
|
|
List<String> in = (List<String>) object;
|
|
|
|
List<String> output = new ArrayList<>();
|
|
|
|
for (String input : in) {
|
|
|
|
output.add(input.replace(placeholder, replacement));
|
|
|
|
}
|
|
|
|
object = output;
|
|
|
|
}
|
|
|
|
return object;
|
|
|
|
}
|
2021-11-28 01:13:21 +00:00
|
|
|
}
|