Skip to content

Commit

Permalink
yes
Browse files Browse the repository at this point in the history
  • Loading branch information
nothendev committed Oct 9, 2021
1 parent 017ba65 commit dd1868f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/main/java/ru/magmacube/csfbungee/CSF.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void onEnable()
LogFilter filter = new LogFilter(this);
filter.inject();

// Inject filter on every plugins
// Inject filter on every plugin
for(Plugin plugin : getProxy().getPluginManager().getPlugins())
filter.inject(plugin.getLogger());
}
Expand Down
25 changes: 6 additions & 19 deletions src/main/java/ru/magmacube/csfbungee/LogFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,44 +11,31 @@ public class LogFilter implements CustomFilter
{
private Logger log;
private Set<String> ignored;

LogFilter(CSF plugin)
{
LogFilter(CSF plugin) {
this.log = plugin.getProxy().getLogger();
this.ignored = new HashSet<>(plugin.getConfig().getIgnoredLines());
}

@Override
public boolean isLoggable(LogRecord record)
{
public boolean isLoggable(LogRecord record) {
boolean found = false;

for(String line : ignored)
{
if(found)
break;

found = record.getMessage().toLowerCase().startsWith(line.toLowerCase());
found = record.getMessage().toLowerCase().contains(line.toLowerCase());
}

return !(found);
}

Filter inject(Logger log)
{
Filter inject(Logger log) {
this.log = log;
return inject();
}

@Override
public Filter inject()
{
public Filter inject() {
log.setFilter(this);
return log.getFilter();
}

void updateIgnoredLines(List<String> newList)
{
void updateIgnoredLines(List<String> newList) {
ignored.clear();
ignored.addAll(newList);
}
Expand Down
8 changes: 3 additions & 5 deletions src/main/java/ru/magmacube/csfbungee/ReloadCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class ReloadCmd extends Command

ReloadCmd(CSF plugin)
{
super("consolespamfixbungee", "csf.admin", "csfb");
super("csf", "csf.admin", "csfb");
this.plugin = plugin;
}

Expand All @@ -34,15 +34,13 @@ public void execute(CommandSender sender, String[] args)

try
{
plugin.reloadConfig();
((LogFilter) plugin.getLogger().getFilter()).updateIgnoredLines(plugin.getConfig().getIgnoredLines());
plugin.reloadConfig(); ((LogFilter) plugin.getLogger().getFilter()).updateIgnoredLines(plugin.getConfig().getIgnoredLines());
sender.sendMessage(new TextComponent(ChatColor.GREEN + "Successfully updated ignored lines"));
}
catch(Exception e)
{
sender.sendMessage(new TextComponent(ChatColor.RED + "Error whilst updating ignored lines. Check the console" +
" for more information."));
System.err.println("[ConsoleSpamFixBungee] Could not update ignored lines: " + e.getMessage());
" for more information.")); System.err.println("[ConsoleSpamFixBungee] Could not update ignored lines: " + e.getMessage());
e.printStackTrace();
}
}
Expand Down

0 comments on commit dd1868f

Please sign in to comment.