Search in sources :

Example 6 with ProxiedPlayer

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

the class BossBarSenderTest method testSend.

@Test
public void testSend() {
    List<ProxiedPlayer> players = new ArrayList<>();
    players.add(TestObjects.getPlayer());
    players.add(TestObjects.getPlayer());
    int sendCalls = 0;
    BossBarSender bossBarSender = new BossBarSender();
    bossBarSender.doSend(TestObjects.getPlayer(), "");
    verify(TestObjects.getPlayer().unsafe(), times(sendCalls)).sendPacket(any(Chat.class));
    bossBarSender.doSend(TestObjects.getPlayer(), "", 1);
    verify(TestObjects.getPlayer().unsafe(), times(sendCalls)).sendPacket(any(Chat.class));
    BossBarSender.send(TestObjects.getPlayer(), new Message(""));
    verify(TestObjects.getPlayer().unsafe(), times(sendCalls)).sendPacket(any(Chat.class));
    bossBarSender.doSend(players, "");
    verify(TestObjects.getPlayer().unsafe(), times(sendCalls)).sendPacket(any(Chat.class));
    bossBarSender.doSend(players, "", 1);
    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)

Example 7 with ProxiedPlayer

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

the class TitleSenderTest 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();
    TitleSender titleSender = new TitleSender();
    titleSender.doSend(TestObjects.getPlayer(), "");
    sendCalls += 2;
    verify(TestObjects.getPlayer().unsafe(), times(sendCalls)).sendPacket(any(Chat.class));
    titleSender.doSend(TestObjects.getPlayer(), "", 1);
    sendCalls += 2;
    verify(TestObjects.getPlayer().unsafe(), times(sendCalls)).sendPacket(any(Chat.class));
    titleSender.doSend(TestObjects.getPlayer(), "", new TitleMetadata());
    sendCalls += 2;
    verify(TestObjects.getPlayer().unsafe(), times(sendCalls)).sendPacket(any(Chat.class));
    TitleSender.send(TestObjects.getPlayer(), new Message(""));
    sendCalls += 2;
    verify(TestObjects.getPlayer().unsafe(), times(sendCalls)).sendPacket(any(Chat.class));
    TitleSender.send(TestObjects.getPlayer(), new Message(""), new TitleMetadata(10, 10, 20));
    sendCalls += 2;
    verify(TestObjects.getPlayer().unsafe(), times(sendCalls)).sendPacket(any(Chat.class));
    titleSender.doSend(players, "");
    sendCalls += playerCount * 2;
    verify(TestObjects.getPlayer().unsafe(), times(sendCalls)).sendPacket(any(Chat.class));
    titleSender.doSend(players, "", 1);
    sendCalls += playerCount * 2;
    verify(TestObjects.getPlayer().unsafe(), times(sendCalls)).sendPacket(any(Chat.class));
    titleSender.doSend(players, "", new TitleMetadata());
    sendCalls += playerCount * 2;
    verify(TestObjects.getPlayer().unsafe(), times(sendCalls)).sendPacket(any(Chat.class));
    TitleSender.send(players, new Message(""));
    sendCalls += playerCount * 2;
    verify(TestObjects.getPlayer().unsafe(), times(sendCalls)).sendPacket(any(Chat.class));
    TitleSender.send(players, new Message(""), new TitleMetadata(true));
    sendCalls += playerCount * 2;
    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)

Example 8 with ProxiedPlayer

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

the class TitleSender method send.

/**
 * Sends a JSON message to a player shown as title.
 *
 * @param player   The player that should receive the message
 * @param json     The message in JSON format to be sent
 * @param metadata The metadata object giving more details on how the message should be displayed
 */
public static void send(@NotNull ProxiedPlayer player, @NotNull String json, @NotNull TitleMetadata metadata) {
    Title titleTimes = new Title(), titleSend = new Title();
    titleTimes.setAction(Title.Action.TIMES);
    titleTimes.setFadeIn(metadata.getFadeIn());
    titleTimes.setStay(metadata.getStay());
    titleTimes.setFadeOut(metadata.getFadeOut());
    titleSend.setAction(metadata.getTitleType());
    titleSend.setText(json);
    player.unsafe().sendPacket(titleTimes);
    player.unsafe().sendPacket(titleSend);
}
Also used : Title(net.md_5.bungee.protocol.packet.Title)

Example 9 with ProxiedPlayer

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

the class TitleSender method send.

/**
 * Sends a JSON message to players shown as title.
 *
 * @param players  The player that should receive the message
 * @param json     The message in JSON format to be sent
 * @param metadata The metadata object giving more details on how the message should be displayed
 */
public static void send(@NotNull Collection<? extends ProxiedPlayer> players, @NotNull String json, @NotNull TitleMetadata metadata) {
    Title titleTimes = new Title(), titleSend = new Title();
    titleTimes.setAction(Title.Action.TIMES);
    titleTimes.setFadeIn(metadata.getFadeIn());
    titleTimes.setStay(metadata.getStay());
    titleTimes.setFadeOut(metadata.getFadeOut());
    titleSend.setAction(metadata.getTitleType());
    titleSend.setText(json);
    for (ProxiedPlayer player : players) {
        player.unsafe().sendPacket(titleTimes);
        player.unsafe().sendPacket(titleSend);
    }
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) Title(net.md_5.bungee.protocol.packet.Title)

Example 10 with ProxiedPlayer

use of net.md_5.bungee.api.connection.ProxiedPlayer in project SkinsRestorerX by DoNotSpamPls.

the class PlayerCommands method execute.

public void execute(CommandSender sender, final String[] args) {
    if (!(sender instanceof ProxiedPlayer)) {
        sender.sendMessage(new TextComponent(Locale.NOT_PLAYER));
        return;
    }
    final ProxiedPlayer p = (ProxiedPlayer) sender;
    // Skin Help
    if (args.length == 0 || args.length > 2) {
        if (!Config.SKINWITHOUTPERM) {
            if (p.hasPermission("skinsrestorer.playercmds")) {
                help(p);
            } else {
                p.sendMessage(new TextComponent(Locale.PLAYER_HAS_NO_PERMISSION));
            }
        } else {
            help(p);
        }
    }
    // Skin Clear and Skin (name)
    if (args.length == 1) {
        if (args[0].equalsIgnoreCase("clear")) {
            CooldownStorage.resetCooldown(p.getName());
            CooldownStorage.setCooldown(p.getName(), Config.SKIN_CHANGE_COOLDOWN, TimeUnit.SECONDS);
            ProxyServer.getInstance().getScheduler().runAsync(SkinsRestorer.getInstance(), () -> {
                SkinStorage.removePlayerSkin(p.getName());
                SkinStorage.setPlayerSkin(p.getName(), p.getName());
                SkinApplier.applySkin(p);
                p.sendMessage(new TextComponent(Locale.SKIN_CLEAR_SUCCESS));
            });
        } else {
            // skin <skin>
            final String skin = args[0];
            if (Config.DISABLED_SKINS_ENABLED)
                if (!p.hasPermission("skinsrestorer.bypassdisabled")) {
                    for (String dskin : Config.DISABLED_SKINS) if (skin.equalsIgnoreCase(dskin)) {
                        p.sendMessage(new TextComponent(Locale.SKIN_DISABLED));
                        return;
                    }
                }
            if (!p.hasPermission("skinsrestorer.bypasscooldown") && CooldownStorage.hasCooldown(p.getName())) {
                p.sendMessage(new TextComponent(Locale.SKIN_COOLDOWN_NEW.replace("%s", "" + CooldownStorage.getCooldown(p.getName()))));
                return;
            }
            CooldownStorage.resetCooldown(p.getName());
            CooldownStorage.setCooldown(p.getName(), Config.SKIN_CHANGE_COOLDOWN, TimeUnit.SECONDS);
            ProxyServer.getInstance().getScheduler().runAsync(SkinsRestorer.getInstance(), () -> {
                try {
                    MojangAPI.getUUID(skin);
                    SkinStorage.setPlayerSkin(p.getName(), skin);
                    SkinApplier.applySkin(p);
                    p.sendMessage(new TextComponent(Locale.SKIN_CHANGE_SUCCESS));
                } catch (SkinRequestException e) {
                    p.sendMessage(new TextComponent(e.getReason()));
                }
            });
            return;
        }
    }
    // skin set
    if (args.length == 2) {
        if (args[0].equalsIgnoreCase("set")) {
            final String skin = args[1];
            if (Config.DISABLED_SKINS_ENABLED)
                if (!p.hasPermission("skinsrestorer.bypassdisabled")) {
                    for (String dskin : Config.DISABLED_SKINS) if (skin.equalsIgnoreCase(dskin)) {
                        p.sendMessage(new TextComponent(Locale.SKIN_DISABLED));
                        return;
                    }
                }
            if (!p.hasPermission("skinsrestorer.bypasscooldown") && CooldownStorage.hasCooldown(p.getName())) {
                p.sendMessage(new TextComponent(Locale.SKIN_COOLDOWN_NEW.replace("%s", "" + CooldownStorage.getCooldown(p.getName()))));
                return;
            }
            CooldownStorage.resetCooldown(p.getName());
            CooldownStorage.setCooldown(p.getName(), Config.SKIN_CHANGE_COOLDOWN, TimeUnit.SECONDS);
            ProxyServer.getInstance().getScheduler().runAsync(SkinsRestorer.getInstance(), () -> {
                try {
                    MojangAPI.getUUID(skin);
                    SkinStorage.setPlayerSkin(p.getName(), skin);
                    SkinApplier.applySkin(p);
                    p.sendMessage(new TextComponent(Locale.SKIN_CHANGE_SUCCESS));
                } catch (SkinRequestException e) {
                    p.sendMessage(new TextComponent(e.getReason()));
                }
            });
        } else {
            help(p);
        }
    }
}
Also used : TextComponent(net.md_5.bungee.api.chat.TextComponent) ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) SkinRequestException(skinsrestorer.shared.utils.MojangAPI.SkinRequestException)

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