Add filter to suppress misleading errors

This commit is contained in:
PikaMug 2022-01-22 18:42:06 -05:00
parent 25910ac66d
commit 47f52fbb1f
4 changed files with 74 additions and 8 deletions

View File

@ -160,7 +160,12 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.32</version>
<version>1.7.33</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.17.1</version>
</dependency>
<dependency>
<groupId>me.blackvein.quests</groupId>

View File

@ -15,14 +15,14 @@ package me.blackvein.quests;
import com.codisimus.plugins.phatloots.PhatLootsAPI;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.herocraftonline.heroes.characters.classes.HeroClass;
import me.blackvein.quests.actions.IAction;
import me.blackvein.quests.actions.ActionFactory;
import me.blackvein.quests.actions.Action;
import me.blackvein.quests.actions.ActionFactory;
import me.blackvein.quests.actions.BukkitActionFactory;
import me.blackvein.quests.conditions.Condition;
import me.blackvein.quests.actions.IAction;
import me.blackvein.quests.conditions.BukkitConditionFactory;
import me.blackvein.quests.conditions.ICondition;
import me.blackvein.quests.conditions.Condition;
import me.blackvein.quests.conditions.ConditionFactory;
import me.blackvein.quests.conditions.ICondition;
import me.blackvein.quests.config.ISettings;
import me.blackvein.quests.convo.misc.MiscStringPrompt;
import me.blackvein.quests.convo.misc.NpcOfferQuestPrompt;
@ -44,6 +44,7 @@ import me.blackvein.quests.listeners.NpcListener;
import me.blackvein.quests.listeners.PartiesListener;
import me.blackvein.quests.listeners.PlayerListener;
import me.blackvein.quests.listeners.UniteListener;
import me.blackvein.quests.logging.QuestsLog4JFilter;
import me.blackvein.quests.module.ICustomObjective;
import me.blackvein.quests.player.IQuester;
import me.blackvein.quests.quests.BukkitQuestFactory;
@ -72,6 +73,7 @@ import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.npc.NPC;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.TextComponent;
import org.apache.logging.log4j.LogManager;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Color;
@ -271,6 +273,7 @@ public class Quests extends JavaPlugin implements QuestsAPI {
});
// 12 - Delay loading of Quests, Actions and modules
((org.apache.logging.log4j.core.Logger) LogManager.getRootLogger()).addFilter(new QuestsLog4JFilter());
delayLoadQuestInfo();
}

View File

@ -300,9 +300,10 @@ public class NpcsPrompt extends QuestsEditorNumericPrompt {
= (List<Integer>) context.getSessionData(pref + CK.S_DELIVERY_NPCS);
if (deliveryNpcs != null) {
for (final int i : deliveryNpcs) {
text.append(")\n").append(ChatColor.GRAY).append(" - ").append(ChatColor.AQUA).append(i)
.append(" (").append(plugin.getDependencies().getCitizens().getNPCRegistry()
.getById(i).getName());
text.append("\n").append(ChatColor.GRAY).append(" - ").append(ChatColor.AQUA).append(i)
.append(ChatColor.GRAY).append(" (").append(ChatColor.AQUA)
.append(plugin.getDependencies().getCitizens().getNPCRegistry()
.getById(i).getName()).append(ChatColor.GRAY).append(")");
}
}
return text.toString();

View File

@ -0,0 +1,57 @@
package me.blackvein.quests.logging;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.Marker;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.Logger;
import org.apache.logging.log4j.core.filter.AbstractFilter;
import org.apache.logging.log4j.message.Message;
public class QuestsLog4JFilter extends AbstractFilter {
private static final long serialVersionUID = -5594073755007974514L;
/**
* Validates a message and returns the {@link Result} value
* depending on whether the message contains undesirable data.
*
* @param message The message to filter for
*
* @return Result of DENY or NUETRAL
*/
private static Result validateMessage(String message) {
if (message == null) {
return Result.NEUTRAL;
}
// Paper outputs errors when dependencies for module events are missing
return message.contains("Plugin Quests") ? Result.DENY : Result.NEUTRAL;
}
@Override
public Result filter(LogEvent event) {
if (event == null) {
return Result.NEUTRAL;
}
return validateMessage(event.getMessage().getFormattedMessage());
}
@Override
public Result filter(Logger logger, Level level, Marker marker, Message msg, Throwable t) {
return validateMessage(msg.getFormattedMessage());
}
@Override
public Result filter(Logger logger, Level level, Marker marker, String msg, Object... params) {
return validateMessage(msg);
}
@Override
public Result filter(Logger logger, Level level, Marker marker, Object msg, Throwable t) {
if (msg == null) {
return Result.NEUTRAL;
}
return validateMessage(msg.toString());
}
}