Skip to content

Commit

Permalink
fix: Wrong audience in CommandSpy Placeholders format
Browse files Browse the repository at this point in the history
  • Loading branch information
4drian3d committed Apr 25, 2022
1 parent 3d56ddf commit 28b96a2
Showing 1 changed file with 14 additions and 16 deletions.
@@ -1,7 +1,5 @@
package me.dreamerzero.chatregulator.listener.command;

import java.util.function.Predicate;

import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.event.EventTask;
import com.velocitypowered.api.event.PostOrder;
Expand All @@ -16,6 +14,7 @@
import me.dreamerzero.chatregulator.config.MainConfig;
import me.dreamerzero.chatregulator.enums.Permissions;
import me.dreamerzero.chatregulator.modules.CommandSpy;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;

Expand Down Expand Up @@ -43,22 +42,21 @@ public EventTask onCommand(final CommandExecuteEvent event){
final String command = event.getCommand();

if(CommandSpy.shouldAnnounce(source, command, config)){
final TagResolver resolver = TagResolver.resolver(
Placeholder.unparsed("command", command),
Placeholder.unparsed("player", player.getUsername())
final Component message = plugin.getFormatter().parse(
Configuration.getMessages().getCommandSpyMessages().getMessage(),
player,
TagResolver.resolver(
Placeholder.unparsed("command", command),
Placeholder.unparsed("player", player.getUsername())
)
);
plugin.getProxy().getAllPlayers().stream()
.filter(PERMISSION_PREDICATE)
.forEach((final Player p) -> p.sendMessage(
plugin.getFormatter().parse(
Configuration.getMessages().getCommandSpyMessages().getMessage(),
p,
resolver
)
));
plugin.getProxy().getAllPlayers().forEach(pl -> {
if(pl.hasPermission(Permissions.COMMANDSPY_ALERT)) {
pl.sendMessage(message);
}
});
plugin.getProxy().getConsoleCommandSource().sendMessage(message);
}
});
}

private static final Predicate<CommandSource> PERMISSION_PREDICATE = s -> s.hasPermission(Permissions.COMMANDSPY_ALERT);
}

0 comments on commit 28b96a2

Please sign in to comment.