Skip to content

Commit

Permalink
lenient by default for PlaceholderValueProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
HSGamer committed Oct 30, 2024
1 parent 084dbc4 commit b0e9155
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private void migrateConfig() {
map.put("placeholder", placeholder);
map.put("online", prefix.contains("[online]"));
map.put("async", prefix.contains("[async]"));
map.put("lenient", prefix.contains("[lenient]"));
map.put("show-errors", !prefix.contains("[lenient]"));
} else {
map.put("placeholder", value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class PlaceholderValueProvider implements ValueProvider {
private final String placeholder;
private final boolean isOnlineOnly;
private final boolean isAsync;
private final boolean isLenient;
private final boolean showErrors;

public PlaceholderValueProvider(TopperPlugin plugin, Map<String, Object> map) {
this.plugin = plugin;
Expand All @@ -33,7 +33,7 @@ public PlaceholderValueProvider(TopperPlugin plugin, Map<String, Object> map) {
.map(String::toLowerCase)
.map(Boolean::parseBoolean)
.orElse(false);
isLenient = Optional.ofNullable(map.get("lenient"))
showErrors = Optional.ofNullable(map.get("show-errors"))
.map(Object::toString)
.map(String::toLowerCase)
.map(Boolean::parseBoolean)
Expand All @@ -56,14 +56,14 @@ public CompletableFuture<Optional<Double>> getValue(UUID uuid) {
try {
String parsed = PlaceholderAPI.setPlaceholders(player, placeholder).trim();
if (parsed.isEmpty()) {
if (!isLenient) {
if (showErrors) {
plugin.getLogger().warning("The placeholder " + placeholder + " returns empty");
}
return Optional.empty();
}
return Optional.of(Double.parseDouble(parsed));
} catch (Exception e) {
if (!isLenient) {
if (showErrors) {
plugin.getLogger().log(Level.WARNING, "There is an error while parsing the placeholder: " + placeholder, e);
}
return Optional.empty();
Expand Down

0 comments on commit b0e9155

Please sign in to comment.