mirror of
https://github.com/Minestom/Minestom.git
synced 2025-03-02 11:21:15 +01:00
Added Acquirable#currentEntities
This commit is contained in:
parent
11b1bbea2e
commit
bd3e4e2f0a
@ -561,7 +561,7 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
if(isRemoved())
|
||||
if (isRemoved())
|
||||
return;
|
||||
|
||||
callEvent(PlayerDisconnectEvent.class, new PlayerDisconnectEvent(this));
|
||||
|
@ -1,10 +1,13 @@
|
||||
package net.minestom.server.lock;
|
||||
|
||||
import net.minestom.server.entity.Entity;
|
||||
import net.minestom.server.instance.Chunk;
|
||||
import net.minestom.server.thread.BatchThread;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Phaser;
|
||||
import java.util.function.Consumer;
|
||||
@ -20,6 +23,17 @@ import java.util.function.Consumer;
|
||||
*/
|
||||
public interface Acquirable<T> {
|
||||
|
||||
ThreadLocal<Collection<Entity>> CURRENT_ENTITIES = ThreadLocal.withInitial(Collections::emptyList);
|
||||
|
||||
static @NotNull Collection<@NotNull Entity> currentEntities() {
|
||||
return CURRENT_ENTITIES.get();
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
static void refreshEntities(@NotNull Collection<@NotNull Entity> entities) {
|
||||
CURRENT_ENTITIES.set(entities);
|
||||
}
|
||||
|
||||
/**
|
||||
* Blocks the current thread until 'this' can be acquired,
|
||||
* and execute {@code consumer} as a callback with the acquired object.
|
||||
|
@ -10,6 +10,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Used to link chunks into multiple groups.
|
||||
@ -97,6 +98,11 @@ public abstract class ThreadProvider {
|
||||
|
||||
// Execute tick
|
||||
thread.getMainRunnable().startTick(countDownLatch, () -> {
|
||||
final var entitiesList = chunkEntries.stream().map(chunkEntry -> chunkEntry.entities).collect(Collectors.toList());
|
||||
final var entities = entitiesList.stream()
|
||||
.flatMap(Collection::stream)
|
||||
.collect(Collectors.toList());
|
||||
Acquirable.refreshEntities(Collections.unmodifiableList(entities));
|
||||
chunkEntries.forEach(chunkEntry -> {
|
||||
chunkEntry.chunk.tick(time);
|
||||
chunkEntry.entities.forEach(entity -> {
|
||||
|
Loading…
Reference in New Issue
Block a user