mirror of
https://github.com/Oth3r/Sit.git
synced 2025-09-20 00:13:21 +02:00
move entity spawning to the server loop to fix C2ME crash
move checkplayers to Data from FileData
This commit is contained in:
parent
9eeb379dd9
commit
757ee9668a
5 changed files with 56 additions and 26 deletions
|
@ -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<ServerPlayerEntity, Integer> 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<ServerPlayerEntity, Integer> 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
|
||||
|
|
|
@ -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<ServerPlayerEntity, Integer> 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<ServerPlayerEntity, Integer> 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<ServerPlayerEntity, DisplayEntity.TextDisplayEntity> 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<ServerPlayerEntity, DisplayEntity.TextDisplayEntity> getSpawnList() {
|
||||
return new HashMap<>(spawnList);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) -> {
|
||||
|
|
|
@ -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<ServerPlayerEntity, Integer> checkPlayers = FileData.getCheckPlayers();
|
||||
HashMap<ServerPlayerEntity, Integer> 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<ServerPlayerEntity, DisplayEntity.TextDisplayEntity> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue