Cleanup + reduced default chunk view distance to 8

This commit is contained in:
themode 2020-11-19 07:00:41 +01:00
parent fae8e30272
commit 828069c685
6 changed files with 22 additions and 16 deletions

View File

@ -124,7 +124,7 @@ public final class MinecraftServer {
private static boolean initialized;
private static boolean started;
private static int chunkViewDistance = 10;
private static int chunkViewDistance = 8;
private static int entityViewDistance = 5;
private static int compressionThreshold = 256;
private static ResponseDataConsumer responseDataConsumer;

View File

@ -1,6 +1,5 @@
package net.minestom.server.entity;
import io.netty.channel.Channel;
import net.minestom.server.MinecraftServer;
import net.minestom.server.advancements.AdvancementTab;
import net.minestom.server.attribute.Attribute;
@ -57,7 +56,6 @@ import net.minestom.server.utils.callback.OptionalCallback;
import net.minestom.server.utils.chunk.ChunkCallback;
import net.minestom.server.utils.chunk.ChunkUtils;
import net.minestom.server.utils.instance.InstanceUtils;
import net.minestom.server.utils.player.PlayerUtils;
import net.minestom.server.utils.time.CooldownUtils;
import net.minestom.server.utils.time.TimeUnit;
import net.minestom.server.utils.time.UpdateOption;
@ -342,14 +340,8 @@ public class Player extends LivingEntity implements CommandSender {
@Override
public void update(long time) {
// Flush all pending packets
if (PlayerUtils.isNettyClient(this)) {
Channel channel = ((NettyPlayerConnection) playerConnection).getChannel();
channel.eventLoop().execute(() -> channel.flush());
}
// Network tick verification
playerConnection.updateStats();
// Network tick
this.playerConnection.update();
// Process received packets
ClientPlayPacket packet;

View File

@ -11,6 +11,7 @@ import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@ -93,8 +94,13 @@ public final class PacketListenerManager {
* @return true if the packet is not cancelled, false otherwise
*/
public <T extends ServerPacket> boolean processServerPacket(@NotNull T packet, @NotNull Player player) {
final List<PacketConsumer<ServerPacket>> consumers = CONNECTION_MANAGER.getSendPacketConsumers();
if (consumers.isEmpty()) {
return true;
}
final PacketController packetController = new PacketController();
for (PacketConsumer<ServerPacket> packetConsumer : CONNECTION_MANAGER.getSendPacketConsumers()) {
for (PacketConsumer<ServerPacket> packetConsumer : consumers) {
packetConsumer.accept(player, packetController, packet);
}

View File

@ -145,11 +145,11 @@ public final class ConnectionManager {
/**
* Gets all the listeners which are called for each packet received.
*
* @return an unmodifiable list of packet's consumers
* @return a list of packet's consumers
*/
@NotNull
public List<PacketConsumer<ClientPlayPacket>> getReceivePacketConsumers() {
return Collections.unmodifiableList(receivePacketConsumers);
return receivePacketConsumers;
}
/**
@ -164,7 +164,7 @@ public final class ConnectionManager {
/**
* Gets all the listeners which are called for each packet sent.
*
* @return an unmodifiable list of packet's consumers
* @return a list of packet's consumers
*/
@NotNull
public List<PacketConsumer<ServerPacket>> getSendPacketConsumers() {

View File

@ -56,6 +56,14 @@ public class NettyPlayerConnection extends PlayerConnection {
this.remoteAddress = channel.remoteAddress();
}
@Override
public void update() {
// Flush
this.channel.eventLoop().execute(() -> channel.flush());
// Network stats
super.update();
}
/**
* Sets the encryption key and add the codecs to the pipeline.
*

View File

@ -45,7 +45,7 @@ public abstract class PlayerConnection {
/**
* Updates values related to the network connection.
*/
public void updateStats() {
public void update() {
// Check rate limit
if (MinecraftServer.getRateLimit() > 0) {
tickCounter++;