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 initialized;
private static boolean started; private static boolean started;
private static int chunkViewDistance = 10; private static int chunkViewDistance = 8;
private static int entityViewDistance = 5; private static int entityViewDistance = 5;
private static int compressionThreshold = 256; private static int compressionThreshold = 256;
private static ResponseDataConsumer responseDataConsumer; private static ResponseDataConsumer responseDataConsumer;

View File

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

View File

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

View File

@ -56,6 +56,14 @@ public class NettyPlayerConnection extends PlayerConnection {
this.remoteAddress = channel.remoteAddress(); 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. * 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. * Updates values related to the network connection.
*/ */
public void updateStats() { public void update() {
// Check rate limit // Check rate limit
if (MinecraftServer.getRateLimit() > 0) { if (MinecraftServer.getRateLimit() > 0) {
tickCounter++; tickCounter++;