mirror of
https://github.com/Minestom/Minestom.git
synced 2025-03-02 11:21:15 +01:00
Merge branch 'master' into command-redirection
This commit is contained in:
commit
7bbc99956d
@ -1,12 +1,10 @@
|
||||
package net.minestom.server.command.builder.arguments.minecraft;
|
||||
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.command.builder.NodeMaker;
|
||||
import net.minestom.server.command.builder.arguments.Argument;
|
||||
import net.minestom.server.command.builder.exception.ArgumentSyntaxException;
|
||||
import net.minestom.server.entity.EntityType;
|
||||
import net.minestom.server.entity.GameMode;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.network.packet.server.play.DeclareCommandsPacket;
|
||||
import net.minestom.server.registry.Registries;
|
||||
import net.minestom.server.utils.entity.EntityFinder;
|
||||
@ -17,6 +15,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Represents the target selector argument.
|
||||
@ -30,6 +29,7 @@ public class ArgumentEntity extends Argument<EntityFinder> {
|
||||
public static final int INVALID_ARGUMENT_NAME = -5;
|
||||
public static final int INVALID_ARGUMENT_VALUE = -6;
|
||||
|
||||
private static final Pattern USERNAME_PATTERN = Pattern.compile("[a-zA-Z0-9_]{1,16}");
|
||||
private static final String SELECTOR_PREFIX = "@";
|
||||
private static final List<String> SELECTOR_VARIABLES = Arrays.asList("@p", "@r", "@a", "@e", "@s");
|
||||
private static final List<String> PLAYERS_ONLY_SELECTOR = Arrays.asList("@p", "@r", "@a", "@s");
|
||||
@ -105,8 +105,7 @@ public class ArgumentEntity extends Argument<EntityFinder> {
|
||||
}
|
||||
|
||||
// Check if the input is a valid player name
|
||||
final Player player = MinecraftServer.getConnectionManager().getPlayer(input);
|
||||
if (player != null) {
|
||||
if (USERNAME_PATTERN.matcher(input).matches()) {
|
||||
return new EntityFinder()
|
||||
.setTargetSelector(EntityFinder.TargetSelector.MINESTOM_USERNAME)
|
||||
.setConstantName(input);
|
||||
|
@ -1270,18 +1270,13 @@ public class Entity implements Viewable, EventHandler, DataContainer, Permission
|
||||
|
||||
final Instance instance = getInstance();
|
||||
if (instance != null) {
|
||||
|
||||
// Needed to refresh the client chunks when connecting for the first time
|
||||
final boolean forceUpdate = this instanceof Player && ((Player) this).getViewableChunks().isEmpty();
|
||||
|
||||
final Chunk lastChunk = instance.getChunkAt(lastX, lastZ);
|
||||
final Chunk newChunk = instance.getChunkAt(x, z);
|
||||
|
||||
Check.notNull(lastChunk, "The entity " + getEntityId() + " was in an unloaded chunk at " + lastX + ";" + lastZ);
|
||||
Check.notNull(newChunk, "The entity " + getEntityId() + " tried to move in an unloaded chunk at " + x + ";" + z);
|
||||
|
||||
final boolean chunkChange = lastChunk != newChunk;
|
||||
if (forceUpdate || chunkChange) {
|
||||
if (lastChunk != newChunk) {
|
||||
instance.switchEntityChunk(this, lastChunk, newChunk);
|
||||
if (this instanceof Player) {
|
||||
// Refresh player view
|
||||
|
@ -89,6 +89,7 @@ public class Player extends LivingEntity implements CommandSender {
|
||||
|
||||
private DimensionType dimensionType;
|
||||
private GameMode gameMode;
|
||||
// Chunks that the player can view
|
||||
protected final Set<Chunk> viewableChunks = new CopyOnWriteArraySet<>();
|
||||
|
||||
private final AtomicInteger teleportId = new AtomicInteger();
|
||||
@ -1507,10 +1508,12 @@ public class Player extends LivingEntity implements CommandSender {
|
||||
final int chunkX = ChunkUtils.getChunkCoordX(chunkIndex);
|
||||
final int chunkZ = ChunkUtils.getChunkCoordZ(chunkIndex);
|
||||
|
||||
UnloadChunkPacket unloadChunkPacket = new UnloadChunkPacket();
|
||||
// TODO prevent the client from getting lag spikes when re-loading large chunks
|
||||
// Probably by having a distinction between visible and loaded (cache) chunks
|
||||
/*UnloadChunkPacket unloadChunkPacket = new UnloadChunkPacket();
|
||||
unloadChunkPacket.chunkX = chunkX;
|
||||
unloadChunkPacket.chunkZ = chunkZ;
|
||||
playerConnection.sendPacket(unloadChunkPacket);
|
||||
playerConnection.sendPacket(unloadChunkPacket);*/
|
||||
|
||||
final Chunk chunk = instance.getChunk(chunkX, chunkZ);
|
||||
if (chunk != null)
|
||||
@ -2327,7 +2330,7 @@ public class Player extends LivingEntity implements CommandSender {
|
||||
// In this case we send the smallest amount of chunks possible
|
||||
// Will be updated in PlayerSettings#refresh.
|
||||
// Non-compliant clients might also be stuck with this view
|
||||
return 1;
|
||||
return 3;
|
||||
} else {
|
||||
final int serverRange = MinecraftServer.getChunkViewDistance();
|
||||
return Math.min(playerRange, serverRange);
|
||||
|
@ -69,8 +69,8 @@ public class DynamicChunk extends Chunk {
|
||||
|
||||
public DynamicChunk(@Nullable Biome[] biomes, int chunkX, int chunkZ) {
|
||||
this(biomes, chunkX, chunkZ,
|
||||
new PaletteStorage(15, 2),
|
||||
new PaletteStorage(15, 2));
|
||||
new PaletteStorage(8, 2),
|
||||
new PaletteStorage(8, 2));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -228,7 +228,6 @@ public class PaletteStorage implements PublicCloneable<PaletteStorage> {
|
||||
* @param newBitsPerEntry the new bits per entry count
|
||||
*/
|
||||
private void resize(int newBitsPerEntry) {
|
||||
// FIXME: artifacts when resizing
|
||||
newBitsPerEntry = fixBitsPerEntry(newBitsPerEntry);
|
||||
|
||||
PaletteStorage paletteStorageCache = new PaletteStorage(newBitsPerEntry, bitsIncrement);
|
||||
@ -275,7 +274,7 @@ public class PaletteStorage implements PublicCloneable<PaletteStorage> {
|
||||
|
||||
final int section = ChunkUtils.getSectionAt(y);
|
||||
|
||||
final int valuesPerLong = paletteStorage.valuesPerLong;
|
||||
int valuesPerLong = paletteStorage.valuesPerLong;
|
||||
|
||||
if (paletteStorage.sectionBlocks[section].length == 0) {
|
||||
if (blockId == 0) {
|
||||
@ -294,6 +293,9 @@ public class PaletteStorage implements PublicCloneable<PaletteStorage> {
|
||||
// Change to palette value
|
||||
blockId = paletteStorage.getPaletteIndex(section, blockId);
|
||||
|
||||
// The storage could have been resized
|
||||
valuesPerLong = paletteStorage.valuesPerLong;
|
||||
|
||||
final int sectionIndex = getSectionIndex(x, y, z);
|
||||
|
||||
final int index = sectionIndex / valuesPerLong;
|
||||
|
@ -23,6 +23,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ChunkDataPacket implements ServerPacket, CacheablePacket {
|
||||
@ -69,11 +70,7 @@ public class ChunkDataPacket implements ServerPacket, CacheablePacket {
|
||||
if (section.length > 0) { // section contains at least one block
|
||||
mask |= 1 << i;
|
||||
Utils.writeBlocks(blocks, paletteStorage.getPalette(i), section, paletteStorage.getBitsPerEntry());
|
||||
} else {
|
||||
mask |= 0;
|
||||
}
|
||||
} else {
|
||||
mask |= 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -60,6 +60,7 @@ public class NettyPlayerConnection extends PlayerConnection {
|
||||
private UUID bungeeUuid;
|
||||
private PlayerSkin bungeeSkin;
|
||||
|
||||
private static final int FLUSH_SIZE = 20000;
|
||||
private final ByteBuf tickBuffer = Unpooled.directBuffer();
|
||||
|
||||
public NettyPlayerConnection(@NotNull SocketChannel channel) {
|
||||
@ -164,6 +165,7 @@ public class NettyPlayerConnection extends PlayerConnection {
|
||||
synchronized (tickBuffer) {
|
||||
final ByteBuf body = framedPacket.getBody();
|
||||
tickBuffer.writeBytes(body, body.readerIndex(), body.readableBytes());
|
||||
preventiveWrite();
|
||||
}
|
||||
return;
|
||||
} else if (message instanceof ServerPacket) {
|
||||
@ -171,12 +173,14 @@ public class NettyPlayerConnection extends PlayerConnection {
|
||||
final ByteBuf buffer = PacketUtils.createFramedPacket(serverPacket, true);
|
||||
synchronized (tickBuffer) {
|
||||
tickBuffer.writeBytes(buffer);
|
||||
preventiveWrite();
|
||||
}
|
||||
buffer.release();
|
||||
return;
|
||||
} else if (message instanceof ByteBuf) {
|
||||
synchronized (tickBuffer) {
|
||||
tickBuffer.writeBytes((ByteBuf) message);
|
||||
preventiveWrite();
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -196,6 +200,12 @@ public class NettyPlayerConnection extends PlayerConnection {
|
||||
}
|
||||
}
|
||||
|
||||
private void preventiveWrite() {
|
||||
if (tickBuffer.writerIndex() > FLUSH_SIZE) {
|
||||
writeWaitingPackets();
|
||||
}
|
||||
}
|
||||
|
||||
private void writeWaitingPackets() {
|
||||
synchronized (tickBuffer) {
|
||||
final ByteBuf copy = tickBuffer.copy();
|
||||
|
Loading…
Reference in New Issue
Block a user