use of me.dreamerzero.chatregulator.InfractionPlayer in project ChatRegulator by 4drian3d.
the class PlaceholderTest method playerPlaceholders.
@Test
@DisplayName("Player Placeholders")
void playerPlaceholders() {
Player p = TestsUtils.createNormalPlayer("Adrianed_04yt");
InfractionPlayer player = InfractionPlayer.get(p);
MiniMessage mm = MiniMessage.builder().tags(TagResolver.resolver(PlaceholderUtils.getPlaceholders(player), StandardTags.color())).build();
Component componentWithPlaceholders = mm.deserialize("<aqua>Player <player> or <name> with" + " <regular> regular infractions," + " <flood> flood infractions," + " <spam> spam infractions," + " <unicode> unicode infractions," + " and <caps> caps infractions");
Component expectedComponent = Component.text("Player Adrianed_04yt or Adrianed_04yt with" + " 0 regular infractions," + " 0 flood infractions," + " 0 spam infractions," + " 0 unicode infractions," + " and 0 caps infractions", NamedTextColor.AQUA);
assertEqualsComponent(expectedComponent, componentWithPlaceholders);
}
use of me.dreamerzero.chatregulator.InfractionPlayer in project ChatRegulator by 4drian3d.
the class PlaceholderUtils method getPlaceholders.
/**
* Obtain placeholders from an {@link InfractionPlayer}
* @param player the {@link InfractionPlayer}
* @return placeholders based on this player
*/
@NotNull
public static TagResolver getPlaceholders(@NotNull final InfractionPlayer player) {
final ViolationCount count = Objects.requireNonNull(player).getViolations();
final TagResolver.Builder resolver = TagResolver.builder().resolvers(Placeholder.unparsed("player", player.username()), Placeholder.unparsed("name", player.username()), integerPlaceholder("flood", count.getCount(InfractionType.FLOOD)), integerPlaceholder("spam", count.getCount(InfractionType.SPAM)), integerPlaceholder("regular", count.getCount(InfractionType.REGULAR)), integerPlaceholder("unicode", count.getCount(InfractionType.UNICODE)), integerPlaceholder("caps", count.getCount(InfractionType.CAPS)), integerPlaceholder("command", count.getCount(InfractionType.BCOMMAND)), integerPlaceholder("syntax", count.getCount(InfractionType.SYNTAX)));
Player p = player.getPlayer();
if (p != null) {
p.getCurrentServer().ifPresent(server -> resolver.resolver(Placeholder.unparsed("server", server.getServer().getServerInfo().getName())));
}
return resolver.build();
}
use of me.dreamerzero.chatregulator.InfractionPlayer in project ChatRegulator by 4drian3d.
the class LeaveListener method onLeave.
/**
* In case the player leaves the server,
* his online status is marked as false.
* @param event the event
*/
@Subscribe(order = PostOrder.LAST)
public EventTask onLeave(final DisconnectEvent event) {
return EventTask.async(() -> {
final InfractionPlayer player = InfractionPlayer.get(event.getPlayer());
player.isOnline(false);
final UUID uuid = event.getPlayer().getUniqueId();
plugin.getProxy().getScheduler().buildTask(plugin, () -> {
if (plugin.getProxy().getPlayer(uuid).isEmpty()) {
plugin.getLogger().debug("The player {} was eliminated", player.username());
plugin.removePlayer(uuid);
}
}).delay(Configuration.getConfig().getGeneralConfig().deleteUsersTime(), Configuration.getConfig().getGeneralConfig().unit()).schedule();
});
}
use of me.dreamerzero.chatregulator.InfractionPlayer in project ChatRegulator by 4drian3d.
the class ChatListener method onChat.
/**
* Chat Listener for detections
* @param event the chat event
* @param continuation the event cycle
*/
@Subscribe(order = PostOrder.FIRST)
public void onChat(final PlayerChatEvent event, final Continuation continuation) {
if (!event.getResult().isAllowed()) {
continuation.resume();
return;
}
final Player player = event.getPlayer();
final AtomicReference<String> message = new AtomicReference<String>(event.getMessage());
final InfractionPlayer infractor = InfractionPlayer.get(player);
final EventWrapper<PlayerChatEvent> wrapper = new ChatWrapper(event, continuation);
if (unicode(infractor, message, wrapper, plugin) || caps(infractor, message, wrapper, plugin) || flood(infractor, message, wrapper, plugin) || regular(infractor, message, wrapper, plugin) || spam(infractor, message, wrapper, plugin)) {
return;
}
if (Configuration.getConfig().getFormatConfig().enabled()) {
message.set(Replacer.applyFormat(message.get()));
event.setResult(ChatResult.message(message.get()));
}
infractor.lastMessage(message.get());
continuation.resume();
}
use of me.dreamerzero.chatregulator.InfractionPlayer in project ChatRegulator by 4drian3d.
the class SpamTest method chatTest.
@Test
@DisplayName("Chat Test")
void chatTest() {
Player p = TestsUtils.createNormalPlayer("Juan");
InfractionPlayer player = InfractionPlayer.get(p);
player.lastMessage("holaaaaaaaa");
player.lastMessage("holaaaaaaaa");
player.lastMessage("holaaaaaaaa");
player.lastMessage("holaaaaaaaa");
player.lastMessage("holaaaaaaaa");
assertTrue(SpamCheck.createCheck(player, "holaaaaaaaa", SourceType.CHAT).join().isInfraction());
}
Aggregations