forked from virt-mirrors/Sit
move sitEntities list to Data from FileData
This commit is contained in:
parent
8f89a049f9
commit
09f5e31544
6 changed files with 30 additions and 33 deletions
|
@ -101,4 +101,25 @@ public class Data {
|
|||
public static HashMap<ServerPlayerEntity, DisplayEntity.TextDisplayEntity> getSpawnList() {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ public class Logic {
|
|||
if (player.isSneaking()) return 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 (hitResult != null) {
|
||||
|
@ -78,7 +78,7 @@ public class Logic {
|
|||
* removes the entity bound to the player from the game, using the 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
|
||||
if (entity == null) return;
|
||||
|
||||
|
@ -94,14 +94,14 @@ public class Logic {
|
|||
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);
|
||||
if (Data.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);
|
||||
Data.addSitEntity(player, sitEntity);
|
||||
// remove the entity from the spawn list
|
||||
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.
|
||||
*/
|
||||
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
|
||||
if (entity == null) return;
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@ package one.oth3r.sit.utl;
|
|||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.decoration.DisplayEntity;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import one.oth3r.sit.file.FileData;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
|
@ -17,7 +16,7 @@ public class LoopManager {
|
|||
time = 0;
|
||||
|
||||
// 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()) {
|
||||
DisplayEntity.TextDisplayEntity entity = entities.get(player);
|
||||
|
||||
|
@ -41,7 +40,7 @@ public class LoopManager {
|
|||
Entity entity = player.getVehicle();
|
||||
if (entity instanceof DisplayEntity.TextDisplayEntity tde && entity.getName().getString().equals(Data.ENTITY_NAME)) {
|
||||
// bind the entity to the player
|
||||
FileData.addSitEntity(player, tde);
|
||||
Data.addSitEntity(player, tde);
|
||||
// check if the player is still allowed to sit
|
||||
Logic.checkSittingValidity(player);
|
||||
// remove the player from the check
|
||||
|
|
|
@ -325,7 +325,7 @@ public class Utl {
|
|||
// remove the entity
|
||||
entity.setRemoved(net.minecraft.entity.Entity.RemovalReason.DISCARDED);
|
||||
// remove the entity from the data set if exists
|
||||
FileData.removeSitEntity(entity);
|
||||
Data.removeSitEntity(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue