Update T2Creplace.java
Fixed error when PlaceholderAPI is not installed
This commit is contained in:
parent
f8619e4802
commit
addc485ca8
@ -1,6 +1,7 @@
|
|||||||
package net.t2code.t2codelib.SPIGOT.api.messages;
|
package net.t2code.t2codelib.SPIGOT.api.messages;
|
||||||
|
|
||||||
import me.clip.placeholderapi.PlaceholderAPI;
|
import me.clip.placeholderapi.PlaceholderAPI;
|
||||||
|
import net.t2code.t2codelib.SPIGOT.api.plugins.T2CpluginCheck;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -17,10 +18,16 @@ public class T2Creplace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String replace(String prefix, Player player, String Text) {
|
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("[ue]", "ü").replace("[UE]", "Ü").replace("[oe]", "ö")
|
||||||
.replace("[OE]", "Ö").replace("[ae]", "ä").replace("[AE]", "Ä")
|
.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) {
|
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) {
|
public static Object replaceObject(String prefix, Player player, Object object) {
|
||||||
if (object instanceof String) {
|
if (object instanceof String) {
|
||||||
|
|
||||||
|
if (T2CpluginCheck.papi()) {
|
||||||
object = PlaceholderAPI.setPlaceholders(player, replaceLegacyColor((String) object).replace("[prefix]", prefix).replace("[ue]", "ü")
|
object = PlaceholderAPI.setPlaceholders(player, replaceLegacyColor((String) object).replace("[prefix]", prefix).replace("[ue]", "ü")
|
||||||
.replace("[UE]", "Ü").replace("[oe]", "ö").replace("[OE]", "Ö")
|
.replace("[UE]", "Ü").replace("[oe]", "ö").replace("[OE]", "Ö")
|
||||||
.replace("[ae]", "ä").replace("[AE]", "Ä").replace("[nl]", "\n"));
|
.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) {
|
if (object instanceof List) {
|
||||||
List<String> in = (List<String>) object;
|
List<String> in = (List<String>) object;
|
||||||
List<String> output = new ArrayList<>();
|
List<String> output = new ArrayList<>();
|
||||||
for (String input : in) {
|
for (String input : in) {
|
||||||
|
if (T2CpluginCheck.papi()) {
|
||||||
output.add(PlaceholderAPI.setPlaceholders(player, replaceLegacyColor(input).replace("[prefix]", prefix)
|
output.add(PlaceholderAPI.setPlaceholders(player, replaceLegacyColor(input).replace("[prefix]", prefix)
|
||||||
.replace("[ue]", "ü").replace("[UE]", "Ü").replace("[oe]", "ö")
|
.replace("[ue]", "ü").replace("[UE]", "Ü").replace("[oe]", "ö")
|
||||||
.replace("[OE]", "Ö").replace("[ae]", "ä").replace("[AE]", "Ä")
|
.replace("[OE]", "Ö").replace("[ae]", "ä").replace("[AE]", "Ä")
|
||||||
.replace("[nl]", "\n")));
|
.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;
|
object = output;
|
||||||
}
|
}
|
||||||
@ -84,10 +106,18 @@ public class T2Creplace {
|
|||||||
return Collections.singletonList("Text is null");
|
return Collections.singletonList("Text is null");
|
||||||
}
|
}
|
||||||
for (String input : Text) {
|
for (String input : Text) {
|
||||||
|
if (T2CpluginCheck.papi()) {
|
||||||
output.add(PlaceholderAPI.setPlaceholders(player, replaceLegacyColor(input).replace("[prefix]", prefix)
|
output.add(PlaceholderAPI.setPlaceholders(player, replaceLegacyColor(input).replace("[prefix]", prefix)
|
||||||
.replace("[ue]", "ü").replace("[UE]", "Ü").replace("[oe]", "ö")
|
.replace("[ue]", "ü").replace("[UE]", "Ü").replace("[oe]", "ö")
|
||||||
.replace("[OE]", "Ö").replace("[ae]", "ä").replace("[AE]", "Ä")
|
.replace("[OE]", "Ö").replace("[ae]", "ä").replace("[AE]", "Ä")
|
||||||
.replace("[nl]", "\n")));
|
.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;
|
return output;
|
||||||
}
|
}
|
||||||
@ -115,10 +145,15 @@ public class T2Creplace {
|
|||||||
public static List<String> replacePrice(String prefix, Player player, List<String> Text, String price) {
|
public static List<String> replacePrice(String prefix, Player player, List<String> Text, String price) {
|
||||||
List<String> rp = new ArrayList<>();
|
List<String> rp = new ArrayList<>();
|
||||||
for (String s : Text) {
|
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("[ue]", "ü").replace("[UE]", "Ü").replace("[oe]", "ö")
|
||||||
.replace("[OE]", "Ö").replace("[ae]", "ä").replace("[AE]", "Ä").replace("[nl]", "\n")
|
.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;
|
return rp;
|
||||||
}
|
}
|
||||||
@ -132,10 +167,16 @@ public class T2Creplace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String replacePrice(String prefix, Player player, String Text, String price) {
|
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("[ue]", "ü").replace("[UE]", "Ü").replace("[oe]", "ö")
|
||||||
.replace("[OE]", "Ö").replace("[ae]", "ä").replace("[AE]", "Ä")
|
.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) {
|
public static String replaceLegacyColor(String text) {
|
||||||
@ -172,7 +213,7 @@ public class T2Creplace {
|
|||||||
.replace("&r", "<reset>").replace("§r", "<reset>");
|
.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) {
|
if (object instanceof String) {
|
||||||
object = ((String) object).replace(placeholder, replacement);
|
object = ((String) object).replace(placeholder, replacement);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user