Make BlockInventoryHolder block strings immutable; clean up lectern unloading

This commit is contained in:
Camotoy 2021-02-16 19:09:57 -05:00
parent 72186d91f1
commit 22c39d285e
No known key found for this signature in database
GPG key ID: 7EEFB66FE798081F
2 changed files with 7 additions and 4 deletions

View file

@ -26,7 +26,7 @@
package org.geysermc.connector.network.translators.inventory.holder;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.Position;
import com.google.common.collect.Sets;
import com.google.common.collect.ImmutableSet;
import com.nukkitx.math.vector.Vector3i;
import com.nukkitx.nbt.NbtMap;
import com.nukkitx.protocol.bedrock.data.inventory.ContainerType;
@ -40,6 +40,7 @@ import org.geysermc.connector.network.translators.inventory.InventoryTranslator;
import org.geysermc.connector.network.translators.world.block.BlockTranslator;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
/**
@ -58,8 +59,10 @@ public class BlockInventoryHolder extends InventoryHolder {
this.defaultJavaBlockState = BlockTranslator.getJavaBlockState(javaBlockIdentifier);
this.containerType = containerType;
if (validBlocks != null) {
this.validBlocks = Sets.newHashSet(validBlocks);
this.validBlocks.add(javaBlockIdentifier.split("\\[")[0]);
Set<String> validBlocksTemp = new HashSet<>(validBlocks.length + 1);
Collections.addAll(validBlocksTemp, validBlocks);
validBlocksTemp.add(javaBlockIdentifier.split("\\[")[0]);
this.validBlocks = ImmutableSet.copyOf(validBlocksTemp);
} else {
this.validBlocks = Collections.singleton(javaBlockIdentifier.split("\\[")[0]);
}

View file

@ -54,7 +54,7 @@ public class JavaUnloadChunkTranslator extends PacketTranslator<ServerUnloadChun
iterator = session.getLecternCache().iterator();
while (iterator.hasNext()) {
Vector3i position = iterator.next();
if (Math.floor((double) position.getX() / 16) == packet.getX() && Math.floor((double) position.getZ() / 16) == packet.getZ()) {
if ((position.getX() >> 4) == packet.getX() && (position.getZ() >> 4) == packet.getZ()) {
iterator.remove();
}
}