diff --git a/src/main/java/one/oth3r/sit/command/SitCommand.java b/src/main/java/one/oth3r/sit/command/SitCommand.java index ce1ac48..0c80ed4 100644 --- a/src/main/java/one/oth3r/sit/command/SitCommand.java +++ b/src/main/java/one/oth3r/sit/command/SitCommand.java @@ -13,7 +13,6 @@ import net.minecraft.util.math.BlockPos; import one.oth3r.sit.utl.Data; import one.oth3r.sit.utl.Logic; import one.oth3r.sit.utl.Utl; -import one.oth3r.sit.file.FileData; import java.util.concurrent.CompletableFuture; @@ -67,7 +66,7 @@ public class SitCommand { } // if already sitting, ignore - if (FileData.getSitEntity(player) != null) return 1; + if (Data.getSitEntity(player) != null) return 1; // try to make the player sit Logic.sit(player, pos, null); diff --git a/src/main/java/one/oth3r/sit/file/FileData.java b/src/main/java/one/oth3r/sit/file/FileData.java index 4d3138f..556e478 100644 --- a/src/main/java/one/oth3r/sit/file/FileData.java +++ b/src/main/java/one/oth3r/sit/file/FileData.java @@ -1,6 +1,5 @@ package one.oth3r.sit.file; -import net.minecraft.entity.decoration.DisplayEntity; import net.minecraft.server.network.ServerPlayerEntity; import one.oth3r.sit.utl.Data; import one.oth3r.sit.utl.Utl; @@ -57,27 +56,6 @@ public class FileData { return playerSettings.getOrDefault(player, sittingConfig); } - /** - * a list of every Sit! entity in the server, bound to the player - */ - private static final HashMap 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 getSitEntities() { - return new HashMap<>(sitEntities); - } - /** * loads all config files to memory */ diff --git a/src/main/java/one/oth3r/sit/utl/Data.java b/src/main/java/one/oth3r/sit/utl/Data.java index 0486cf3..8c67fde 100644 --- a/src/main/java/one/oth3r/sit/utl/Data.java +++ b/src/main/java/one/oth3r/sit/utl/Data.java @@ -101,4 +101,25 @@ public class Data { public static HashMap getSpawnList() { return new HashMap<>(spawnList); } + + /** + * a list of every Sit! entity in the server, bound to the player + */ + private static final HashMap 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 getSitEntities() { + return new HashMap<>(sitEntities); + } } diff --git a/src/main/java/one/oth3r/sit/utl/Logic.java b/src/main/java/one/oth3r/sit/utl/Logic.java index e0e055e..1c03670 100644 --- a/src/main/java/one/oth3r/sit/utl/Logic.java +++ b/src/main/java/one/oth3r/sit/utl/Logic.java @@ -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; diff --git a/src/main/java/one/oth3r/sit/utl/LoopManager.java b/src/main/java/one/oth3r/sit/utl/LoopManager.java index eb51085..219cce4 100644 --- a/src/main/java/one/oth3r/sit/utl/LoopManager.java +++ b/src/main/java/one/oth3r/sit/utl/LoopManager.java @@ -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 entities = FileData.getSitEntities(); + HashMap 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 diff --git a/src/main/java/one/oth3r/sit/utl/Utl.java b/src/main/java/one/oth3r/sit/utl/Utl.java index 609662d..fbda90a 100644 --- a/src/main/java/one/oth3r/sit/utl/Utl.java +++ b/src/main/java/one/oth3r/sit/utl/Utl.java @@ -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); } /**