List of usage examples for com.google.common.io ByteArrayDataOutput toByteArray
byte[] toByteArray();
From source file:io.github.leonardosnt.bungeechannelapi.BungeeChannelApi.java
/** * Kick any player on this proxy.//from w w w . ja v a2s . c o m * * @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:cpw.mods.fml.common.network.ModMissingPacket.java
@Override public byte[] generatePacket(Object... data) { ByteArrayDataOutput dat = ByteStreams.newDataOutput(); List<String> missing = (List<String>) data[0]; List<String> badVersion = (List<String>) data[1]; dat.writeInt(missing.size());/*from ww w. ja v a2s.c om*/ for (String missed : missing) { ModContainer mc = Loader.instance().getIndexedModList().get(missed); dat.writeUTF(missed); dat.writeUTF(mc.getVersion()); } dat.writeInt(badVersion.size()); for (String bad : badVersion) { ModContainer mc = Loader.instance().getIndexedModList().get(bad); dat.writeUTF(bad); dat.writeUTF(mc.getVersion()); } return dat.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 w w w.j av a 2 s .co 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:com.volumetricpixels.rockyplugin.chunk.ChunkCacheHandler.java
/** * // w w w . j a v a2 s.c o m * @param buffer * @throws IOException */ public static byte[] handleCompression(String playerName, byte[] buffer) throws IOException { Set<Long> playerCache = cache.getPlayerCache(playerName); // Each chunk sended is handled by: // - BlockType: Whole byte per block // - BlockMetaData: Half byte per block // - BlockLight: Half byte per block // - SkyLight: Half byte per block (Only of handleLight is TRUE) // - AddArray: Half byte per block (Only if extraMask has the bit, // support for FORGE) // - BiomeArray: Whole byte per XZ coordinate (Only if isContinous is // TRUE) int chunkLen = buffer.length / ChunkCache.CHUNK_PARTITION_SIZE; if ((chunkLen & 0x7FF) != 0) { chunkLen++; } ByteArrayDataOutput out = ByteStreams.newDataOutput(); byte[] chunkData = new byte[ChunkCache.CHUNK_PARTITION_SIZE]; // Write the magic number out.writeInt(ChunkCache.CHUNK_MAGIC_NUMBER); // Write the number of section inside the packet out.writeShort(chunkLen); // For each CHUNK_PARTITION_SIZE block, check the hash of it. for (int i = 0; i < chunkLen; i++) { int index = i * ChunkCache.CHUNK_PARTITION_SIZE; int length = ChunkCache.CHUNK_PARTITION_SIZE; if (index + ChunkCache.CHUNK_PARTITION_SIZE > buffer.length) { length = buffer.length - index; } // Calculate the hash of the current block System.arraycopy(buffer, index, chunkData, 0x0000, length); long hash = ChunkCache.calculateHash(chunkData); // Write the hash into the packet out.writeLong(hash); // Add the hash into the player cache boolean isPresent = playerCache.add(hash); // Writes the length of the section out.writeShort(isPresent ? length : 0); // Check for the chunk with the player cache if (isPresent) { // Writes the data of the section out.write(chunkData); statCacheMiss.incrementAndGet(); } else { statCacheHit.incrementAndGet(); } statTotal.incrementAndGet(); } return out.toByteArray(); }
From source file:de.minebench.syncinv.SyncInv.java
/** * Connect a player to a bungee server/*from w ww . j a v a 2 s. c o m*/ * @param playerId The UUID of the player * @param server The name of the server */ public void connectToServer(UUID playerId, String server) { Player player = getServer().getPlayer(playerId); if (player != null && player.isOnline()) { ByteArrayDataOutput out = ByteStreams.newDataOutput(); out.writeUTF("Connect"); out.writeUTF(server); player.sendPluginMessage(this, "BungeeCord", out.toByteArray()); } }
From source file:shadowmage.ancient_warfare.common.network.PacketBase.java
/** * create the custom250packet from the current data in this packet. *//*w w w . j av a 2s . co m*/ protected void constructPacket() { ByteArrayDataOutput data = ByteStreams.newDataOutput(); /** * write the packet type number to the stream, decoded in packetHandler to create a new packet */ data.writeInt(this.getPacketType()); /** * write default packet data NBTCompound to the stream */ NBTWriter.writeTagToStream(packetData, data); /** * write custom data to the output stream */ this.writeDataToStream(data); this.packet250 = new Packet250CustomPayload(); packet250.isChunkDataPacket = this.chunkPacket; packet250.channel = this.getChannel(); packet250.data = data.toByteArray(); packet250.length = packet250.data.length; }
From source file:shadowmage.ancient_framework.common.network.PacketBase.java
/** * create the custom250packet from the current data in this packet. */// ww w . j av a 2 s.c om protected void constructPacket() { ByteArrayDataOutput data = ByteStreams.newDataOutput(); /** * write the packet type number to the stream, decoded in packetHandler to create a new packet */ data.writeInt(this.getPacketType()); /** * write default packet data NBTCompound to the stream */ NBTTools.writeTagToStream(packetData, data); /** * write custom data to the output stream */ this.writeDataToStream(data); this.packet250 = new Packet250CustomPayload(); packet250.isChunkDataPacket = this.chunkPacket; packet250.channel = this.getChannel(); packet250.data = data.toByteArray(); packet250.length = packet250.data.length; }
From source file:org.apache.hadoop.hbase.client.Mutation.java
/** * Marks that the clusters with the given clusterIds have consumed the mutation * @param clusterIds of the clusters that have consumed the mutation *//*from ww w . ja va2s . c o m*/ public void setClusterIds(List<UUID> clusterIds) { ByteArrayDataOutput out = ByteStreams.newDataOutput(); out.writeInt(clusterIds.size()); for (UUID clusterId : clusterIds) { out.writeLong(clusterId.getMostSignificantBits()); out.writeLong(clusterId.getLeastSignificantBits()); } setAttribute(CONSUMED_CLUSTER_IDS, out.toByteArray()); }
From source file:io.github.leonardosnt.bungeechannelapi.BungeeChannelApi.java
/** * Send a custom plugin message to said server. This is one of the most useful channels ever. * <b>Remember, the sending and receiving server(s) need to have a player online.</b> * * @param server the name of the server to send to, * ALL to send to every server (except the one sending the plugin message), * or ONLINE to send to every server that's online (except the one sending the plugin message). * * @param channelName Subchannel for plugin usage. * @param data data to send./*w w w .ja v a 2s . com*/ * @throws IllegalArgumentException if there is no players online. */ public void forward(String server, String channelName, byte[] data) { Player player = getFirstPlayer(); ByteArrayDataOutput output = ByteStreams.newDataOutput(); output.writeUTF("Forward"); output.writeUTF(server); output.writeUTF(channelName); output.writeShort(data.length); output.write(data); player.sendPluginMessage(this.plugin, "BungeeCord", output.toByteArray()); }
From source file:de.paleocrafter.pmfw.tileentity.TileEntityWithData.java
public byte[] getPacketData() { ByteArrayDataOutput out = ByteStreams.newDataOutput(); Class<?> clazz = this.getClass(); int superClassCount = 0; while ((clazz = clazz.getSuperclass()) != TileEntityWithData.class) { superClassCount++;//from ww w. ja v a 2 s. co m } out.writeInt(superClassCount); clazz = this.getClass(); int iteration = 0; do { writePacketFromClass(out, clazz, iteration); iteration++; } while ((clazz = clazz.getSuperclass()) != TileEntityWithData.class); return out.toByteArray(); }