diff --git a/src/main/java/net/minestom/server/UpdateManager.java b/src/main/java/net/minestom/server/UpdateManager.java index 37fc0ae7e..419d0d8eb 100644 --- a/src/main/java/net/minestom/server/UpdateManager.java +++ b/src/main/java/net/minestom/server/UpdateManager.java @@ -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 tickStartCallbacks = Queues.newConcurrentLinkedQueue(); - private final Queue tickEndCallbacks = Queues.newConcurrentLinkedQueue(); + private final Queue tickStartCallbacks = new ConcurrentLinkedQueue<>(); + private final Queue tickEndCallbacks = new ConcurrentLinkedQueue<>(); private final List> tickMonitors = new CopyOnWriteArrayList<>(); /** diff --git a/src/main/java/net/minestom/server/entity/Entity.java b/src/main/java/net/minestom/server/entity/Entity.java index 68966e023..ddd0a833a 100644 --- a/src/main/java/net/minestom/server/entity/Entity.java +++ b/src/main/java/net/minestom/server/entity/Entity.java @@ -1,6 +1,5 @@ package net.minestom.server.entity; -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; @@ -53,6 +52,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; @@ -127,7 +127,7 @@ public class Entity implements Viewable, Tickable, EventHandler, Da private final List effects = new CopyOnWriteArrayList<>(); // list of scheduled tasks to be executed during the next entity tick - protected final Queue> nextTick = Queues.newConcurrentLinkedQueue(); + protected final Queue> nextTick = new ConcurrentLinkedQueue<>(); // Tick related private long ticks; diff --git a/src/main/java/net/minestom/server/entity/Player.java b/src/main/java/net/minestom/server/entity/Player.java index 48f36afbd..873decdb6 100644 --- a/src/main/java/net/minestom/server/entity/Player.java +++ b/src/main/java/net/minestom/server/entity/Player.java @@ -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; @@ -87,6 +86,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; @@ -119,7 +119,7 @@ public class Player extends LivingEntity implements CommandSender, Localizable, private final AtomicInteger teleportId = new AtomicInteger(); private int receivedTeleportId; - private final Queue packets = Queues.newConcurrentLinkedQueue(); + private final Queue packets = new ConcurrentLinkedQueue<>(); private final boolean levelFlat; private final PlayerSettings settings; private float exp; diff --git a/src/main/java/net/minestom/server/entity/ai/goal/DoNothingGoal.java b/src/main/java/net/minestom/server/entity/ai/goal/DoNothingGoal.java index 05afd09c6..aed3f1b92 100644 --- a/src/main/java/net/minestom/server/entity/ai/goal/DoNothingGoal.java +++ b/src/main/java/net/minestom/server/entity/ai/goal/DoNothingGoal.java @@ -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 diff --git a/src/main/java/net/minestom/server/instance/Instance.java b/src/main/java/net/minestom/server/instance/Instance.java index 0015a33a2..d0f9352b3 100644 --- a/src/main/java/net/minestom/server/instance/Instance.java +++ b/src/main/java/net/minestom/server/instance/Instance.java @@ -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; @@ -47,6 +46,7 @@ import org.jetbrains.annotations.Nullable; import java.util.*; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentLinkedQueue; import java.util.function.Consumer; /** @@ -98,7 +98,7 @@ public abstract class Instance implements BlockModifier, Tickable, EventHandler< protected UUID uniqueId; // list of scheduled tasks to be executed during the next instance tick - protected final Queue> nextTick = Queues.newConcurrentLinkedQueue(); + protected final Queue> nextTick = new ConcurrentLinkedQueue<>(); // instance custom data private Data data; diff --git a/src/main/java/net/minestom/server/scoreboard/Team.java b/src/main/java/net/minestom/server/scoreboard/Team.java index f316c44b8..aa6cc59fa 100644 --- a/src/main/java/net/minestom/server/scoreboard/Team.java +++ b/src/main/java/net/minestom/server/scoreboard/Team.java @@ -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 playerMembers = Collections.newSetFromMap(new MapMaker().weakKeys().makeMap()); + private final Set playerMembers = ConcurrentHashMap.newKeySet(); private boolean isPlayerMembersUpToDate; // Adventure diff --git a/src/main/java/net/minestom/server/utils/MathUtils.java b/src/main/java/net/minestom/server/utils/MathUtils.java index 788ec6a20..3012f80b1 100644 --- a/src/main/java/net/minestom/server/utils/MathUtils.java +++ b/src/main/java/net/minestom/server/utils/MathUtils.java @@ -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) { diff --git a/src/main/java/net/minestom/server/utils/Vector.java b/src/main/java/net/minestom/server/utils/Vector.java index c77d69219..1833b8a7b 100644 --- a/src/main/java/net/minestom/server/utils/Vector.java +++ b/src/main/java/net/minestom/server/utils/Vector.java @@ -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 { * @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); }