Example usage for com.google.common.io ByteArrayDataOutput toByteArray

List of usage examples for com.google.common.io ByteArrayDataOutput toByteArray

Introduction

In this page you can find the example usage for com.google.common.io ByteArrayDataOutput toByteArray.

Prototype

byte[] toByteArray();

Source Link

Document

Returns the contents that have been written to this instance, as a byte array.

Usage

From source file:io.github.leonardosnt.bungeechannelapi.BungeeChannelApi.java

/**
 * Connects a player to said subserver./* ww  w .ja  v  a  2  s .  c o  m*/
 *
 * @param player the player you want to teleport.
 * @param serverName the name of server to connect to, as defined in BungeeCord config.yml.
 */
public void connect(Player player, String serverName) {
    ByteArrayDataOutput output = ByteStreams.newDataOutput();
    output.writeUTF("Connect");
    output.writeUTF(serverName);
    player.sendPluginMessage(this.plugin, "BungeeCord", output.toByteArray());
}

From source file:io.github.leonardosnt.bungeechannelapi.BungeeChannelApi.java

/**
 * Request the IP of any server on this proxy.
 *
 * @param serverName the name of the server.
 * @return A {@link CompletableFuture} that, when completed, will return the requested ip.
 * @throws IllegalArgumentException if there is no players online.
 *//*from  w w w  .java  2  s.c o  m*/
public CompletableFuture<InetSocketAddress> getServerIp(String serverName) {
    Player player = getFirstPlayer();
    CompletableFuture<InetSocketAddress> future = new CompletableFuture<>();

    synchronized (callbackMap) {
        callbackMap.compute("ServerIP-" + serverName, this.computeQueueValue(future));
    }

    ByteArrayDataOutput output = ByteStreams.newDataOutput();
    output.writeUTF("ServerIP");
    output.writeUTF(serverName);
    player.sendPluginMessage(this.plugin, "BungeeCord", output.toByteArray());
    return future;
}

From source file:io.github.leonardosnt.bungeechannelapi.BungeeChannelApi.java

/**
 * Request the UUID of any player connected to the BungeeCord proxy.
 *
 * @param playerName the name of the player whose UUID you would like.
 * @return A {@link CompletableFuture} that, when completed, will return the UUID of {@code playerName}.
 * @throws IllegalArgumentException if there is no players online.
 *///  w  w w  . ja v  a2  s  .c o  m
public CompletableFuture<String> getUUID(String playerName) {
    Player player = getFirstPlayer();
    CompletableFuture<String> future = new CompletableFuture<>();

    synchronized (callbackMap) {
        callbackMap.compute("UUIDOther-" + playerName, this.computeQueueValue(future));
    }

    ByteArrayDataOutput output = ByteStreams.newDataOutput();
    output.writeUTF("UUIDOther");
    output.writeUTF(playerName);
    player.sendPluginMessage(this.plugin, "BungeeCord", output.toByteArray());
    return future;
}

From source file:io.github.leonardosnt.bungeechannelapi.BungeeChannelApi.java

/**
 * Get a list of players connected on a certain server, or on ALL the servers.
 *
 * @param serverName the name of the server to get the list of connected players, or ALL for global online player list
 * @return A {@link CompletableFuture} that, when completed, will return a
 *         list of players connected on a certain server, or on ALL the servers.
 * @throws IllegalArgumentException if there is no players online.
 *///from  w  ww.j  a va2  s. c o m
public CompletableFuture<List<String>> getPlayerList(String serverName) {
    Player player = getFirstPlayer();
    CompletableFuture<List<String>> future = new CompletableFuture<>();

    synchronized (callbackMap) {
        callbackMap.compute("PlayerList-" + serverName, this.computeQueueValue(future));
    }

    ByteArrayDataOutput output = ByteStreams.newDataOutput();
    output.writeUTF("PlayerList");
    output.writeUTF(serverName);
    player.sendPluginMessage(this.plugin, "BungeeCord", output.toByteArray());
    return future;
}

From source file:io.github.leonardosnt.bungeechannelapi.BungeeChannelApi.java

/**
 * Get the amount of players on a certain server, or on ALL the servers.
 *
 * @param serverName the server name of the server to get the player count of, or ALL to get the global player count
 * @return A {@link CompletableFuture} that, when completed, will return
 *         the amount of players on a certain server, or on ALL the servers.
 * @throws IllegalArgumentException if there is no players online.
 *///from w ww . ja  v a  2s.  c  o m
public CompletableFuture<Integer> getPlayerCount(String serverName) {
    Player player = getFirstPlayer();
    CompletableFuture<Integer> future = new CompletableFuture<>();

    synchronized (callbackMap) {
        callbackMap.compute("PlayerCount-" + serverName, this.computeQueueValue(future));
    }

    ByteArrayDataOutput output = ByteStreams.newDataOutput();
    output.writeUTF("PlayerCount");
    output.writeUTF(serverName);
    player.sendPluginMessage(this.plugin, "BungeeCord", output.toByteArray());
    return future;
}

From source file:com.minestein.novacore.listener.Events.java

/**
 * Listens for the kicking of a player./*w  w  w .j  a v  a 2s  . co m*/
 *
 * @param event The event.
 */
@EventHandler
public void onKick(PlayerKickEvent event) {
    if (event.getReason().equalsIgnoreCase("clYou have lost! The game is restarting...")) {
        event.setCancelled(true);
        ByteArrayDataOutput out = ByteStreams.newDataOutput();
        out.writeUTF("Connect");
        out.writeUTF("lobby");
        event.getPlayer().sendPluginMessage(Core.plugin, "BungeeCord", out.toByteArray());

        event.getPlayer()
                .sendMessage("8[5NOVA6U8] 4You lost that game of r" + Core.getPrefix() + "4!");
    } else if (event.getReason().equalsIgnoreCase("alYou have won! The game is restarting...")) {
        event.setCancelled(true);
        ByteArrayDataOutput out = ByteStreams.newDataOutput();
        out.writeUTF("Connect");
        out.writeUTF("lobby");
        event.getPlayer().sendPluginMessage(Core.plugin, "BungeeCord", out.toByteArray());

        event.getPlayer()
                .sendMessage("8[5NOVA6U8] aYou won that game of r" + Core.getPrefix() + "a!");
    }
}

From source file:io.github.leonardosnt.bungeechannelapi.BungeeChannelApi.java

/**
 * Send a message (as in, a chat message) to the specified player.
 *
 * @param playerName the name of the player to send the chat message.
 * @param message the message to send to the player.
 * @throws IllegalArgumentException if there is no players online.
 *//*  w w w. j  ava 2  s  .c om*/
public void sendMessage(String playerName, String message) {
    Player player = getFirstPlayer();
    ByteArrayDataOutput output = ByteStreams.newDataOutput();

    output.writeUTF("Message");
    output.writeUTF(playerName);
    output.writeUTF(message);
    player.sendPluginMessage(this.plugin, "BungeeCord", output.toByteArray());
}

From source file:de.jonas.Game.java

public void GameLobby() {
    for (ItemSpawner is : Rush.spawner) {
        is.unregister();//  ww w  .  j a  v  a2  s . co m
    }
    ByteArrayDataOutput out = ByteStreams.newDataOutput(); //BungeeCoord Connection
    out.writeUTF("Connect");
    out.writeUTF(pl.getConfig().getString("main.lobbyservername"));
    Bukkit.getServer().getLogger().log(Level.INFO, "Sending all Players to ''{0}''",
            pl.getConfig().getString("main.lobbyservername"));
    for (Player p : Bukkit.getOnlinePlayers()) { //Send all Players to Lobby Server
        p.sendPluginMessage(pl, "BungeeCord", out.toByteArray());
        this.players.remove(p.getName()); //Remove Players from the List
    }
    pl.getServer().getLogger().log(Level.INFO, "Done sending Players.");
    //this.reset(); Map Reset
    this.state = GameState.LOBBY; //Set State
    this.motd = pl.getConfig().getString("motd.lobby"); //Set Motd
    //Bukkit.getServer().getPluginManager().disablePlugin(pl);
    //Bukkit.getServer().getPluginManager().enablePlugin(pl);
    pl.getServer().getScheduler().scheduleSyncDelayedTask(pl, new Runnable() {
        @Override
        public void run() {
            Bukkit.shutdown();
        }
    }, Rush.SecondsToTicks(3));
}

From source file:codecrafter47.bungeetablistplus.bukkitbridge.BukkitBridge.java

@EventHandler
@SneakyThrows//w  ww  .j  ava 2 s .  co m
public void onChannelRegistration(PlayerRegisterChannelEvent event) {
    if (BridgeProtocolConstants.CHANNEL.equals(event.getChannel())) {
        ByteArrayDataOutput data = ByteStreams.newDataOutput();
        data.writeByte(BridgeProtocolConstants.MESSAGE_ID_SERVER_ENABLE_CONNECTION);
        DataStreamUtils.writeUUID(data, serverId);
        event.getPlayer().sendPluginMessage(plugin, BridgeProtocolConstants.CHANNEL, data.toByteArray());
    }
}

From source file:io.github.leonardosnt.bungeechannelapi.BungeeChannelApi.java

/**
 * Connect a named player to said subserver.
 *
 * @param playerName name of the player to teleport.
 * @param server name of server to connect to, as defined in BungeeCord config.yml.
 * @throws IllegalArgumentException if there is no players online.
 *///w ww . j a v a  2s .c  o m
public void connectOther(String playerName, String server) {
    Player player = getFirstPlayer();
    ByteArrayDataOutput output = ByteStreams.newDataOutput();

    output.writeUTF("ConnectOther");
    output.writeUTF(playerName);
    output.writeUTF(server);

    player.sendPluginMessage(this.plugin, "BungeeCord", output.toByteArray());
}