From 2e1ae46d77e24f61cbd48148366119bc173f5ea1 Mon Sep 17 00:00:00 2001 From: Oth3r Date: Mon, 26 Aug 2024 14:38:21 -0500 Subject: [PATCH] fixed sit while seated causing sit entities to not be removed for the player --- src/main/java/one/oth3r/sit/utl/Logic.java | 20 +++++++++++++++++++ .../java/one/oth3r/sit/utl/LoopManager.java | 10 ++-------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/main/java/one/oth3r/sit/utl/Logic.java b/src/main/java/one/oth3r/sit/utl/Logic.java index f81c013..9875358 100644 --- a/src/main/java/one/oth3r/sit/utl/Logic.java +++ b/src/main/java/one/oth3r/sit/utl/Logic.java @@ -84,6 +84,26 @@ public class Logic { Utl.Entity.remove(entity); } + /** + * spawns a sit entity for the player, they HAVE TO BE in the spawn list + */ + public static void spawnEntity(ServerPlayerEntity player) { + // return if not in the list + if (Data.getSpawnList().get(player) == null) return; + + // if the player is already sitting on a sit entity, remove it before spawning a new one + if (FileData.getSitEntity(player) != null) Logic.removeEntity(player); + // get the new entity + DisplayEntity.TextDisplayEntity sitEntity = Data.getSpawnList().get(player); + // spawn and ride the entity + player.getServerWorld().spawnEntity(sitEntity); + player.startRiding(sitEntity); + // add the entity to the list + FileData.addSitEntity(player, sitEntity); + // remove the entity from the spawn list + Data.removeSpawnList(player); + } + /** * checks if the player should still be sitting, e.g. the block was destroyed ect. */ diff --git a/src/main/java/one/oth3r/sit/utl/LoopManager.java b/src/main/java/one/oth3r/sit/utl/LoopManager.java index db4b12c..55bb0a3 100644 --- a/src/main/java/one/oth3r/sit/utl/LoopManager.java +++ b/src/main/java/one/oth3r/sit/utl/LoopManager.java @@ -51,16 +51,10 @@ public class LoopManager { } } + // spawn entities for everyone in the spawn list HashMap spawnList = Data.getSpawnList(); for (ServerPlayerEntity player : spawnList.keySet()) { - DisplayEntity.TextDisplayEntity sitEntity = spawnList.get(player); - - player.getServerWorld().spawnEntity(sitEntity); - player.startRiding(sitEntity); - // add the entity to the list - FileData.addSitEntity(player, sitEntity); - // remove the entity from the list - Data.removeSpawnList(player); + Logic.spawnEntity(player); } } }