Search in sources :

Example 46 with ProxiedPlayer

use of net.md_5.bungee.api.connection.ProxiedPlayer 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 47 with ProxiedPlayer

use of net.md_5.bungee.api.connection.ProxiedPlayer 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 48 with ProxiedPlayer

use of net.md_5.bungee.api.connection.ProxiedPlayer 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)

Example 49 with ProxiedPlayer

use of net.md_5.bungee.api.connection.ProxiedPlayer in project CloudNet by Dytanic.

the class CommandCloudDev method execute.

@Override
public void execute(CommandSender commandSender, String[] args) {
    if (!(commandSender instanceof ProxiedPlayer))
        return;
    switch(args.length) {
        case 0:
            for (ServerInfo serverInfo : CloudProxy.getInstance().getCachedServers().values()) {
                if (serverInfo.getServerConfig().getProperties().contains(NetworkUtils.DEV_PROPERTY)) {
                    DevService service = serverInfo.getServerConfig().getProperties().getObject(NetworkUtils.DEV_PROPERTY, DevService.class);
                    if (service.getUniqueId().equals(((ProxiedPlayer) commandSender).getUniqueId())) {
                        ((ProxiedPlayer) commandSender).connect(ProxyServer.getInstance().getServerInfo(serverInfo.getServiceId().getServerId()));
                        return;
                    }
                }
            }
            commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "/cdev forTemplate <group> <template>");
            commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "/cdev forTemplate <group>");
            commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "/cdev testServer <group>");
            commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "/cdev testServer <group> <template>");
            break;
        case 2:
            {
                for (ServerInfo serverInfo : CloudProxy.getInstance().getCachedServers().values()) {
                    if (serverInfo.getServerConfig().getProperties().contains(NetworkUtils.DEV_PROPERTY)) {
                        DevService service = serverInfo.getServerConfig().getProperties().getObject(NetworkUtils.DEV_PROPERTY, DevService.class);
                        if (service.getUniqueId().equals(((ProxiedPlayer) commandSender).getUniqueId())) {
                            ((ProxiedPlayer) commandSender).connect(ProxyServer.getInstance().getServerInfo(serverInfo.getServiceId().getServerId()));
                            return;
                        }
                    }
                }
                if (args[0].equalsIgnoreCase("forTemplate")) {
                    if (!CloudAPI.getInstance().getServerGroupMap().containsKey(args[1])) {
                        commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "The group doesn't exist");
                        return;
                    }
                    ServerConfig serverConfig = new ServerConfig(true, commandSender.getName(), new Document(NetworkUtils.DEV_PROPERTY, new DevService(((ProxiedPlayer) commandSender).getUniqueId(), true)), System.currentTimeMillis());
                    CloudAPI.getInstance().startGameServer(CloudAPI.getInstance().getServerGroupData(args[1]), serverConfig, "Dev" + args[1] + "-" + commandSender.getName());
                    ((ProxiedPlayer) commandSender).sendMessage(CloudAPI.getInstance().getPrefix() + "The server will start up now...");
                    return;
                }
                if (args[0].equalsIgnoreCase("testServer")) {
                    if (!CloudAPI.getInstance().getServerGroupMap().containsKey(args[1])) {
                        commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "The group doesn't exist");
                        return;
                    }
                    ServerConfig serverConfig = new ServerConfig(true, commandSender.getName(), new Document(), System.currentTimeMillis());
                    CloudAPI.getInstance().startCloudServer("TestServer-" + ((ProxiedPlayer) commandSender).getUniqueId(), serverConfig, 356, true);
                    ((ProxiedPlayer) commandSender).sendMessage(CloudAPI.getInstance().getPrefix() + "The server will start up now...");
                    return;
                }
            }
        case 3:
            {
                for (ServerInfo serverInfo : CloudProxy.getInstance().getCachedServers().values()) {
                    if (serverInfo.getServerConfig().getProperties().contains(NetworkUtils.DEV_PROPERTY)) {
                        DevService service = serverInfo.getServerConfig().getProperties().getObject(NetworkUtils.DEV_PROPERTY, DevService.class);
                        if (service.getUniqueId().equals(((ProxiedPlayer) commandSender).getUniqueId())) {
                            ((ProxiedPlayer) commandSender).connect(ProxyServer.getInstance().getServerInfo(serverInfo.getServiceId().getServerId()));
                            return;
                        }
                    }
                }
                if (args[0].equalsIgnoreCase("forTemplate")) {
                    if (!CloudAPI.getInstance().getServerGroupMap().containsKey(args[1])) {
                        commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "The group doesn't exist");
                        return;
                    }
                    ServerGroup serverGroup = CloudAPI.getInstance().getServerGroup(args[1]);
                    if (CollectionWrapper.filter(serverGroup.getTemplates(), new Acceptable<Template>() {

                        @Override
                        public boolean isAccepted(Template template) {
                            return template.getName().equalsIgnoreCase(args[2]);
                        }
                    }) == null) {
                        commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "The template doesn't exist");
                        return;
                    }
                    ServerConfig serverConfig = new ServerConfig(true, commandSender.getName(), new Document(NetworkUtils.DEV_PROPERTY, new DevService(((ProxiedPlayer) commandSender).getUniqueId(), true)), System.currentTimeMillis());
                    CloudAPI.getInstance().startGameServer(CloudAPI.getInstance().getServerGroupData(args[1]), serverConfig, CloudAPI.getInstance().getServerGroupData(args[1]).getMemory(), true, new Properties(), CollectionWrapper.filter(serverGroup.getTemplates(), new Acceptable<Template>() {

                        @Override
                        public boolean isAccepted(Template e) {
                            return e.getName().equalsIgnoreCase(args[2]);
                        }
                    }), "Dev" + args[1] + "-" + commandSender.getName());
                    ((ProxiedPlayer) commandSender).sendMessage(CloudAPI.getInstance().getPrefix() + "The server will start up now...");
                    return;
                }
                if (args[0].equalsIgnoreCase("testServer")) {
                    if (!CloudAPI.getInstance().getServerGroupMap().containsKey(args[1])) {
                        commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "The group doesn't exist");
                        return;
                    }
                    ServerGroup serverGroup = CloudAPI.getInstance().getServerGroup(args[1]);
                    if (CollectionWrapper.filter(serverGroup.getTemplates(), new Acceptable<Template>() {

                        @Override
                        public boolean isAccepted(Template template) {
                            return template.getName().equalsIgnoreCase(args[2]);
                        }
                    }) == null) {
                        commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "The template doesn't exist");
                        return;
                    }
                    ServerConfig serverConfig = new ServerConfig(true, commandSender.getName(), new Document(), System.currentTimeMillis());
                    /*
                    CloudAPI.getInstance().startGameServer(CloudAPI.getInstance().getServerGroupData(args[1]), serverConfig,
                            CloudAPI.getInstance().getServerGroupData(args[1]).getMemory(),
                            new String[0], null, "TestServer-" + commandSender.getName(), false, true, new Properties(),
                            null, Arrays.asList()
                            , "Dev" + args[1] + "-" + commandSender.getName());
                    */
                    CloudAPI.getInstance().startCloudServer("TestServer-" + ((ProxiedPlayer) commandSender).getUniqueId(), serverConfig, 356, true);
                    ((ProxiedPlayer) commandSender).sendMessage(CloudAPI.getInstance().getPrefix() + "The server will start up now...");
                    return;
                }
            }
            break;
    }
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) ServerConfig(de.dytanic.cloudnet.lib.server.ServerConfig) ServerGroup(de.dytanic.cloudnet.lib.server.ServerGroup) ServerInfo(de.dytanic.cloudnet.lib.server.info.ServerInfo) DevService(de.dytanic.cloudnet.lib.server.advanced.DevService) Document(de.dytanic.cloudnet.lib.utility.document.Document) Properties(java.util.Properties) Template(de.dytanic.cloudnet.lib.server.template.Template)

Example 50 with ProxiedPlayer

use of net.md_5.bungee.api.connection.ProxiedPlayer in project CloudNet by Dytanic.

the class CommandHub method execute.

@Override
public void execute(CommandSender commandSender, String[] args) {
    if (!(commandSender instanceof ProxiedPlayer))
        return;
    ServerInfo serverInfo = CloudProxy.getInstance().getCachedServers().get(((ProxiedPlayer) commandSender).getServer().getInfo().getName());
    if (serverInfo != null)
        if (CloudProxy.getInstance().getProxyGroup().getProxyConfig().getDynamicFallback().getNamedFallbackes().contains(serverInfo.getServiceId().getGroup())) {
            commandSender.sendMessage(ChatColor.translateAlternateColorCodes('&', CloudAPI.getInstance().getCloudNetwork().getMessages().getString("hub-already")));
            return;
        }
    String fallback = CloudProxy.getInstance().fallbackOnEnabledKick((((ProxiedPlayer) commandSender)), CloudAPI.getInstance().getGroup(), ((ProxiedPlayer) commandSender).getServer().getInfo().getName());
    ProxiedPlayerFallbackEvent proxiedPlayerFallbackEvent = new ProxiedPlayerFallbackEvent((ProxiedPlayer) commandSender, CloudAPI.getInstance().getOnlinePlayer(((ProxiedPlayer) commandSender).getUniqueId()), ProxiedPlayerFallbackEvent.FallbackType.HUB_COMMAND, fallback);
    ProxyServer.getInstance().getPluginManager().callEvent(proxiedPlayerFallbackEvent);
    fallback = proxiedPlayerFallbackEvent.getFallback();
    ProxyServer.getInstance().getPluginManager().callEvent(proxiedPlayerFallbackEvent);
    if (fallback == null)
        commandSender.sendMessage(ChatColor.translateAlternateColorCodes('&', CloudAPI.getInstance().getCloudNetwork().getMessages().getString("hubCommandNoServerFound")));
    else
        ((ProxiedPlayer) commandSender).connect(ProxyServer.getInstance().getServerInfo(fallback));
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) ServerInfo(de.dytanic.cloudnet.lib.server.info.ServerInfo) ProxiedPlayerFallbackEvent(de.dytanic.cloudnet.bridge.event.proxied.ProxiedPlayerFallbackEvent)

Aggregations

ProxiedPlayer (net.md_5.bungee.api.connection.ProxiedPlayer)50 EventHandler (net.md_5.bungee.event.EventHandler)20 TextComponent (net.md_5.bungee.api.chat.TextComponent)17 IOException (java.io.IOException)10 ArrayList (java.util.ArrayList)10 Configuration (net.md_5.bungee.config.Configuration)6 YamlConfiguration (net.md_5.bungee.config.YamlConfiguration)6 UserPreference (com.github.games647.changeskin.core.model.UserPreference)5 Message (at.pcgamingfreaks.Bungee.Message.Message)4 User (me.lucko.luckperms.common.model.User)4 ComponentBuilder (net.md_5.bungee.api.chat.ComponentBuilder)4 Test (org.junit.Test)4 SkinModel (com.github.games647.changeskin.core.model.skin.SkinModel)3 ByteArrayDataInput (com.google.common.io.ByteArrayDataInput)3 PacketSpyAction (fr.glowstoner.fireapi.bigbrother.spy.packets.PacketSpyAction)3 Tristate (me.lucko.luckperms.api.Tristate)3 Chat (net.md_5.bungee.protocol.packet.Chat)3 ServerInfo (de.dytanic.cloudnet.lib.server.info.ServerInfo)2 FirePlayer (fr.glowstoner.fireapi.player.FirePlayer)2 Message (io.github.lxgaming.discordbot.entries.Message)2