Java Code Examples for protocolsupport.utils.Utils

The following examples show how to use protocolsupport.utils.Utils. These examples are extracted from open source projects. 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
private void initialize(final ChannelHandlerContext ctx) {
	this.lastReadTime = System.nanoTime();
	this.timeoutTask = ctx.executor().schedule(new Runnable() {
		@Override
		public void run() {
			if (ctx.channel().isOpen()) {
				long untilTimeout = timeoutTime - (Utils.currentTimeMillisFromNanoTime() - lastReadTime);
				if (untilTimeout <= 0) {
					ctx.fireExceptionCaught(ReadTimeoutException.INSTANCE);
				} else {
					ctx.executor().schedule(this, untilTimeout, TimeUnit.MILLISECONDS);
				}
			}
		}
	}, this.timeoutTime, TimeUnit.MILLISECONDS);
}
 
Example 2
@Override
protected void writeToClient() {
	ClientBoundPacketData scoreboardteam = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_SCOREBOARD_TEAM);
	StringSerializer.writeString(scoreboardteam, version, name);
	MiscSerializer.writeByteEnum(scoreboardteam, mode);
	if ((mode == Mode.CREATE) || (mode == Mode.UPDATE)) {
		StringSerializer.writeString(scoreboardteam, version, LegacyChat.clampLegacyText(displayName.toLegacyText(clientCache.getLocale()), 32));
		Any<String, String> nfix = formatPrefixSuffix();
		StringSerializer.writeString(scoreboardteam, version, nfix.getObj1());
		StringSerializer.writeString(scoreboardteam, version, nfix.getObj2());
		scoreboardteam.writeByte(friendlyFire);
	}
	if ((mode == Mode.CREATE) || (mode == Mode.PLAYERS_ADD) || (mode == Mode.PLAYERS_REMOVE)) {
		ArraySerializer.writeShortTArray(scoreboardteam, players, (to, element) -> StringSerializer.writeString(to, version, Utils.clampString(element, 16)));
	}
	codec.write(scoreboardteam);
}
 
Example 3
@Override
protected void writeToClient() {
	ClientBoundPacketData scoreboardteam = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_SCOREBOARD_TEAM);
	StringSerializer.writeVarIntUTF8String(scoreboardteam, name);
	MiscSerializer.writeByteEnum(scoreboardteam, mode);
	if ((mode == Mode.CREATE) || (mode == Mode.UPDATE)) {
		StringSerializer.writeVarIntUTF8String(scoreboardteam, LegacyChat.clampLegacyText(displayName.toLegacyText(clientCache.getLocale()), 32));
		Any<String, String> nfix = formatPrefixSuffix();
		StringSerializer.writeVarIntUTF8String(scoreboardteam, nfix.getObj1());
		StringSerializer.writeVarIntUTF8String(scoreboardteam, nfix.getObj2());
		scoreboardteam.writeByte(friendlyFire);
		StringSerializer.writeVarIntUTF8String(scoreboardteam, nameTagVisibility);
		scoreboardteam.writeByte(format.isColor() ? format.ordinal() : -1);
	}
	if ((mode == Mode.CREATE) || (mode == Mode.PLAYERS_ADD) || (mode == Mode.PLAYERS_REMOVE)) {
		ArraySerializer.writeVarIntTArray(scoreboardteam, players, (to, element) -> StringSerializer.writeVarIntUTF8String(to, Utils.clampString(element, 16)));
	}
	codec.write(scoreboardteam);
}
 
Example 4
public static ClientBoundPacketData create(
	ProtocolVersion version,
	int x, int y, int z,
	String sound, float volume, float pitch
) {
	ClientBoundPacketData worldcustomsound = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_WORLD_CUSTOM_SOUND);
	sound = SoundRemapper.getSoundName(version, sound);
	if (version.isBeforeOrEq(ProtocolVersion.MINECRAFT_1_5_2)) {
		sound = Utils.clampString(sound, 32);
	}
	StringSerializer.writeString(worldcustomsound, version, sound);
	worldcustomsound.writeInt(x);
	worldcustomsound.writeInt(y);
	worldcustomsound.writeInt(z);
	worldcustomsound.writeFloat(volume);
	worldcustomsound.writeByte((int) (pitch * 63.5));
	return worldcustomsound;
}
 
Example 5
public ChatColor asBasic() {
	if (isBasic()) {
		return this;
	}

	ChatColor similarColor = null;
	long similarColorDiff = Long.MAX_VALUE;
	for (ChatColor basic : BASIC_BY_BUKKIT.values()) {
		long colorDiff = Utils.getColorDiff(getRed(), basic.getRed(), getGreen(), basic.getGreen(), getBlue(), basic.getBlue());
		if (colorDiff <= similarColorDiff) {
			similarColorDiff = colorDiff;
			similarColor = basic;
		}
	}
	return similarColor;
}
 
Example 6
public static boolean throttle(InetAddress address) {
	synchronized (tracker) {
		long ctime = Utils.currentTimeMillisFromNanoTime();
		LongIterator iterator = tracker.values().iterator();
		while (iterator.hasNext()) {
			if (iterator.nextLong() < ctime) {
				iterator.remove();
			}
		}
		long ret = tracker.put(address, ctime + time);
		return ret != tracker.defaultReturnValue();
	}
}
 
Example 7
@Override
protected void writeToClient() {
	ClientBoundPacketData scoreboardscore = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_SCOREBOARD_SCORE);
	StringSerializer.writeString(scoreboardscore, version, Utils.clampString(name, 16));
	scoreboardscore.writeByte(mode);
	if (mode != 1) {
		StringSerializer.writeString(scoreboardscore, version, objectiveName);
		scoreboardscore.writeInt(value);
	}
	codec.write(scoreboardscore);
}
 
Example 8
@Override
protected void writeToClient() {
	for (int[] part : Utils.splitArray(entityIds, 120)) {
		ClientBoundPacketData entitydestroy = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_ENTITY_DESTROY);
		entitydestroy.writeByte(part.length);
		for (int i = 0; i < part.length; i++) {
			entitydestroy.writeInt(part[i]);
		}
		codec.write(entitydestroy);
	}
}
 
Example 9
@Override
protected void writeToClient() {
	String prefix = start <= 1 ? "/" : "";
	ClientBoundPacketData tabcomplete = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_TAB_COMPLETE);
	StringSerializer.writeShortUTF16BEString(tabcomplete, Utils.clampString(String.join("\u0000", Arrays.stream(matches).map(input -> prefix + input.getMatch()).collect(Collectors.toList())), Short.MAX_VALUE));
	codec.write(tabcomplete);
}
 
Example 10
@Override
protected void writeToClient() {
	ClientBoundPacketData spawnnamed = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_SPAWN_NAMED);
	spawnnamed.writeInt(entity.getId());
	PlayerListEntry entry = playerlistCache.getEntry(entity.getUUID());
	StringSerializer.writeShortUTF16BEString(spawnnamed, entry != null ? Utils.clampString(entry.getUserName(), 16) : "UNKNOWN");
	spawnnamed.writeInt((int) (x * 32));
	spawnnamed.writeInt((int) (y * 32));
	spawnnamed.writeInt((int) (z * 32));
	spawnnamed.writeByte(yaw);
	spawnnamed.writeByte(pitch);
	spawnnamed.writeShort(0);
	NetworkEntityMetadataSerializer.writeLegacyData(spawnnamed, version, I18NData.DEFAULT_LOCALE, NetworkEntityMetadataList.EMPTY);
	codec.write(spawnnamed);
}
 
Example 11
@Override
protected void writeToClient() {
	ClientBoundPacketData spawnnamed = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_SPAWN_NAMED);
	VarNumberSerializer.writeVarInt(spawnnamed, entity.getId());
	UUID uuid = entity.getUUID();
	StringSerializer.writeVarIntUTF8String(spawnnamed, version == ProtocolVersion.MINECRAFT_1_7_10 ? uuid.toString() : uuid.toString().replace("-", ""));
	PlayerListEntry entry = playerlistCache.getEntry(uuid);
	if (entry != null) {
		StringSerializer.writeVarIntUTF8String(spawnnamed, Utils.clampString(entry.getUserName(), 16));
		if (version == ProtocolVersion.MINECRAFT_1_7_10) {
			ArraySerializer.writeVarIntTArray(spawnnamed, entry.getProperties(true), (to, property) -> {
				StringSerializer.writeVarIntUTF8String(to, property.getName());
				StringSerializer.writeVarIntUTF8String(to, property.getValue());
				StringSerializer.writeVarIntUTF8String(to, property.getSignature());
			});
		}
	} else {
		StringSerializer.writeVarIntUTF8String(spawnnamed, "UNKNOWN");
		if (version == ProtocolVersion.MINECRAFT_1_7_10) {
			VarNumberSerializer.writeVarInt(spawnnamed, 0);
		}
	}
	spawnnamed.writeInt((int) (x * 32));
	spawnnamed.writeInt((int) (y * 32));
	spawnnamed.writeInt((int) (z * 32));
	spawnnamed.writeByte(yaw);
	spawnnamed.writeByte(pitch);
	spawnnamed.writeShort(0);
	NetworkEntityMetadataSerializer.writeLegacyData(spawnnamed, version, I18NData.DEFAULT_LOCALE, NetworkEntityMetadataList.EMPTY);
	codec.write(spawnnamed);
}
 
Example 12
public static RelMove[] getRelMoves(RelMove relMove, int limit) {
	int maxVal = Math.abs(relMove.getX());
	maxVal = Math.max(Math.abs(relMove.getY()), maxVal);
	maxVal = Math.max(Math.abs(relMove.getZ()), maxVal);
	RelMove[] moves = new RelMove[Utils.getSplitCount(maxVal, limit)];
	for (int i = 0; i < moves.length; i++) {
		moves[i] = new RelMove(relMove.decreaseX(limit), relMove.decreaseY(limit), relMove.decreaseZ(limit));
	}
	return moves;
}
 
Example 13
@Override
public String toString() {
	return Utils.toStringAllFields(this);
}
 
Example 14
public static String readShortUTF16BEString(ByteBuf buf) {
	return new String(Utils.readBytes(buf, buf.readUnsignedShort() * 2), StandardCharsets.UTF_16BE);
}
 
Example 15
public static byte[] readShortLengthByteArray(ByteBuf to) {
	return Utils.readBytes(to, to.readShort());
}
 
Example 16
@Override
public String toString() {
	return Utils.toStringAllFields(this);
}
 
Example 17
@Override
public String toString() {
	return Utils.toStringAllFields(this);
}
 
Example 18
public void setLastRead() {
	this.lastReadTime = Utils.currentTimeMillisFromNanoTime();
}
 
Example 19
public NumberBitsStorageCompact(int bitsPerNumber, int size) {
	this.bitsPerNumber = bitsPerNumber;
	this.singleNumberMask = (1L << bitsPerNumber) - 1L;
	this.storage = new long[Utils.ceilToBase(size * bitsPerNumber, Long.SIZE) / Long.SIZE];
}
 
Example 20
@Override
public String toString() {
	return Utils.toStringAllFields(this);
}
 
Example 21
Source Project: ProtocolSupport   Source File: NBT.java    License: GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public String toString() {
	return Utils.toStringAllFields(this);
}
 
Example 22
@Override
public String toString() {
	return Utils.toStringAllFields(this);
}
 
Example 23
@Override
public String toString() {
	return Utils.toStringAllFields(this);
}
 
Example 24
@Override
public String toString() {
	return Utils.toStringAllFields(this);
}
 
Example 25
@Override
public String toString() {
	return Utils.toStringAllFields(this);
}
 
Example 26
@Override
public String toString() {
	return Utils.toStringAllFields(this);
}
 
Example 27
@Override
public String toString() {
	return Utils.toStringAllFields(this);
}
 
Example 28
@Override
public String toString() {
	return Utils.toStringAllFields(this);
}
 
Example 29
@Override
public String toString() {
	return Utils.toStringAllFields(this);
}
 
Example 30
@Override
public String toString() {
	return Utils.toStringAllFields(this);
}