Search in sources :

Example 1 with ProxiedPlayer

use of net.md_5.bungee.api.connection.ProxiedPlayer in project DiscordBot by LXGaming.

the class DiscordBotListener method onCommandReceived.

@Override
public void onCommandReceived(Message message) {
    if (message.getMessage().equals("list")) {
        StringBuilder stringBuilder = new StringBuilder();
        for (ProxiedPlayer proxiedPlayer : ProxyServer.getInstance().getPlayers()) {
            stringBuilder.append(proxiedPlayer.getName() + ", ");
        }
        if (stringBuilder.toString().endsWith(", ")) {
            stringBuilder.delete(stringBuilder.length() - 2, stringBuilder.length());
        }
        DiscordBotCore.getInstance().getMessageSender().sendMessage(message.setMessage(stringBuilder.toString()));
    }
    return;
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer)

Example 2 with ProxiedPlayer

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

the class ProxiedListener method initTabHeaderFooter.

private void initTabHeaderFooter(ProxiedPlayer proxiedPlayer) {
    TabList tabList = CloudProxy.getInstance().getProxyGroup().getProxyConfig().getTabList();
    proxiedPlayer.setTabHeader(new TextComponent(ChatColor.translateAlternateColorCodes('&', tabList.getHeader().replace("%proxy%", CloudAPI.getInstance().getServerId()).replace("%server%", (proxiedPlayer.getServer() != null ? proxiedPlayer.getServer().getInfo().getName() : CloudProxy.getInstance().getProxyGroup().getName())).replace("%online_players%", CloudAPI.getInstance().getOnlineCount() + NetworkUtils.EMPTY_STRING).replace("%max_players%", CloudProxy.getInstance().getProxyGroup().getProxyConfig().getMaxPlayers() + NetworkUtils.EMPTY_STRING).replace("%group%", (proxiedPlayer.getServer() != null && CloudProxy.getInstance().getCachedServers().containsKey(proxiedPlayer.getServer().getInfo().getName()) ? CloudProxy.getInstance().getCachedServers().get(proxiedPlayer.getServer().getInfo().getName()).getServiceId().getGroup() : "Hub")).replace("%proxy_group%", CloudProxy.getInstance().getProxyGroup().getName()))), new TextComponent(ChatColor.translateAlternateColorCodes('&', tabList.getFooter().replace("%proxy%", CloudAPI.getInstance().getServerId()).replace("%server%", (proxiedPlayer.getServer() != null ? proxiedPlayer.getServer().getInfo().getName() : CloudProxy.getInstance().getProxyGroup().getName())).replace("%online_players%", CloudAPI.getInstance().getOnlineCount() + NetworkUtils.EMPTY_STRING).replace("%max_players%", CloudProxy.getInstance().getProxyGroup().getProxyConfig().getMaxPlayers() + NetworkUtils.EMPTY_STRING).replace("%group%", (proxiedPlayer.getServer() != null && CloudProxy.getInstance().getCachedServers().containsKey(proxiedPlayer.getServer().getInfo().getName()) ? CloudProxy.getInstance().getCachedServers().get(proxiedPlayer.getServer().getInfo().getName()).getServiceId().getGroup() : "Hub")).replace("%proxy_group%", CloudProxy.getInstance().getProxyGroup().getName()))));
}
Also used : TextComponent(net.md_5.bungee.api.chat.TextComponent) TabList(de.dytanic.cloudnet.lib.proxylayout.TabList)

Example 3 with ProxiedPlayer

use of net.md_5.bungee.api.connection.ProxiedPlayer in project commands by aikar.

the class ACFBungeeUtil method findPlayerSmart.

public static ProxiedPlayer findPlayerSmart(CommandIssuer issuer, String search) {
    CommandSender requester = issuer.getIssuer();
    String name = ACFUtil.replace(search, ":confirm", "");
    if (name.length() < 3) {
        issuer.sendError(MinecraftMessageKeys.USERNAME_TOO_SHORT);
        return null;
    }
    if (!isValidName(name)) {
        issuer.sendError(MinecraftMessageKeys.IS_NOT_A_VALID_NAME, "{name}", name);
        return null;
    }
    List<ProxiedPlayer> matches = new ArrayList<>(ProxyServer.getInstance().matchPlayer(name));
    if (matches.size() > 1) {
        String allMatches = matches.stream().map(ProxiedPlayer::getName).collect(Collectors.joining(", "));
        issuer.sendError(MinecraftMessageKeys.MULTIPLE_PLAYERS_MATCH, "{search}", name, "{all}", allMatches);
        return null;
    }
    if (matches.isEmpty()) {
        issuer.sendError(MinecraftMessageKeys.NO_PLAYER_FOUND_SERVER, "{search}", name);
        return null;
    }
    return matches.get(0);
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) ArrayList(java.util.ArrayList) CommandSender(net.md_5.bungee.api.CommandSender)

Example 4 with ProxiedPlayer

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

the class MessageTest method testSend.

@Test
public void testSend() throws Exception {
    int sendMessageCalls = 0;
    int doSendCalls = 0;
    Message message = new Message("");
    CommandSender mockedCommandSender = mock(CommandSender.class);
    ProxiedPlayer mockedProxiedPlayer = mock(ProxiedPlayer.class);
    Field method = Message.class.getDeclaredField("method");
    method.setAccessible(true);
    ChatSender mockedSender = mock(ChatSender.class);
    doNothing().when(mockedSender).doSend(any(ProxiedPlayer.class), anyString(), anyObject());
    SendMethod sendMethod = (SendMethod) method.get(message);
    Field defaultSender = sendMethod.getClass().getDeclaredField("defaultSender");
    defaultSender.setAccessible(true);
    defaultSender.set(sendMethod, mockedSender);
    message.send(mockedCommandSender, (Object[]) null);
    // noinspection deprecation
    verify(mockedCommandSender, times(++sendMessageCalls)).sendMessage(anyString());
    message.send(mockedCommandSender);
    // noinspection deprecation
    verify(mockedCommandSender, times(++sendMessageCalls)).sendMessage(anyString());
    message.send(mockedCommandSender, "Test");
    // noinspection deprecation
    verify(mockedCommandSender, times(++sendMessageCalls)).sendMessage(anyString());
    message.send(mockedProxiedPlayer, (Object[]) null);
    verify(mockedSender, times(++doSendCalls)).doSend(any(ProxiedPlayer.class), anyString(), anyObject());
    message.send(mockedProxiedPlayer);
    verify(mockedSender, times(++doSendCalls)).doSend(any(ProxiedPlayer.class), anyString(), anyObject());
    message.send(mockedProxiedPlayer, "Test");
    verify(mockedSender, times(++doSendCalls)).doSend(any(ProxiedPlayer.class), anyString(), anyObject());
    doSendCalls = 0;
    List<ProxiedPlayer> proxiedPlayers = new ArrayList<>();
    message.send(proxiedPlayers);
    verify(mockedSender, times(doSendCalls)).doSend(anyCollectionOf(ProxiedPlayer.class), anyString(), anyObject());
    proxiedPlayers.add(mockedProxiedPlayer);
    message.send(proxiedPlayers, (Object[]) null);
    verify(mockedSender, times(++doSendCalls)).doSend(anyCollectionOf(ProxiedPlayer.class), anyString(), anyObject());
    message.send(proxiedPlayers);
    verify(mockedSender, times(++doSendCalls)).doSend(anyCollectionOf(ProxiedPlayer.class), anyString(), anyObject());
    message.send(proxiedPlayers, "Test");
    verify(mockedSender, times(++doSendCalls)).doSend(anyCollectionOf(ProxiedPlayer.class), anyString(), anyObject());
    message.setSendMethod(null);
    message.send(mockedCommandSender);
    // noinspection deprecation
    verify(mockedCommandSender, times(sendMessageCalls)).sendMessage(anyString());
    message.send(proxiedPlayers);
    verify(mockedSender, times(doSendCalls)).doSend(anyCollectionOf(ProxiedPlayer.class), anyString(), anyObject());
    defaultSender.setAccessible(false);
    method.setAccessible(false);
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) Field(java.lang.reflect.Field) ChatSender(at.pcgamingfreaks.Bungee.Message.Sender.ChatSender) SendMethod(at.pcgamingfreaks.Bungee.Message.Sender.SendMethod) ArrayList(java.util.ArrayList) CommandSender(net.md_5.bungee.api.CommandSender) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 5 with ProxiedPlayer

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

the class ActionBarSenderTest 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();
    ActionBarSender actionBarSender = new ActionBarSender();
    actionBarSender.doSend(TestObjects.getPlayer(), "");
    verify(TestObjects.getPlayer().unsafe(), times(++sendCalls)).sendPacket(any(Chat.class));
    actionBarSender.doSend(TestObjects.getPlayer(), "", 1);
    verify(TestObjects.getPlayer().unsafe(), times(++sendCalls)).sendPacket(any(Chat.class));
    ActionBarSender.send(TestObjects.getPlayer(), new Message(""));
    verify(TestObjects.getPlayer().unsafe(), times(++sendCalls)).sendPacket(any(Chat.class));
    actionBarSender.doSend(players, "");
    sendCalls += playerCount;
    verify(TestObjects.getPlayer().unsafe(), times(sendCalls)).sendPacket(any(Chat.class));
    actionBarSender.doSend(players, "", 1);
    sendCalls += playerCount;
    verify(TestObjects.getPlayer().unsafe(), times(sendCalls)).sendPacket(any(Chat.class));
    ActionBarSender.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