mirror of
https://github.com/Minestom/Minestom.git
synced 2024-11-08 11:50:36 +01:00
Add tests for manual viewer/viewable update
This commit is contained in:
parent
688ab31d79
commit
7634096bce
@ -6,6 +6,8 @@ import net.minestom.server.coordinate.Pos;
|
||||
import net.minestom.server.network.packet.server.play.SpawnLivingEntityPacket;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@ -113,6 +115,24 @@ public class EntityViewIntegrationTest {
|
||||
assertEquals(1, p2.getViewers().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void viewableRuleUpdate(Env env) {
|
||||
var instance = env.createFlatInstance();
|
||||
var p1 = env.createPlayer(instance, new Pos(0, 42, 0));
|
||||
|
||||
AtomicBoolean enabled = new AtomicBoolean(false);
|
||||
p1.updateViewableRule(player -> enabled.get());
|
||||
|
||||
var p2 = env.createPlayer(instance, new Pos(0, 42, 0));
|
||||
assertEquals(0, p1.getViewers().size());
|
||||
assertEquals(1, p2.getViewers().size());
|
||||
|
||||
enabled.set(true);
|
||||
p1.updateViewableRule();
|
||||
assertEquals(1, p1.getViewers().size());
|
||||
assertEquals(1, p2.getViewers().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void viewerRule(Env env) {
|
||||
var instance = env.createFlatInstance();
|
||||
@ -130,6 +150,23 @@ public class EntityViewIntegrationTest {
|
||||
assertEquals(0, p2.getViewers().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void viewerRuleUpdate(Env env) {
|
||||
var instance = env.createFlatInstance();
|
||||
var p1 = env.createPlayer(instance, new Pos(0, 42, 0));
|
||||
AtomicBoolean enabled = new AtomicBoolean(false);
|
||||
p1.updateViewerRule(player -> enabled.get());
|
||||
|
||||
var p2 = env.createPlayer(instance, new Pos(0, 42, 0));
|
||||
assertEquals(1, p1.getViewers().size());
|
||||
assertEquals(0, p2.getViewers().size());
|
||||
|
||||
enabled.set(true);
|
||||
p1.updateViewerRule();
|
||||
assertEquals(1, p1.getViewers().size());
|
||||
assertEquals(1, p2.getViewers().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void vehicle(Env env) {
|
||||
var instance = env.createFlatInstance();
|
||||
|
Loading…
Reference in New Issue
Block a user