diff --git a/src/main/java/one/oth3r/sit/file/FileData.java b/src/main/java/one/oth3r/sit/file/FileData.java index 1eb86a5..9ffefd2 100644 --- a/src/main/java/one/oth3r/sit/file/FileData.java +++ b/src/main/java/one/oth3r/sit/file/FileData.java @@ -78,23 +78,6 @@ public class FileData { return new HashMap<>(sitEntities); } - /** - * a list of players who just joined, to check if they are mounted to a Sit! entity - */ - private static final HashMap checkPlayers = new HashMap<>(); - - public static void setCheckPlayer(ServerPlayerEntity player, Integer time) { - checkPlayers.put(player, time); - } - - public static void removeCheckPlayer(ServerPlayerEntity player) { - checkPlayers.remove(player); - } - - public static HashMap getCheckPlayers() { - return new HashMap<>(checkPlayers); - } - /** * loads all config files to memory * @param tryLegacy try to load the legacy file, usually only used on server startup diff --git a/src/main/java/one/oth3r/sit/utl/Data.java b/src/main/java/one/oth3r/sit/utl/Data.java index 09a8f17..524fd7f 100644 --- a/src/main/java/one/oth3r/sit/utl/Data.java +++ b/src/main/java/one/oth3r/sit/utl/Data.java @@ -1,10 +1,14 @@ package one.oth3r.sit.utl; import net.fabricmc.loader.api.FabricLoader; +import net.minecraft.entity.decoration.DisplayEntity; import net.minecraft.server.MinecraftServer; +import net.minecraft.server.network.ServerPlayerEntity; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.util.HashMap; + public class Data { public static final String MOD_ID = "sit-oth3r"; public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID); @@ -61,4 +65,38 @@ public class Data { public static void setSupportedServer(boolean supportedServer) { Data.supportedServer = supportedServer; } + + /** + * a list of players who just joined, to check if they are mounted to a Sit! entity + */ + private static final HashMap checkPlayers = new HashMap<>(); + + public static void setCheckPlayer(ServerPlayerEntity player, Integer time) { + checkPlayers.put(player, time); + } + + public static void removeCheckPlayer(ServerPlayerEntity player) { + checkPlayers.remove(player); + } + + public static HashMap getCheckPlayers() { + return new HashMap<>(checkPlayers); + } + + /** + * a list of players who just joined, to check if they are mounted to a Sit! entity + */ + private static final HashMap spawnList = new HashMap<>(); + + public static void setSpawnList(ServerPlayerEntity player, DisplayEntity.TextDisplayEntity entity) { + spawnList.put(player, entity); + } + + public static void removeSpawnList(ServerPlayerEntity player) { + spawnList.remove(player); + } + + public static HashMap getSpawnList() { + return new HashMap<>(spawnList); + } } diff --git a/src/main/java/one/oth3r/sit/utl/Events.java b/src/main/java/one/oth3r/sit/utl/Events.java index 90ac73a..8e1ba77 100644 --- a/src/main/java/one/oth3r/sit/utl/Events.java +++ b/src/main/java/one/oth3r/sit/utl/Events.java @@ -150,7 +150,7 @@ public class Events { // PLAYER JOIN ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> { FileData.setPlayerSetting(handler.player, FileData.getSittingConfig()); - FileData.setCheckPlayer(handler.player, 5); + Data.setCheckPlayer(handler.player, 5); }); ServerPlayConnectionEvents.DISCONNECT.register((handler, server) -> { diff --git a/src/main/java/one/oth3r/sit/utl/LoopManager.java b/src/main/java/one/oth3r/sit/utl/LoopManager.java index 5001207..db4b12c 100644 --- a/src/main/java/one/oth3r/sit/utl/LoopManager.java +++ b/src/main/java/one/oth3r/sit/utl/LoopManager.java @@ -30,13 +30,13 @@ public class LoopManager { // get the player's sit entity when they join // todo make it so it updates the sitting height and pos based on the block so if it changed while offline it still works (or if stair changes shape) - HashMap checkPlayers = FileData.getCheckPlayers(); + HashMap checkPlayers = Data.getCheckPlayers(); for (ServerPlayerEntity player : checkPlayers.keySet()) { Integer time = checkPlayers.get(player); // tick down or remove the player if at the end time -= 1; - if (time <= 0) FileData.removeCheckPlayer(player); - else FileData.setCheckPlayer(player, time); + if (time <= 0) Data.removeCheckPlayer(player); + else Data.setCheckPlayer(player, time); if (player.getVehicle() != null) { Entity entity = player.getVehicle(); @@ -46,10 +46,22 @@ public class LoopManager { // check if the player is still allowed to sit Logic.checkSittingValidity(player); // remove the player from the check - FileData.removeCheckPlayer(player); + Data.removeCheckPlayer(player); } } } + + 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); + } } } } diff --git a/src/main/java/one/oth3r/sit/utl/Utl.java b/src/main/java/one/oth3r/sit/utl/Utl.java index f070ca7..815500c 100644 --- a/src/main/java/one/oth3r/sit/utl/Utl.java +++ b/src/main/java/one/oth3r/sit/utl/Utl.java @@ -298,10 +298,7 @@ public class Utl { * spawns the entity and make the player sit on it */ public static void spawnSit(ServerPlayerEntity player, DisplayEntity.TextDisplayEntity entity) { - player.getServerWorld().spawnEntity(entity); - player.startRiding(entity); - // add the entity to the list - FileData.addSitEntity(player, entity); + Data.setSpawnList(player, entity); } /**