Search in sources :

Example 36 with EventHandler

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

the class ProxiedListener method handlePost.

@EventHandler
public void handlePost(PostLoginEvent e) {
    CloudProxy.getInstance().update();
    CloudAPI.getInstance().getNetworkConnection().sendPacket(new PacketOutLoginSuccess(e.getPlayer().getUniqueId()));
    if (CloudProxy.getInstance().getProxyGroup().getProxyConfig().isFastConnect()) {
        try {
            Field channelWrapper;
            try {
                channelWrapper = UserConnection.class.getDeclaredField("ch");
                channelWrapper.setAccessible(true);
            } catch (Exception ex) {
                channelWrapper = UserConnection.class.getField("ch");
                channelWrapper.setAccessible(true);
            }
            Field field;
            try {
                field = ChannelWrapper.class.getDeclaredField("ch");
                field.setAccessible(true);
            } catch (Exception ex) {
                field = ChannelWrapper.class.getField("ch");
                field.setAccessible(true);
            }
            Channel channel = (Channel) field.get(channelWrapper.get(e.getPlayer()));
            channel.pipeline().addAfter("packet-encoder", "cloudConnection", new MessageToMessageEncoder<DefinedPacket>() {

                @Override
                protected void encode(ChannelHandlerContext channelHandlerContext, DefinedPacket definedPacket, List<Object> out) throws Exception {
                    if (definedPacket instanceof Respawn) {
                        if (((Respawn) definedPacket).getDimension() != ((UserConnection) e.getPlayer()).getDimension())
                            ((Respawn) definedPacket).setDimension(((UserConnection) e.getPlayer()).getDimension());
                    }
                    out.add(definedPacket);
                }
            });
        } catch (IllegalAccessException | NoSuchFieldException e1) {
            e1.printStackTrace();
        }
    }
}
Also used : Channel(io.netty.channel.Channel) DefinedPacket(net.md_5.bungee.protocol.DefinedPacket) Respawn(net.md_5.bungee.protocol.packet.Respawn) ChannelWrapper(net.md_5.bungee.netty.ChannelWrapper) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) UserConnection(net.md_5.bungee.UserConnection) Field(java.lang.reflect.Field) EventHandler(net.md_5.bungee.event.EventHandler)

Example 37 with EventHandler

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

the class ProxiedListener method handlePlayerServerSwitch.

@EventHandler(priority = EventPriority.HIGHEST)
public void handlePlayerServerSwitch(ServerSwitchEvent e) {
    CloudPlayer cloudPlayer = CloudProxy.getInstance().getCloudPlayers().get(e.getPlayer().getUniqueId());
    cloudPlayer.setServer(e.getPlayer().getServer().getInfo().getName());
    CloudAPI.getInstance().getNetworkConnection().sendPacket(new PacketOutUpdateOnlinePlayer(cloudPlayer));
    CloudAPI.getInstance().sendCustomSubProxyMessage("cloudnet_internal", "player_server_switch", new Document("player", cloudPlayer).append("server", e.getPlayer().getServer().getInfo().getName()));
    if (CloudProxy.getInstance().getProxyGroup() != null && CloudProxy.getInstance().getProxyGroup().getProxyConfig().isEnabled() && CloudProxy.getInstance().getProxyGroup().getProxyConfig().getTabList().isEnabled())
        initTabHeaderFooter(e.getPlayer());
}
Also used : CloudPlayer(de.dytanic.cloudnet.lib.player.CloudPlayer) Document(de.dytanic.cloudnet.lib.utility.document.Document) EventHandler(net.md_5.bungee.event.EventHandler)

Example 38 with EventHandler

use of net.md_5.bungee.event.EventHandler in project commands by aikar.

the class ACFBungeeListener method onPlayerJoin.

@EventHandler
public void onPlayerJoin(PostLoginEvent loginEvent) {
    ProxiedPlayer player = loginEvent.getPlayer();
    // the client settings are sent after a successful login
    Runnable task = () -> manager.readLocale(player);
    plugin.getProxy().getScheduler().schedule(plugin, task, 1, TimeUnit.SECONDS);
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) EventHandler(net.md_5.bungee.event.EventHandler)

Example 39 with EventHandler

use of net.md_5.bungee.event.EventHandler in project commands by aikar.

the class ACFBungeeListener method onDisconnect.

@EventHandler
public void onDisconnect(PlayerDisconnectEvent disconnectEvent) {
    // cleanup
    ProxiedPlayer player = disconnectEvent.getPlayer();
    manager.issuersLocale.remove(player.getUniqueId());
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) EventHandler(net.md_5.bungee.event.EventHandler)

Example 40 with EventHandler

use of net.md_5.bungee.event.EventHandler in project solinia3-core by mixxit.

the class SoliniaPlayer method setInteraction.

@Override
public void setInteraction(UUID interaction, ISoliniaNPC npc) {
    if (interaction == null) {
        this.interaction = interaction;
        this.getBukkitPlayer().sendMessage(ChatColor.GRAY + "* You are no longer interacting");
        return;
    }
    Entity e = Bukkit.getEntity(interaction);
    if (e == null)
        return;
    if (!(e instanceof LivingEntity))
        return;
    if (((Creature) e).getTarget() != null) {
        if (interaction != null) {
            this.getBukkitPlayer().sendMessage(ChatColor.GRAY + "* You are no longer interacting");
            interaction = null;
        }
        return;
    }
    if (Bukkit.getEntity(interaction) instanceof Wolf) {
        Wolf w = (Wolf) Bukkit.getEntity(interaction);
        if (w.getOwner() != null)
            return;
    }
    this.interaction = interaction;
    if (npc != null) {
        this.getBukkitPlayer().sendMessage(ChatColor.GRAY + "* You are now interacting with " + Bukkit.getEntity(interaction).getName() + " [" + npc.getId() + "] - Anything you type will be heared by the NPC and possibly responded to. Words in pink are trigger words you can type");
        if (npc.getMerchantid() > 0) {
            try {
                StateManager.getInstance().getEntityManager().getLivingEntity((LivingEntity) e).say("i have a [" + ChatColor.LIGHT_PURPLE + "SHOP" + ChatColor.AQUA + "] available if you are interested in buying or selling something", getBukkitPlayer());
            } catch (CoreStateInitException cse) {
            // 
            }
        }
        for (ISoliniaNPCEventHandler eventHandler : npc.getEventHandlers()) {
            if (!eventHandler.getInteractiontype().equals(InteractionType.ITEM))
                continue;
            // See if player has any items that are wanted
            int itemId = Integer.parseInt(eventHandler.getTriggerdata());
            if (itemId == 0)
                continue;
            if (Utils.getPlayerTotalCountOfItemId(getBukkitPlayer(), itemId) < 1)
                continue;
            try {
                ISoliniaItem item = StateManager.getInstance().getConfigurationManager().getItem(itemId);
                TextComponent tc = new TextComponent();
                tc.setText(ChatColor.YELLOW + "[QUEST] ");
                TextComponent tc2 = new TextComponent();
                tc2.setText(ChatColor.GRAY + "- Click here to give " + item.getDisplayname() + ChatColor.RESET);
                tc2.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/npcgive " + itemId));
                tc.addExtra(tc2);
                getBukkitPlayer().spigot().sendMessage(tc);
            } catch (CoreStateInitException eNotInitialised) {
                continue;
            }
        }
    }
}
Also used : ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) TextComponent(net.md_5.bungee.api.chat.TextComponent) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) ISoliniaItem(com.solinia.solinia.Interfaces.ISoliniaItem) ISoliniaNPCEventHandler(com.solinia.solinia.Interfaces.ISoliniaNPCEventHandler) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ClickEvent(net.md_5.bungee.api.chat.ClickEvent) Wolf(org.bukkit.entity.Wolf)

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