下面列出了com.google.common.io.ByteArrayDataOutput#writeUTF ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public void onPluginMessageReceived(String channel, Player player, byte[] bytes){
if (!channel.equalsIgnoreCase(Shared.CHANNEL_NAME)) return;
ByteArrayDataInput in = ByteStreams.newDataInput(bytes);
String subChannel = in.readUTF();
if (subChannel.equalsIgnoreCase("Placeholder")){
String placeholder = in.readUTF();
long start = System.nanoTime();
String output = PluginHooks.PlaceholderAPI_setPlaceholders(player, placeholder);
long time = System.nanoTime() - start;
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("Placeholder");
out.writeUTF(placeholder);
out.writeUTF(output);
out.writeLong(time);
player.sendPluginMessage(plugin, Shared.CHANNEL_NAME, out.toByteArray());
}
}
@Override
public void execute(CommandSender commandSender, String[] strings) {
ServerInfo serverInfo = this.getLobby();
if (serverInfo != null && commandSender instanceof ProxiedPlayer) {
ProxiedPlayer player = (ProxiedPlayer) commandSender;
if (!player.getServer().getInfo().getName().equals(serverInfo.getName())) {
player.connect(getLobby());
} else {
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("HubBasics");
out.writeUTF("Lobby");
player.sendData("BungeeCord", out.toByteArray());
}
} else if (serverInfo == null) {
commandSender.sendMessage(new TextComponent(Messages.get(commandSender, "LOBBY_NOT_DEFINED")));
} else {
commandSender.sendMessage(new TextComponent(Messages.get(commandSender, "COMMAND_PLAYER")));
}
}
@EventHandler
public void handleInventoryClick(InventoryClickEvent e) {
if (!(e.getWhoClicked() instanceof Player)) {
return;
}
if (inventories().contains(e.getInventory()) && e.getCurrentItem() != null && e.getSlot() == e.getRawSlot()) {
e.setCancelled(true);
if (ItemStackBuilder.getMaterialIgnoreVersion(mobConfig.getItemLayout().getItemName(),
mobConfig.getItemLayout().getItemId()) == e.getCurrentItem().getType()) {
MobImpl mob = find(e.getInventory());
if (mob.getServerPosition().containsKey(e.getSlot())) {
if (CloudAPI.getInstance().getServerId().equalsIgnoreCase(mob.getServerPosition().get(e.getSlot()))) {
return;
}
ByteArrayDataOutput byteArrayDataOutput = ByteStreams.newDataOutput();
byteArrayDataOutput.writeUTF("Connect");
byteArrayDataOutput.writeUTF(mob.getServerPosition().get(e.getSlot()));
((Player) e.getWhoClicked()).sendPluginMessage(CloudServer.getInstance().getPlugin(),
"BungeeCord",
byteArrayDataOutput.toByteArray());
}
}
}
}
public void sendSWRMessage(Player player, String server, ArrayList<String> messages) {
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("Forward");
out.writeUTF(server);
out.writeUTF("SWRMessaging");
ByteArrayOutputStream msgbytes = new ByteArrayOutputStream();
DataOutputStream msgout = new DataOutputStream(msgbytes);
try {
for (String msg: messages) {
msgout.writeUTF(msg);
}
} catch (IOException e) {
e.printStackTrace();
}
out.writeShort(msgbytes.toByteArray().length);
out.write(msgbytes.toByteArray());
player.sendPluginMessage(this, "BungeeCord", out.toByteArray());
}
private static void internalMove(Player player) {
String server = Main.getConfigurator().config.getString("bungee.server");
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("Connect");
out.writeUTF(server);
player.sendPluginMessage(Main.getInstance(), "BungeeCord", out.toByteArray());
}
@Override
public void sendOutgoingMessage(@NonNull OutgoingMessage outgoingMessage) {
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF(outgoingMessage.asEncodedString());
byte[] message = out.toByteArray();
dispatchMessage(message);
}
@Override
public void writeTo(ByteArrayDataOutput out) {
out.writeBoolean(allowed);
out.writeInt(skin.getRowId());
out.writeUTF(skin.getEncodedValue());
out.writeUTF(skin.getSignature());
out.writeUTF(receiverUUID.toString());
}
@Override
public void writeTo(ByteArrayDataOutput out) {
out.writeUTF(commandName);
out.writeUTF(args);
out.writeBoolean(isSource);
out.writeBoolean(isOP);
}
private void serializeMultimap(Multimap<String, String> collection, boolean includeNames, ByteArrayDataOutput output) {
output.writeInt(collection.keySet().size());
for (Map.Entry<String, Collection<String>> entry : collection.asMap().entrySet()) {
output.writeUTF(entry.getKey());
if (includeNames) {
serializeCollection(entry.getValue(), output);
} else {
output.writeInt(entry.getValue().size());
}
}
}
@Override
public void appendPayload(ByteArrayDataOutput out) {
out.writeUTF(this.playerName);
out.writeUTF(this.channelName);
out.writeShort(this.data.length);
out.write(this.data);
}
static void writeConstantPool(ConstantPool constantPool, ByteArrayDataOutput output) {
output.writeShort(constantPool.nextEntry);
for (ConstantPool.Entry e : constantPool.constants()) {
output.writeByte(e.kind().tag());
Value value = e.value();
switch (e.kind()) {
case CLASS_INFO:
case STRING:
case MODULE:
case PACKAGE:
output.writeShort(((IntValue) value).value());
break;
case INTEGER:
output.writeInt(((IntValue) value).value());
break;
case DOUBLE:
output.writeDouble(((DoubleValue) value).value());
break;
case FLOAT:
output.writeFloat(((FloatValue) value).value());
break;
case LONG:
output.writeLong(((LongValue) value).value());
break;
case UTF8:
output.writeUTF(((StringValue) value).value());
break;
}
}
}
private void serializeMultiset(Multiset<String> collection, ByteArrayDataOutput output) {
output.writeInt(collection.elementSet().size());
for (Multiset.Entry<String> entry : collection.entrySet()) {
output.writeUTF(entry.getElement());
output.writeInt(entry.getCount());
}
}
public void teleport(Player player) {
if (this.server != null) {
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("Connect");
out.writeUTF(this.server);
player.sendPluginMessage(HubBasics.getInstance(), "BungeeCord", out.toByteArray());
} else {
player.teleport(this.toBukkitLocation());
}
}
public void sendBungeeMsg(Player player, String subchannel, String message) {
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF(subchannel);
if (!message.equalsIgnoreCase("none")) {
out.writeUTF(message);
}
player.sendPluginMessage(this, "BungeeCord", out.toByteArray());
}
private void sendForwardedBungeecordMessage(final String subChannel, final String... data) {
final ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("Forward");
out.writeUTF("ONLINE");
out.writeUTF(subChannel);
final ByteArrayDataOutput dataOut = ByteStreams.newDataOutput();
for (final String element : data) {
dataOut.writeUTF(element);
}
final byte[] dataBytes = dataOut.toByteArray();
out.writeShort(dataBytes.length);
out.write(dataBytes);
bukkitService.sendBungeeMessage(out.toByteArray());
}
@Override
public void write(ByteArrayDataOutput out)
{
out.writeInt(world.provider.dimensionId);
out.writeInt(x);
out.writeInt(y);
out.writeInt(z);
out.writeUTF(playername);
out.writeInt(action);
}
@Override
public void appendPayload(ByteArrayDataOutput out) {
out.writeUTF(this.serverName);
}
@Override
public void appendPayload(ByteArrayDataOutput out) {
out.writeUTF(this.serverName);
}
@Override
public void appendPayload(ByteArrayDataOutput out) {
out.writeUTF(this.playerName);
out.writeUTF(this.message);
}
@Override
public void writeTo(ByteArrayDataOutput out) {
out.writeUTF(playerName);
}