move sitEntities list to Data from FileData

This commit is contained in:
Oth3r 2024-11-15 11:19:39 -06:00
commit 09f5e31544
6 changed files with 30 additions and 33 deletions

View file

@ -13,7 +13,6 @@ import net.minecraft.util.math.BlockPos;
import one.oth3r.sit.utl.Data; import one.oth3r.sit.utl.Data;
import one.oth3r.sit.utl.Logic; import one.oth3r.sit.utl.Logic;
import one.oth3r.sit.utl.Utl; import one.oth3r.sit.utl.Utl;
import one.oth3r.sit.file.FileData;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
@ -67,7 +66,7 @@ public class SitCommand {
} }
// if already sitting, ignore // if already sitting, ignore
if (FileData.getSitEntity(player) != null) return 1; if (Data.getSitEntity(player) != null) return 1;
// try to make the player sit // try to make the player sit
Logic.sit(player, pos, null); Logic.sit(player, pos, null);

View file

@ -1,6 +1,5 @@
package one.oth3r.sit.file; package one.oth3r.sit.file;
import net.minecraft.entity.decoration.DisplayEntity;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import one.oth3r.sit.utl.Data; import one.oth3r.sit.utl.Data;
import one.oth3r.sit.utl.Utl; import one.oth3r.sit.utl.Utl;
@ -57,27 +56,6 @@ public class FileData {
return playerSettings.getOrDefault(player, sittingConfig); return playerSettings.getOrDefault(player, sittingConfig);
} }
/**
* a list of every Sit! entity in the server, bound to the player
*/
private static final HashMap<ServerPlayerEntity, DisplayEntity.TextDisplayEntity> sitEntities = new HashMap<>();
public static void addSitEntity(ServerPlayerEntity player, DisplayEntity.TextDisplayEntity entity) {
sitEntities.put(player, entity);
}
public static void removeSitEntity(DisplayEntity.TextDisplayEntity entity) {
sitEntities.values().remove(entity);
}
public static DisplayEntity.TextDisplayEntity getSitEntity(ServerPlayerEntity player) {
return sitEntities.get(player);
}
public static HashMap<ServerPlayerEntity, DisplayEntity.TextDisplayEntity> getSitEntities() {
return new HashMap<>(sitEntities);
}
/** /**
* loads all config files to memory * loads all config files to memory
*/ */

View file

@ -101,4 +101,25 @@ public class Data {
public static HashMap<ServerPlayerEntity, DisplayEntity.TextDisplayEntity> getSpawnList() { public static HashMap<ServerPlayerEntity, DisplayEntity.TextDisplayEntity> getSpawnList() {
return new HashMap<>(spawnList); return new HashMap<>(spawnList);
} }
/**
* a list of every Sit! entity in the server, bound to the player
*/
private static final HashMap<ServerPlayerEntity, DisplayEntity.TextDisplayEntity> sitEntities = new HashMap<>();
public static void addSitEntity(ServerPlayerEntity player, DisplayEntity.TextDisplayEntity entity) {
sitEntities.put(player, entity);
}
public static void removeSitEntity(DisplayEntity.TextDisplayEntity entity) {
sitEntities.values().remove(entity);
}
public static DisplayEntity.TextDisplayEntity getSitEntity(ServerPlayerEntity player) {
return sitEntities.get(player);
}
public static HashMap<ServerPlayerEntity, DisplayEntity.TextDisplayEntity> getSitEntities() {
return new HashMap<>(sitEntities);
}
} }

View file

@ -20,7 +20,7 @@ public class Logic {
if (player.isSneaking()) return false; if (player.isSneaking()) return false;
// if sitting on a sit entity and sit while seated off, false // if sitting on a sit entity and sit while seated off, false
if (!FileData.getServerConfig().canSitWhileSeated() && FileData.getSitEntity(player) != null) return false; if (!FileData.getServerConfig().canSitWhileSeated() && Data.getSitEntity(player) != null) return false;
// if hit result isnt null (check the hands of the player) & the player hand checker returns false (can't sit with the items in the hand), quit // if hit result isnt null (check the hands of the player) & the player hand checker returns false (can't sit with the items in the hand), quit
if (hitResult != null) { if (hitResult != null) {
@ -78,7 +78,7 @@ public class Logic {
* removes the entity bound to the player from the game, using the player * removes the entity bound to the player from the game, using the player
*/ */
public static void removeEntity(ServerPlayerEntity player) { public static void removeEntity(ServerPlayerEntity player) {
DisplayEntity.TextDisplayEntity entity = FileData.getSitEntity(player); DisplayEntity.TextDisplayEntity entity = Data.getSitEntity(player);
// make sure the player has a sit entity bounded to them // make sure the player has a sit entity bounded to them
if (entity == null) return; if (entity == null) return;
@ -94,14 +94,14 @@ public class Logic {
if (Data.getSpawnList().get(player) == null) return; 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 the player is already sitting on a sit entity, remove it before spawning a new one
if (FileData.getSitEntity(player) != null) Logic.removeEntity(player); if (Data.getSitEntity(player) != null) Logic.removeEntity(player);
// get the new entity // get the new entity
DisplayEntity.TextDisplayEntity sitEntity = Data.getSpawnList().get(player); DisplayEntity.TextDisplayEntity sitEntity = Data.getSpawnList().get(player);
// spawn and ride the entity // spawn and ride the entity
player.getServerWorld().spawnEntity(sitEntity); player.getServerWorld().spawnEntity(sitEntity);
player.startRiding(sitEntity); player.startRiding(sitEntity);
// add the entity to the list // add the entity to the list
FileData.addSitEntity(player, sitEntity); Data.addSitEntity(player, sitEntity);
// remove the entity from the spawn list // remove the entity from the spawn list
Data.removeSpawnList(player); Data.removeSpawnList(player);
} }
@ -110,7 +110,7 @@ public class Logic {
* checks if the player should still be sitting, e.g. the block was destroyed ect. * checks if the player should still be sitting, e.g. the block was destroyed ect.
*/ */
public static void checkSittingValidity(ServerPlayerEntity player) { public static void checkSittingValidity(ServerPlayerEntity player) {
DisplayEntity.TextDisplayEntity entity = FileData.getSitEntity(player); DisplayEntity.TextDisplayEntity entity = Data.getSitEntity(player);
// make sure the player has a sit entity bounded to them // make sure the player has a sit entity bounded to them
if (entity == null) return; if (entity == null) return;

View file

@ -3,7 +3,6 @@ package one.oth3r.sit.utl;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.decoration.DisplayEntity; import net.minecraft.entity.decoration.DisplayEntity;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import one.oth3r.sit.file.FileData;
import java.util.HashMap; import java.util.HashMap;
@ -17,7 +16,7 @@ public class LoopManager {
time = 0; time = 0;
// check all sit entities to make sure their still valid // check all sit entities to make sure their still valid
HashMap<ServerPlayerEntity, DisplayEntity.TextDisplayEntity> entities = FileData.getSitEntities(); HashMap<ServerPlayerEntity, DisplayEntity.TextDisplayEntity> entities = Data.getSitEntities();
for (ServerPlayerEntity player : entities.keySet()) { for (ServerPlayerEntity player : entities.keySet()) {
DisplayEntity.TextDisplayEntity entity = entities.get(player); DisplayEntity.TextDisplayEntity entity = entities.get(player);
@ -41,7 +40,7 @@ public class LoopManager {
Entity entity = player.getVehicle(); Entity entity = player.getVehicle();
if (entity instanceof DisplayEntity.TextDisplayEntity tde && entity.getName().getString().equals(Data.ENTITY_NAME)) { if (entity instanceof DisplayEntity.TextDisplayEntity tde && entity.getName().getString().equals(Data.ENTITY_NAME)) {
// bind the entity to the player // bind the entity to the player
FileData.addSitEntity(player, tde); Data.addSitEntity(player, tde);
// 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

View file

@ -325,7 +325,7 @@ public class Utl {
// remove the entity // remove the entity
entity.setRemoved(net.minecraft.entity.Entity.RemovalReason.DISCARDED); entity.setRemoved(net.minecraft.entity.Entity.RemovalReason.DISCARDED);
// remove the entity from the data set if exists // remove the entity from the data set if exists
FileData.removeSitEntity(entity); Data.removeSitEntity(entity);
} }
/** /**