Skip to content

Commit

Permalink
Add error handling if CustomPlaceholder#replace returns null
Browse files Browse the repository at this point in the history
  • Loading branch information
Xitee1 committed Jan 1, 2024
1 parent 8bdddb2 commit 642fe48
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/main/java/de/xite/scoreboard/utils/Placeholders.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,19 @@ public class Placeholders {
};

public static String replace(Player p, String s) {
// Import placeholders from APIs
for(CustomPlaceholders ph : ph)
s = ph.replace(p, s);

// First replace with PAPI if preferred
if(ExternalPlugins.hasPapi && !pl.getConfig().getBoolean("prefer-plugin-placeholders"))
// Replace all custom placeholders first
for(CustomPlaceholders ph : ph) {
String output = ph.replace(p, s);
if(output == null) {
pl.getLogger().severe("Output of CustomPlaceholders#replace cannot be null!" +
"This is NOT a bug in PowerBoard! It is caused by a CustomPlaceholder which was registered from another plugin.");
}else
s = output;
}

// Replace all PAPI placeholders
boolean preferPBPlaceholders = pl.getConfig().getBoolean("prefer-plugin-placeholders");
if(!preferPBPlaceholders && ExternalPlugins.hasPapi)
try {
s = PlaceholderAPI.setPlaceholders(p, s);
}catch (Exception e) {
Expand All @@ -60,7 +67,6 @@ public static String replace(Player p, String s) {


// ---- Deprecated ---- //

for(Map.Entry<String, String> ph : deprecatedPlaceholders.entrySet()) {
String oldPH = ph.getKey();
String newPH = ph.getValue();
Expand All @@ -70,7 +76,7 @@ public static String replace(Player p, String s) {
}
}

// ---- Placeholders from PowerBoard Plugin ---- //
// ---- Placeholders from PowerBoard ---- //
String ph;

// TPS
Expand Down Expand Up @@ -260,7 +266,7 @@ public static String replace(Player p, String s) {
//s = IridiumColorAPI.process(s);

// Replace PAPI if plugin preferred
if(ExternalPlugins.hasPapi && pl.getConfig().getBoolean("prefer-plugin-placeholders"))
if(preferPBPlaceholders && ExternalPlugins.hasPapi)
s = PlaceholderAPI.setPlaceholders(p, s);

return s;
Expand Down

0 comments on commit 642fe48

Please sign in to comment.