<commit_before>/**
 * Copyright © 2013 tuxed <<EMAIL>>
 * This work is free. You can redistribute it and/or modify it under the
 * terms of the Do What The Fuck You Want To Public License, Version 2,
 * as published by Sam Hocevar. See http://www.wtfpl.net/ for more details.
 */
package com.imaginarycode.minecraft.redisbungee;

import com.google.common.base.Joiner;
import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
import com.imaginarycode.minecraft.redisbungee.consumerevents.PlayerChangedServerConsumerEvent;
import com.imaginarycode.minecraft.redisbungee.consumerevents.PlayerLoggedInConsumerEvent;
import com.imaginarycode.minecraft.redisbungee.consumerevents.PlayerLoggedOffConsumerEvent;
import com.imaginarycode.minecraft.redisbungee.events.PubSubMessageEvent;
import lombok.AllArgsConstructor;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.ServerPing;
import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.connection.Server;
import net.md_5.bungee.api.event.*;
import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.event.EventHandler;
import redis.clients.jedis.Jedis;

import java.util.*;

@AllArgsConstructor
public class RedisBungeeListener implements Listener {
    private final RedisBungee plugin;

    @EventHandler
    public void onPlayerConnect(final PostLoginEvent event) {
        if (plugin.getPool() != null) {
            Jedis rsc = plugin.getPool().getResource();
            try {
                for (String server : plugin.getServerIds()) {
                    if (rsc.sismember("server:" + server + ":usersOnline", event.getPlayer().getUniqueId().toString())) {
                        event.getPlayer().disconnect(new ComponentBuilder("You are already logged on to this server.").color(
                                ChatColor.RED).create());
                        return;
                    }
                }
            } finally {
                plugin.getPool().returnResource(rsc);
            }
        }
        plugin.getConsumer().queue(new PlayerLoggedInConsumerEvent(event.getPlayer()));
    }

    @EventHandler
    public void onPlayerDisconnect(final PlayerDisconnectEvent event) {
        plugin.getConsumer().queue(new PlayerLoggedOffConsumerEvent(event.getPlayer()));
    }

    @EventHandler
    public void onServerChange(final ServerConnectedEvent event) {
        plugin.getConsumer().queue(new PlayerChangedServerConsumerEvent(event.getPlayer(), event.getServer().getInfo()));
    }

    @EventHandler
    public void onPing(ProxyPingEvent event) {
        ServerPing old = event.getResponse();
        ServerPing reply = new ServerPing();
        reply.setPlayers(new ServerPing.Players(old.getPlayers().getMax(), plugin.getCount(), null));
        reply.setDescription(old.getDescription());
        reply.setFavicon(old.getFaviconObject());
        reply.setVersion(old.getVersion());
        event.setResponse(reply);
    }

    @EventHandler
    public void onPluginMessage(final PluginMessageEvent event) {<commit_msg>Preserve the old sample<commit_after>/**
 * Copyright © 2013 tuxed <<EMAIL>>
 * This work is free. You can redistribute it and/or modify it under the
 * terms of the Do What The Fuck You Want To Public License, Version 2,
 * as published by Sam Hocevar. See http://www.wtfpl.net/ for more details.
 */
package com.imaginarycode.minecraft.redisbungee;

import com.google.common.base.Joiner;
import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
import com.imaginarycode.minecraft.redisbungee.consumerevents.PlayerChangedServerConsumerEvent;
import com.imaginarycode.minecraft.redisbungee.consumerevents.PlayerLoggedInConsumerEvent;
import com.imaginarycode.minecraft.redisbungee.consumerevents.PlayerLoggedOffConsumerEvent;
import com.imaginarycode.minecraft.redisbungee.events.PubSubMessageEvent;
import lombok.AllArgsConstructor;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.ServerPing;
import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.connection.Server;
import net.md_5.bungee.api.event.*;
import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.event.EventHandler;
import redis.clients.jedis.Jedis;

import java.util.*;

@AllArgsConstructor
public class RedisBungeeListener implements Listener {
    private final RedisBungee plugin;

    @EventHandler
    public void onPlayerConnect(final PostLoginEvent event) {
        if (plugin.getPool() != null) {
            Jedis rsc = plugin.getPool().getResource();
            try {
                for (String server : plugin.getServerIds()) {
                    if (rsc.sismember("server:" + server + ":usersOnline", event.getPlayer().getUniqueId().toString())) {
                        event.getPlayer().disconnect(new ComponentBuilder("You are already logged on to this server.").color(
                                ChatColor.RED).create());
                        return;
                    }
                }
            } finally {
                plugin.getPool().returnResource(rsc);
            }
        }
        plugin.getConsumer().queue(new PlayerLoggedInConsumerEvent(event.getPlayer()));
    }

    @EventHandler
    public void onPlayerDisconnect(final PlayerDisconnectEvent event) {
        plugin.getConsumer().queue(new PlayerLoggedOffConsumerEvent(event.getPlayer()));
    }

    @EventHandler
    public void onServerChange(final ServerConnectedEvent event) {
        plugin.getConsumer().queue(new PlayerChangedServerConsumerEvent(event.getPlayer(), event.getServer().getInfo()));
    }

    @EventHandler
    public void onPing(ProxyPingEvent event) {
        ServerPing old = event.getResponse();
        ServerPing reply = new ServerPing();
        reply.setPlayers(new ServerPing.Players(old.getPlayers().getMax(), plugin.getCount(), old.getPlayers().getSample()));
        reply.setDescription(old.getDescription());
        reply.setFavicon(old.getFaviconObject());
        reply.setVersion(old.getVersion());
        event.setResponse(reply);
    }

    @EventHandler
    public void onPluginMessage(final PluginMessageEvent event) {
{'fraction_non_alphanumeric': 0.10581506196377502, 'fraction_numerical': 0.0038131553860819827, 'mean_word_length': 3.3837047353760448, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '20043', 'n_tokens_mistral': 1822, 'n_tokens_neox': 1798, 'n_words': 345}