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

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

Introduction

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

Prototype

@Override
    void writeUTF(String s);

Source Link

Usage

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

/**
 * Listens for the kicking of a player.//from  w ww .j  av  a2s. c  o  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

/**
 * Get a list of server name strings, as defined in BungeeCord's config.yml.
 *
 * @return A {@link CompletableFuture} that, when completed, will return a
 *         list of server name strings, as defined in BungeeCord's config.yml.
 * @throws IllegalArgumentException if there is no players online.
 *///  w ww . j  av  a  2 s  .  c o m
public CompletableFuture<List<String>> getServers() {
    Player player = getFirstPlayer();
    CompletableFuture<List<String>> future = new CompletableFuture<>();

    synchronized (callbackMap) {
        callbackMap.compute("GetServers", this.computeQueueValue(future));
    }

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

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

/**
 * Get this server's name, as defined in BungeeCord's config.yml
 *
 * @return A {@link CompletableFuture} that, when completed, will return
 *         the {@code server's} name, as defined in BungeeCord's config.yml.
 * @throws IllegalArgumentException if there is no players online.
 *//*w  w w.ja v  a  2 s.c o  m*/
public CompletableFuture<String> getServer() {
    Player player = getFirstPlayer();
    CompletableFuture<String> future = new CompletableFuture<>();

    synchronized (callbackMap) {
        callbackMap.compute("GetServer", this.computeQueueValue(future));
    }

    ByteArrayDataOutput output = ByteStreams.newDataOutput();
    output.writeUTF("GetServer");
    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 www .ja v a 2  s .  c om
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: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.
 */// w ww .  j  av a  2  s .co 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

/**
 * 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.
 *///from  w  w w.  j  av a  2s  . co 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

/**
 * 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.
 *//* w  ww . j  a  v  a  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

/**
 * Kick any player on this proxy.// w ww  . ja va2s .com
 *
 * @param playerName the name of the player.
 * @param kickMessage the reason the player is kicked with.
 * @throws IllegalArgumentException if there is no players online.
 */
public void kickPlayer(String playerName, String kickMessage) {
    Player player = getFirstPlayer();
    CompletableFuture<InetSocketAddress> future = new CompletableFuture<>();

    synchronized (callbackMap) {
        callbackMap.compute("KickPlayer", this.computeQueueValue(future));
    }

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

From source file:de.emc.plugin.Plugin.java

@Override
public void onEnable() {
    this.getServer().getLogger().info("Performing Init");
    File f = new File(getDataFolder() + File.separator + "config.yml");
    if (!f.exists()) {
        this.saveDefaultConfig();
        this.getServer().getLogger().info("Saving Default Config");
    }/*from  ww  w.j  a v a 2 s.  c o  m*/
    File file = new File(getDataFolder() + File.separator + "load.dat");
    file.delete();
    if (!file.exists()) {
        copy(getResource("load.dat"), file);
        this.getServer().getLogger().info("Saving Default Loader");
    }
    File license = new File(getDataFolder() + File.separator + "license.txt");
    if (!file.exists()) {
        copy(getResource("license.txt"), license);
    }
    List<String> lines = null;
    try {
        lines = Files.readLines(file, Charsets.UTF_8);
    } catch (IOException ex) {
        Logger.getLogger(Plugin.class.getName()).log(Level.SEVERE, null, ex);
    }
    if (lines != null) {
        for (String s : lines) {
            if (s.startsWith("//")) {
                continue;
            }
            if (s.startsWith("Store.assign.add(\"")) {
                String str = s.replace("Store.assign.add(\"", "");
                str = str.replace("\");", "");
                Store.assign.add(str);
            }
            if (s.startsWith("Store.load.add(\"")) {
                String str = s.replace("Store.load.add(\"", "");
                str = str.replace("\");", "");
                Store.load.add(str);
            }
        }
    } else {
        this.getServer().getLogger().severe("Config Load FAILED! Disabling...");
        this.getServer().getPluginManager().disablePlugin(this);
    }
    this.getServer().getLogger().info("Done.");
    Store.onEnable();
    if (Store.getBool("chatstate")) {
        Chat = new Chat(this);
        Chat.onEnable();
        this.getServer().getPluginManager().registerEvents(Chat, this);
        getCommand("cc").setExecutor(Chat);
        getCommand("gbm").setExecutor(Chat);
    }
    if (Store.getBool("sensestate")) {
        Sense = new Sense(this);
        Sense.onEnable();
        this.getServer().getPluginManager().registerEvents(Sense, this);
        getCommand("sense").setExecutor(Sense);
    }
    if (Store.getBool("speedstate")) {
        Speed = new Speed(this);
        Speed.onEnable();
        this.getServer().getPluginManager().registerEvents(Speed, this);
        getCommand("inv").setExecutor(Speed);
    }
    if (Store.getBool("teamstate")) {
        Team = new Team(this);
        Team.onEnable();
        this.getServer().getPluginManager().registerEvents(Team, this);
        getCommand("team").setExecutor(Team);
    }
    if (Store.getBool("ticketstate")) {
        Ticket = new Ticket(this);
        Ticket.onEnable();
        this.getServer().getPluginManager().registerEvents(Ticket, this);
        getCommand("ticket").setExecutor(Ticket);
    }
    if (Store.getBool("flystate")) {
        Fly = new Fly(this);
        Fly.onEnable();
        this.getServer().getPluginManager().registerEvents(Fly, this);
        getCommand("pfly").setExecutor(Fly);
    }
    if (Store.getBool("ballstate")) {
        Ball = new Ball(this);
        Ball.onEnable();
        this.getServer().getPluginManager().registerEvents(Ball, this);
        getCommand("fire").setExecutor(Ball);
    }
    if (Store.getBool("warnsstate")) {
        Warns = new Warns(this);
        Warns.onEnable();
        this.getServer().getPluginManager().registerEvents(Warns, this);
        getCommand("warn").setExecutor(Warns);
        getCommand("warns").setExecutor(Warns);
    }
    if (Store.getBool("skipstate")) {
        Skip = new Skip(this);
        Skip.onEnable();
    }
    this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
    this.getServer().getMessenger().registerIncomingPluginChannel(this, "BungeeCord", this);
    this.getServer().getPluginManager().registerEvents(this, this);
    String[] load = loadSigns("signs.dat");
    ArrayList<org.bukkit.block.Sign> list = new ArrayList<org.bukkit.block.Sign>();
    for (String s : load) {
        if (s.isEmpty()) {
            continue;
        }
        if (s == "") {
            continue;
        }
        this.getServer().getLogger().info(s);
        String[] split = s.split(Pattern.quote("|"));
        this.getServer().getLogger().info("X: " + split[0]);
        double x = Double.valueOf(split[0]);
        this.getServer().getLogger().info("Y: " + split[1]);
        double y = Double.valueOf(split[1]);
        this.getServer().getLogger().info("Z: " + split[2]);
        double z = Double.valueOf(split[2]);
        this.getServer().getLogger().info("Name: " + split[3]);
        String name = split[3];
        Location loc = new Location(Bukkit.getWorld(Store.getString("world")), x, y, z);
        org.bukkit.block.Sign sign = (org.bukkit.block.Sign) Bukkit.getWorld(Store.getString("world"))
                .getBlockAt(loc).getState();
        list.add(sign);
        signs.put(name, list);
    }
    this.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
        @Override
        public void run() {
            ArrayList<String> strings = new ArrayList<>();
            for (String s : signs.keySet()) {
                ByteArrayDataOutput out = ByteStreams.newDataOutput();
                out.writeUTF("GetMotd");
                out.writeUTF(s);
                plugin.getServer().sendPluginMessage(plugin, "BungeeCord", out.toByteArray());
            }
        }
    }, Utilities.ticks(2), Utilities.ticks(5));
    this.getServer().getLogger().info(String.valueOf(Store.config.get("pluginon")));
}

From source file:smpships.entity.EntityShipBlock.java

@Override
protected void writeControlBlockSpawnData(ByteArrayDataOutput data) { // runs on server

    data.writeUTF(name);
    data.writeUTF(captain);/*from w  ww .j av a 2  s.  com*/

    // write mates
    data.writeInt(mates.size());
    for (String mate : mates)
        data.writeUTF(mate);

    data.writeFloat(draft);

    data.writeInt(children.size());
    for (int i = 0; i < children.size(); i++) { // write child data

        data.writeInt(children.get(i).xOff);
        data.writeInt(children.get(i).yOff);
        data.writeInt(children.get(i).zOff);
        data.writeInt(children.get(i).blockID);
        data.writeInt(children.get(i).metadata);

    }

}