use of it.unimi.dsi.fastutil.objects.Object2LongMap in project LanternServer by LanternPowered.
the class CodecPlayOutAdvancements method encode.
@Override
public ByteBuffer encode(CodecContext context, MessagePlayOutAdvancements message) throws CodecException {
final ByteBuffer buf = context.byteBufAlloc().buffer();
buf.writeBoolean(message.getClear());
final List<MessagePlayOutAdvancements.AdvStruct> addedAdvStructs = message.getAddedAdvStructs();
buf.writeVarInt(addedAdvStructs.size());
for (MessagePlayOutAdvancements.AdvStruct struct : addedAdvStructs) {
buf.writeString(struct.getId());
final Optional<String> optParent = struct.getParentId();
buf.writeBoolean(optParent.isPresent());
optParent.ifPresent(buf::writeString);
final Optional<MessagePlayOutAdvancements.AdvStruct.Display> optDisplay = struct.getDisplay();
buf.writeBoolean(optDisplay.isPresent());
if (optDisplay.isPresent()) {
final MessagePlayOutAdvancements.AdvStruct.Display display = optDisplay.get();
buf.write(Types.LOCALIZED_TEXT, display.getTitle());
buf.write(Types.LOCALIZED_TEXT, display.getDescription());
buf.write(Types.ITEM_STACK, display.getIcon().createStack());
buf.writeVarInt(((LanternAdvancementType) display.getType()).getInternalId());
final Optional<String> optBackground = display.getBackground();
int flags = 0;
if (optBackground.isPresent()) {
flags |= 0x1;
}
if (display.doesShowToast()) {
flags |= 0x2;
}
if (display.isHidden()) {
flags |= 0x4;
}
buf.writeInteger(flags);
optBackground.ifPresent(buf::writeString);
buf.writeFloat((float) display.getX());
buf.writeFloat((float) display.getY());
}
final Collection<String> criteria = struct.getCriteria();
buf.writeVarInt(criteria.size());
criteria.forEach(buf::writeString);
final String[][] requirements = struct.getRequirements();
buf.writeVarInt(requirements.length);
for (String[] requirements1 : requirements) {
buf.writeVarInt(requirements1.length);
for (String requirement : requirements1) {
buf.writeString(requirement);
}
}
}
final List<String> removed = message.getRemovedAdvs();
buf.writeVarInt(removed.size());
removed.forEach(buf::writeString);
final Map<String, Object2LongMap<String>> progress = message.getProgress();
buf.writeVarInt(progress.size());
for (Map.Entry<String, Object2LongMap<String>> entry : progress.entrySet()) {
buf.writeString(entry.getKey());
buf.writeVarInt(entry.getValue().size());
for (Object2LongMap.Entry<String> entry1 : entry.getValue().object2LongEntrySet()) {
buf.writeString(entry1.getKey());
final long time = entry1.getLongValue();
buf.writeBoolean(time != -1L);
if (time != -1L) {
buf.writeLong(time);
}
}
}
return buf;
}
Aggregations