Update T2Creplace.java

Fixed error when PlaceholderAPI is not installed
This commit is contained in:
JaTiTV 2023-07-08 21:29:30 +02:00
parent f8619e4802
commit addc485ca8

View File

@ -1,6 +1,7 @@
package net.t2code.t2codelib.SPIGOT.api.messages;
import me.clip.placeholderapi.PlaceholderAPI;
import net.t2code.t2codelib.SPIGOT.api.plugins.T2CpluginCheck;
import org.bukkit.entity.Player;
import java.util.ArrayList;
@ -17,10 +18,16 @@ public class T2Creplace {
}
public static String replace(String prefix, Player player, String Text) {
return replaceLegacyColor(PlaceholderAPI.setPlaceholders(player, Text.replace("[prefix]", prefix)
String input = Text.replace("[prefix]", prefix)
.replace("[ue]", "ü").replace("[UE]", "Ü").replace("[oe]", "ö")
.replace("[OE]", "Ö").replace("[ae]", "ä").replace("[AE]", "Ä")
.replace("[nl]", "\n")));
.replace("[nl]", "\n");
if (T2CpluginCheck.papi()) {
return replaceLegacyColor(PlaceholderAPI.setPlaceholders(player, input));
} else {
return replaceLegacyColor(input);
}
}
public static Object replaceObject(String prefix, Object object) {
@ -46,18 +53,33 @@ public class T2Creplace {
public static Object replaceObject(String prefix, Player player, Object object) {
if (object instanceof String) {
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"));
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");
}
}
if (object instanceof List) {
List<String> in = (List<String>) object;
List<String> output = new ArrayList<>();
for (String input : in) {
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")));
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"));
}
}
object = output;
}
@ -84,10 +106,18 @@ public class T2Creplace {
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")));
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"));
}
}
return output;
}
@ -115,10 +145,15 @@ public class T2Creplace {
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)
String input = s.replace("[prefix]", prefix)
.replace("[ue]", "ü").replace("[UE]", "Ü").replace("[oe]", "ö")
.replace("[OE]", "Ö").replace("[ae]", "ä").replace("[AE]", "Ä").replace("[nl]", "\n")
.replace("[price]", String.valueOf(price)))));
.replace("[price]", String.valueOf(price));
if (T2CpluginCheck.papi()) {
rp.add(replaceLegacyColor(PlaceholderAPI.setPlaceholders(player, input)));
} else {
rp.add(replaceLegacyColor(input));
}
}
return rp;
}
@ -132,10 +167,16 @@ public class T2Creplace {
}
public static String replacePrice(String prefix, Player player, String Text, String price) {
return replaceLegacyColor(PlaceholderAPI.setPlaceholders(player, Text.replace("[prefix]", prefix)
String input = Text.replace("[prefix]", prefix)
.replace("[ue]", "ü").replace("[UE]", "Ü").replace("[oe]", "ö")
.replace("[OE]", "Ö").replace("[ae]", "ä").replace("[AE]", "Ä")
.replace("[price]", String.valueOf(price)).replace("[nl]", "\n")));
.replace("[price]", String.valueOf(price)).replace("[nl]", "\n");
if (T2CpluginCheck.papi()) {
return replaceLegacyColor(PlaceholderAPI.setPlaceholders(player, input));
} else {
return replaceLegacyColor(input);
}
}
public static String replaceLegacyColor(String text) {
@ -172,7 +213,7 @@ public class T2Creplace {
.replace("&r", "<reset>").replace("§r", "<reset>");
}
public static Object replace(Object object,String placeholder,String replacement) {
public static Object replace(Object object, String placeholder, String replacement) {
if (object instanceof String) {
object = ((String) object).replace(placeholder, replacement);
}