本文整理汇总了Java中cn.nukkit.utils.Binary类的典型用法代码示例。如果您正苦于以下问题:Java Binary类的具体用法?Java Binary怎么用?Java Binary使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Binary类属于cn.nukkit.utils包,在下文中一共展示了Binary类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: encode
import cn.nukkit.utils.Binary; //导入依赖的package包/类
@Override
public void encode() {
this.reset();
this.putEntityUniqueId(this.entityUniqueId);
this.putEntityRuntimeId(this.entityRuntimeId);
this.putUnsignedVarInt(this.type);
this.putVector3f(this.x, this.y, this.z);
this.putVector3f(this.speedX, this.speedY, this.speedZ);
this.putLFloat(this.pitch);
this.putLFloat(this.yaw);
this.putAttributeList(this.attributes);
this.put(Binary.writeMetadata(this.metadata));
this.putUnsignedVarInt(this.links.length);
for (Object[] link : this.links) {
this.putVarLong((long) link[0]);
this.putVarLong((long) link[1]);
this.putByte((byte) link[2]);
}
}
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:20,代码来源:AddEntityPacket.java
示例2: toFastBinary
import cn.nukkit.utils.Binary; //导入依赖的package包/类
@Override
public byte[] toFastBinary() {
BinaryStream stream = new BinaryStream(new byte[65536]);
stream.put(Binary.writeInt(this.x));
stream.put(Binary.writeInt(this.z));
stream.put(this.getBlockIdArray());
stream.put(this.getBlockDataArray());
stream.put(this.getBlockSkyLightArray());
stream.put(this.getBlockLightArray());
for (int height : this.getHeightMapArray()) {
stream.putByte((byte) height);
}
for (int color : this.getBiomeColorArray()) {
stream.put(Binary.writeInt(color));
}
stream.putByte((byte) ((this.isLightPopulated() ? 1 << 2 : 0) + (this.isPopulated() ? 1 << 2 : 0) + (this.isGenerated() ? 1 : 0)));
return stream.getBuffer();
}
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:19,代码来源:Chunk.java
示例3: ChunkRequestTask
import cn.nukkit.utils.Binary; //导入依赖的package包/类
public ChunkRequestTask(Level level, Chunk chunk) {
this.levelId = level.getId();
this.chunk = chunk.toFastBinary();
this.chunkX = chunk.getX();
this.chunkZ = chunk.getZ();
byte[] buffer = new byte[0];
for (BlockEntity blockEntity : chunk.getBlockEntities().values()) {
if (blockEntity instanceof BlockEntitySpawnable) {
try {
buffer = Binary.appendBytes(buffer, NBTIO.write(((BlockEntitySpawnable) blockEntity).getSpawnCompound(), ByteOrder.BIG_ENDIAN, true));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
this.blockEntities = buffer;
}
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:22,代码来源:ChunkRequestTask.java
示例4: getShortQuery
import cn.nukkit.utils.Binary; //导入依赖的package包/类
public byte[] getShortQuery() {
ByteBuffer query = ByteBuffer.allocate(65536);
query.put(this.serverName.getBytes(StandardCharsets.UTF_8));
query.put((byte) 0x00);
query.put(this.gameType.getBytes(StandardCharsets.UTF_8));
query.put((byte) 0x00);
query.put(this.map.getBytes(StandardCharsets.UTF_8));
query.put((byte) 0x00);
query.put(String.valueOf(this.numPlayers).getBytes(StandardCharsets.UTF_8));
query.put((byte) 0x00);
query.put(String.valueOf(this.maxPlayers).getBytes(StandardCharsets.UTF_8));
query.put((byte) 0x00);
query.put(Binary.writeLShort(this.port));
query.put(this.ip.getBytes(StandardCharsets.UTF_8));
query.put((byte) 0x00);
return Arrays.copyOf(query.array(), query.position());
}
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:18,代码来源:QueryRegenerateEvent.java
示例5: encode
import cn.nukkit.utils.Binary; //导入依赖的package包/类
@Override
public void encode() {
this.reset();
this.putEntityUniqueId(this.entityUniqueId);
this.putEntityRuntimeId(this.entityRuntimeId);
this.putUnsignedVarInt(this.type);
this.putVector3f(this.x, this.y, this.z);
this.putVector3f(this.speedX, this.speedY, this.speedZ);
this.putLFloat(this.pitch);
this.putLFloat(this.yaw);
this.putAttributeList(this.attributes);
this.put(Binary.writeMetadata(this.metadata));
this.putUnsignedVarInt(this.links.length);
for (Link link : this.links) {
this.putVarLong(link.from);
this.putVarLong(link.to);
this.putByte((byte) link.action);
this.putByte((byte) link.unknownByte);
}
}
开发者ID:JupiterDevelopmentTeam,项目名称:Jupiter,代码行数:21,代码来源:AddEntityPacket.java
示例6: encode
import cn.nukkit.utils.Binary; //导入依赖的package包/类
@Override
public void encode() {
this.reset();
this.putUUID(this.uuid);
this.putString(this.username);
this.putEntityUniqueId(this.entityUniqueId);
this.putEntityRuntimeId(this.entityRuntimeId);
this.putVector3f(this.x, this.y, this.z);
this.putVector3f(this.speedX, this.speedY, this.speedZ);
this.putLFloat(this.pitch);
this.putLFloat(this.yaw); //TODO headrot
this.putLFloat(this.yaw);
this.putSlot(this.item);
this.put(Binary.writeMetadata(this.metadata));
}
开发者ID:JupiterDevelopmentTeam,项目名称:Jupiter,代码行数:17,代码来源:AddPlayerPacket.java
示例7: encode
import cn.nukkit.utils.Binary; //导入依赖的package包/类
@Override
public void encode() {
this.reset();
this.putVarLong(this.entityUniqueId);
this.putVarLong(this.entityRuntimeId);
this.putUnsignedVarInt(this.type);
this.putVector3f(this.x, this.y, this.z);
this.putVector3f(this.speedX, this.speedY, this.speedZ);
this.putLFloat(this.pitch);
this.putLFloat(this.yaw);
this.putAttributeList(this.attributes);
this.put(Binary.writeMetadata(this.metadata));
this.putUnsignedVarInt(this.links.length);
for (Object[] link : this.links) {
this.putVarLong((long) link[0]);
this.putVarLong((long) link[1]);
this.putByte((byte) link[2]);
}
}
开发者ID:CoreXDevelopment,项目名称:CoreX,代码行数:20,代码来源:AddEntityPacket.java
示例8: readChunk
import cn.nukkit.utils.Binary; //导入依赖的package包/类
public Chunk readChunk(int chunkX, int chunkZ) {
byte[] data;
if (!this.chunkExists(chunkX, chunkZ) || (data = this.db.get(TerrainKey.create(chunkX, chunkZ).toArray())) == null) {
return null;
}
byte[] flags = this.db.get(FlagsKey.create(chunkX, chunkZ).toArray());
if (flags == null) {
flags = new byte[]{0x03};
}
return Chunk.fromBinary(
Binary.appendBytes(
Binary.writeLInt(chunkX),
Binary.writeLInt(chunkZ),
data,
flags)
, this);
}
开发者ID:JupiterDevelopmentTeam,项目名称:Jupiter,代码行数:20,代码来源:LevelDB.java
示例9: sendOption
import cn.nukkit.utils.Binary; //导入依赖的package包/类
public void sendOption(String name, String value) {
byte[] buffer = Binary.appendBytes(
RakNet.PACKET_SET_OPTION,
new byte[]{(byte) (name.length() & 0xff)},
name.getBytes(StandardCharsets.UTF_8),
value.getBytes(StandardCharsets.UTF_8)
);
this.server.pushMainToThreadPacket(buffer);
}
开发者ID:CoreXDevelopment,项目名称:CoreX,代码行数:10,代码来源:ServerHandler.java
示例10: decode
import cn.nukkit.utils.Binary; //导入依赖的package包/类
@Override
public void decode() {
this.selectedHotbarSlot = (int) this.getUnsignedVarInt();
this.windowId = this.getByte();
int count = (int) this.getUnsignedVarInt();
slots = new int[count];
for (int i = 0; i < count; ++i) {
this.slots[i] = Binary.signInt((int) this.getUnsignedVarInt());
}
this.selectHotbarSlot = this.getBoolean();
}
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:13,代码来源:PlayerHotbarPacket.java
示例11: blockAddress
import cn.nukkit.utils.Binary; //导入依赖的package包/类
public void blockAddress(String address, int timeout) {
byte[] buffer = Binary.appendBytes(
RakNet.PACKET_BLOCK_ADDRESS,
new byte[]{(byte) (address.length() & 0xff)},
address.getBytes(StandardCharsets.UTF_8),
Binary.writeInt(timeout)
);
this.server.pushMainToThreadPacket(buffer);
}
开发者ID:CoreXDevelopment,项目名称:CoreX,代码行数:10,代码来源:ServerHandler.java
示例12: streamClose
import cn.nukkit.utils.Binary; //导入依赖的package包/类
protected void streamClose(String identifier, String reason) {
byte[] buffer = Binary.appendBytes(
RakNet.PACKET_CLOSE_SESSION,
new byte[]{(byte) (identifier.length() & 0xff)},
identifier.getBytes(StandardCharsets.UTF_8),
new byte[]{(byte) (reason.length() & 0xff)},
reason.getBytes(StandardCharsets.UTF_8)
);
this.server.pushThreadToMainPacket(buffer);
}
开发者ID:CoreXDevelopment,项目名称:CoreX,代码行数:11,代码来源:SessionManager.java
示例13: decode
import cn.nukkit.utils.Binary; //导入依赖的package包/类
@Override
public void decode() {
super.decode();
this.seqNumber = this.getLTriad();
while (!this.feof()) {
byte[] data = Binary.subBytes(this.buffer, this.offset);
EncapsulatedPacket packet = EncapsulatedPacket.fromBinary(data, false);
this.offset += packet.getOffset();
if (packet.buffer.length == 0) {
break;
}
this.packets.add(packet);
}
}
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:16,代码来源:DataPacket.java
示例14: getTokenString
import cn.nukkit.utils.Binary; //导入依赖的package包/类
public static String getTokenString(String token, String salt) {
try {
return String.valueOf(Binary.readInt(Binary.subBytes(MessageDigest.getInstance("SHA-512").digest((salt + ":" + token).getBytes()), 7, 4)));
} catch (NoSuchAlgorithmException e) {
return String.valueOf(new Random().nextInt());
}
}
开发者ID:CoreXDevelopment,项目名称:CoreX,代码行数:8,代码来源:QueryHandler.java
示例15: invalidSession
import cn.nukkit.utils.Binary; //导入依赖的package包/类
protected void invalidSession(String identifier) {
byte[] buffer = Binary.appendBytes(
RakNet.PACKET_INVALID_SESSION,
new byte[]{(byte) (identifier.length() & 0xff)},
identifier.getBytes(StandardCharsets.UTF_8)
);
this.server.pushMainToThreadPacket(buffer);
}
开发者ID:CoreXDevelopment,项目名称:CoreX,代码行数:9,代码来源:ServerHandler.java
示例16: sendRaw
import cn.nukkit.utils.Binary; //导入依赖的package包/类
public void sendRaw(String address, int port, byte[] payload) {
byte[] buffer = Binary.appendBytes(
RakNet.PACKET_RAW,
new byte[]{(byte) (address.length() & 0xff)},
address.getBytes(StandardCharsets.UTF_8),
Binary.writeShort(port),
payload
);
this.server.pushMainToThreadPacket(buffer);
}
开发者ID:FrontierDevs,项目名称:Jenisys3,代码行数:11,代码来源:ServerHandler.java
示例17: streamEncapsulated
import cn.nukkit.utils.Binary; //导入依赖的package包/类
public void streamEncapsulated(Session session, EncapsulatedPacket packet, int flags) {
String id = session.getAddress() + ":" + session.getPort();
byte[] buffer = Binary.appendBytes(
RakNet.PACKET_ENCAPSULATED,
new byte[]{(byte) (id.length() & 0xff)},
id.getBytes(StandardCharsets.UTF_8),
new byte[]{(byte) (flags & 0xff)},
packet.toBinary(true)
);
this.server.pushThreadToMainPacket(buffer);
}
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:12,代码来源:SessionManager.java
示例18: streamRAW
import cn.nukkit.utils.Binary; //导入依赖的package包/类
public void streamRAW(String address, int port, byte[] payload) {
byte[] buffer = Binary.appendBytes(
RakNet.PACKET_RAW,
new byte[]{(byte) (address.length() & 0xff)},
address.getBytes(StandardCharsets.UTF_8),
Binary.writeShort(port),
payload
);
this.server.pushThreadToMainPacket(buffer);
}
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:11,代码来源:SessionManager.java
示例19: streamInvalid
import cn.nukkit.utils.Binary; //导入依赖的package包/类
protected void streamInvalid(String identifier) {
byte[] buffer = Binary.appendBytes(
RakNet.PACKET_INVALID_SESSION,
new byte[]{(byte) (identifier.length() & 0xff)},
identifier.getBytes(StandardCharsets.UTF_8)
);
this.server.pushThreadToMainPacket(buffer);
}
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:9,代码来源:SessionManager.java
示例20: streamOpen
import cn.nukkit.utils.Binary; //导入依赖的package包/类
protected void streamOpen(Session session) {
String identifier = session.getAddress() + ":" + session.getPort();
byte[] buffer = Binary.appendBytes(
RakNet.PACKET_OPEN_SESSION,
new byte[]{(byte) (identifier.length() & 0xff)},
identifier.getBytes(StandardCharsets.UTF_8),
new byte[]{(byte) (session.getAddress().length() & 0xff)},
session.getAddress().getBytes(StandardCharsets.UTF_8),
Binary.writeShort(session.getPort()),
Binary.writeLong(session.getID())
);
this.server.pushThreadToMainPacket(buffer);
}
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:14,代码来源:SessionManager.java
注:本文中的cn.nukkit.utils.Binary类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论