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