SteamWar/SpigotCore
Archiviert
13
0

Merge pull request 'Add option to hide REntities' (#252) from hideEntities into master
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Reviewed-on: #252
Dieser Commit ist enthalten in:
Lixfel 2023-12-30 12:08:34 +01:00
Commit 62796040b0
2 geänderte Dateien mit 26 neuen und 4 gelöschten Zeilen

Datei anzeigen

@ -59,6 +59,8 @@ public class REntity {
private byte pitch;
private byte headYaw;
@Getter
private boolean hidden;
@Getter
private boolean invisible;
@Getter
@ -104,6 +106,19 @@ public class REntity {
this.objectData = objectData;
}
public void hide(boolean hide) {
if(hidden == hide)
return;
if(hide) {
despawn(packet -> server.updateEntity(this, packet));
hidden = true;
} else {
hidden = false;
spawn(packet -> server.updateEntity(this, packet));
}
}
public void move(Location location) {
move(location.getX(), location.getY(), location.getZ(), location.getPitch(), location.getYaw(), rotToByte(location.getYaw()));
}

Datei anzeigen

@ -138,7 +138,8 @@ public class REntityServer implements Listener {
if(fromId == toId)
return;
onMissing(players.get(fromId), players.get(toId), entity::despawn);
if(!entity.isHidden())
onMissing(players.get(fromId), players.get(toId), entity::despawn);
removeEntityFromChunk(entity);
}
@ -149,10 +150,14 @@ public class REntityServer implements Listener {
return;
addEntityToChunk(entity);
onMissing(players.get(toId), players.get(fromId), entity::spawn);
if(!entity.isHidden())
onMissing(players.get(toId), players.get(fromId), entity::spawn);
}
void updateEntity(REntity entity, Object packet) {
if(entity.isHidden())
return;
for(Player player : players.getOrDefault(entityToId(entity), emptyPlayers)) {
TinyProtocol.instance.sendPacket(player, packet);
}
@ -260,7 +265,8 @@ public class REntityServer implements Listener {
long id = chunkToId(x, z);
players.computeIfAbsent(id, i -> new HashSet<>()).add(player);
for(REntity entity : entities.getOrDefault(id, emptyEntities)) {
entity.spawn(packet -> TinyProtocol.instance.sendPacket(player, packet));
if(!entity.isHidden())
entity.spawn(packet -> TinyProtocol.instance.sendPacket(player, packet));
}
}
@ -273,7 +279,8 @@ public class REntityServer implements Listener {
players.remove(id);
for(REntity entity : entities.getOrDefault(id, emptyEntities)) {
entity.despawn(packet -> TinyProtocol.instance.sendPacket(player, packet));
if(!entity.isHidden())
entity.despawn(packet -> TinyProtocol.instance.sendPacket(player, packet));
}
}