forked from virt-mirrors/Sit
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);
|
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
|
* loads all config files to memory
|
||||||
* @param tryLegacy try to load the legacy file, usually only used on server startup
|
* @param tryLegacy try to load the legacy file, usually only used on server startup
|
||||||
|
|
|
@ -1,10 +1,14 @@
|
||||||
package one.oth3r.sit.utl;
|
package one.oth3r.sit.utl;
|
||||||
|
|
||||||
import net.fabricmc.loader.api.FabricLoader;
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
|
import net.minecraft.entity.decoration.DisplayEntity;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
public class Data {
|
public class Data {
|
||||||
public static final String MOD_ID = "sit-oth3r";
|
public static final String MOD_ID = "sit-oth3r";
|
||||||
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
|
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
|
||||||
|
@ -61,4 +65,38 @@ public class Data {
|
||||||
public static void setSupportedServer(boolean supportedServer) {
|
public static void setSupportedServer(boolean supportedServer) {
|
||||||
Data.supportedServer = 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
|
// PLAYER JOIN
|
||||||
ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> {
|
ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> {
|
||||||
FileData.setPlayerSetting(handler.player, FileData.getSittingConfig());
|
FileData.setPlayerSetting(handler.player, FileData.getSittingConfig());
|
||||||
FileData.setCheckPlayer(handler.player, 5);
|
Data.setCheckPlayer(handler.player, 5);
|
||||||
});
|
});
|
||||||
|
|
||||||
ServerPlayConnectionEvents.DISCONNECT.register((handler, server) -> {
|
ServerPlayConnectionEvents.DISCONNECT.register((handler, server) -> {
|
||||||
|
|
|
@ -30,13 +30,13 @@ public class LoopManager {
|
||||||
|
|
||||||
// get the player's sit entity when they join
|
// 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)
|
// 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()) {
|
for (ServerPlayerEntity player : checkPlayers.keySet()) {
|
||||||
Integer time = checkPlayers.get(player);
|
Integer time = checkPlayers.get(player);
|
||||||
// tick down or remove the player if at the end
|
// tick down or remove the player if at the end
|
||||||
time -= 1;
|
time -= 1;
|
||||||
if (time <= 0) FileData.removeCheckPlayer(player);
|
if (time <= 0) Data.removeCheckPlayer(player);
|
||||||
else FileData.setCheckPlayer(player, time);
|
else Data.setCheckPlayer(player, time);
|
||||||
|
|
||||||
if (player.getVehicle() != null) {
|
if (player.getVehicle() != null) {
|
||||||
Entity entity = player.getVehicle();
|
Entity entity = player.getVehicle();
|
||||||
|
@ -46,9 +46,21 @@ public class LoopManager {
|
||||||
// check if the player is still allowed to sit
|
// check if the player is still allowed to sit
|
||||||
Logic.checkSittingValidity(player);
|
Logic.checkSittingValidity(player);
|
||||||
// remove the player from the check
|
// 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
|
* spawns the entity and make the player sit on it
|
||||||
*/
|
*/
|
||||||
public static void spawnSit(ServerPlayerEntity player, DisplayEntity.TextDisplayEntity entity) {
|
public static void spawnSit(ServerPlayerEntity player, DisplayEntity.TextDisplayEntity entity) {
|
||||||
player.getServerWorld().spawnEntity(entity);
|
Data.setSpawnList(player, entity);
|
||||||
player.startRiding(entity);
|
|
||||||
// add the entity to the list
|
|
||||||
FileData.addSitEntity(player, entity);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue