Search in sources :

Example 1 with EventHandler

use of net.md_5.bungee.event.EventHandler in project DiscordBot by LXGaming.

the class PlayerListener method onPostLogin.

@EventHandler(priority = EventPriority.HIGHEST)
public void onPostLogin(PostLoginEvent event) {
    if (event.getPlayer() == null) {
        return;
    }
    if (!DiscordBotCore.getInstance().getConfiguration().isPlayerJoin() || event.getPlayer().hasPermission("DiscordBot.Silent")) {
        return;
    }
    Message message = new Message().setChannel(DiscordBotCore.getInstance().getConfiguration().getChannels().get("Global").getChannel()).setFormat(DiscordBotCore.getInstance().getConfiguration().getPlayerFormat().get("Join")).setName(event.getPlayer().getName()).setNick(event.getPlayer().getDisplayName()).setServer("Unknown").setMessage("Joined").setDiscord(true).setMinecraft(false).setConsole(false).setRedis(false);
    if (event.getPlayer().getServer() != null && event.getPlayer().getServer().getInfo() != null) {
        message.setServer(event.getPlayer().getServer().getInfo().getName());
    }
    DiscordBotCore.getInstance().getMessageSender().sendMessage(message);
    return;
}
Also used : Message(io.github.lxgaming.discordbot.entries.Message) EventHandler(net.md_5.bungee.event.EventHandler)

Example 2 with EventHandler

use of net.md_5.bungee.event.EventHandler in project DiscordBot by LXGaming.

the class PlayerListener method onPlayerDisconnect.

//EventPriority is on Lowest due to LuckPerms unloading player data which causes permissions to be null.
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerDisconnect(PlayerDisconnectEvent event) {
    if (!DiscordBotCore.getInstance().getConfiguration().isPlayerQuit() || event.getPlayer().hasPermission("DiscordBot.Silent")) {
        return;
    }
    Message message = new Message().setChannel(DiscordBotCore.getInstance().getConfiguration().getChannels().get("Global").getChannel()).setFormat(DiscordBotCore.getInstance().getConfiguration().getPlayerFormat().get("Quit")).setName(event.getPlayer().getName()).setNick(event.getPlayer().getDisplayName()).setServer("Unknown").setMessage("Quit").setDiscord(true).setMinecraft(false).setConsole(false).setRedis(false);
    if (event.getPlayer().getServer() != null && event.getPlayer().getServer().getInfo() != null) {
        message.setServer(event.getPlayer().getServer().getInfo().getName());
    }
    DiscordBotCore.getInstance().getMessageSender().sendMessage(message);
    return;
}
Also used : Message(io.github.lxgaming.discordbot.entries.Message) EventHandler(net.md_5.bungee.event.EventHandler)

Example 3 with EventHandler

use of net.md_5.bungee.event.EventHandler in project CloudNet by Dytanic.

the class ProxiedListener method handleLogin.

@EventHandler(priority = EventPriority.LOWEST)
public void handleLogin(LoginEvent e) {
    PlayerConnection playerConnection = new PlayerConnection(e.getConnection().getUniqueId(), e.getConnection().getName(), e.getConnection().getVersion(), e.getConnection().getAddress().getAddress().getHostAddress(), e.getConnection().getAddress().getPort(), e.getConnection().isOnlineMode(), e.getConnection().isLegacy());
    CloudPlayer cloudPlayer = CloudAPI.getInstance().getNetworkConnection().getPacketManager().sendQuery(new PacketOutPlayerLoginRequest(playerConnection), CloudAPI.getInstance().getNetworkConnection()).getResult().getObject("player", new TypeToken<CloudPlayer>() {
    }.getType());
    if (cloudPlayer == null) {
        e.setCancelReason(TextComponent.fromLegacyText("§cYou are already on the network!"));
        e.setCancelled(true);
    }
    CommandSender cloudCommandSender = new CloudPlayerCommandSender(cloudPlayer);
    if (CloudProxy.getInstance().getProxyGroup() != null) {
        ProxyConfig proxyConfig = CloudProxy.getInstance().getProxyGroup().getProxyConfig();
        if ((proxyConfig.isEnabled() && proxyConfig.isMaintenance())) {
            PermissionCheckEvent permissionCheckEvent = new PermissionCheckEvent(cloudCommandSender, "cloudnet.maintenance", false);
            if (!proxyConfig.getWhitelist().contains(e.getConnection().getName()) && !ProxyServer.getInstance().getPluginManager().callEvent(permissionCheckEvent).hasPermission()) {
                e.setCancelled(true);
                e.setCancelReason(ChatColor.translateAlternateColorCodes('&', CloudAPI.getInstance().getCloudNetwork().getMessages().getString("kick-maintenance")));
                return;
            }
        }
    }
    ProxyGroup proxyGroup = CloudProxy.getInstance().getProxyGroup();
    if (proxyGroup.getProxyConfig().isEnabled())
        if (CloudAPI.getInstance().getOnlineCount() >= CloudProxy.getInstance().getProxyGroup().getProxyConfig().getMaxPlayers()) {
            PermissionCheckEvent permissionCheckEvent = new PermissionCheckEvent(cloudCommandSender, "cloudnet.fulljoin", false);
            if (!ProxyServer.getInstance().getPluginManager().callEvent(permissionCheckEvent).hasPermission()) {
                e.setCancelled(true);
                e.setCancelReason(ChatColor.translateAlternateColorCodes('&', CloudAPI.getInstance().getCloudNetwork().getMessages().getString("full-join")));
                return;
            }
        }
    CloudProxy.getInstance().getCloudPlayers().put(cloudPlayer.getUniqueId(), cloudPlayer);
}
Also used : CloudPlayerCommandSender(de.dytanic.cloudnet.bridge.internal.util.CloudPlayerCommandSender) ProxyGroup(de.dytanic.cloudnet.lib.server.ProxyGroup) TypeToken(com.google.gson.reflect.TypeToken) CloudPlayer(de.dytanic.cloudnet.lib.player.CloudPlayer) CommandSender(net.md_5.bungee.api.CommandSender) CloudPlayerCommandSender(de.dytanic.cloudnet.bridge.internal.util.CloudPlayerCommandSender) ProxyConfig(de.dytanic.cloudnet.lib.proxylayout.ProxyConfig) PlayerConnection(de.dytanic.cloudnet.lib.player.PlayerConnection) EventHandler(net.md_5.bungee.event.EventHandler)

Example 4 with EventHandler

use of net.md_5.bungee.event.EventHandler in project CloudNet by Dytanic.

the class ProxiedListener method handleServerKick.

@EventHandler
public void handleServerKick(ServerKickEvent e) {
    if (e.getCancelServer() != null) {
        ServerInfo serverInfo = CloudProxy.getInstance().getCachedServers().get(e.getKickedFrom().getName());
        String fallback;
        if (CloudAPI.getInstance().getServerGroupData(serverInfo.getServiceId().getGroup()) != null && CloudAPI.getInstance().getServerGroupData(serverInfo.getServiceId().getGroup()).isKickedForceFallback()) {
            fallback = CloudProxy.getInstance().fallbackOnEnabledKick(e.getPlayer(), serverInfo.getServiceId().getGroup(), e.getKickedFrom().getName());
        } else {
            fallback = CloudProxy.getInstance().fallback(e.getPlayer(), e.getKickedFrom().getName());
        }
        ProxiedPlayerFallbackEvent proxiedPlayerFallbackEvent = new ProxiedPlayerFallbackEvent(e.getPlayer(), CloudAPI.getInstance().getOnlinePlayer(e.getPlayer().getUniqueId()), ProxiedPlayerFallbackEvent.FallbackType.SERVER_KICK, fallback);
        ProxyServer.getInstance().getPluginManager().callEvent(proxiedPlayerFallbackEvent);
        fallback = proxiedPlayerFallbackEvent.getFallback();
        if (fallback != null) {
            e.setCancelled(true);
            e.setCancelServer((ProxyServer.getInstance().getServerInfo(fallback)));
            e.getPlayer().sendMessage(e.getKickReasonComponent());
        }
    }
}
Also used : ServerInfo(de.dytanic.cloudnet.lib.server.info.ServerInfo) ProxiedPlayerFallbackEvent(de.dytanic.cloudnet.bridge.event.proxied.ProxiedPlayerFallbackEvent) EventHandler(net.md_5.bungee.event.EventHandler)

Example 5 with EventHandler

use of net.md_5.bungee.event.EventHandler in project CloudNet by Dytanic.

the class ProxiedListener method handleProxyPing.

@EventHandler(priority = EventPriority.HIGHEST)
public void handleProxyPing(ProxyPingEvent event) {
    ProxyGroup proxyGroup = CloudAPI.getInstance().getProxyGroupData(CloudAPI.getInstance().getGroup());
    if (proxyGroup != null && proxyGroup.getProxyConfig().isEnabled()) {
        ProxyConfig proxyConfig = proxyGroup.getProxyConfig();
        ServerPing serverPing = event.getResponse();
        if (!proxyConfig.isMaintenance()) {
            Motd motd = proxyConfig.getMotdsLayouts().get(NetworkUtils.RANDOM.nextInt(proxyConfig.getMotdsLayouts().size()));
            serverPing.setDescription(ChatColor.translateAlternateColorCodes('&', motd.getFirstLine() + "\n" + motd.getSecondLine()).replace("%proxy%", CloudAPI.getInstance().getServerId()).replace("%version%", CloudProxy.class.getPackage().getImplementationVersion()));
        } else {
            serverPing.setDescription(ChatColor.translateAlternateColorCodes('&', proxyConfig.getMaintenanceMotdLayout().getFirstLine() + "\n" + proxyConfig.getMaintenanceMotdLayout().getSecondLine()).replace("%proxy%", CloudAPI.getInstance().getServerId()).replace("%version%", CloudProxy.class.getPackage().getImplementationVersion()));
        }
        int onlineCount = CloudAPI.getInstance().getOnlineCount();
        int max = (proxyConfig.getAutoSlot().isEnabled() ? onlineCount + proxyConfig.getAutoSlot().getDynamicSlotSize() : proxyConfig.getMaxPlayers());
        ServerPing.PlayerInfo[] playerInfos = new ServerPing.PlayerInfo[proxyConfig.getPlayerInfo().length];
        for (short i = 0; i < playerInfos.length; i++) {
            playerInfos[i] = new ServerPing.PlayerInfo(ChatColor.translateAlternateColorCodes('&', proxyConfig.getPlayerInfo()[i]), UUID.randomUUID());
        }
        serverPing.setPlayers(new ServerPing.Players(max, onlineCount, playerInfos));
        if (proxyConfig.isMaintenance())
            serverPing.setVersion(new ServerPing.Protocol(proxyConfig.getMaintenaceProtocol(), 1));
        event.setResponse(serverPing);
    }
}
Also used : ProxyGroup(de.dytanic.cloudnet.lib.server.ProxyGroup) Motd(de.dytanic.cloudnet.lib.proxylayout.Motd) ProxyConfig(de.dytanic.cloudnet.lib.proxylayout.ProxyConfig) CloudProxy(de.dytanic.cloudnet.bridge.CloudProxy) ServerPing(net.md_5.bungee.api.ServerPing) EventHandler(net.md_5.bungee.event.EventHandler)

Aggregations

EventHandler (net.md_5.bungee.event.EventHandler)37 ProxiedPlayer (net.md_5.bungee.api.connection.ProxiedPlayer)20 TextComponent (net.md_5.bungee.api.chat.TextComponent)7 IOException (java.io.IOException)5 User (me.lucko.luckperms.common.model.User)4 EventHandler (org.bukkit.event.EventHandler)4 UserPreference (com.github.games647.changeskin.core.model.UserPreference)3 ByteArrayDataInput (com.google.common.io.ByteArrayDataInput)3 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)3 ISoliniaItem (com.solinia.solinia.Interfaces.ISoliniaItem)3 CloudPlayer (de.dytanic.cloudnet.lib.player.CloudPlayer)3 PacketSpyAction (fr.glowstoner.fireapi.bigbrother.spy.packets.PacketSpyAction)3 Message (io.github.lxgaming.discordbot.entries.Message)3 Tristate (me.lucko.luckperms.api.Tristate)3 ComponentBuilder (net.md_5.bungee.api.chat.ComponentBuilder)3 PendingConnection (net.md_5.bungee.api.connection.PendingConnection)3 Entity (org.bukkit.entity.Entity)3 Player (org.bukkit.entity.Player)3 SoliniaItemException (com.solinia.solinia.Exceptions.SoliniaItemException)2 ISoliniaLivingEntity (com.solinia.solinia.Interfaces.ISoliniaLivingEntity)2