Merge branch 'master' into new-block-api

This commit is contained in:
TheMode 2021-06-20 23:52:08 +02:00
commit c2270f8922
25 changed files with 76 additions and 81 deletions

View File

@ -108,11 +108,10 @@ dependencies {
testCompileOnly "org.mockito:mockito-core:2.28.2"
// Netty
api 'io.netty:netty-handler:4.1.63.Final'
api 'io.netty:netty-codec:4.1.63.Final'
api 'io.netty:netty-transport-native-epoll:4.1.63.Final:linux-x86_64'
api 'io.netty:netty-transport-native-kqueue:4.1.63.Final:osx-x86_64'
api 'io.netty.incubator:netty-incubator-transport-native-io_uring:0.0.5.Final:linux-x86_64'
api 'io.netty:netty-handler:4.1.65.Final'
api 'io.netty:netty-codec:4.1.65.Final'
api 'io.netty:netty-transport-native-epoll:4.1.65.Final:linux-x86_64'
api 'io.netty:netty-transport-native-kqueue:4.1.65.Final:osx-x86_64'
// https://mvnrepository.com/artifact/it.unimi.dsi/fastutil
api 'it.unimi.dsi:fastutil:8.5.4'
@ -136,6 +135,8 @@ dependencies {
// https://search.maven.org/artifact/org.fusesource.jansi/jansi/2.3.2/jar
implementation 'org.fusesource.jansi:jansi:2.3.2'
implementation 'com.github.ben-manes.caffeine:caffeine:3.0.2'
// Guava 21.0+ required for Mixin
api 'com.google.guava:guava:30.1-jre'

View File

@ -1,6 +1,5 @@
package net.minestom.server;
import com.google.common.collect.Queues;
import net.minestom.server.acquirable.Acquirable;
import net.minestom.server.instance.Chunk;
import net.minestom.server.instance.Instance;
@ -34,8 +33,8 @@ public final class UpdateManager {
// TODO make configurable
private ThreadProvider threadProvider = new SingleThreadProvider();
private final Queue<LongConsumer> tickStartCallbacks = Queues.newConcurrentLinkedQueue();
private final Queue<LongConsumer> tickEndCallbacks = Queues.newConcurrentLinkedQueue();
private final Queue<LongConsumer> tickStartCallbacks = new ConcurrentLinkedQueue<>();
private final Queue<LongConsumer> tickEndCallbacks = new ConcurrentLinkedQueue<>();
private final List<Consumer<TickMonitor>> tickMonitors = new CopyOnWriteArrayList<>();
/**

View File

@ -1,6 +1,5 @@
package net.minestom.server.acquirable;
import com.google.common.annotations.Beta;
import net.minestom.server.entity.Entity;
import net.minestom.server.thread.ThreadProvider;
import net.minestom.server.thread.TickThread;
@ -14,7 +13,7 @@ import java.util.Optional;
import java.util.function.Consumer;
import java.util.stream.Stream;
@Beta
@ApiStatus.Experimental
public interface Acquirable<T> {
/**

View File

@ -1,15 +1,15 @@
package net.minestom.server.acquirable;
import com.google.common.annotations.Beta;
import net.minestom.server.thread.TickThread;
import net.minestom.server.utils.async.AsyncUtils;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import java.util.*;
import java.util.function.Consumer;
import java.util.stream.Stream;
@Beta
@ApiStatus.Experimental
public class AcquirableCollection<E> implements Collection<Acquirable<E>> {
private final Collection<Acquirable<E>> acquirableCollection;

View File

@ -1,6 +1,5 @@
package net.minestom.server.command.builder;
import com.google.common.annotations.Beta;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import net.minestom.server.command.CommandSender;
@ -10,6 +9,7 @@ import net.minestom.server.command.builder.arguments.ArgumentType;
import net.minestom.server.command.builder.arguments.ArgumentWord;
import net.minestom.server.command.builder.condition.CommandCondition;
import net.minestom.server.utils.StringUtils;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
@ -221,7 +221,7 @@ public class Command {
* @param format the syntax format
* @return the newly created {@link CommandSyntax syntaxes}.
*/
@Beta
@ApiStatus.Experimental
public @NotNull Collection<CommandSyntax> addSyntax(@NotNull CommandExecutor executor, @NotNull String format) {
return addSyntax(executor, ArgumentType.generate(format));
}
@ -302,7 +302,7 @@ public class Command {
public void globalListener(@NotNull CommandSender sender, @NotNull CommandContext context, @NotNull String command) {
}
@Beta
@ApiStatus.Experimental
public @NotNull Set<String> getSyntaxesStrings() {
Set<String> syntaxes = new HashSet<>();
@ -320,7 +320,7 @@ public class Command {
return syntaxes;
}
@Beta
@ApiStatus.Experimental
public @NotNull String getSyntaxesTree() {
Node commandNode = new Node();
commandNode.names.addAll(Arrays.asList(getNames()));

View File

@ -1,7 +1,7 @@
package net.minestom.server.command.builder;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import it.unimi.dsi.fastutil.ints.Int2ObjectRBTreeMap;
import net.minestom.server.command.CommandSender;
import net.minestom.server.command.builder.arguments.Argument;
@ -25,7 +25,7 @@ public class CommandDispatcher {
private final Map<String, Command> commandMap = new HashMap<>();
private final Set<Command> commands = new HashSet<>();
private final Cache<String, CommandResult> cache = CacheBuilder.newBuilder()
private final Cache<String, CommandResult> cache = Caffeine.newBuilder()
.expireAfterWrite(30, TimeUnit.SECONDS)
.build();

View File

@ -1,6 +1,5 @@
package net.minestom.server.command.builder.arguments;
import com.google.common.annotations.Beta;
import net.minestom.server.command.builder.ArgumentCallback;
import net.minestom.server.command.builder.Command;
import net.minestom.server.command.builder.CommandExecutor;
@ -8,6 +7,7 @@ import net.minestom.server.command.builder.NodeMaker;
import net.minestom.server.command.builder.exception.ArgumentSyntaxException;
import net.minestom.server.command.builder.suggestion.SuggestionCallback;
import net.minestom.server.network.packet.server.play.DeclareCommandsPacket;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -210,8 +210,8 @@ public abstract class Argument<T> {
/**
* Gets the suggestion callback of the argument
*
* @see #setSuggestionCallback
* @return the suggestion callback of the argument, null if it doesn't exist
* @see #setSuggestionCallback
*/
@Nullable
public SuggestionCallback getSuggestionCallback() {
@ -247,7 +247,7 @@ public abstract class Argument<T> {
* @param <O> The type of output expected.
* @return A new ArgumentMap that can get this complex object type.
*/
@Beta
@ApiStatus.Experimental
public <O> @NotNull ArgumentMap<T, O> map(@NotNull ArgumentMap.Mapper<T, O> mapper) {
return new ArgumentMap<>(this, mapper);
}

View File

@ -1,6 +1,5 @@
package net.minestom.server.command.builder.arguments;
import com.google.common.annotations.Beta;
import net.minestom.server.MinecraftServer;
import net.minestom.server.command.builder.CommandDispatcher;
import net.minestom.server.command.builder.CommandResult;
@ -8,6 +7,7 @@ import net.minestom.server.command.builder.NodeMaker;
import net.minestom.server.command.builder.exception.ArgumentSyntaxException;
import net.minestom.server.network.packet.server.play.DeclareCommandsPacket;
import net.minestom.server.utils.StringUtils;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
public class ArgumentCommand extends Argument<CommandResult> {
@ -69,7 +69,7 @@ public class ArgumentCommand extends Argument<CommandResult> {
return shortcut;
}
@Beta
@ApiStatus.Experimental
public ArgumentCommand setShortcut(@NotNull String shortcut) {
this.shortcut = shortcut;
return this;

View File

@ -1,6 +1,5 @@
package net.minestom.server.command.builder.arguments;
import com.google.common.annotations.Beta;
import net.minestom.server.command.builder.arguments.minecraft.*;
import net.minestom.server.command.builder.arguments.minecraft.registry.*;
import net.minestom.server.command.builder.arguments.number.ArgumentDouble;
@ -11,6 +10,7 @@ import net.minestom.server.command.builder.arguments.relative.ArgumentRelativeBl
import net.minestom.server.command.builder.arguments.relative.ArgumentRelativeVec2;
import net.minestom.server.command.builder.arguments.relative.ArgumentRelativeVec3;
import net.minestom.server.command.builder.parser.ArgumentParser;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
/**
@ -248,7 +248,7 @@ public class ArgumentType {
* <p>
* Note: this feature is in beta and is very likely to change depending on feedback.
*/
@Beta
@ApiStatus.Experimental
public static Argument<?>[] generate(@NotNull String format) {
return ArgumentParser.generate(format);
}

View File

@ -1,6 +1,5 @@
package net.minestom.server.command.builder.parser;
import com.google.common.annotations.Beta;
import net.minestom.server.command.builder.arguments.*;
import net.minestom.server.command.builder.arguments.minecraft.*;
import net.minestom.server.command.builder.arguments.minecraft.registry.*;
@ -12,6 +11,7 @@ import net.minestom.server.command.builder.arguments.relative.ArgumentRelativeVe
import net.minestom.server.command.builder.arguments.relative.ArgumentRelativeVec3;
import net.minestom.server.command.builder.exception.ArgumentSyntaxException;
import net.minestom.server.utils.StringUtils;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -63,7 +63,7 @@ public class ArgumentParser {
ARGUMENT_FUNCTION_MAP.put("relativevec2", ArgumentRelativeVec2::new);
}
@Beta
@ApiStatus.Experimental
public static @NotNull Argument<?>[] generate(@NotNull String format) {
List<Argument<?>> result = new ArrayList<>();

View File

@ -1,7 +1,5 @@
package net.minestom.server.entity;
import com.google.common.annotations.Beta;
import com.google.common.collect.Queues;
import net.kyori.adventure.sound.Sound;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.event.HoverEvent;
@ -55,6 +53,7 @@ import org.jetbrains.annotations.Nullable;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.atomic.AtomicInteger;
@ -129,7 +128,7 @@ public class Entity implements Viewable, Tickable, EventHandler<EntityEvent>, Da
private final List<TimedPotion> effects = new CopyOnWriteArrayList<>();
// list of scheduled tasks to be executed during the next entity tick
protected final Queue<Consumer<Entity>> nextTick = Queues.newConcurrentLinkedQueue();
protected final Queue<Consumer<Entity>> nextTick = new ConcurrentLinkedQueue<>();
// Tick related
private long ticks;
@ -1601,12 +1600,12 @@ public class Entity implements Viewable, Tickable, EventHandler<EntityEvent>, Da
return Objects.requireNonNullElse(this.customSynchronizationCooldown, SYNCHRONIZATION_COOLDOWN);
}
@Beta
@ApiStatus.Experimental
public <T extends Entity> @NotNull Acquirable<T> getAcquirable() {
return (Acquirable<T>) acquirable;
}
@Beta
@ApiStatus.Experimental
public <T extends Entity> @NotNull Acquirable<T> getAcquirable(@NotNull Class<T> clazz) {
return (Acquirable<T>) acquirable;
}

View File

@ -1,6 +1,5 @@
package net.minestom.server.entity;
import com.google.common.collect.Queues;
import net.kyori.adventure.audience.MessageType;
import net.kyori.adventure.bossbar.BossBar;
import net.kyori.adventure.identity.Identified;
@ -85,6 +84,7 @@ import org.jetbrains.annotations.Nullable;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.UnaryOperator;
@ -117,7 +117,7 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
private final AtomicInteger teleportId = new AtomicInteger();
private int receivedTeleportId;
private final Queue<ClientPlayPacket> packets = Queues.newConcurrentLinkedQueue();
private final Queue<ClientPlayPacket> packets = new ConcurrentLinkedQueue<>();
private final boolean levelFlat;
private final PlayerSettings settings;
private float exp;

View File

@ -24,7 +24,7 @@ public class DoNothingGoal extends GoalSelector {
public DoNothingGoal(EntityCreature entityCreature, long time, float chance) {
super(entityCreature);
this.time = time;
this.chance = MathUtils.clampFloat(chance, 0, 1);
this.chance = MathUtils.clamp(chance, 0, 1);
}
@Override

View File

@ -1,7 +1,7 @@
package net.minestom.server.extras.velocity;
import com.google.common.net.InetAddresses;
import io.netty.buffer.ByteBuf;
import net.minestom.server.MinecraftServer;
import net.minestom.server.entity.PlayerSkin;
import net.minestom.server.utils.binary.BinaryReader;
import org.jetbrains.annotations.NotNull;
@ -9,6 +9,7 @@ import org.jetbrains.annotations.NotNull;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.security.InvalidKeyException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
@ -73,7 +74,12 @@ public final class VelocityProxy {
}
public static InetAddress readAddress(@NotNull BinaryReader reader) {
return InetAddresses.forString(reader.readSizedString());
try {
return InetAddress.getByName(reader.readSizedString());
} catch (UnknownHostException e) {
MinecraftServer.getExceptionManager().handleException(e);
return null;
}
}
public static PlayerSkin readSkin(@NotNull BinaryReader reader) {

View File

@ -1,6 +1,5 @@
package net.minestom.server.instance;
import com.google.common.collect.Queues;
import net.kyori.adventure.identity.Identity;
import net.kyori.adventure.pointer.Pointers;
import net.minestom.server.MinecraftServer;
@ -49,6 +48,7 @@ import net.minestom.server.event.handler.EventHandler;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.function.Consumer;
/**
@ -100,7 +100,7 @@ public abstract class Instance implements BlockGetter, BlockSetter, Tickable, Ev
protected UUID uniqueId;
// list of scheduled tasks to be executed during the next instance tick
protected final Queue<Consumer<Instance>> nextTick = Queues.newConcurrentLinkedQueue();
protected final Queue<Consumer<Instance>> nextTick = new ConcurrentLinkedQueue<>();
// instance custom data
private Data data;

View File

@ -1,8 +1,8 @@
package net.minestom.server.item;
import com.google.common.annotations.Beta;
import net.kyori.adventure.text.Component;
import net.minestom.server.item.metadata.*;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -100,7 +100,7 @@ public class ItemStackBuilder {
return this;
}
@Beta
@ApiStatus.Experimental
@Contract(value = "_ -> this")
public @NotNull ItemStackBuilder stackingRule(@Nullable StackingRule stackingRule) {
this.stackingRule = stackingRule;

View File

@ -13,9 +13,6 @@ import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.ServerSocketChannel;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.incubator.channel.uring.IOUring;
import io.netty.incubator.channel.uring.IOUringEventLoopGroup;
import io.netty.incubator.channel.uring.IOUringServerSocketChannel;
import net.minestom.server.MinecraftServer;
import net.minestom.server.network.PacketProcessor;
import net.minestom.server.network.netty.channel.ClientChannel;
@ -82,14 +79,7 @@ public final class NettyServer {
// Find boss/worker event group
{
if (IOUring.isAvailable()) {
boss = new IOUringEventLoopGroup(2);
worker = new IOUringEventLoopGroup(workerThreadCount);
channel = IOUringServerSocketChannel.class;
LOGGER.info("Using io_uring");
} else if (Epoll.isAvailable()) {
if (Epoll.isAvailable()) {
boss = new EpollEventLoopGroup(2);
worker = new EpollEventLoopGroup(workerThreadCount);

View File

@ -1,6 +1,5 @@
package net.minestom.server.scoreboard;
import com.google.common.collect.MapMaker;
import net.kyori.adventure.identity.Identity;
import net.kyori.adventure.pointer.Pointers;
import net.kyori.adventure.text.Component;
@ -22,6 +21,7 @@ import org.jetbrains.annotations.NotNull;
import java.util.Collection;
import java.util.Collections;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArraySet;
/**
@ -72,7 +72,7 @@ public class Team implements PacketGroupingAudience {
*/
private Component suffix;
private final Set<Player> playerMembers = Collections.newSetFromMap(new MapMaker().weakKeys().makeMap());
private final Set<Player> playerMembers = ConcurrentHashMap.newKeySet();
private boolean isPlayerMembersUpToDate;
// Adventure

View File

@ -1,10 +1,10 @@
package net.minestom.server.tag;
import com.google.common.annotations.Beta;
import org.jetbrains.annotations.ApiStatus;
/**
* Represents an element which can read and write {@link Tag tags}.
*/
@Beta
@ApiStatus.Experimental
public interface TagHandler extends TagReadable, TagWritable {
}

View File

@ -47,10 +47,6 @@ public final class MathUtils {
return Direction.HORIZONTAL[directionIndex];
}
public static float clampFloat(float t, float a, float b) {
return Math.max(a, Math.min(t, b));
}
public static boolean isBetween(byte number, byte min, byte max) {
return number >= min && number <= max;
}
@ -84,11 +80,15 @@ public final class MathUtils {
}
public static int clamp(int value, int min, int max) {
if (value < min) {
return min;
} else {
return Math.min(value, max);
}
return Math.min(Math.max(value, min), max);
}
public static float clamp(float value, float min, float max) {
return Math.min(Math.max(value, min), max);
}
public static double clamp(double value, double min, double max) {
return Math.min(Math.max(value, min), max);
}
public static double mod(final double a, final double b) {

View File

@ -1,6 +1,5 @@
package net.minestom.server.utils;
import com.google.common.primitives.Doubles;
import net.minestom.server.MinecraftServer;
import net.minestom.server.utils.clone.PublicCloneable;
import org.jetbrains.annotations.NotNull;
@ -167,7 +166,7 @@ public class Vector implements PublicCloneable<Vector> {
* @return angle in radians
*/
public float angle(@NotNull Vector other) {
double dot = Doubles.constrainToRange(dot(other) / (length() * other.length()), -1.0, 1.0);
double dot = MathUtils.clamp(dot(other) / (length() * other.length()), -1.0, 1.0);
return (float) Math.acos(dot);
}

View File

@ -1,8 +1,8 @@
package net.minestom.server.utils.cache;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.RemovalListener;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.github.benmanes.caffeine.cache.RemovalListener;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -24,7 +24,7 @@ public class TemporaryCache<T> {
* @param duration the time before considering an object unused
*/
public TemporaryCache(long duration, TimeUnit timeUnit, RemovalListener<UUID, T> removalListener) {
this.cache = CacheBuilder.newBuilder()
this.cache = Caffeine.newBuilder()
.expireAfterWrite(duration, timeUnit)
.removalListener(removalListener)
.build();

View File

@ -6,8 +6,10 @@ import java.util.concurrent.TimeUnit;
public class TemporaryPacketCache extends TemporaryCache<TimedBuffer> {
public TemporaryPacketCache(long duration, TimeUnit timeUnit) {
super(duration, timeUnit, notification -> {
final ByteBuf buffer = notification.getValue().getBuffer();
super(duration, timeUnit, (key, value, cause) -> {
if (value == null)
return;
final ByteBuf buffer = value.getBuffer();
synchronized (buffer) {
buffer.release();
}

View File

@ -1,8 +1,8 @@
package net.minestom.server.utils.location;
import com.google.common.annotations.Beta;
import net.minestom.server.entity.Entity;
import net.minestom.server.utils.Position;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -31,7 +31,7 @@ public abstract class RelativeLocation<T> {
*/
public abstract T from(@Nullable Position position);
@Beta
@ApiStatus.Experimental
public abstract T fromView(@Nullable Position position);
/**
@ -45,7 +45,7 @@ public abstract class RelativeLocation<T> {
return from(entityPosition);
}
@Beta
@ApiStatus.Experimental
public T fromView(@Nullable Entity entity) {
final Position entityPosition = entity != null ? entity.getPosition() : new Position();
return fromView(entityPosition);

View File

@ -1,7 +1,7 @@
package net.minestom.server.utils.mojang;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import net.minestom.server.MinecraftServer;
@ -17,12 +17,12 @@ import java.util.concurrent.TimeUnit;
*/
public final class MojangUtils {
private static final Cache<String, JsonObject> UUID_CACHE = CacheBuilder.newBuilder()
private static final Cache<String, JsonObject> UUID_CACHE = Caffeine.newBuilder()
.expireAfterWrite(30, TimeUnit.SECONDS)
.softValues()
.build();
private static final Cache<String, JsonObject> USERNAME_CACHE = CacheBuilder.newBuilder()
private static final Cache<String, JsonObject> USERNAME_CACHE = Caffeine.newBuilder()
.expireAfterWrite(30, TimeUnit.SECONDS)
.softValues()
.build();