diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/placeholder/PlaceholderOccurrence.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/placeholder/PlaceholderOccurrence.java index 8042b22e..777ecad2 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/placeholder/PlaceholderOccurrence.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/placeholder/PlaceholderOccurrence.java @@ -13,19 +13,25 @@ import java.util.Objects; public class PlaceholderOccurrence { + private final String unparsedContent; private final PluginName pluginName; private final PlaceholderIdentifier identifier; private final String argument; private final int hashCode; // Cached for performance reasons - private PlaceholderOccurrence(PluginName pluginName, PlaceholderIdentifier identifier, String argument) { + private PlaceholderOccurrence(String unparsedContent, PluginName pluginName, PlaceholderIdentifier identifier, String argument) { + this.unparsedContent = unparsedContent; this.pluginName = pluginName; this.identifier = identifier; this.argument = argument; this.hashCode = Objects.hash(pluginName, identifier, argument); } + public String getUnparsedContent() { + return unparsedContent; + } + public @Nullable PluginName getPluginName() { return pluginName; } @@ -39,11 +45,11 @@ public class PlaceholderOccurrence { } /* - * Valid placeholder formats: - * {identifier} - * {identifier: argument} - * {pluginName/identifier} - * {pluginName/identifier: argument} + * Valid placeholder content formats (delimiters are not included in the content): + * "identifier" + * "identifier: argument" + * "pluginName/identifier" + * "pluginName/identifier: argument" * * identifier is required, pluginName and argument are optional */ @@ -67,7 +73,7 @@ public class PlaceholderOccurrence { } PlaceholderIdentifier identifier = new PlaceholderIdentifier(identifierString); - return new PlaceholderOccurrence(pluginName, identifier, argument); + return new PlaceholderOccurrence(placeholderContent, pluginName, identifier, argument); } @Override diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/placeholder/tracking/ActivePlaceholderTracker.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/placeholder/tracking/ActivePlaceholderTracker.java index ce8fe98c..36ab0f7b 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/placeholder/tracking/ActivePlaceholderTracker.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/placeholder/tracking/ActivePlaceholderTracker.java @@ -66,7 +66,7 @@ public class ActivePlaceholderTracker implements PlaceholderReplaceFunction { } return activePlaceholder.computeReplacement(player, tickClock.getCurrentTick()); } catch (PlaceholderException e) { - exceptionHandler.handle(e); + exceptionHandler.handle(e, placeholderOccurrence); return "[Error]"; } } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/placeholder/tracking/PlaceholderExceptionHandler.java b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/placeholder/tracking/PlaceholderExceptionHandler.java index ab583c8a..2274f5da 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/placeholder/tracking/PlaceholderExceptionHandler.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/plugin/placeholder/tracking/PlaceholderExceptionHandler.java @@ -7,8 +7,8 @@ package me.filoghost.holographicdisplays.plugin.placeholder.tracking; import me.filoghost.fcommons.logging.Log; import me.filoghost.holographicdisplays.plugin.placeholder.PlaceholderException; +import me.filoghost.holographicdisplays.plugin.placeholder.PlaceholderOccurrence; import me.filoghost.holographicdisplays.plugin.tick.TickClock; -import me.filoghost.holographicdisplays.plugin.placeholder.registry.PlaceholderExpansion; import java.util.Map; import java.util.WeakHashMap; @@ -16,28 +16,27 @@ import java.util.WeakHashMap; class PlaceholderExceptionHandler { private final TickClock tickClock; - private final Map lastErrorLogByPlaceholderExpansion; + private final Map lastErrorLogByPlaceholderContent; PlaceholderExceptionHandler(TickClock tickClock) { this.tickClock = tickClock; - this.lastErrorLogByPlaceholderExpansion = new WeakHashMap<>(); + this.lastErrorLogByPlaceholderContent = new WeakHashMap<>(); } - void handle(PlaceholderException exception) { - PlaceholderExpansion placeholderExpansion = exception.getPlaceholderExpansion(); - Long lastErrorLog = lastErrorLogByPlaceholderExpansion.get(placeholderExpansion); + void handle(PlaceholderException exception, PlaceholderOccurrence placeholderOccurrence) { + String unparsedContent = placeholderOccurrence.getUnparsedContent(); + Long lastErrorLog = lastErrorLogByPlaceholderContent.get(unparsedContent); long currentTick = tickClock.getCurrentTick(); if (lastErrorLog != null && currentTick - lastErrorLog < 20) { return; // Avoid spamming the console too frequently } - lastErrorLogByPlaceholderExpansion.put(placeholderExpansion, currentTick); + lastErrorLogByPlaceholderContent.put(unparsedContent, currentTick); - Log.warning("The placeholder \"" + placeholderExpansion.getIdentifier() + "\"" - + " registered by the plugin " + placeholderExpansion.getPluginName() - + " generated an exception." - + " Please contact the author of " + placeholderExpansion.getPluginName(), + Log.warning("The placeholder {" + unparsedContent + "}" + + " registered by the plugin " + exception.getPlaceholderExpansion().getPluginName() + + " generated an exception.", exception.getCause()); }