Search in sources :

Example 1 with InfractionPlayer

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);
}
Also used : Player(com.velocitypowered.api.proxy.Player) InfractionPlayer(me.dreamerzero.chatregulator.InfractionPlayer) InfractionPlayer(me.dreamerzero.chatregulator.InfractionPlayer) Component(net.kyori.adventure.text.Component) MiniMessage(net.kyori.adventure.text.minimessage.MiniMessage) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 2 with InfractionPlayer

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();
}
Also used : Player(com.velocitypowered.api.proxy.Player) InfractionPlayer(me.dreamerzero.chatregulator.InfractionPlayer) TagResolver(net.kyori.adventure.text.minimessage.tag.resolver.TagResolver) ViolationCount(me.dreamerzero.chatregulator.ViolationCount) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with InfractionPlayer

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();
    });
}
Also used : InfractionPlayer(me.dreamerzero.chatregulator.InfractionPlayer) UUID(java.util.UUID) Subscribe(com.velocitypowered.api.event.Subscribe)

Example 4 with InfractionPlayer

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();
}
Also used : InfractionPlayer(me.dreamerzero.chatregulator.InfractionPlayer) Player(com.velocitypowered.api.proxy.Player) PlayerChatEvent(com.velocitypowered.api.event.player.PlayerChatEvent) ChatWrapper(me.dreamerzero.chatregulator.wrapper.event.ChatWrapper) AtomicReference(java.util.concurrent.atomic.AtomicReference) InfractionPlayer(me.dreamerzero.chatregulator.InfractionPlayer) Subscribe(com.velocitypowered.api.event.Subscribe)

Example 5 with InfractionPlayer

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());
}
Also used : Player(com.velocitypowered.api.proxy.Player) InfractionPlayer(me.dreamerzero.chatregulator.InfractionPlayer) InfractionPlayer(me.dreamerzero.chatregulator.InfractionPlayer) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

InfractionPlayer (me.dreamerzero.chatregulator.InfractionPlayer)7 Player (com.velocitypowered.api.proxy.Player)6 DisplayName (org.junit.jupiter.api.DisplayName)3 Test (org.junit.jupiter.api.Test)3 Subscribe (com.velocitypowered.api.event.Subscribe)2 NotNull (org.jetbrains.annotations.NotNull)2 PlayerChatEvent (com.velocitypowered.api.event.player.PlayerChatEvent)1 Locale (java.util.Locale)1 Objects (java.util.Objects)1 UUID (java.util.UUID)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 ChatRegulator (me.dreamerzero.chatregulator.ChatRegulator)1 ViolationCount (me.dreamerzero.chatregulator.ViolationCount)1 Configuration (me.dreamerzero.chatregulator.config.Configuration)1 CommandsConfig (me.dreamerzero.chatregulator.config.MainConfig.CommandsConfig)1 Executable (me.dreamerzero.chatregulator.config.MainConfig.Executable)1 InfractionType (me.dreamerzero.chatregulator.enums.InfractionType)1 ChatWrapper (me.dreamerzero.chatregulator.wrapper.event.ChatWrapper)1 Component (net.kyori.adventure.text.Component)1 MiniMessage (net.kyori.adventure.text.minimessage.MiniMessage)1