mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-30 13:08:19 +01:00
Merge branch 'master' into new-block-api
This commit is contained in:
commit
c2270f8922
11
build.gradle
11
build.gradle
@ -108,11 +108,10 @@ dependencies {
|
|||||||
testCompileOnly "org.mockito:mockito-core:2.28.2"
|
testCompileOnly "org.mockito:mockito-core:2.28.2"
|
||||||
|
|
||||||
// Netty
|
// Netty
|
||||||
api 'io.netty:netty-handler:4.1.63.Final'
|
api 'io.netty:netty-handler:4.1.65.Final'
|
||||||
api 'io.netty:netty-codec:4.1.63.Final'
|
api 'io.netty:netty-codec:4.1.65.Final'
|
||||||
api 'io.netty:netty-transport-native-epoll:4.1.63.Final:linux-x86_64'
|
api 'io.netty:netty-transport-native-epoll:4.1.65.Final:linux-x86_64'
|
||||||
api 'io.netty:netty-transport-native-kqueue:4.1.63.Final:osx-x86_64'
|
api 'io.netty:netty-transport-native-kqueue:4.1.65.Final:osx-x86_64'
|
||||||
api 'io.netty.incubator:netty-incubator-transport-native-io_uring:0.0.5.Final:linux-x86_64'
|
|
||||||
|
|
||||||
// https://mvnrepository.com/artifact/it.unimi.dsi/fastutil
|
// https://mvnrepository.com/artifact/it.unimi.dsi/fastutil
|
||||||
api 'it.unimi.dsi:fastutil:8.5.4'
|
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
|
// https://search.maven.org/artifact/org.fusesource.jansi/jansi/2.3.2/jar
|
||||||
implementation 'org.fusesource.jansi:jansi:2.3.2'
|
implementation 'org.fusesource.jansi:jansi:2.3.2'
|
||||||
|
|
||||||
|
implementation 'com.github.ben-manes.caffeine:caffeine:3.0.2'
|
||||||
|
|
||||||
// Guava 21.0+ required for Mixin
|
// Guava 21.0+ required for Mixin
|
||||||
api 'com.google.guava:guava:30.1-jre'
|
api 'com.google.guava:guava:30.1-jre'
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package net.minestom.server;
|
package net.minestom.server;
|
||||||
|
|
||||||
import com.google.common.collect.Queues;
|
|
||||||
import net.minestom.server.acquirable.Acquirable;
|
import net.minestom.server.acquirable.Acquirable;
|
||||||
import net.minestom.server.instance.Chunk;
|
import net.minestom.server.instance.Chunk;
|
||||||
import net.minestom.server.instance.Instance;
|
import net.minestom.server.instance.Instance;
|
||||||
@ -34,8 +33,8 @@ public final class UpdateManager {
|
|||||||
// TODO make configurable
|
// TODO make configurable
|
||||||
private ThreadProvider threadProvider = new SingleThreadProvider();
|
private ThreadProvider threadProvider = new SingleThreadProvider();
|
||||||
|
|
||||||
private final Queue<LongConsumer> tickStartCallbacks = Queues.newConcurrentLinkedQueue();
|
private final Queue<LongConsumer> tickStartCallbacks = new ConcurrentLinkedQueue<>();
|
||||||
private final Queue<LongConsumer> tickEndCallbacks = Queues.newConcurrentLinkedQueue();
|
private final Queue<LongConsumer> tickEndCallbacks = new ConcurrentLinkedQueue<>();
|
||||||
private final List<Consumer<TickMonitor>> tickMonitors = new CopyOnWriteArrayList<>();
|
private final List<Consumer<TickMonitor>> tickMonitors = new CopyOnWriteArrayList<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package net.minestom.server.acquirable;
|
package net.minestom.server.acquirable;
|
||||||
|
|
||||||
import com.google.common.annotations.Beta;
|
|
||||||
import net.minestom.server.entity.Entity;
|
import net.minestom.server.entity.Entity;
|
||||||
import net.minestom.server.thread.ThreadProvider;
|
import net.minestom.server.thread.ThreadProvider;
|
||||||
import net.minestom.server.thread.TickThread;
|
import net.minestom.server.thread.TickThread;
|
||||||
@ -14,7 +13,7 @@ import java.util.Optional;
|
|||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
@Beta
|
@ApiStatus.Experimental
|
||||||
public interface Acquirable<T> {
|
public interface Acquirable<T> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
package net.minestom.server.acquirable;
|
package net.minestom.server.acquirable;
|
||||||
|
|
||||||
import com.google.common.annotations.Beta;
|
|
||||||
import net.minestom.server.thread.TickThread;
|
import net.minestom.server.thread.TickThread;
|
||||||
import net.minestom.server.utils.async.AsyncUtils;
|
import net.minestom.server.utils.async.AsyncUtils;
|
||||||
|
import org.jetbrains.annotations.ApiStatus;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
@Beta
|
@ApiStatus.Experimental
|
||||||
public class AcquirableCollection<E> implements Collection<Acquirable<E>> {
|
public class AcquirableCollection<E> implements Collection<Acquirable<E>> {
|
||||||
|
|
||||||
private final Collection<Acquirable<E>> acquirableCollection;
|
private final Collection<Acquirable<E>> acquirableCollection;
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package net.minestom.server.command.builder;
|
package net.minestom.server.command.builder;
|
||||||
|
|
||||||
import com.google.common.annotations.Beta;
|
|
||||||
import com.google.gson.JsonArray;
|
import com.google.gson.JsonArray;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import net.minestom.server.command.CommandSender;
|
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.arguments.ArgumentWord;
|
||||||
import net.minestom.server.command.builder.condition.CommandCondition;
|
import net.minestom.server.command.builder.condition.CommandCondition;
|
||||||
import net.minestom.server.utils.StringUtils;
|
import net.minestom.server.utils.StringUtils;
|
||||||
|
import org.jetbrains.annotations.ApiStatus;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@ -221,7 +221,7 @@ public class Command {
|
|||||||
* @param format the syntax format
|
* @param format the syntax format
|
||||||
* @return the newly created {@link CommandSyntax syntaxes}.
|
* @return the newly created {@link CommandSyntax syntaxes}.
|
||||||
*/
|
*/
|
||||||
@Beta
|
@ApiStatus.Experimental
|
||||||
public @NotNull Collection<CommandSyntax> addSyntax(@NotNull CommandExecutor executor, @NotNull String format) {
|
public @NotNull Collection<CommandSyntax> addSyntax(@NotNull CommandExecutor executor, @NotNull String format) {
|
||||||
return addSyntax(executor, ArgumentType.generate(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) {
|
public void globalListener(@NotNull CommandSender sender, @NotNull CommandContext context, @NotNull String command) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Beta
|
@ApiStatus.Experimental
|
||||||
public @NotNull Set<String> getSyntaxesStrings() {
|
public @NotNull Set<String> getSyntaxesStrings() {
|
||||||
Set<String> syntaxes = new HashSet<>();
|
Set<String> syntaxes = new HashSet<>();
|
||||||
|
|
||||||
@ -320,7 +320,7 @@ public class Command {
|
|||||||
return syntaxes;
|
return syntaxes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Beta
|
@ApiStatus.Experimental
|
||||||
public @NotNull String getSyntaxesTree() {
|
public @NotNull String getSyntaxesTree() {
|
||||||
Node commandNode = new Node();
|
Node commandNode = new Node();
|
||||||
commandNode.names.addAll(Arrays.asList(getNames()));
|
commandNode.names.addAll(Arrays.asList(getNames()));
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package net.minestom.server.command.builder;
|
package net.minestom.server.command.builder;
|
||||||
|
|
||||||
import com.google.common.cache.Cache;
|
import com.github.benmanes.caffeine.cache.Cache;
|
||||||
import com.google.common.cache.CacheBuilder;
|
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectRBTreeMap;
|
import it.unimi.dsi.fastutil.ints.Int2ObjectRBTreeMap;
|
||||||
import net.minestom.server.command.CommandSender;
|
import net.minestom.server.command.CommandSender;
|
||||||
import net.minestom.server.command.builder.arguments.Argument;
|
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 Map<String, Command> commandMap = new HashMap<>();
|
||||||
private final Set<Command> commands = new HashSet<>();
|
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)
|
.expireAfterWrite(30, TimeUnit.SECONDS)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package net.minestom.server.command.builder.arguments;
|
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.ArgumentCallback;
|
||||||
import net.minestom.server.command.builder.Command;
|
import net.minestom.server.command.builder.Command;
|
||||||
import net.minestom.server.command.builder.CommandExecutor;
|
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.exception.ArgumentSyntaxException;
|
||||||
import net.minestom.server.command.builder.suggestion.SuggestionCallback;
|
import net.minestom.server.command.builder.suggestion.SuggestionCallback;
|
||||||
import net.minestom.server.network.packet.server.play.DeclareCommandsPacket;
|
import net.minestom.server.network.packet.server.play.DeclareCommandsPacket;
|
||||||
|
import org.jetbrains.annotations.ApiStatus;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@ -210,8 +210,8 @@ public abstract class Argument<T> {
|
|||||||
/**
|
/**
|
||||||
* Gets the suggestion callback of the argument
|
* Gets the suggestion callback of the argument
|
||||||
*
|
*
|
||||||
* @see #setSuggestionCallback
|
|
||||||
* @return the suggestion callback of the argument, null if it doesn't exist
|
* @return the suggestion callback of the argument, null if it doesn't exist
|
||||||
|
* @see #setSuggestionCallback
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public SuggestionCallback getSuggestionCallback() {
|
public SuggestionCallback getSuggestionCallback() {
|
||||||
@ -247,7 +247,7 @@ public abstract class Argument<T> {
|
|||||||
* @param <O> The type of output expected.
|
* @param <O> The type of output expected.
|
||||||
* @return A new ArgumentMap that can get this complex object type.
|
* @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) {
|
public <O> @NotNull ArgumentMap<T, O> map(@NotNull ArgumentMap.Mapper<T, O> mapper) {
|
||||||
return new ArgumentMap<>(this, mapper);
|
return new ArgumentMap<>(this, mapper);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package net.minestom.server.command.builder.arguments;
|
package net.minestom.server.command.builder.arguments;
|
||||||
|
|
||||||
import com.google.common.annotations.Beta;
|
|
||||||
import net.minestom.server.MinecraftServer;
|
import net.minestom.server.MinecraftServer;
|
||||||
import net.minestom.server.command.builder.CommandDispatcher;
|
import net.minestom.server.command.builder.CommandDispatcher;
|
||||||
import net.minestom.server.command.builder.CommandResult;
|
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.command.builder.exception.ArgumentSyntaxException;
|
||||||
import net.minestom.server.network.packet.server.play.DeclareCommandsPacket;
|
import net.minestom.server.network.packet.server.play.DeclareCommandsPacket;
|
||||||
import net.minestom.server.utils.StringUtils;
|
import net.minestom.server.utils.StringUtils;
|
||||||
|
import org.jetbrains.annotations.ApiStatus;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class ArgumentCommand extends Argument<CommandResult> {
|
public class ArgumentCommand extends Argument<CommandResult> {
|
||||||
@ -69,7 +69,7 @@ public class ArgumentCommand extends Argument<CommandResult> {
|
|||||||
return shortcut;
|
return shortcut;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Beta
|
@ApiStatus.Experimental
|
||||||
public ArgumentCommand setShortcut(@NotNull String shortcut) {
|
public ArgumentCommand setShortcut(@NotNull String shortcut) {
|
||||||
this.shortcut = shortcut;
|
this.shortcut = shortcut;
|
||||||
return this;
|
return this;
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package net.minestom.server.command.builder.arguments;
|
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.*;
|
||||||
import net.minestom.server.command.builder.arguments.minecraft.registry.*;
|
import net.minestom.server.command.builder.arguments.minecraft.registry.*;
|
||||||
import net.minestom.server.command.builder.arguments.number.ArgumentDouble;
|
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.ArgumentRelativeVec2;
|
||||||
import net.minestom.server.command.builder.arguments.relative.ArgumentRelativeVec3;
|
import net.minestom.server.command.builder.arguments.relative.ArgumentRelativeVec3;
|
||||||
import net.minestom.server.command.builder.parser.ArgumentParser;
|
import net.minestom.server.command.builder.parser.ArgumentParser;
|
||||||
|
import org.jetbrains.annotations.ApiStatus;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -248,7 +248,7 @@ public class ArgumentType {
|
|||||||
* <p>
|
* <p>
|
||||||
* Note: this feature is in beta and is very likely to change depending on feedback.
|
* 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) {
|
public static Argument<?>[] generate(@NotNull String format) {
|
||||||
return ArgumentParser.generate(format);
|
return ArgumentParser.generate(format);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package net.minestom.server.command.builder.parser;
|
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.*;
|
||||||
import net.minestom.server.command.builder.arguments.minecraft.*;
|
import net.minestom.server.command.builder.arguments.minecraft.*;
|
||||||
import net.minestom.server.command.builder.arguments.minecraft.registry.*;
|
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.arguments.relative.ArgumentRelativeVec3;
|
||||||
import net.minestom.server.command.builder.exception.ArgumentSyntaxException;
|
import net.minestom.server.command.builder.exception.ArgumentSyntaxException;
|
||||||
import net.minestom.server.utils.StringUtils;
|
import net.minestom.server.utils.StringUtils;
|
||||||
|
import org.jetbrains.annotations.ApiStatus;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@ -63,7 +63,7 @@ public class ArgumentParser {
|
|||||||
ARGUMENT_FUNCTION_MAP.put("relativevec2", ArgumentRelativeVec2::new);
|
ARGUMENT_FUNCTION_MAP.put("relativevec2", ArgumentRelativeVec2::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Beta
|
@ApiStatus.Experimental
|
||||||
public static @NotNull Argument<?>[] generate(@NotNull String format) {
|
public static @NotNull Argument<?>[] generate(@NotNull String format) {
|
||||||
List<Argument<?>> result = new ArrayList<>();
|
List<Argument<?>> result = new ArrayList<>();
|
||||||
|
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package net.minestom.server.entity;
|
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.sound.Sound;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.event.HoverEvent;
|
import net.kyori.adventure.text.event.HoverEvent;
|
||||||
@ -55,6 +53,7 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
import java.util.concurrent.CopyOnWriteArrayList;
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
import java.util.concurrent.CopyOnWriteArraySet;
|
import java.util.concurrent.CopyOnWriteArraySet;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
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<>();
|
private final List<TimedPotion> effects = new CopyOnWriteArrayList<>();
|
||||||
|
|
||||||
// list of scheduled tasks to be executed during the next entity tick
|
// 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
|
// Tick related
|
||||||
private long ticks;
|
private long ticks;
|
||||||
@ -1601,12 +1600,12 @@ public class Entity implements Viewable, Tickable, EventHandler<EntityEvent>, Da
|
|||||||
return Objects.requireNonNullElse(this.customSynchronizationCooldown, SYNCHRONIZATION_COOLDOWN);
|
return Objects.requireNonNullElse(this.customSynchronizationCooldown, SYNCHRONIZATION_COOLDOWN);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Beta
|
@ApiStatus.Experimental
|
||||||
public <T extends Entity> @NotNull Acquirable<T> getAcquirable() {
|
public <T extends Entity> @NotNull Acquirable<T> getAcquirable() {
|
||||||
return (Acquirable<T>) acquirable;
|
return (Acquirable<T>) acquirable;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Beta
|
@ApiStatus.Experimental
|
||||||
public <T extends Entity> @NotNull Acquirable<T> getAcquirable(@NotNull Class<T> clazz) {
|
public <T extends Entity> @NotNull Acquirable<T> getAcquirable(@NotNull Class<T> clazz) {
|
||||||
return (Acquirable<T>) acquirable;
|
return (Acquirable<T>) acquirable;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package net.minestom.server.entity;
|
package net.minestom.server.entity;
|
||||||
|
|
||||||
import com.google.common.collect.Queues;
|
|
||||||
import net.kyori.adventure.audience.MessageType;
|
import net.kyori.adventure.audience.MessageType;
|
||||||
import net.kyori.adventure.bossbar.BossBar;
|
import net.kyori.adventure.bossbar.BossBar;
|
||||||
import net.kyori.adventure.identity.Identified;
|
import net.kyori.adventure.identity.Identified;
|
||||||
@ -85,6 +84,7 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.function.UnaryOperator;
|
import java.util.function.UnaryOperator;
|
||||||
|
|
||||||
@ -117,7 +117,7 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
|
|||||||
private final AtomicInteger teleportId = new AtomicInteger();
|
private final AtomicInteger teleportId = new AtomicInteger();
|
||||||
private int receivedTeleportId;
|
private int receivedTeleportId;
|
||||||
|
|
||||||
private final Queue<ClientPlayPacket> packets = Queues.newConcurrentLinkedQueue();
|
private final Queue<ClientPlayPacket> packets = new ConcurrentLinkedQueue<>();
|
||||||
private final boolean levelFlat;
|
private final boolean levelFlat;
|
||||||
private final PlayerSettings settings;
|
private final PlayerSettings settings;
|
||||||
private float exp;
|
private float exp;
|
||||||
|
@ -24,7 +24,7 @@ public class DoNothingGoal extends GoalSelector {
|
|||||||
public DoNothingGoal(EntityCreature entityCreature, long time, float chance) {
|
public DoNothingGoal(EntityCreature entityCreature, long time, float chance) {
|
||||||
super(entityCreature);
|
super(entityCreature);
|
||||||
this.time = time;
|
this.time = time;
|
||||||
this.chance = MathUtils.clampFloat(chance, 0, 1);
|
this.chance = MathUtils.clamp(chance, 0, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package net.minestom.server.extras.velocity;
|
package net.minestom.server.extras.velocity;
|
||||||
|
|
||||||
import com.google.common.net.InetAddresses;
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import net.minestom.server.MinecraftServer;
|
||||||
import net.minestom.server.entity.PlayerSkin;
|
import net.minestom.server.entity.PlayerSkin;
|
||||||
import net.minestom.server.utils.binary.BinaryReader;
|
import net.minestom.server.utils.binary.BinaryReader;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@ -9,6 +9,7 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import javax.crypto.Mac;
|
import javax.crypto.Mac;
|
||||||
import javax.crypto.spec.SecretKeySpec;
|
import javax.crypto.spec.SecretKeySpec;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
|
import java.net.UnknownHostException;
|
||||||
import java.security.InvalidKeyException;
|
import java.security.InvalidKeyException;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
@ -73,7 +74,12 @@ public final class VelocityProxy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static InetAddress readAddress(@NotNull BinaryReader reader) {
|
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) {
|
public static PlayerSkin readSkin(@NotNull BinaryReader reader) {
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package net.minestom.server.instance;
|
package net.minestom.server.instance;
|
||||||
|
|
||||||
import com.google.common.collect.Queues;
|
|
||||||
import net.kyori.adventure.identity.Identity;
|
import net.kyori.adventure.identity.Identity;
|
||||||
import net.kyori.adventure.pointer.Pointers;
|
import net.kyori.adventure.pointer.Pointers;
|
||||||
import net.minestom.server.MinecraftServer;
|
import net.minestom.server.MinecraftServer;
|
||||||
@ -49,6 +48,7 @@ import net.minestom.server.event.handler.EventHandler;
|
|||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -100,7 +100,7 @@ public abstract class Instance implements BlockGetter, BlockSetter, Tickable, Ev
|
|||||||
protected UUID uniqueId;
|
protected UUID uniqueId;
|
||||||
|
|
||||||
// list of scheduled tasks to be executed during the next instance tick
|
// 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
|
// instance custom data
|
||||||
private Data data;
|
private Data data;
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package net.minestom.server.item;
|
package net.minestom.server.item;
|
||||||
|
|
||||||
import com.google.common.annotations.Beta;
|
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.minestom.server.item.metadata.*;
|
import net.minestom.server.item.metadata.*;
|
||||||
|
import org.jetbrains.annotations.ApiStatus;
|
||||||
import org.jetbrains.annotations.Contract;
|
import org.jetbrains.annotations.Contract;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
@ -100,7 +100,7 @@ public class ItemStackBuilder {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Beta
|
@ApiStatus.Experimental
|
||||||
@Contract(value = "_ -> this")
|
@Contract(value = "_ -> this")
|
||||||
public @NotNull ItemStackBuilder stackingRule(@Nullable StackingRule stackingRule) {
|
public @NotNull ItemStackBuilder stackingRule(@Nullable StackingRule stackingRule) {
|
||||||
this.stackingRule = stackingRule;
|
this.stackingRule = stackingRule;
|
||||||
|
@ -13,9 +13,6 @@ import io.netty.channel.nio.NioEventLoopGroup;
|
|||||||
import io.netty.channel.socket.ServerSocketChannel;
|
import io.netty.channel.socket.ServerSocketChannel;
|
||||||
import io.netty.channel.socket.SocketChannel;
|
import io.netty.channel.socket.SocketChannel;
|
||||||
import io.netty.channel.socket.nio.NioServerSocketChannel;
|
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.MinecraftServer;
|
||||||
import net.minestom.server.network.PacketProcessor;
|
import net.minestom.server.network.PacketProcessor;
|
||||||
import net.minestom.server.network.netty.channel.ClientChannel;
|
import net.minestom.server.network.netty.channel.ClientChannel;
|
||||||
@ -82,14 +79,7 @@ public final class NettyServer {
|
|||||||
|
|
||||||
// Find boss/worker event group
|
// Find boss/worker event group
|
||||||
{
|
{
|
||||||
if (IOUring.isAvailable()) {
|
if (Epoll.isAvailable()) {
|
||||||
boss = new IOUringEventLoopGroup(2);
|
|
||||||
worker = new IOUringEventLoopGroup(workerThreadCount);
|
|
||||||
|
|
||||||
channel = IOUringServerSocketChannel.class;
|
|
||||||
|
|
||||||
LOGGER.info("Using io_uring");
|
|
||||||
} else if (Epoll.isAvailable()) {
|
|
||||||
boss = new EpollEventLoopGroup(2);
|
boss = new EpollEventLoopGroup(2);
|
||||||
worker = new EpollEventLoopGroup(workerThreadCount);
|
worker = new EpollEventLoopGroup(workerThreadCount);
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package net.minestom.server.scoreboard;
|
package net.minestom.server.scoreboard;
|
||||||
|
|
||||||
import com.google.common.collect.MapMaker;
|
|
||||||
import net.kyori.adventure.identity.Identity;
|
import net.kyori.adventure.identity.Identity;
|
||||||
import net.kyori.adventure.pointer.Pointers;
|
import net.kyori.adventure.pointer.Pointers;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
@ -22,6 +21,7 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.CopyOnWriteArraySet;
|
import java.util.concurrent.CopyOnWriteArraySet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -72,7 +72,7 @@ public class Team implements PacketGroupingAudience {
|
|||||||
*/
|
*/
|
||||||
private Component suffix;
|
private Component suffix;
|
||||||
|
|
||||||
private final Set<Player> playerMembers = Collections.newSetFromMap(new MapMaker().weakKeys().makeMap());
|
private final Set<Player> playerMembers = ConcurrentHashMap.newKeySet();
|
||||||
private boolean isPlayerMembersUpToDate;
|
private boolean isPlayerMembersUpToDate;
|
||||||
|
|
||||||
// Adventure
|
// Adventure
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package net.minestom.server.tag;
|
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}.
|
* Represents an element which can read and write {@link Tag tags}.
|
||||||
*/
|
*/
|
||||||
@Beta
|
@ApiStatus.Experimental
|
||||||
public interface TagHandler extends TagReadable, TagWritable {
|
public interface TagHandler extends TagReadable, TagWritable {
|
||||||
}
|
}
|
||||||
|
@ -47,10 +47,6 @@ public final class MathUtils {
|
|||||||
return Direction.HORIZONTAL[directionIndex];
|
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) {
|
public static boolean isBetween(byte number, byte min, byte max) {
|
||||||
return number >= min && number <= max;
|
return number >= min && number <= max;
|
||||||
}
|
}
|
||||||
@ -84,11 +80,15 @@ public final class MathUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static int clamp(int value, int min, int max) {
|
public static int clamp(int value, int min, int max) {
|
||||||
if (value < min) {
|
return Math.min(Math.max(value, min), max);
|
||||||
return min;
|
|
||||||
} else {
|
|
||||||
return Math.min(value, 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) {
|
public static double mod(final double a, final double b) {
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package net.minestom.server.utils;
|
package net.minestom.server.utils;
|
||||||
|
|
||||||
import com.google.common.primitives.Doubles;
|
|
||||||
import net.minestom.server.MinecraftServer;
|
import net.minestom.server.MinecraftServer;
|
||||||
import net.minestom.server.utils.clone.PublicCloneable;
|
import net.minestom.server.utils.clone.PublicCloneable;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@ -167,7 +166,7 @@ public class Vector implements PublicCloneable<Vector> {
|
|||||||
* @return angle in radians
|
* @return angle in radians
|
||||||
*/
|
*/
|
||||||
public float angle(@NotNull Vector other) {
|
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);
|
return (float) Math.acos(dot);
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package net.minestom.server.utils.cache;
|
package net.minestom.server.utils.cache;
|
||||||
|
|
||||||
import com.google.common.cache.Cache;
|
import com.github.benmanes.caffeine.cache.Cache;
|
||||||
import com.google.common.cache.CacheBuilder;
|
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||||
import com.google.common.cache.RemovalListener;
|
import com.github.benmanes.caffeine.cache.RemovalListener;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@ -24,7 +24,7 @@ public class TemporaryCache<T> {
|
|||||||
* @param duration the time before considering an object unused
|
* @param duration the time before considering an object unused
|
||||||
*/
|
*/
|
||||||
public TemporaryCache(long duration, TimeUnit timeUnit, RemovalListener<UUID, T> removalListener) {
|
public TemporaryCache(long duration, TimeUnit timeUnit, RemovalListener<UUID, T> removalListener) {
|
||||||
this.cache = CacheBuilder.newBuilder()
|
this.cache = Caffeine.newBuilder()
|
||||||
.expireAfterWrite(duration, timeUnit)
|
.expireAfterWrite(duration, timeUnit)
|
||||||
.removalListener(removalListener)
|
.removalListener(removalListener)
|
||||||
.build();
|
.build();
|
||||||
|
@ -6,8 +6,10 @@ import java.util.concurrent.TimeUnit;
|
|||||||
|
|
||||||
public class TemporaryPacketCache extends TemporaryCache<TimedBuffer> {
|
public class TemporaryPacketCache extends TemporaryCache<TimedBuffer> {
|
||||||
public TemporaryPacketCache(long duration, TimeUnit timeUnit) {
|
public TemporaryPacketCache(long duration, TimeUnit timeUnit) {
|
||||||
super(duration, timeUnit, notification -> {
|
super(duration, timeUnit, (key, value, cause) -> {
|
||||||
final ByteBuf buffer = notification.getValue().getBuffer();
|
if (value == null)
|
||||||
|
return;
|
||||||
|
final ByteBuf buffer = value.getBuffer();
|
||||||
synchronized (buffer) {
|
synchronized (buffer) {
|
||||||
buffer.release();
|
buffer.release();
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package net.minestom.server.utils.location;
|
package net.minestom.server.utils.location;
|
||||||
|
|
||||||
import com.google.common.annotations.Beta;
|
|
||||||
import net.minestom.server.entity.Entity;
|
import net.minestom.server.entity.Entity;
|
||||||
import net.minestom.server.utils.Position;
|
import net.minestom.server.utils.Position;
|
||||||
|
import org.jetbrains.annotations.ApiStatus;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@ -31,7 +31,7 @@ public abstract class RelativeLocation<T> {
|
|||||||
*/
|
*/
|
||||||
public abstract T from(@Nullable Position position);
|
public abstract T from(@Nullable Position position);
|
||||||
|
|
||||||
@Beta
|
@ApiStatus.Experimental
|
||||||
public abstract T fromView(@Nullable Position position);
|
public abstract T fromView(@Nullable Position position);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -45,7 +45,7 @@ public abstract class RelativeLocation<T> {
|
|||||||
return from(entityPosition);
|
return from(entityPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Beta
|
@ApiStatus.Experimental
|
||||||
public T fromView(@Nullable Entity entity) {
|
public T fromView(@Nullable Entity entity) {
|
||||||
final Position entityPosition = entity != null ? entity.getPosition() : new Position();
|
final Position entityPosition = entity != null ? entity.getPosition() : new Position();
|
||||||
return fromView(entityPosition);
|
return fromView(entityPosition);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package net.minestom.server.utils.mojang;
|
package net.minestom.server.utils.mojang;
|
||||||
|
|
||||||
import com.google.common.cache.Cache;
|
import com.github.benmanes.caffeine.cache.Cache;
|
||||||
import com.google.common.cache.CacheBuilder;
|
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.google.gson.JsonParser;
|
import com.google.gson.JsonParser;
|
||||||
import net.minestom.server.MinecraftServer;
|
import net.minestom.server.MinecraftServer;
|
||||||
@ -17,12 +17,12 @@ import java.util.concurrent.TimeUnit;
|
|||||||
*/
|
*/
|
||||||
public final class MojangUtils {
|
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)
|
.expireAfterWrite(30, TimeUnit.SECONDS)
|
||||||
.softValues()
|
.softValues()
|
||||||
.build();
|
.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)
|
.expireAfterWrite(30, TimeUnit.SECONDS)
|
||||||
.softValues()
|
.softValues()
|
||||||
.build();
|
.build();
|
||||||
|
Loading…
Reference in New Issue
Block a user