Data -> FileData

This commit is contained in:
Oth3r 2024-07-23 12:27:01 -05:00
commit 7d06735b3c
9 changed files with 26 additions and 26 deletions

View file

@ -14,7 +14,7 @@ import net.minecraft.util.math.BlockPos;
import one.oth3r.sit.utl.Logic; import one.oth3r.sit.utl.Logic;
import one.oth3r.sit.Sit; import one.oth3r.sit.Sit;
import one.oth3r.sit.utl.Utl; import one.oth3r.sit.utl.Utl;
import one.oth3r.sit.file.Data; import one.oth3r.sit.file.FileData;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
@ -65,7 +65,7 @@ public class SitCommand {
} }
// if already sitting, ignore // if already sitting, ignore
if (Data.getSitEntity(player) != null) return 1; if (FileData.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

@ -5,7 +5,7 @@ import net.minecraft.server.network.ServerPlayerEntity;
import java.util.HashMap; import java.util.HashMap;
public class Data { public class FileData {
/** /**
* Sit! config file * Sit! config file
*/ */

View file

@ -79,7 +79,7 @@ public class LangReader {
public static void loadLanguageFile() { public static void loadLanguageFile() {
ClassLoader classLoader = Sit.class.getClassLoader(); ClassLoader classLoader = Sit.class.getClassLoader();
try { try {
InputStream inputStream = classLoader.getResourceAsStream("assets/sit/lang/"+ Data.getServerConfig().getLang() +".json"); InputStream inputStream = classLoader.getResourceAsStream("assets/sit/lang/"+ FileData.getServerConfig().getLang() +".json");
// if the input stream is null, the language file wasn't found // if the input stream is null, the language file wasn't found
if (inputStream == null) { if (inputStream == null) {

View file

@ -169,7 +169,7 @@ public class ServerConfig {
Sit.LOGGER.info(String.format("Creating new `%s`", getFile().getName())); Sit.LOGGER.info(String.format("Creating new `%s`", getFile().getName()));
} }
try (BufferedWriter writer = Files.newBufferedWriter(getFile().toPath(), StandardCharsets.UTF_8)) { try (BufferedWriter writer = Files.newBufferedWriter(getFile().toPath(), StandardCharsets.UTF_8)) {
writer.write(Utl.getGson().toJson(Data.getServerConfig())); writer.write(Utl.getGson().toJson(FileData.getServerConfig()));
} catch (Exception e) { } catch (Exception e) {
Sit.LOGGER.info(String.format("ERROR SAVING '%s`: %s", getFile().getName(), e.getMessage())); Sit.LOGGER.info(String.format("ERROR SAVING '%s`: %s", getFile().getName(), e.getMessage()));
} }

View file

@ -93,7 +93,7 @@ public class SittingConfig {
Sit.LOGGER.info(String.format("Creating new `%s`", getFile().getName())); Sit.LOGGER.info(String.format("Creating new `%s`", getFile().getName()));
} }
try (BufferedWriter writer = Files.newBufferedWriter(getFile().toPath(), StandardCharsets.UTF_8)) { try (BufferedWriter writer = Files.newBufferedWriter(getFile().toPath(), StandardCharsets.UTF_8)) {
writer.write(Utl.getGson().toJson(Data.getSittingConfig())); writer.write(Utl.getGson().toJson(FileData.getSittingConfig()));
} catch (Exception e) { } catch (Exception e) {
Sit.LOGGER.error(String.format("ERROR SAVING '%s`: %s", getFile().getName(), e.getMessage())); Sit.LOGGER.error(String.format("ERROR SAVING '%s`: %s", getFile().getName(), e.getMessage()));
} }

View file

@ -47,7 +47,7 @@ public class Updater {
sittingConfig = update(sittingConfig); sittingConfig = update(sittingConfig);
// set the config in the mod data // set the config in the mod data
Data.setSittingConfig(sittingConfig); FileData.setSittingConfig(sittingConfig);
} }
/** /**
@ -90,7 +90,7 @@ public class Updater {
serverConfig = update(serverConfig); serverConfig = update(serverConfig);
// set the config in the mod data // set the config in the mod data
Data.setServerConfig(serverConfig); FileData.setServerConfig(serverConfig);
} }
/** /**
@ -273,8 +273,8 @@ public class Updater {
} catch (JsonSyntaxException ignored) {} } catch (JsonSyntaxException ignored) {}
} }
Data.setServerConfig(serverConfig); FileData.setServerConfig(serverConfig);
Data.setSittingConfig(sittingConfig); FileData.setSittingConfig(sittingConfig);
ServerConfig.save(); ServerConfig.save();
SittingConfig.save(); SittingConfig.save();
} catch (Exception e) { } catch (Exception e) {

View file

@ -7,7 +7,7 @@ import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.Hand; import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import one.oth3r.sit.file.Data; import one.oth3r.sit.file.FileData;
import one.oth3r.sit.file.SittingConfig; import one.oth3r.sit.file.SittingConfig;
import one.oth3r.sit.file.HandSetting; import one.oth3r.sit.file.HandSetting;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@ -18,7 +18,7 @@ public class Logic {
if (player.isSneaking()) return false; if (player.isSneaking()) return false;
// if sitting on a stair and sit while seated off, false // if sitting on a stair and sit while seated off, false
if (Data.getSitEntity(player) != null && !Data.getServerConfig().isSitWhileSeated()) return false; if (FileData.getSitEntity(player) != null && !FileData.getServerConfig().isSitWhileSeated()) 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) {
@ -46,7 +46,7 @@ public class Logic {
* checks the hands of the player and the items in each hand and sees if the player can sit down * checks the hands of the player and the items in each hand and sees if the player can sit down
*/ */
public static boolean checkHands(ServerPlayerEntity player) { public static boolean checkHands(ServerPlayerEntity player) {
SittingConfig sittingConfig = Data.getPlayerSetting(player); SittingConfig sittingConfig = FileData.getPlayerSetting(player);
// if can't sit with hand, false // if can't sit with hand, false
if (!sittingConfig.canSitWithHand()) return false; if (!sittingConfig.canSitWithHand()) return false;
@ -71,7 +71,7 @@ public class Logic {
* removes the entity from the game, using the player * removes the entity from the game, using the player
*/ */
public static void removeEntity(ServerPlayerEntity player) { public static void removeEntity(ServerPlayerEntity player) {
DisplayEntity.TextDisplayEntity entity = Data.getSitEntity(player); DisplayEntity.TextDisplayEntity entity = FileData.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;
@ -83,7 +83,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 = Data.getSitEntity(player); DisplayEntity.TextDisplayEntity entity = FileData.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;
@ -114,7 +114,7 @@ public class Logic {
* reloads the config files * reloads the config files
*/ */
public static void reload() { public static void reload() {
Data.loadFiles(false); FileData.loadFiles(false);
} }
} }

View file

@ -4,7 +4,7 @@ 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.Sit; import one.oth3r.sit.Sit;
import one.oth3r.sit.file.Data; import one.oth3r.sit.file.FileData;
import java.util.HashMap; import java.util.HashMap;
@ -18,7 +18,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 = Data.getSitEntities(); HashMap<ServerPlayerEntity, DisplayEntity.TextDisplayEntity> entities = FileData.getSitEntities();
for (ServerPlayerEntity player : entities.keySet()) { for (ServerPlayerEntity player : entities.keySet()) {
DisplayEntity.TextDisplayEntity entity = entities.get(player); DisplayEntity.TextDisplayEntity entity = entities.get(player);
@ -31,23 +31,23 @@ 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 = Data.getCheckPlayers(); HashMap<ServerPlayerEntity, Integer> checkPlayers = FileData.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) Data.removeCheckPlayer(player); if (time <= 0) FileData.removeCheckPlayer(player);
else Data.setCheckPlayer(player, time); else FileData.setCheckPlayer(player, time);
if (player.getVehicle() != null) { if (player.getVehicle() != null) {
Entity entity = player.getVehicle(); Entity entity = player.getVehicle();
if (entity instanceof DisplayEntity.TextDisplayEntity tde && entity.getName().getString().equals(Sit.ENTITY_NAME)) { if (entity instanceof DisplayEntity.TextDisplayEntity tde && entity.getName().getString().equals(Sit.ENTITY_NAME)) {
// bind the entity to the player // bind the entity to the player
Data.addSitEntity(player, tde); FileData.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
Data.removeCheckPlayer(player); FileData.removeCheckPlayer(player);
} }
} }
} }

View file

@ -150,7 +150,7 @@ public class Utl {
* @return null if not a valid block * @return null if not a valid block
*/ */
public static Double getSittingHeight(BlockState blockState, ServerPlayerEntity player, BlockPos blockPos, @Nullable BlockHitResult hit) { public static Double getSittingHeight(BlockState blockState, ServerPlayerEntity player, BlockPos blockPos, @Nullable BlockHitResult hit) {
ServerConfig config = Data.getServerConfig(); ServerConfig config = FileData.getServerConfig();
Block block = blockState.getBlock(); Block block = blockState.getBlock();
// only if custom is enabled // only if custom is enabled
@ -254,7 +254,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
Data.removeSitEntity(entity); FileData.removeSitEntity(entity);
} }
/** /**
@ -264,7 +264,7 @@ public class Utl {
player.getServerWorld().spawnEntity(entity); player.getServerWorld().spawnEntity(entity);
player.startRiding(entity); player.startRiding(entity);
// add the entity to the list // add the entity to the list
Data.addSitEntity(player, entity); FileData.addSitEntity(player, entity);
} }
/** /**