Skip to content

Commit

Permalink
Invert offline and online placeholder parsing logic
Browse files Browse the repository at this point in the history
  • Loading branch information
EverNife committed Apr 30, 2024
1 parent bc0d2b1 commit 379c512
Showing 1 changed file with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ public SimplePAPIHook(Plugin plugin, PAPIRegexReplacer PAPI_REGEX_REPLACER) {
this.isPDSection = PDSection.class.isAssignableFrom(PAPI_REGEX_REPLACER.getReferClass());
}

@Override
public @Nullable String onPlaceholderRequest(@Nullable Player player, @NotNull String placeholder) {
return this.onPlaceholderRequest(player, placeholder);
}

@Override
public @Nullable String onRequest(OfflinePlayer player, @NotNull String placeholder) {
IPlayerData playerData = player == null ? null : PlayerController.getPlayerData(player);

if (playerData != null && isPDSection){
Expand All @@ -36,19 +42,15 @@ public SimplePAPIHook(Plugin plugin, PAPIRegexReplacer PAPI_REGEX_REPLACER) {
.apply(startingPlaceholder, playerData);

if (startingPlaceholder.equals(parsedPlaceholder)){
return null; //The placeholder has not been parsed, this is not an error, it simply did not exist
return null; //The placeholder has not been parsed, this is not an error, it simply does not exist
}

return parsedPlaceholder;
}catch (Exception e){
this.plugin.getLogger().warning("Failed to parse the Placeholder [" + placeholder + "]");
e.printStackTrace();
return "[ErrorOnPlaceholder]";
return "[ErrorOnPlaceholder=='%" + placeholder + "%']";
}
}

@Override
public @Nullable String onRequest(OfflinePlayer player, @NotNull String params) {
return player != null && player.isOnline() ? this.onPlaceholderRequest((Player)player, params) : this.onPlaceholderRequest((Player)null, params);
}
}

0 comments on commit 379c512

Please sign in to comment.