List of usage examples for com.google.common.io ByteArrayDataOutput writeUTF
@Override
void writeUTF(String s);
From source file:tk.playerforcehd.networklib.bukkit.connection.NetworkManager.java
/** * Execute a command in the console of a speciefied server * * @param command the command which get executed * @param serverName the name of the server the the command get executed *///from www . j a v a 2s . c o m public void executeCommand_Server(String command, String serverName) { ByteArrayDataOutput stream = ByteStreams.newDataOutput(); stream.writeUTF("executeCommand"); stream.writeUTF("server_" + serverName); stream.writeUTF(command); Bukkit.getOnlinePlayers().iterator().next().sendPluginMessage(this.thePlugin, "BungeeCord", stream.toByteArray()); }
From source file:tk.playerforcehd.networklib.bukkit.connection.NetworkManager.java
/** * Let's a player execute a command on his current server * * @param command the command which get executes * @param player the player who executes it *//* w w w . j ava 2 s . c o m*/ public void executeCommand_Player(String command, Player player) { ByteArrayDataOutput stream = ByteStreams.newDataOutput(); stream.writeUTF("executeCommand"); stream.writeUTF(player.getName()); stream.writeUTF(command); Bukkit.getOnlinePlayers().iterator().next().sendPluginMessage(this.thePlugin, "BungeeCord", stream.toByteArray()); }
From source file:tk.playerforcehd.networklib.bukkit.connection.NetworkManager.java
/** * Send a plugin mesage to a player//from w w w . j av a2 s . c o m * * @param subchannel the subchannel where the message get send * @param messages The messages to send */ public void sendMessageToPlayer(Player player, String subchannel, String... messages) { ByteArrayDataOutput stream = ByteStreams.newDataOutput(); stream.writeUTF(subchannel); for (String write : messages) { stream.writeUTF(write); } PluginMessageOutgoingEvent pluginMessageOutgoingEvent = new PluginMessageOutgoingEvent(this.channel, stream); Bukkit.getPluginManager().callEvent(pluginMessageOutgoingEvent); if (!pluginMessageOutgoingEvent.isCancelled()) { player.sendPluginMessage(thePlugin, pluginMessageOutgoingEvent.getChannel(), pluginMessageOutgoingEvent.getByteArrayDataOutput().toByteArray()); } }
From source file:de.jonas.Game.java
public void GameLobby() { for (ItemSpawner is : Rush.spawner) { is.unregister();//ww w . ja va 2s .c o 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:tk.playerforcehd.networklib.bukkit.connection.NetworkManager.java
/** * Send a plugin mesage to the proxy//from ww w . ja v a2 s.c o m * * @param subchannel the subchannel where the message get send * @param messages The messages to write */ public void sendMessageToProxy(String subchannel, String... messages) { ByteArrayDataOutput stream = ByteStreams.newDataOutput(); stream.writeUTF(subchannel); for (String write : messages) { stream.writeUTF(write); } PluginMessageOutgoingEvent pluginMessageOutgoingEvent = new PluginMessageOutgoingEvent(this.channel, stream); Bukkit.getPluginManager().callEvent(pluginMessageOutgoingEvent); if (!pluginMessageOutgoingEvent.isCancelled()) { for (Player p : Bukkit.getOnlinePlayers()) { p.sendPluginMessage(thePlugin, pluginMessageOutgoingEvent.getChannel(), pluginMessageOutgoingEvent.getByteArrayDataOutput().toByteArray()); break; } } }
From source file:com.gmail.tracebachi.DeltaEssentials.Listeners.PlayerDataIOListener.java
public void onPlayerSaveSuccess(String name, String destServer) { PlayerPostSaveEvent savedEvent = new PlayerPostSaveEvent(name); Bukkit.getPluginManager().callEvent(savedEvent); Player player = Bukkit.getPlayerExact(name); if (player == null) { return;// w w w .j av a 2 s. c o m } if (destServer == null) { return; } ByteArrayDataOutput output = ByteStreams.newDataOutput(); output.writeUTF("Connect"); output.writeUTF(destServer); player.sendPluginMessage(plugin, "BungeeCord", output.toByteArray()); plugin.getPlayerLockManager().add(name, System.currentTimeMillis() + 15000); // TODO Make configurable time }
From source file:io.github.apfelcreme.GuildsBungee.GuildsBungee.java
/** * notifies servers about a login or a logout * * @param uuid the player/* w w w . j a v a 2s .c o m*/ * @param isOnline the status */ public void sendPlayerStatusChange(UUID uuid, boolean isOnline) { for (ServerInfo serverInfo : ProxyServer.getInstance().getServers().values()) { ByteArrayDataOutput out = ByteStreams.newDataOutput(); out.writeUTF(isOnline ? "joined" : "disconnected"); out.writeUTF(uuid.toString()); serverInfo.sendData("guilds:player", out.toByteArray()); } }
From source file:io.github.apfelcreme.GuildsBungee.GuildsBungee.java
private void sendQueueingMessage(String operation, String args, Object... write) { ByteArrayDataOutput out = ByteStreams.newDataOutput(); out.writeUTF(args); for (Object w : write) { if (w instanceof String) { out.writeUTF((String) w); } else if (w instanceof Integer) { out.writeInt((Integer) w); } else {/*from w w w . j av a 2 s.c om*/ try (ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream oOut = new ObjectOutputStream(bos)) { oOut.writeObject(w); out.write(bos.toByteArray()); } catch (IOException e) { e.printStackTrace(); } } } QueueingPluginMessage pm = new QueueingPluginMessage(operation, args, out); for (ServerInfo serverInfo : getProxy().getServers().values()) { if (serverInfo.getPlayers().size() > 0) { pm.send(serverInfo); } } if (pm.getSendTo().size() < getProxy().getServers().size()) { // plugin message wasn't sent to all servers because no players where online, queue it pmQueue.put(pm.getCommand(), pm); } else { // remove previously queued plugin message if we already send a newer one pmQueue.remove(pm.getCommand()); } }
From source file:io.github.apfelcreme.GuildsBungee.GuildsBungee.java
/** * sends a player to its home//from w ww . j av a 2 s .c o m * * @param uuid the player uuid * @param guild the guild * @param homeServer the ip of the server the home is on * @param source the server the message is coming from */ private void sendPlayerToGuildHome(UUID uuid, String guild, String homeServer, Server source) throws IOException { ServerInfo target = source.getInfo(); if (!source.getInfo().getAddress().toString().split("/")[1].equals(homeServer)) { ProxiedPlayer player = getProxy().getPlayer(uuid); if (player != null) { if (new InetSocketAddress(homeServer.split(":")[0], Integer.parseInt(homeServer.split(":")[1])) .getAddress().isReachable(2000)) { target = getTargetServer(homeServer); if (target != null) { player.connect(target); } else { getLogger().severe("Targetserver nicht gefunden!"); } } else { ByteArrayDataOutput out = ByteStreams.newDataOutput(); out.writeUTF("homeServerUnreachable"); out.writeUTF(uuid.toString()); source.sendData("guilds:error", out.toByteArray()); return; } } } ByteArrayDataOutput out = ByteStreams.newDataOutput(); out.writeUTF("home"); out.writeUTF(uuid.toString()); out.writeUTF(guild); if (target != null) { target.sendData("guilds:player", out.toByteArray()); } }
From source file:net.minecraftforge.gradle.patcher.TaskGenBinPatches.java
private void createBinPatches(HashMap<String, byte[]> patches, String root, File base, File target) throws Exception { JarFile cleanJ = new JarFile(base); JarFile dirtyJ = new JarFile(target); for (Map.Entry<String, String> entry : obfMapping.entrySet()) { String obf = entry.getKey(); String srg = entry.getValue(); if (!patchedFiles.contains(obf)) // Not in the list of patch files.. we didn't edit it. {//w ww .ja v a 2 s. c o m continue; } JarEntry cleanE = cleanJ.getJarEntry(obf + ".class"); JarEntry dirtyE = dirtyJ.getJarEntry(obf + ".class"); if (dirtyE == null) //Something odd happened.. a base MC class wasn't in the obfed jar? { continue; } byte[] clean = (cleanE != null ? ByteStreams.toByteArray(cleanJ.getInputStream(cleanE)) : new byte[0]); byte[] dirty = ByteStreams.toByteArray(dirtyJ.getInputStream(dirtyE)); byte[] diff = delta.compute(clean, dirty); ByteArrayDataOutput out = ByteStreams.newDataOutput(diff.length + 50); out.writeUTF(obf); // Clean name out.writeUTF(obf.replace('/', '.')); // Source Notch name out.writeUTF(srg.replace('/', '.')); // Source SRG Name out.writeBoolean(cleanE != null); // Exists in Clean if (cleanE != null) { out.writeInt(adlerHash(clean)); // Hash of Clean file } out.writeInt(diff.length); // Patch length out.write(diff); // Patch patches.put(root + srg.replace('/', '.') + ".binpatch", out.toByteArray()); } cleanJ.close(); dirtyJ.close(); }