Search in sources :

Example 31 with EventHandler

use of net.md_5.bungee.event.EventHandler in project LuckPerms by lucko.

the class BungeePermissionCheckListener method onPlayerPermissionCheck.

@EventHandler(priority = EventPriority.HIGH)
public void onPlayerPermissionCheck(PermissionCheckEvent e) {
    if (!(e.getSender() instanceof ProxiedPlayer)) {
        return;
    }
    Objects.requireNonNull(e.getPermission(), "permission");
    Objects.requireNonNull(e.getSender(), "sender");
    ProxiedPlayer player = ((ProxiedPlayer) e.getSender());
    User user = this.plugin.getUserManager().getIfLoaded(player.getUniqueId());
    if (user == null) {
        e.setHasPermission(false);
        return;
    }
    Contexts contexts = this.plugin.getContextManager().getApplicableContexts(player);
    Tristate result = user.getCachedData().getPermissionData(contexts).getPermissionValue(e.getPermission(), CheckOrigin.PLATFORM_PERMISSION_CHECK);
    if (result == Tristate.UNDEFINED && this.plugin.getConfiguration().get(ConfigKeys.APPLY_BUNGEE_CONFIG_PERMISSIONS)) {
        // just use the result provided by the proxy when the event was created
        return;
    }
    e.setHasPermission(result.asBoolean());
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) User(me.lucko.luckperms.common.model.User) Tristate(me.lucko.luckperms.api.Tristate) Contexts(me.lucko.luckperms.api.Contexts) EventHandler(net.md_5.bungee.event.EventHandler)

Example 32 with EventHandler

use of net.md_5.bungee.event.EventHandler in project LuckPerms by lucko.

the class BungeeMessenger method onPluginMessage.

@EventHandler
public void onPluginMessage(PluginMessageEvent e) {
    if (!e.getTag().equals(CHANNEL)) {
        return;
    }
    e.setCancelled(true);
    if (e.getSender() instanceof ProxiedPlayer) {
        return;
    }
    byte[] data = e.getData();
    ByteArrayDataInput in = ByteStreams.newDataInput(data);
    String msg = in.readUTF();
    if (this.consumer.consumeIncomingMessageAsString(msg)) {
        // Forward to other servers
        this.plugin.getBootstrap().getScheduler().doAsync(() -> {
            for (ServerInfo server : this.plugin.getBootstrap().getProxy().getServers().values()) {
                server.sendData(CHANNEL, data, true);
            }
        });
    }
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) ServerInfo(net.md_5.bungee.api.config.ServerInfo) ByteArrayDataInput(com.google.common.io.ByteArrayDataInput) EventHandler(net.md_5.bungee.event.EventHandler)

Example 33 with EventHandler

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

the class ProxiedListener method handleDisconnect.

@EventHandler(priority = EventPriority.HIGHEST)
public void handleDisconnect(PlayerDisconnectEvent e) {
    CloudPlayer cloudPlayer = CloudProxy.getInstance().getCloudPlayers().get(e.getPlayer().getUniqueId());
    if (cloudPlayer != null) {
        CloudAPI.getInstance().getNetworkConnection().sendPacket(new PacketOutLogoutPlayer(cloudPlayer, e.getPlayer().getUniqueId()));
    } else {
        CloudAPI.getInstance().getNetworkConnection().sendPacket(new PacketOutLogoutPlayer(null, e.getPlayer().getUniqueId()));
    }
    CloudProxy.getInstance().getCloudPlayers().remove(e.getPlayer().getUniqueId());
    ProxyServer.getInstance().getScheduler().schedule(CloudProxy.getInstance().getPlugin(), new Runnable() {

        @Override
        public void run() {
            CloudProxy.getInstance().update();
        }
    }, 250, TimeUnit.MILLISECONDS);
}
Also used : CloudPlayer(de.dytanic.cloudnet.lib.player.CloudPlayer) EventHandler(net.md_5.bungee.event.EventHandler)

Example 34 with EventHandler

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

the class ProxiedListener method handleServerConnect.

@EventHandler(priority = EventPriority.HIGHEST)
public void handleServerConnect(ServerConnectEvent event) {
    if (event.getPlayer().getServer() == null) {
        String fallback = CloudProxy.getInstance().fallback(event.getPlayer());
        ProxiedPlayerFallbackEvent proxiedPlayerFallbackEvent = new ProxiedPlayerFallbackEvent(event.getPlayer(), CloudAPI.getInstance().getOnlinePlayer(event.getPlayer().getUniqueId()), ProxiedPlayerFallbackEvent.FallbackType.SERVER_KICK, fallback);
        ProxyServer.getInstance().getPluginManager().callEvent(proxiedPlayerFallbackEvent);
        fallback = proxiedPlayerFallbackEvent.getFallback();
        if (fallback != null) {
            event.setTarget(ProxyServer.getInstance().getServerInfo(fallback));
            CloudAPI.getInstance().getNetworkConnection().getChannel().writeAndFlush(new PacketOutCustomSubChannelMessage(DefaultType.BUKKIT, event.getTarget().getName(), "cloudnet_internal", "server_connect_request", new Document("uniqueId", event.getPlayer().getUniqueId())));
            NetworkUtils.sleepUninterruptedly(6);
        } else
            event.setCancelled(true);
    } else {
        CloudAPI.getInstance().getNetworkConnection().getChannel().writeAndFlush(new PacketOutCustomSubChannelMessage(DefaultType.BUKKIT, event.getTarget().getName(), "cloudnet_internal", "server_connect_request", new Document("uniqueId", event.getPlayer().getUniqueId())));
        NetworkUtils.sleepUninterruptedly(6);
    }
}
Also used : ProxiedPlayerFallbackEvent(de.dytanic.cloudnet.bridge.event.proxied.ProxiedPlayerFallbackEvent) Document(de.dytanic.cloudnet.lib.utility.document.Document) EventHandler(net.md_5.bungee.event.EventHandler)

Example 35 with EventHandler

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

the class ProxiedListener method handleChannel.

@EventHandler
public void handleChannel(PluginMessageEvent pluginMessageEvent) {
    if (!(pluginMessageEvent.getReceiver() instanceof ProxiedPlayer))
        return;
    if (pluginMessageEvent.getTag().equalsIgnoreCase("CloudNet")) {
        ByteArrayDataInput byteArrayDataInput = ByteStreams.newDataInput(pluginMessageEvent.getData());
        switch(byteArrayDataInput.readUTF().toLowerCase()) {
            case "connect":
                List<String> servers = CloudProxy.getInstance().getServers(byteArrayDataInput.readUTF());
                if (servers.size() == 0)
                    return;
                ((ProxiedPlayer) pluginMessageEvent.getReceiver()).connect(ProxyServer.getInstance().getServerInfo(servers.get(NetworkUtils.RANDOM.nextInt(servers.size()))));
                break;
            case "fallback":
                ((ProxiedPlayer) pluginMessageEvent.getReceiver()).connect(ProxyServer.getInstance().getServerInfo(CloudProxy.getInstance().fallback(((ProxiedPlayer) pluginMessageEvent.getReceiver()))));
                break;
            case "command":
                ProxyServer.getInstance().getPluginManager().dispatchCommand(((ProxiedPlayer) pluginMessageEvent.getReceiver()), byteArrayDataInput.readUTF());
                break;
        }
    }
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) ByteArrayDataInput(com.google.common.io.ByteArrayDataInput) 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