Java Code Examples for com.google.common.io.ByteArrayDataInput#readUTF()

The following examples show how to use com.google.common.io.ByteArrayDataInput#readUTF() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BungeeCordVariables.java    From ScoreboardStats with MIT License 6 votes vote down vote up
@Override
public void onPluginMessageReceived(String channel, Player player, byte[] message) {
    if (!channel.equals(BUNGEE_CHANNEL)) {
        return;
    }

    ByteArrayDataInput in = ByteStreams.newDataInput(message);
    String subChannel = in.readUTF();
    if ("PlayerCount".equals(subChannel)) {
        try {
            String server = in.readUTF();
            int count = in.readInt();

            if ("ALL".equals(server)) {
                onlinePlayers = count;
            }
        } catch (Exception eofException) {
            //happens if bungeecord doesn't know the server
            //ignore the admin should be notified by seeing the -1
        }
    }
}
 
Example 2
Source File: PluginMessageListener.java    From ResourcepacksPlugins with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void pluginMessageReceived(PluginMessageEvent event) {
    if(!plugin.isEnabled() || !event.getTag().equals("rp:plugin") || !(event.getSender() instanceof Server))
        return;

    ByteArrayDataInput in = ByteStreams.newDataInput(event.getData());
    String subchannel = in.readUTF();
    if("authMeLogin".equals(subchannel)) {
        String playerName = in.readUTF();
        UUID playerId = UUID.fromString(in.readUTF());

        plugin.setAuthenticated(playerId, true);
        if(!plugin.hasBackend(playerId) && plugin.getConfig().getBoolean("useauth", false)) {
            ProxiedPlayer player = plugin.getProxy().getPlayer(playerId);
            if(player != null) {
                String serverName = "";
                if(player.getServer() != null) {
                    serverName = player.getServer().getInfo().getName();
                }
                plugin.getPackManager().applyPack(playerId, serverName);
            }
        }
    }
}
 
Example 3
Source File: ConstantPoolReader.java    From turbine with Apache License 2.0 6 votes vote down vote up
/**
 * Reads a constant value at the given index, which must be one of CONSTANT_String_info,
 * CONSTANT_Integer_info, CONSTANT_Float_info, CONSTANT_Long_info, or CONSTANT_Double_info.
 */
Const.Value constant(int index) {
  ByteArrayDataInput reader = byteReader.seek(constantPool[index - 1]);
  byte tag = reader.readByte();
  switch (tag) {
    case CONSTANT_LONG:
      return new Const.LongValue(reader.readLong());
    case CONSTANT_FLOAT:
      return new Const.FloatValue(reader.readFloat());
    case CONSTANT_DOUBLE:
      return new Const.DoubleValue(reader.readDouble());
    case CONSTANT_INTEGER:
      return new Const.IntValue(reader.readInt());
    case CONSTANT_STRING:
      return new Const.StringValue(utf8(reader.readUnsignedShort()));
    case CONSTANT_UTF8:
      return new Const.StringValue(reader.readUTF());
    default:
      throw new AssertionError(String.format("bad tag: %x", tag));
  }
}
 
Example 4
Source File: PluginMessageMessenger.java    From LuckPerms with MIT License 6 votes vote down vote up
@EventHandler
public void onPluginMessage(PluginMessageEvent e) {
    if (!e.getTag().equals(CHANNEL)) {
        return;
    }

    e.setCancelled(true);

    if (e.getSender() instanceof ProxiedPlayer) {
        return;
    }

    byte[] data = e.getData();

    ByteArrayDataInput in = ByteStreams.newDataInput(data);
    String msg = in.readUTF();

    if (this.consumer.consumeIncomingMessageAsString(msg)) {
        // Forward to other servers
        this.plugin.getBootstrap().getScheduler().executeAsync(() -> dispatchMessage(data));
    }
}
 
Example 5
Source File: BungeeListener.java    From HubBasics with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void onPluginMessageReceived(String channel, @NotNull Player player, @NotNull byte[] message) {
    if (!channel.equals("BungeeCord")) {
        return;
    }
    ByteArrayDataInput in = ByteStreams.newDataInput(message);
    String subChannel = in.readUTF();
    if (subChannel.equals("HubBasics")) {
        String action = in.readUTF();
        if (action.equalsIgnoreCase("Lobby")) {
            LobbyModule module = (LobbyModule) HubBasics.getInstance()
                    .getModuleManager().getModule(EnumModules.Lobby);
            HLocation location = module.getLocation();
            if (location != null) {
                location.teleport(player);
            }
        }
    }
}
 
Example 6
Source File: PartiesPacket.java    From Parties with GNU Affero General Public License v3.0 6 votes vote down vote up
public static PartiesPacket read(ADPPlugin plugin, byte[] bytes) {
	PartiesPacket ret = null;
	try {
		ByteArrayDataInput input = ByteStreams.newDataInput(bytes);
		String foundVersion = input.readUTF();
		
		if (foundVersion.equals(plugin.getVersion())) {
			PartiesPacket packet = new PartiesPacket(foundVersion);
			packet.type = PacketType.valueOf(input.readUTF());
			packet.partyName = input.readUTF();
			packet.playerUuid = UUID.fromString(input.readUTF());
			packet.payload = input.readUTF();
			ret = packet;
		} else {
			plugin.getLoggerManager().printError(Constants.DEBUG_LOG_MESSAGING_FAILED_VERSION
					.replace("{current}", plugin.getVersion())
					.replace("{version}", foundVersion));
		}
	} catch (Exception ex) {
		plugin.getLoggerManager().printError(Constants.DEBUG_LOG_MESSAGING_FAILED_READ
				.replace("{message}", ex.getMessage()));
	}
	return ret;
}
 
Example 7
Source File: ForwardMessage.java    From ChangeSkin with MIT License 5 votes vote down vote up
@Override
public void readFrom(ByteArrayDataInput in) {
    commandName = in.readUTF();
    args = in.readUTF();

    isSource = in.readBoolean();
    isOP = in.readBoolean();
}
 
Example 8
Source File: PacketSolderingStation.java    From ExtraCells1 with MIT License 5 votes vote down vote up
@Override
public void read(ByteArrayDataInput in) throws ProtocolException
{
	playerName = in.readUTF();
	x = in.readInt();
	y = in.readInt();
	z = in.readInt();
	deltaSize = in.readInt();
	deltaTypes = in.readInt();
	slotID = in.readInt();
}
 
Example 9
Source File: PluginMessageMessenger.java    From LuckPerms with MIT License 5 votes vote down vote up
@Override
public void onPluginMessageReceived(String s, @NonNull Player player, @NonNull byte[] bytes) {
    if (!s.equals(CHANNEL)) {
        return;
    }

    ByteArrayDataInput in = ByteStreams.newDataInput(bytes);
    String msg = in.readUTF();

    this.consumer.consumeIncomingMessageAsString(msg);
}
 
Example 10
Source File: NickNamerPlugin.java    From NickNamer with MIT License 5 votes vote down vote up
@Override
public void onPluginMessageReceived(String s, Player player, byte[] bytes) {
	if (!bungeecord) { return; }
	if (channelIdentifier.equals(s)) {
		ByteArrayDataInput in = ByteStreams.newDataInput(bytes);
		String sub = in.readUTF();
		UUID who = UUID.fromString(in.readUTF());
		if ("name".equals(sub)) {
			String name = in.readUTF();

			if (name == null || "reset".equals(name)) {
				getAPI().removeNick(who);
			} else {
				getAPI().setNick(who, name);
			}
		} else if ("skin".equals(sub)) {
			String skin = in.readUTF();

			if (skin == null || "reset".equals(skin)) {
				getAPI().removeSkin(who);
			} else {
				getAPI().setSkin(who, skin);
			}
		} else if ("data".equals(sub)) {
			try {
				String owner = in.readUTF();
				JsonObject data = new JsonParser().parse(in.readUTF()).getAsJsonObject();
				SkinLoaderBridge.getSkinProvider().put(owner, new GameProfileWrapper(data).toJson());
			} catch (JsonParseException e) {
				e.printStackTrace();
			}
		} else {
			getLogger().warning("Unknown incoming plugin message: " + sub);
		}
	}
}
 
Example 11
Source File: SkyWarsReloaded.java    From SkyWarsReloaded with GNU General Public License v3.0 5 votes vote down vote up
public void onPluginMessageReceived(String channel, Player player, byte[] message) {
	if (!channel.equals("BungeeCord")) {
		return;
    }
    ByteArrayDataInput in = ByteStreams.newDataInput(message);
    String subchannel = in.readUTF();
   
    if (subchannel.equals("GetServer")) {
    	servername = in.readUTF();
    }
    
    if (subchannel.equals("SWRMessaging")) {
    	short len = in.readShort();
    	byte[] msgbytes = new byte[len];
    	in.readFully(msgbytes);

    	DataInputStream msgin = new DataInputStream(new ByteArrayInputStream(msgbytes));
    	try {
			String header = msgin.readUTF();
			if (header.equalsIgnoreCase("RequestUpdate")) {
				String sendToServer = msgin.readUTF();
				String playerCount = "" + GameMap.getMaps().get(0).getAlivePlayers().size();
				String maxPlayers = "" + GameMap.getMaps().get(0).getMaxPlayers();
				String gameStarted = "" + GameMap.getMaps().get(0).getMatchState().toString();
				ArrayList<String> messages = new ArrayList<>();
				messages.add("ServerUpdate");
				messages.add(servername);
				messages.add(playerCount);
				messages.add(maxPlayers);
				messages.add(gameStarted);
				sendSWRMessage(player, sendToServer, messages);					
			}
		} catch (IOException e) {
			e.printStackTrace();
		} 
    }
}
 
Example 12
Source File: PermResultMessage.java    From ChangeSkin with MIT License 5 votes vote down vote up
@Override
public void readFrom(ByteArrayDataInput in) {
    allowed = in.readBoolean();

    int rowId = in.readInt();
    String encodedValue = in.readUTF();
    String encodedSignature = in.readUTF();

    skin = SkinModel.createSkinFromEncoded(encodedValue, encodedSignature);
    skin.setRowId(rowId);

    receiverUUID = UUID.fromString(in.readUTF());
}
 
Example 13
Source File: CheckPermMessage.java    From ChangeSkin with MIT License 5 votes vote down vote up
@Override
public void readFrom(ByteArrayDataInput in) {
    int rowId = in.readInt();
    String encodedData = in.readUTF();
    String encodedSignature = in.readUTF();

    targetSkin = SkinModel.createSkinFromEncoded(encodedData, encodedSignature);
    targetSkin.setRowId(rowId);

    //continue on success only
    receiverUUD = UUID.fromString(in.readUTF());
    skinPerm = in.readBoolean();
    isOp = in.readBoolean();
}
 
Example 14
Source File: BungeeCordImpl.java    From helper with MIT License 5 votes vote down vote up
@Override
public boolean acceptResponse(Player receiver, ByteArrayDataInput in) {
    String ip = in.readUTF();
    int port = in.readInt();
    this.callback.supply(Maps.immutableEntry(ip, port));
    return true;
}
 
Example 15
Source File: PacketMEBattery.java    From ExtraCells1 with MIT License 5 votes vote down vote up
@Override
public void read(ByteArrayDataInput in) throws ProtocolException
{
	world = DimensionManager.getWorld(in.readInt());
	x = in.readInt();
	y = in.readInt();
	z = in.readInt();
	playername = in.readUTF();
}
 
Example 16
Source File: PluginMessenger.java    From TAB with Apache License 2.0 5 votes vote down vote up
@Subscribe
public void on(PluginMessageEvent event){
	if (!event.getIdentifier().getId().equalsIgnoreCase(Shared.CHANNEL_NAME)) return;
	ByteArrayDataInput in = ByteStreams.newDataInput(event.getData());
	String subChannel = in.readUTF();
	if (event.getTarget() instanceof Player && subChannel.equalsIgnoreCase("Placeholder")){
		event.setResult(ForwardResult.handled());
		ITabPlayer receiver = Shared.getPlayer(((Player) event.getTarget()).getUniqueId());
		if (receiver == null) return;
		String placeholder = in.readUTF();
		String output = in.readUTF();
		long cpu = in.readLong();
		PlayerPlaceholder pl = (PlayerPlaceholder) Placeholders.getPlaceholder(placeholder); //all bridge placeholders are marked as player
		if (pl != null) {
			pl.lastValue.put(receiver.getName(), output);
			pl.lastValue.put("null", output);
			Set<Refreshable> update = PlaceholderManager.getPlaceholderUsage(pl.getIdentifier());
			Shared.featureCpu.runTask("refreshing", new Runnable() {

				@Override
				public void run() {
					for (Refreshable r : update) {
						long startTime = System.nanoTime();
						r.refresh(receiver, false);
						Shared.featureCpu.addTime(r.getRefreshCPU(), System.nanoTime()-startTime);
					}
				}
			});
			Shared.bukkitBridgePlaceholderCpu.addTime(pl.getIdentifier(), cpu);
		} else {
			Shared.debug("Received output for unknown placeholder " + placeholder);
		}
	}
}
 
Example 17
Source File: PacketBusFluidExport.java    From ExtraCells1 with MIT License 5 votes vote down vote up
@Override
public void read(ByteArrayDataInput in) throws ProtocolException
{
	world = DimensionManager.getWorld(in.readInt());
	x = in.readInt();
	y = in.readInt();
	z = in.readInt();
	playername = in.readUTF();
	action = in.readInt();
}
 
Example 18
Source File: ChangePremiumMessage.java    From FastLogin with MIT License 4 votes vote down vote up
@Override
public void readFrom(ByteArrayDataInput input) {
    willEnable = input.readBoolean();
    playerName = input.readUTF();
    isSourceInvoker = input.readBoolean();
}
 
Example 19
Source File: BungeeCordImpl.java    From helper with MIT License 4 votes vote down vote up
@Override
public boolean acceptResponse(Player receiver, ByteArrayDataInput in) {
    String uuid = in.readUTF();
    this.callback.supply(UUID.fromString(uuid));
    return true;
}
 
Example 20
Source File: SkinUpdateMessage.java    From ChangeSkin with MIT License 4 votes vote down vote up
@Override
public void readFrom(ByteArrayDataInput in) {
    playerName = in.readUTF();
}