mirror of
https://github.com/Melledy/Grasscutter.git
synced 2024-11-22 18:56:15 +00:00
Deregister empty scenes if a player leaves them
This commit is contained in:
parent
c65443f422
commit
dd8d1752ed
@ -117,6 +117,7 @@ public class GenshinScene {
|
||||
}
|
||||
|
||||
public void removePlayer(GenshinPlayer player) {
|
||||
// Remove player from scene
|
||||
getPlayers().remove(player);
|
||||
player.setScene(null);
|
||||
|
||||
@ -127,6 +128,11 @@ public class GenshinScene {
|
||||
for (EntityGadget gadget : player.getTeamManager().getGadgets()) {
|
||||
this.removeEntity(gadget);
|
||||
}
|
||||
|
||||
// Deregister scene if not in use
|
||||
if (this.getEntities().size() <= 0) {
|
||||
this.getWorld().deregisterScene(this);
|
||||
}
|
||||
}
|
||||
|
||||
private void setupPlayerAvatars(GenshinPlayer player) {
|
||||
|
@ -111,7 +111,7 @@ public class World implements Iterable<GenshinPlayer> {
|
||||
SceneData sceneData = GenshinData.getSceneDataMap().get(sceneId);
|
||||
if (sceneData != null) {
|
||||
scene = new GenshinScene(this, sceneData);
|
||||
this.getScenes().put(sceneId, scene);
|
||||
this.registerScene(scene);
|
||||
return scene;
|
||||
}
|
||||
|
||||
@ -198,6 +198,14 @@ public class World implements Iterable<GenshinPlayer> {
|
||||
}
|
||||
}
|
||||
|
||||
public void registerScene(GenshinScene scene) {
|
||||
this.getScenes().put(scene.getId(), scene);
|
||||
}
|
||||
|
||||
public void deregisterScene(GenshinScene scene) {
|
||||
this.getScenes().remove(scene.getId());
|
||||
}
|
||||
|
||||
public boolean transferPlayerToScene(GenshinPlayer player, int sceneId, Position pos) {
|
||||
if (player.getScene().getId() == sceneId || GenshinData.getSceneDataMap().get(sceneId) == null) {
|
||||
return false;
|
||||
|
Loading…
Reference in New Issue
Block a user