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:net.nifheim.beelzebu.coins.bukkit.utils.bungee.PluginMessage.java

public void sendToBungeeCord(String channel, String message) {
    ByteArrayDataOutput out = ByteStreams.newDataOutput();
    out.writeUTF(channel);
    out.writeUTF(message);//w  w  w  .j a va2 s  .c o  m
    Player p = Iterables.getFirst(Bukkit.getOnlinePlayers(), null);
    if (p != null) {
        p.sendPluginMessage(Main.getInstance(), "Coins", out.toByteArray());
    }
}

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

@Override
public void sendOutgoingMessage(@Nonnull OutgoingMessage outgoingMessage) {
    new BukkitRunnable() {
        @Override//  w  ww .j av a  2s .c o  m
        public void run() {
            Collection<? extends Player> players = BungeeMessenger.this.plugin.getBootstrap().getServer()
                    .getOnlinePlayers();
            Player p = Iterables.getFirst(players, null);
            if (p == null) {
                return;
            }

            ByteArrayDataOutput out = ByteStreams.newDataOutput();
            out.writeUTF(outgoingMessage.asEncodedString());

            byte[] data = out.toByteArray();

            p.sendPluginMessage(BungeeMessenger.this.plugin.getBootstrap(), CHANNEL, data);
            cancel();
        }
    }.runTaskTimer(this.plugin.getBootstrap(), 1L, 100L);
}

From source file:net.nifheim.beelzebu.coins.bukkit.utils.bungee.PluginMessage.java

public void sendToBungeeCord(String channel, List<String> messages) {
    ByteArrayDataOutput out = ByteStreams.newDataOutput();
    out.writeUTF(channel);
    messages.forEach(message -> {/* ww w  . j ava 2 s  . co m*/
        out.writeUTF(message);
    });
    Player p = Iterables.getFirst(Bukkit.getOnlinePlayers(), null);
    if (p != null) {
        p.sendPluginMessage(Main.getInstance(), "Coins", out.toByteArray());
    }
}

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

/**
 * teleports a player to a location. If that location is on a different Bukkit instance, he is being sent to that server
 *
 * @param uuid           the player uuid
 * @param targetLocation the target location the player is being teleported to.
 */// w w  w . j a v  a  2  s .  c  o  m
public void teleportPlayer(UUID uuid, Location targetLocation) {
    ProxiedPlayer player = ProxyServer.getInstance().getPlayer(uuid);
    if (player != null) {
        try {
            ServerInfo serverInfo = LitePortals.getInstance().getTargetServer(targetLocation.getServer());
            if (serverInfo != null) {
                if (!player.getServer().getInfo().equals(serverInfo)
                        && serverInfo.getAddress().getAddress().isReachable(2000)) {
                    player.connect(serverInfo);
                    LitePortals.getInstance().getLogger()
                            .info(player.getName() + " used a LitePortal to " + serverInfo.getName());
                }

                ByteArrayDataOutput out = ByteStreams.newDataOutput();
                out.writeUTF("WARP");
                out.writeUTF(uuid.toString());
                out.writeUTF(targetLocation.getWorld());
                out.writeDouble(targetLocation.getX());
                out.writeDouble(targetLocation.getY());
                out.writeDouble(targetLocation.getZ());
                out.writeDouble(targetLocation.getYaw());
                serverInfo.sendData("LitePortals", out.toByteArray());
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:de.mineformers.robots.network.packet.PacketFactoryController.java

@Override
public void write(ByteArrayDataOutput out) {
    super.write(out);
    out.writeInt(orientation);//from  ww w . j a va  2  s  .c o  m
    out.writeBoolean(validMultiblock);
    out.writeUTF(selectedModule);
}

From source file:eplus.network.packets.ConfigPacket.java

@Override
public void write(ByteArrayDataOutput output) {
    output.writeInt(configSettings.size());

    for (String key : configSettings.keySet()) {
        output.writeUTF(key);
        output.writeUTF(configSettings.get(key));
    }// ww  w.  j a va2 s  . com
}

From source file:de.themoep.servertags.bungee.ServerTags.java

private void sendPluginMessage(Connection connection, String subchannel, String... args) {
    ByteArrayDataOutput out = ByteStreams.newDataOutput();
    out.writeUTF(subchannel);
    for (String s : args) {
        out.writeUTF(s);//from  w  w w .ja  v a2 s.c o  m
    }
    if (connection instanceof Server) {
        ((Server) connection).sendData(getDescription().getName(), out.toByteArray());
    } else if (connection instanceof ProxiedPlayer) {
        ((ProxiedPlayer) connection).sendData(getDescription().getName(), out.toByteArray());
    } else {
        getLogger().log(Level.SEVERE,
                "Tried to send a plugin message on a connection which doesn't support it!");
    }
}

From source file:co.uk.randompanda30.sao.task.ShutdownTask.java

@Override
public void run() {
    long t = TEMP.restartcounter;

    if (t == 215800) {
        Dispatch.broadcastMessage(Messages.MessagesValues.MODULES_AUTOSHUTDOWN_SHUTDOWNIN.value.toString()
                .replace("%time", Integer.toString(10)), true);
        Yell.broadcastSound(Sound.NOTE_BASS, 1, 1);
    } else if (t == 215820) {
        Dispatch.broadcastMessage(Messages.MessagesValues.MODULES_AUTOSHUTDOWN_SHUTDOWNIN.value.toString()
                .replace("%time", Integer.toString(9)), true);
        Yell.broadcastSound(Sound.NOTE_BASS, 1, 1);
    } else if (t == 215840) {
        Dispatch.broadcastMessage(Messages.MessagesValues.MODULES_AUTOSHUTDOWN_SHUTDOWNIN.value.toString()
                .replace("%time", Integer.toString(8)), true);
        Yell.broadcastSound(Sound.NOTE_BASS, 1, 1);
    } else if (t == 215860) {
        Dispatch.broadcastMessage(Messages.MessagesValues.MODULES_AUTOSHUTDOWN_SHUTDOWNIN.value.toString()
                .replace("%time", Integer.toString(7)), true);
        Yell.broadcastSound(Sound.NOTE_BASS, 1, 1);
    } else if (t == 215880) {
        Dispatch.broadcastMessage(Messages.MessagesValues.MODULES_AUTOSHUTDOWN_SHUTDOWNIN.value.toString()
                .replace("%time", Integer.toString(6)), true);
        Yell.broadcastSound(Sound.NOTE_BASS, 1, 1);
    } else if (t == 215900) {
        Dispatch.broadcastMessage(Messages.MessagesValues.MODULES_AUTOSHUTDOWN_SHUTDOWNIN.value.toString()
                .replace("%time", Integer.toString(5)), true);
        Yell.broadcastSound(Sound.NOTE_BASS, 1, 1);
    } else if (t == 215920) {
        Dispatch.broadcastMessage(Messages.MessagesValues.MODULES_AUTOSHUTDOWN_SHUTDOWNIN.value.toString()
                .replace("%time", Integer.toString(4)), true);
        Yell.broadcastSound(Sound.NOTE_BASS, 1, 1);
    } else if (t == 215940) {
        Dispatch.broadcastMessage(Messages.MessagesValues.MODULES_AUTOSHUTDOWN_SHUTDOWNIN.value.toString()
                .replace("%time", Integer.toString(3)), true);
        Yell.broadcastSound(Sound.NOTE_BASS, 1, 1);
    } else if (t == 215960) {
        Dispatch.broadcastMessage(Messages.MessagesValues.MODULES_AUTOSHUTDOWN_SHUTDOWNIN.value.toString()
                .replace("%time", Integer.toString(2)), true);
        Yell.broadcastSound(Sound.NOTE_BASS, 1, 1);
    } else if (t == 215980) {
        Dispatch.broadcastMessage(Messages.MessagesValues.MODULES_AUTOSHUTDOWN_SHUTDOWNIN.value.toString()
                .replace("%time", Integer.toString(1)), true);
        Yell.broadcastSound(Sound.NOTE_BASS, 1, 1);

        if (TEMP.isBackingup) {
            Dispatch.broadcastMessage(
                    (String) Messages.MessagesValues.MODULES_AUTOSHUTDOWN_STOPPEDFORBACKUP.value, true);
            TEMP.pendingRestart = true;//ww  w.j  a va  2 s .  c o m
            this.cancel();
            return;
        }
    } else if (t == 216000) {
        if ((Boolean) Config.ConfigValues.AUTOSHUTDOWN_SENDTOBUNGEE.value) {
            ByteArrayDataOutput out = ByteStreams.newDataOutput();

            out.writeUTF("Connect");
            out.writeUTF("hub");

            for (Player player : Bukkit.getOnlinePlayers()) {
                player.sendPluginMessage(SAO.getPlugin(), "BungeeCord", out.toByteArray());
            }
        } else {
            for (Player player : Bukkit.getOnlinePlayers()) {
                player.kickPlayer("Scheduled restart. Join again in 2 minutes");
            }
        }

        SAO.getPlugin().getServer().savePlayers();

        for (World world : SAO.getPlugin().getServer().getWorlds()) {
            world.save();
            SAO.getPlugin().getServer().unloadWorld(world, true);
        }

        Bukkit.getScheduler().scheduleSyncDelayedTask(SAO.getPlugin(),
                () -> SAO.getPlugin().getServer().shutdown(), 100L);
    }

    TEMP.restartcounter = TEMP.restartcounter + 20;
}

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

/**
 * Send a plugin message to a speciefied player
 *
 * @param proxiedPlayer the player who recieve it
 * @param subchannel    the subchannel or "command"
 * @param messages      the messages of the plugin message
 *///from   w  w  w. j  a  va 2  s . com
public void sendMessageToPlayer(ProxiedPlayer proxiedPlayer, String subchannel, String... messages) {
    ByteArrayDataOutput stream = ByteStreams.newDataOutput();
    stream.writeUTF(subchannel);
    for (String write : messages) {
        stream.writeUTF(write);
    }
    proxiedPlayer.sendData(this.channel, stream.toByteArray());
}

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

/**
 * Send a plugin message a speciefied server
 *
 * @param server     the server who recieve it
 * @param subchannel the subchannel or "command"
 * @param messages   the messages of the plugin message
 * @throws Exception should not get thrown
 *//*from   w  w w  .ja  v  a  2 s.c o m*/
public void sendMessageToServer(ServerInfo server, String subchannel, String... messages) throws Exception {
    ByteArrayDataOutput stream = ByteStreams.newDataOutput();
    stream.writeUTF(subchannel);
    for (String write : messages) {
        stream.writeUTF(write);
    }
    server.sendData(this.channel, stream.toByteArray());
}