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:me.lucko.luckperms.bungee.messaging.BungeeMessagingService.java

@Override
protected void sendMessage(String channel, String message) {

    ByteArrayDataOutput out = ByteStreams.newDataOutput();
    out.writeUTF(message);

    byte[] data = out.toByteArray();

    for (ServerInfo server : plugin.getProxy().getServers().values()) {
        server.sendData(channel, data, true);
    }//from ww w . j  a v  a  2  s  .c  om
}

From source file:io.github.apfelcreme.LitePortals.Bungee.BukkitMessenger.java

/**
 * sends a message to the bukkit to check the position of a player.
 * Bukkit then returns a message with a location of a portal if the player is standing in one
 *
 * @param player the player/*from w w w  . j a va  2  s  . co m*/
 */
public void sendPositionRequest(ProxiedPlayer player) {
    ServerInfo target = player.getServer().getInfo();
    if (target != null) {
        ByteArrayDataOutput out = ByteStreams.newDataOutput();
        out.writeUTF("POSITIONREQUEST");
        out.writeUTF(player.getUniqueId().toString());
        target.sendData("LitePortals", out.toByteArray());
    }
}

From source file:com.minestein.novacore.command.Hub.java

/**
 * @param sender  The thing that sent the command.
 * @param command The command sent./* w w w  . j ava 2s .  co m*/
 * @param s       The command's label.
 * @param strings The arguments to the command.
 * @return ignore
 */
@Override
public boolean onCommand(CommandSender sender, Command command, String s, String[] strings) {
    if (!(sender instanceof Player)) {
        sender.sendMessage(Core.getPrefix() + "4Only players can exit to hub!");
        return true;
    } else {
        final Player p = (Player) sender;

        if (alreadySending.contains(p.getName())) {
            p.sendMessage(Core.getPrefix() + "4You are already going to the hub!");
            return true;
        }

        alreadySending.add(p.getName());

        String[] messages = new String[] { "Through the portal!", "They aren't gonna make it!", "RUUUNNNNNN!",
                "It's a trap!", "Don't do it!" };
        p.sendMessage(Core.getPrefix() + "bSending you to the hub! bo"
                + messages[Core.random.nextInt(messages.length)]);

        Bukkit.getScheduler().runTaskLater(Core.plugin, new Runnable() {
            @Override
            public void run() {
                alreadySending.remove(p.getName());

                ByteArrayDataOutput out = ByteStreams.newDataOutput();
                out.writeUTF("Connect");
                out.writeUTF("lobby");
                p.sendPluginMessage(Core.plugin, "BungeeCord", out.toByteArray());
            }
        }, 30);
    }
    return true;
}

From source file:me.lucko.luckperms.bungee.messaging.BungeeMessenger.java

@Override
public void sendOutgoingMessage(@Nonnull OutgoingMessage outgoingMessage) {
    ByteArrayDataOutput out = ByteStreams.newDataOutput();
    out.writeUTF(outgoingMessage.asEncodedString());

    byte[] data = out.toByteArray();

    for (ServerInfo server : this.plugin.getBootstrap().getProxy().getServers().values()) {
        server.sendData(CHANNEL, data, true);
    }/*from  w w  w .  j a va2  s .c o  m*/
}

From source file:me.lucko.luckperms.bukkit.messaging.BungeeMessagingService.java

@Override
protected void sendMessage(String channel, String message) {
    new BukkitRunnable() {
        @Override/*  w w  w  . j a  v a 2s.co  m*/
        public void run() {
            Collection<? extends Player> players = plugin.getServer().getOnlinePlayers();
            if (players.isEmpty()) {
                return;
            }

            Player p = Iterables.getFirst(players, null);

            ByteArrayDataOutput out = ByteStreams.newDataOutput();
            out.writeUTF(message);

            byte[] data = out.toByteArray();

            p.sendPluginMessage(plugin, channel, data);
            cancel();
        }
    }.runTaskTimer(plugin, 1L, 100L);
}

From source file:me.dobrakmato.plugins.pexel.PexelCore.actions.TeleportAction.java

@Override
public void execute(final Player player) {
    if (this.server.isLocalServer()) {
        // Just teleport player to target location.
        player.teleport(this.location);
    } else {/*from   ww  w  .  j  a v  a2s.  com*/
        // TODO: Add teleport to location. Perform server-wide teleport

        // Teleport to other server using bungee
        ByteArrayDataOutput out = ByteStreams.newDataOutput();
        out.writeUTF("Connect");
        out.writeUTF(this.server.getBungeeName());
        player.sendPluginMessage(Pexel.getCore(), "BungeeCord", out.toByteArray());
    }
}

From source file:io.github.aritzhack.aritzh.bds.BDSString.java

@Override
public byte[] getBytes() {
    ByteArrayDataOutput output = ByteStreams.newDataOutput();
    output.writeByte(this.getType().toByte());
    output.writeUTF(this.name);
    output.writeUTF(this.data);
    return output.toByteArray();
}

From source file:io.github.aritzhack.aritzh.bds.BDSInt.java

@Override
public byte[] getBytes() {
    ByteArrayDataOutput output = ByteStreams.newDataOutput();
    output.writeByte(this.getType().toByte());
    output.writeUTF(this.name);
    output.writeInt(this.data);
    return output.toByteArray();
}

From source file:io.github.aritzhack.aritzh.bds.BDSByte.java

@Override
public byte[] getBytes() {
    ByteArrayDataOutput output = ByteStreams.newDataOutput();
    output.writeByte(this.getType().toByte());
    output.writeUTF(this.name);
    output.writeByte(data);/*  w  ww. j  a  v a  2s .c o  m*/
    return output.toByteArray();
}

From source file:io.github.aritzhack.aritzh.bds.BDSShort.java

@Override
public byte[] getBytes() {
    ByteArrayDataOutput output = ByteStreams.newDataOutput();
    output.writeByte(this.getType().toByte());
    output.writeUTF(this.name);
    output.writeShort(this.data);
    return output.toByteArray();
}