mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-27 11:38:03 +01:00
Use Guava to initialize concurrent linked queues
This commit is contained in:
parent
fec23a9783
commit
42cedf3fbf
@ -1,5 +1,6 @@
|
|||||||
package net.minestom.server;
|
package net.minestom.server;
|
||||||
|
|
||||||
|
import com.google.common.collect.Queues;
|
||||||
import net.minestom.server.entity.EntityManager;
|
import net.minestom.server.entity.EntityManager;
|
||||||
import net.minestom.server.instance.Instance;
|
import net.minestom.server.instance.Instance;
|
||||||
import net.minestom.server.instance.InstanceManager;
|
import net.minestom.server.instance.InstanceManager;
|
||||||
@ -9,7 +10,11 @@ import net.minestom.server.utils.validate.Check;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.*;
|
import java.util.Queue;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.Future;
|
||||||
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.function.LongConsumer;
|
import java.util.function.LongConsumer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -26,8 +31,8 @@ public final class UpdateManager {
|
|||||||
|
|
||||||
private ThreadProvider threadProvider;
|
private ThreadProvider threadProvider;
|
||||||
|
|
||||||
private final ConcurrentLinkedQueue<LongConsumer> tickStartCallbacks = new ConcurrentLinkedQueue<>();
|
private final Queue<LongConsumer> tickStartCallbacks = Queues.newConcurrentLinkedQueue();
|
||||||
private final ConcurrentLinkedQueue<LongConsumer> tickEndCallbacks = new ConcurrentLinkedQueue<>();
|
private final Queue<LongConsumer> tickEndCallbacks = Queues.newConcurrentLinkedQueue();
|
||||||
|
|
||||||
{
|
{
|
||||||
// DEFAULT THREAD PROVIDER
|
// DEFAULT THREAD PROVIDER
|
||||||
@ -106,7 +111,7 @@ public final class UpdateManager {
|
|||||||
* @param callbacks the callbacks to execute
|
* @param callbacks the callbacks to execute
|
||||||
* @param value the value to give to the consumers
|
* @param value the value to give to the consumers
|
||||||
*/
|
*/
|
||||||
private void doTickCallback(ConcurrentLinkedQueue<LongConsumer> callbacks, long value) {
|
private void doTickCallback(Queue<LongConsumer> callbacks, long value) {
|
||||||
if (!callbacks.isEmpty()) {
|
if (!callbacks.isEmpty()) {
|
||||||
LongConsumer callback;
|
LongConsumer callback;
|
||||||
while ((callback = callbacks.poll()) != null) {
|
while ((callback = callbacks.poll()) != null) {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package net.minestom.server.entity;
|
package net.minestom.server.entity;
|
||||||
|
|
||||||
|
import com.google.common.collect.Queues;
|
||||||
import net.minestom.server.MinecraftServer;
|
import net.minestom.server.MinecraftServer;
|
||||||
import net.minestom.server.Viewable;
|
import net.minestom.server.Viewable;
|
||||||
import net.minestom.server.chat.ColoredText;
|
import net.minestom.server.chat.ColoredText;
|
||||||
@ -40,7 +41,6 @@ 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.CopyOnWriteArraySet;
|
import java.util.concurrent.CopyOnWriteArraySet;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
@ -132,7 +132,7 @@ public abstract class Entity implements Viewable, EventHandler, DataContainer, P
|
|||||||
protected Pose pose = Pose.STANDING;
|
protected Pose pose = Pose.STANDING;
|
||||||
|
|
||||||
// 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 ConcurrentLinkedQueue<Consumer<Entity>> nextTick = new ConcurrentLinkedQueue<>();
|
protected final Queue<Consumer<Entity>> nextTick = Queues.newConcurrentLinkedQueue();
|
||||||
|
|
||||||
// Tick related
|
// Tick related
|
||||||
private long ticks;
|
private long ticks;
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package net.minestom.server.entity;
|
package net.minestom.server.entity;
|
||||||
|
|
||||||
|
import com.google.common.collect.Queues;
|
||||||
import net.minestom.server.MinecraftServer;
|
import net.minestom.server.MinecraftServer;
|
||||||
import net.minestom.server.chat.ChatColor;
|
import net.minestom.server.chat.ChatColor;
|
||||||
import net.minestom.server.chat.ColoredText;
|
import net.minestom.server.chat.ColoredText;
|
||||||
@ -11,8 +12,8 @@ import net.minestom.server.network.packet.server.play.KeepAlivePacket;
|
|||||||
import net.minestom.server.utils.validate.Check;
|
import net.minestom.server.utils.validate.Check;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.Queue;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public final class EntityManager {
|
public final class EntityManager {
|
||||||
@ -23,7 +24,7 @@ public final class EntityManager {
|
|||||||
private static final long KEEP_ALIVE_KICK = 30_000;
|
private static final long KEEP_ALIVE_KICK = 30_000;
|
||||||
private static final ColoredText TIMEOUT_TEXT = ColoredText.of(ChatColor.RED + "Timeout");
|
private static final ColoredText TIMEOUT_TEXT = ColoredText.of(ChatColor.RED + "Timeout");
|
||||||
|
|
||||||
private final ConcurrentLinkedQueue<Player> waitingPlayers = new ConcurrentLinkedQueue<>();
|
private final Queue<Player> waitingPlayers = Queues.newConcurrentLinkedQueue();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Connects waiting players.
|
* Connects waiting players.
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package net.minestom.server.entity;
|
package net.minestom.server.entity;
|
||||||
|
|
||||||
|
import com.google.common.collect.Queues;
|
||||||
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;
|
||||||
@ -65,7 +66,6 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
|
||||||
import java.util.concurrent.CopyOnWriteArraySet;
|
import java.util.concurrent.CopyOnWriteArraySet;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
@ -134,7 +134,7 @@ public class Player extends LivingEntity implements CommandSender {
|
|||||||
private final AtomicInteger teleportId = new AtomicInteger();
|
private final AtomicInteger teleportId = new AtomicInteger();
|
||||||
|
|
||||||
protected boolean onGround;
|
protected boolean onGround;
|
||||||
private final ConcurrentLinkedQueue<ClientPlayPacket> packets = new ConcurrentLinkedQueue<>();
|
private final Queue<ClientPlayPacket> packets = Queues.newConcurrentLinkedQueue();
|
||||||
private final boolean levelFlat;
|
private final boolean levelFlat;
|
||||||
private final PlayerSettings settings;
|
private final PlayerSettings settings;
|
||||||
private float exp;
|
private float exp;
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package net.minestom.server.instance;
|
package net.minestom.server.instance;
|
||||||
|
|
||||||
|
import com.google.common.collect.Queues;
|
||||||
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
|
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
|
||||||
import it.unimi.dsi.fastutil.longs.Long2ObjectMaps;
|
import it.unimi.dsi.fastutil.longs.Long2ObjectMaps;
|
||||||
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
|
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
|
||||||
@ -39,7 +40,6 @@ 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.CopyOnWriteArraySet;
|
import java.util.concurrent.CopyOnWriteArraySet;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
@ -93,7 +93,7 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
|
|||||||
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 ConcurrentLinkedQueue<Consumer<Instance>> nextTick = new ConcurrentLinkedQueue<>();
|
protected final Queue<Consumer<Instance>> nextTick = Queues.newConcurrentLinkedQueue();
|
||||||
|
|
||||||
// instance custom data
|
// instance custom data
|
||||||
private Data data;
|
private Data data;
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package net.minestom.server.scoreboard;
|
package net.minestom.server.scoreboard;
|
||||||
|
|
||||||
|
import com.google.common.collect.Queues;
|
||||||
import it.unimi.dsi.fastutil.ints.IntLinkedOpenHashSet;
|
import it.unimi.dsi.fastutil.ints.IntLinkedOpenHashSet;
|
||||||
import net.minestom.server.chat.ChatParser;
|
import net.minestom.server.chat.ChatParser;
|
||||||
import net.minestom.server.chat.ColoredText;
|
import net.minestom.server.chat.ColoredText;
|
||||||
@ -13,8 +14,8 @@ import net.minestom.server.utils.validate.Check;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.Queue;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
|
||||||
import java.util.concurrent.CopyOnWriteArraySet;
|
import java.util.concurrent.CopyOnWriteArraySet;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
@ -45,7 +46,7 @@ public class Sidebar implements Scoreboard {
|
|||||||
|
|
||||||
private final Set<Player> viewers = new CopyOnWriteArraySet<>();
|
private final Set<Player> viewers = new CopyOnWriteArraySet<>();
|
||||||
|
|
||||||
private final ConcurrentLinkedQueue<ScoreboardLine> lines = new ConcurrentLinkedQueue<>();
|
private final Queue<ScoreboardLine> lines = Queues.newConcurrentLinkedQueue();
|
||||||
private final IntLinkedOpenHashSet availableColors = new IntLinkedOpenHashSet();
|
private final IntLinkedOpenHashSet availableColors = new IntLinkedOpenHashSet();
|
||||||
|
|
||||||
private final String objectiveName;
|
private final String objectiveName;
|
||||||
|
Loading…
Reference in New Issue
Block a user