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;
}
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()))));
}
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);
}
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);
}
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));
}
Aggregations