Search in sources :

Example 56 with ProxiedPlayer

use of net.md_5.bungee.api.connection.ProxiedPlayer in project ChangeSkin by games647.

the class MessageListener method onPluginMessage.

@EventHandler
public void onPluginMessage(PluginMessageEvent messageEvent) {
    String channel = messageEvent.getTag();
    if (messageEvent.isCancelled() || !plugin.getName().equals(channel)) {
        return;
    }
    ByteArrayDataInput dataInput = ByteStreams.newDataInput(messageEvent.getData());
    String subChannel = dataInput.readUTF();
    ProxiedPlayer invoker = (ProxiedPlayer) messageEvent.getReceiver();
    if ("PermissionResult".equals(subChannel)) {
        PermResultMessage message = new PermResultMessage();
        message.readFrom(dataInput);
        if (message.isAllowed()) {
            onPermissionSuccess(message, invoker);
        } else {
            plugin.sendMessage(invoker, "no-permission");
        }
    } else if ("ForwardCmd".equals(subChannel)) {
        onCommandForward(invoker, dataInput);
    }
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) PermResultMessage(com.github.games647.changeskin.core.message.PermResultMessage) ByteArrayDataInput(com.google.common.io.ByteArrayDataInput) EventHandler(net.md_5.bungee.event.EventHandler)

Example 57 with ProxiedPlayer

use of net.md_5.bungee.api.connection.ProxiedPlayer in project ChangeSkin by games647.

the class SkinApplier method run.

@Override
public void run() {
    if (!isConnected()) {
        return;
    }
    UUID receiverUUID = receiver.getUniqueId();
    if (invoker instanceof ProxiedPlayer) {
        if (targetSkin != null && core.getConfig().getBoolean("bukkit-permissions")) {
            Server server = ((ProxiedPlayer) invoker).getServer();
            boolean skinPerm = core.getConfig().getBoolean("skinPermission");
            ChannelMessage message = new CheckPermMessage(targetSkin, receiverUUID, skinPerm, bukkitOp);
            plugin.sendPluginMessage(server, message);
            return;
        }
        // uuid was successful resolved, we could now make a cooldown check
        core.getCooldownService().trackPlayer(((ProxiedPlayer) invoker).getUniqueId());
    }
    // check if that specific player is online
    UserPreference preferences = plugin.getLoginSession(receiver.getPendingConnection());
    if (preferences == null) {
        preferences = plugin.getStorage().getPreferences(receiverUUID);
    }
    save(preferences);
    applySkin();
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) Server(net.md_5.bungee.api.connection.Server) CheckPermMessage(com.github.games647.changeskin.core.message.CheckPermMessage) UserPreference(com.github.games647.changeskin.core.model.UserPreference) UUID(java.util.UUID) ChannelMessage(com.github.games647.changeskin.core.message.ChannelMessage)

Example 58 with ProxiedPlayer

use of net.md_5.bungee.api.connection.ProxiedPlayer in project ChangeSkin by games647.

the class InvalidateCommand method execute.

@Override
public void execute(CommandSender sender, String[] args) {
    boolean isOp = sender.getGroups().contains(plugin.getName() + "-OP");
    if (sender instanceof ProxiedPlayer) {
        sender.removeGroups(plugin.getName() + "-OP");
    }
    if (args.length > 0) {
        ProxiedPlayer targetPlayer = ProxyServer.getInstance().getPlayer(args[0]);
        if (targetPlayer == null) {
            plugin.sendMessage(sender, "not-online");
            return;
        }
        String permPrefix = plugin.getName().toLowerCase() + ".command.skinupdate.other.";
        if (!sender.hasPermission(permPrefix + targetPlayer.getUniqueId()) && !sender.hasPermission(permPrefix + '*')) {
            plugin.sendMessage(sender, "no-permission-other");
            return;
        }
        Runnable skinInvalidate = new SkinInvalidator(plugin, sender, targetPlayer, isOp);
        ProxyServer.getInstance().getScheduler().runAsync(plugin, skinInvalidate);
        return;
    }
    if (!(sender instanceof ProxiedPlayer)) {
        plugin.sendMessage(sender, "no-console");
        return;
    }
    ProxiedPlayer receiver = (ProxiedPlayer) sender;
    Runnable skinInvalidate = new SkinInvalidator(plugin, sender, receiver, isOp);
    ProxyServer.getInstance().getScheduler().runAsync(plugin, skinInvalidate);
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) SkinInvalidator(com.github.games647.changeskin.bungee.task.SkinInvalidator)

Example 59 with ProxiedPlayer

use of net.md_5.bungee.api.connection.ProxiedPlayer in project Bukkit_Bungee_PluginLib by GeorgH93.

the class ChatSenderTest method testSend.

@Test
public void testSend() {
    List<ProxiedPlayer> players = new ArrayList<>();
    players.add(TestObjects.getPlayer());
    players.add(TestObjects.getPlayer());
    int sendCalls = 0;
    int playerCount = players.size();
    ChatSender chatSender = new ChatSender();
    chatSender.doSend(TestObjects.getPlayer(), "");
    verify(TestObjects.getPlayer().unsafe(), times(++sendCalls)).sendPacket(any(Chat.class));
    chatSender.doSend(TestObjects.getPlayer(), "", 1);
    verify(TestObjects.getPlayer().unsafe(), times(++sendCalls)).sendPacket(any(Chat.class));
    ChatSender.send(TestObjects.getPlayer(), new Message(""));
    verify(TestObjects.getPlayer().unsafe(), times(++sendCalls)).sendPacket(any(Chat.class));
    chatSender.doSend(players, "");
    sendCalls += playerCount;
    verify(TestObjects.getPlayer().unsafe(), times(sendCalls)).sendPacket(any(Chat.class));
    chatSender.doSend(players, "", 1);
    sendCalls += playerCount;
    verify(TestObjects.getPlayer().unsafe(), times(sendCalls)).sendPacket(any(Chat.class));
    ChatSender.send(players, new Message(""));
    sendCalls += playerCount;
    verify(TestObjects.getPlayer().unsafe(), times(sendCalls)).sendPacket(any(Chat.class));
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) Message(at.pcgamingfreaks.Bungee.Message.Message) ArrayList(java.util.ArrayList) Chat(net.md_5.bungee.protocol.packet.Chat) Test(org.junit.Test)

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