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:tk.playerforcehd.networklib.bungee.connection.NetworkManager.java

/**
 * Send a plugin message to all servers in the network
 *
 * @param subchannel the subchannel or "command"
 * @param messages   the messages of the plugin message
 * @throws Exception should not get thrown
 *//*from   w w w .  j a v  a 2s . co m*/
public void broadcastPluginMessage(String subchannel, String... messages) throws Exception {
    ByteArrayDataOutput stream = ByteStreams.newDataOutput();
    stream.writeUTF(subchannel);
    for (String write : messages) {
        stream.writeUTF(write);
    }
    Collection<ServerInfo> servers = this.thePlugin.getProxy().getServers().values();
    for (ServerInfo currentServer : servers) {
        currentServer.sendData(this.channel, stream.toByteArray());
    }
}

From source file:cpw.mods.fml.common.network.ModListResponsePacket.java

@Override
public byte[] generatePacket(Object... data) {
    Map<String, String> modVersions = (Map<String, String>) data[0];
    List<String> missingMods = (List<String>) data[1];
    ByteArrayDataOutput dat = ByteStreams.newDataOutput();
    dat.writeInt(modVersions.size());//from  w w  w.  j  av  a2  s.c o m
    for (Entry<String, String> version : modVersions.entrySet()) {
        dat.writeUTF(version.getKey());
        dat.writeUTF(version.getValue());
    }
    dat.writeInt(missingMods.size());
    for (String missing : missingMods) {
        dat.writeUTF(missing);
    }
    return dat.toByteArray();
}

From source file:me.dobrakmato.plugins.pexel.PexelCore.EventProcessor.java

@EventHandler
private void onPlayerInteract(final PlayerInteractEvent event) {
    if (event.getClickedBlock() != null) {
        if (event.getClickedBlock().getType() == Material.SIGN
                || event.getClickedBlock().getType() == Material.SIGN_POST) {
            if (event.getPlayer().isOp() && event.getAction() == org.bukkit.event.block.Action.RIGHT_CLICK_BLOCK
                    || !event.getPlayer().isOp()) {
                Sign sign = (Sign) event.getClickedBlock().getState();
                String[] lines = sign.getLines();
                if (lines.length > 1) {
                    String command = lines[0].trim();
                    if (command.equalsIgnoreCase("[Server]")) {
                        ByteArrayDataOutput out = ByteStreams.newDataOutput();
                        out.writeUTF("Connect");
                        out.writeUTF(lines[1]);
                        event.getPlayer().sendPluginMessage(Pexel.getCore(), "BungeeCord", out.toByteArray());
                    } else if (command.equalsIgnoreCase("[Warp]")) {
                        event.getPlayer().performCommand("warp " + lines[1]);
                    } else if (command.equalsIgnoreCase("[Matchmaking]")) {
                        Pexel.getMatchmaking().processSign(lines, event.getPlayer());
                    } else if (command.equalsIgnoreCase("[World]")) {
                        World w = Bukkit.getWorld(lines[1]);
                        if (w == null)
                            event.getPlayer()
                                    .sendMessage(ChatManager.error(Lang.getTranslation("worldnotfound")));
                        else
                            event.getPlayer().teleport(w.getSpawnLocation());
                    }//from  w  w w  . j  a  v  a 2 s . com
                }
            }
        }
    }
}

From source file:net.portalblock.rbbridge.MessageChannelListener.java

@EventHandler
public void onPluginMessage(final PluginMessageEvent event) {
    if (event.getTag().equals("RedisBungee") && event.getSender() instanceof Server) {
        final byte[] data = Arrays.copyOf(event.getData(), event.getData().length);
        plugin.getProxy().getScheduler().runAsync(plugin, new Runnable() {
            @Override/*from w  w  w .  j  a v  a2s  . co  m*/
            public void run() {
                ByteArrayDataInput in = ByteStreams.newDataInput(data);

                String subchannel = in.readUTF();
                ByteArrayDataOutput out = ByteStreams.newDataOutput();
                String type;

                switch (subchannel) {
                case "PlayerList":
                    out.writeUTF("PlayerList");
                    Set<UUID> original = Collections.emptySet();
                    type = in.readUTF();
                    if (type.equals("ALL")) {
                        out.writeUTF("ALL");
                        original = RedisBungee.getApi().getPlayersOnline();
                    } else {
                        try {
                            original = RedisBungee.getApi().getPlayersOnServer(type);
                        } catch (IllegalArgumentException ignored) {
                        }
                    }
                    Set<String> players = new HashSet<String>();
                    for (UUID uuid : original)
                        players.add(RedisBungee.getApi().getNameFromUuid(uuid, false));
                    out.writeUTF(Joiner.on(',').join(players));
                    break;
                case "PlayerCount":
                    out.writeUTF("PlayerCount");
                    type = in.readUTF();
                    if (type.equals("ALL")) {
                        out.writeUTF("ALL");
                        out.writeInt(RedisBungee.getApi().getPlayerCount());
                    } else {
                        out.writeUTF(type);
                        try {
                            out.writeInt(RedisBungee.getApi().getPlayersOnServer(type).size());
                        } catch (IllegalArgumentException e) {
                            out.writeInt(0);
                        }
                    }
                    break;
                case "LastOnline":
                    String user = in.readUTF();
                    out.writeUTF("LastOnline");
                    out.writeUTF(user);
                    out.writeLong(RedisBungee.getApi()
                            .getLastOnline(RedisBungee.getApi().getUuidFromName(user, true)));
                    break;
                default:
                    break;
                }

                ((Server) event.getSender()).sendData("RedisBungee", out.toByteArray());
            }
        });
    }
}

From source file:de.bl4ckskull666.afkbukkit.AFKBukkit.java

public void sendPluginMessage(Player p) {
    if ((_lastFire.containsKey(p.getUniqueId())
            && ((System.currentTimeMillis() - _lastFire.get(p.getUniqueId())) / 1000) < 30)
            && !_isAFK.contains(p.getUniqueId()))
        return;/*from ww w.  j  a v a2 s . c  om*/

    _lastFire.put(p.getUniqueId(), System.currentTimeMillis());

    ByteArrayDataOutput out = ByteStreams.newDataOutput();
    out.writeUTF("AFKB");
    out.writeUTF("Player");
    out.writeUTF(p.getUniqueId().toString());
    ByteArrayDataInput in = ByteStreams.newDataInput(out.toByteArray());
    debugMe("Send PluginMessage with " + in.readLine());
    p.sendPluginMessage(this, "BungeeCord", out.toByteArray());

}

From source file:cpw.mods.fml.common.network.ModIdentifiersPacket.java

@Override
public byte[] generatePacket(Object... data) {
    ByteArrayDataOutput dat = ByteStreams.newDataOutput();
    Collection<NetworkModHandler> networkMods = FMLNetworkHandler.instance().getNetworkIdMap().values();

    dat.writeInt(networkMods.size());//from ww w . j  av a  2  s.  c o m
    for (NetworkModHandler handler : networkMods) {
        dat.writeUTF(handler.getContainer().getModId());
        dat.writeInt(handler.getNetworkId());
    }

    // TODO send the other id maps as well
    return dat.toByteArray();
}

From source file:cpw.mods.fml.common.network.ModListRequestPacket.java

@Override
public byte[] generatePacket(Object... data) {
    ByteArrayDataOutput dat = ByteStreams.newDataOutput();
    Set<ModContainer> activeMods = FMLNetworkHandler.instance().getNetworkModList();
    dat.writeInt(activeMods.size());/*  ww w  .  ja v a 2  s  . co m*/
    for (ModContainer mc : activeMods) {
        dat.writeUTF(mc.getModId());
    }
    dat.writeByte(FMLNetworkHandler.getCompatibilityLevel());
    return dat.toByteArray();
}

From source file:tk.playerforcehd.networklib.bukkit.connection.NetworkManager.java

/**
 * Executer a global broadcast with a permission who recieve it over the network.
 * this can be used to broadcast global things with a plugin
 *
 * @param whoExecuteIt the player who send the plugin message
 * @param message      the message which get send
 *///from  www .  j  ava2 s .  com
public void executeBroadcast(Player whoExecuteIt, String message) {
    ByteArrayDataOutput stream = ByteStreams.newDataOutput();
    stream.writeUTF("broadcast");
    stream.writeUTF(message);
    whoExecuteIt.sendPluginMessage(this.thePlugin, "BungeeCord", stream.toByteArray());
}

From source file:tk.playerforcehd.networklib.bukkit.connection.NetworkManager.java

/**
 * Executer a global broadcast with a permission who recieve it over the network.
 * this can be used to broadcast global things with a plugin
 *
 * @param whoExecuteIt the player who send the plugin message
 * @param permission   the needed permission to recieve the message
 * @param message      the message which get send
 *///from   w  w  w  .  jav a  2  s. c  om
public void executeBroadcast(Player whoExecuteIt, String permission, String message) {
    ByteArrayDataOutput stream = ByteStreams.newDataOutput();
    stream.writeUTF("broadcast");
    stream.writeUTF("Permission:" + permission);
    stream.writeUTF(message);
    whoExecuteIt.sendPluginMessage(this.thePlugin, "BungeeCord", stream.toByteArray());
}

From source file:tk.playerforcehd.networklib.bukkit.connection.NetworkManager.java

/**
 * Execute a command on the proxy/*  w ww. j av  a 2 s . c o m*/
 *
 * @param command the command which get runned
 */
public void executeCommand_Proxy(String command) {
    ByteArrayDataOutput stream = ByteStreams.newDataOutput();
    stream.writeUTF("executeCommand");
    stream.writeUTF("bungee");
    stream.writeUTF(command);
    Bukkit.getOnlinePlayers().iterator().next().sendPluginMessage(this.thePlugin, "BungeeCord",
            stream.toByteArray());
}