diff --git a/src/main/java/net/minestom/server/UpdateManager.java b/src/main/java/net/minestom/server/UpdateManager.java index 7993531d4..553f5f3ba 100644 --- a/src/main/java/net/minestom/server/UpdateManager.java +++ b/src/main/java/net/minestom/server/UpdateManager.java @@ -8,6 +8,7 @@ import net.minestom.server.entity.acquirable.Acquisition; import net.minestom.server.monitoring.TickMonitor; import net.minestom.server.network.ConnectionManager; import net.minestom.server.network.player.NettyPlayerConnection; +import net.minestom.server.thread.PerChunkThreadProvider; import net.minestom.server.thread.PerInstanceThreadProvider; import net.minestom.server.thread.SingleThreadProvider; import net.minestom.server.thread.ThreadProvider; @@ -42,7 +43,7 @@ public final class UpdateManager { // DEFAULT THREAD PROVIDER threadProvider = new PerInstanceThreadProvider(); //threadProvider = new PerChunkThreadProvider(); - threadProvider = new SingleThreadProvider(); + //threadProvider = new SingleThreadProvider(); } /** diff --git a/src/main/java/net/minestom/server/entity/Player.java b/src/main/java/net/minestom/server/entity/Player.java index 4733b0961..250136a42 100644 --- a/src/main/java/net/minestom/server/entity/Player.java +++ b/src/main/java/net/minestom/server/entity/Player.java @@ -326,25 +326,12 @@ public class Player extends LivingEntity implements CommandSender, Localizable, } //System.out.println(getAcquiredElement().getHandler().getBatchThread()); - /*Collection> players = new ArrayList<>(); - if (username.equals("TheMode911")) - for (Player p1 : MinecraftServer.getConnectionManager().getOnlinePlayers()) { + //if (username.equals("TheMode911")) + /*for (Player p1 : MinecraftServer.getConnectionManager().getOnlinePlayers()) { //players.add(p1.getAcquiredElement()); - p1.getAcquiredElement().acquire(o -> { - //System.out.println(getUsername()+": "+o+" "+getAliveTicks()); - for (Player p2 : MinecraftServer.getConnectionManager().getOnlinePlayers()) - p2.getAcquiredElement().acquire(o2 -> { - //System.out.println(getAcquiredElement().getHandler().getBatchThread().monitor.isOccupiedByCurrentThread()); - }); + p1.getAcquirable().acquire(o -> { }); - } - - AcquirableCollection players1 = new AcquirableCollection<>(players); - players1.forEach(player -> { - players1.forEach(player2 -> { - - }); - });*/ + }*/ super.update(time); // Super update (item pickup/fire management) diff --git a/src/main/java/net/minestom/server/entity/acquirable/AcquirableEntity.java b/src/main/java/net/minestom/server/entity/acquirable/AcquirableEntity.java index d0c11897e..e6fb4e2ee 100644 --- a/src/main/java/net/minestom/server/entity/acquirable/AcquirableEntity.java +++ b/src/main/java/net/minestom/server/entity/acquirable/AcquirableEntity.java @@ -3,6 +3,7 @@ package net.minestom.server.entity.acquirable; import net.minestom.server.entity.Entity; import net.minestom.server.thread.BatchThread; import net.minestom.server.thread.ThreadProvider; +import net.minestom.server.utils.consumer.EntityConsumer; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -58,7 +59,7 @@ public class AcquirableEntity { * * @param consumer the acquisition consumer */ - public void acquire(@NotNull Consumer<@NotNull Entity> consumer) { + public void acquire(@NotNull EntityConsumer consumer) { final Thread currentThread = Thread.currentThread(); final BatchThread elementThread = getHandler().getBatchThread(); Acquisition.acquire(currentThread, elementThread, () -> consumer.accept(unwrap())); @@ -72,7 +73,7 @@ public class AcquirableEntity { * @return true if the acquisition happened without synchronization, * false otherwise */ - public boolean tryAcquire(@NotNull Consumer<@NotNull Entity> consumer) { + public boolean tryAcquire(@NotNull EntityConsumer consumer) { final Thread currentThread = Thread.currentThread(); final BatchThread elementThread = getHandler().getBatchThread(); if (Objects.equals(currentThread, elementThread)) { @@ -104,8 +105,8 @@ public class AcquirableEntity { * * @param consumer the consumer of the acquired object */ - public void scheduledAcquire(@NotNull Consumer consumer) { - Acquisition.scheduledAcquireRequest(this, consumer); + public void scheduledAcquire(@NotNull EntityConsumer consumer) { + Acquisition.scheduledAcquireRequest(this, (Consumer) consumer); } /** diff --git a/src/main/java/net/minestom/server/entity/acquirable/AcquirablePlayer.java b/src/main/java/net/minestom/server/entity/acquirable/AcquirablePlayer.java new file mode 100644 index 000000000..7af1fc20f --- /dev/null +++ b/src/main/java/net/minestom/server/entity/acquirable/AcquirablePlayer.java @@ -0,0 +1,21 @@ +package net.minestom.server.entity.acquirable; + +import net.minestom.server.entity.Entity; +import net.minestom.server.entity.Player; +import net.minestom.server.utils.consumer.PlayerConsumer; +import org.jetbrains.annotations.NotNull; + +public class AcquirablePlayer extends AcquirableEntity { + public AcquirablePlayer(@NotNull Entity entity) { + super(entity); + } + + public void acquire(@NotNull PlayerConsumer consumer) { + super.acquire(consumer); + } + + @Override + public @NotNull Player unwrap() { + return (Player) super.unwrap(); + } +} diff --git a/src/main/java/net/minestom/server/utils/consumer/EntityConsumer.java b/src/main/java/net/minestom/server/utils/consumer/EntityConsumer.java new file mode 100644 index 000000000..9fe994761 --- /dev/null +++ b/src/main/java/net/minestom/server/utils/consumer/EntityConsumer.java @@ -0,0 +1,8 @@ +package net.minestom.server.utils.consumer; + +import net.minestom.server.entity.Entity; + +@FunctionalInterface +public interface EntityConsumer { + void accept(Entity entity); +} diff --git a/src/main/java/net/minestom/server/utils/consumer/PlayerConsumer.java b/src/main/java/net/minestom/server/utils/consumer/PlayerConsumer.java new file mode 100644 index 000000000..c7228af88 --- /dev/null +++ b/src/main/java/net/minestom/server/utils/consumer/PlayerConsumer.java @@ -0,0 +1,7 @@ +package net.minestom.server.utils.consumer; + +import net.minestom.server.entity.Player; + +public interface PlayerConsumer extends EntityConsumer { + void accept(Player player); +}