mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-27 19:47:44 +01:00
Merge branch 'master' of https://github.com/Minestom/Minestom
This commit is contained in:
commit
f8840cf7a9
@ -28,9 +28,9 @@ import net.minestom.server.utils.validate.Check;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
//TODO: Default attributes registration (and limitation ?)
|
||||
@ -49,7 +49,7 @@ public abstract class LivingEntity extends Entity implements EquipmentHandler {
|
||||
// Bounding box used for items' pickup (see LivingEntity#setBoundingBox)
|
||||
protected BoundingBox expandedBoundingBox;
|
||||
|
||||
private final Map<String, AttributeInstance> attributeModifiers = new HashMap<>(Attribute.values().length);
|
||||
private final Map<String, AttributeInstance> attributeModifiers = new ConcurrentHashMap<>(Attribute.values().length);
|
||||
|
||||
private boolean isHandActive;
|
||||
private boolean offHand;
|
||||
@ -399,10 +399,8 @@ public abstract class LivingEntity extends Entity implements EquipmentHandler {
|
||||
*/
|
||||
@NotNull
|
||||
public AttributeInstance getAttribute(@NotNull Attribute attribute) {
|
||||
if (!attributeModifiers.containsKey(attribute.getKey())) {
|
||||
attributeModifiers.put(attribute.getKey(), new AttributeInstance(attribute, this::onAttributeChanged));
|
||||
}
|
||||
return attributeModifiers.get(attribute.getKey());
|
||||
return attributeModifiers.computeIfAbsent(attribute.getKey(),
|
||||
s -> new AttributeInstance(attribute, this::onAttributeChanged));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -410,7 +408,8 @@ public abstract class LivingEntity extends Entity implements EquipmentHandler {
|
||||
*
|
||||
* @param instance the modified attribute instance
|
||||
*/
|
||||
protected void onAttributeChanged(@NotNull AttributeInstance instance) { }
|
||||
protected void onAttributeChanged(@NotNull AttributeInstance instance) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the attribute value.
|
||||
|
@ -32,11 +32,11 @@ import java.util.concurrent.ScheduledExecutorService;
|
||||
|
||||
public final class NettyServer {
|
||||
|
||||
public static final Logger LOGGER = LoggerFactory.getLogger(NettyServer.class);
|
||||
|
||||
private static final long DEFAULT_COMPRESSED_CHANNEL_WRITE_LIMIT = 600_000L;
|
||||
private static final long DEFAULT_COMPRESSED_CHANNEL_READ_LIMIT = 100_000L;
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(NettyServer.class);
|
||||
|
||||
private static final long DEFAULT_UNCOMPRESSED_CHANNEL_WRITE_LIMIT = 15_000_000L;
|
||||
private static final long DEFAULT_UNCOMPRESSED_CHANNEL_READ_LIMIT = 1_000_000L;
|
||||
|
||||
@ -79,28 +79,28 @@ public final class NettyServer {
|
||||
|
||||
channel = IOUringServerSocketChannel.class;
|
||||
|
||||
log.info("Using Io_uring");
|
||||
LOGGER.info("Using io_uring");
|
||||
} else if (Epoll.isAvailable()) {
|
||||
boss = new EpollEventLoopGroup(2);
|
||||
worker = new EpollEventLoopGroup(); // thread count = core * 2
|
||||
|
||||
channel = EpollServerSocketChannel.class;
|
||||
|
||||
log.info("Using Epoll");
|
||||
LOGGER.info("Using epoll");
|
||||
} else if (KQueue.isAvailable()) {
|
||||
boss = new KQueueEventLoopGroup(2);
|
||||
worker = new KQueueEventLoopGroup(); // thread count = core * 2
|
||||
|
||||
channel = KQueueServerSocketChannel.class;
|
||||
|
||||
log.info("Using KQueue");
|
||||
LOGGER.info("Using kqueue");
|
||||
} else {
|
||||
boss = new NioEventLoopGroup(2);
|
||||
worker = new NioEventLoopGroup(); // thread count = core * 2
|
||||
|
||||
channel = NioServerSocketChannel.class;
|
||||
|
||||
log.info("Using Nio");
|
||||
LOGGER.info("Using NIO");
|
||||
}
|
||||
|
||||
bootstrap = new ServerBootstrap()
|
||||
|
@ -48,9 +48,12 @@ public final class PacketUtils {
|
||||
final ByteBuf finalBuffer = createFramedPacket(packet, true);
|
||||
final FramedPacket framedPacket = new FramedPacket(finalBuffer);
|
||||
|
||||
// Prevent premature release
|
||||
final int refIncrease = players.size() - 1;
|
||||
if (refIncrease > 0)
|
||||
finalBuffer.retain(refIncrease);
|
||||
|
||||
// Send packet to all players
|
||||
for (Player player : players) {
|
||||
final PlayerConnection playerConnection = player.getPlayerConnection();
|
||||
if (playerConnection instanceof NettyPlayerConnection) {
|
||||
|
Loading…
Reference in New Issue
Block a user