add update file method to template and comment

This commit is contained in:
Oth3r 2024-12-02 12:55:55 -06:00
commit 33271c4aea
3 changed files with 20 additions and 13 deletions

View file

@ -51,6 +51,7 @@ public class CustomBlock {
boolean blockType = checkBlockType(blockState);
if (!blockType) return false;
/// BLOCK STATE CHECKER
// now check if the state is one of the acceptable states
for (String state : blockStates) {
// if there is a NOT (!) blockstate

View file

@ -56,13 +56,24 @@ public interface CustomFile <T extends CustomFile<T>> {
if (file == null) throw new NullPointerException();
// update the instance
updateToNewFile(file);
file.update();
// load the file to the current object
loadFileData(file);
}
@NotNull
Class<T> getFileClass();
void updateToNewFile(T newFile);
/**
* loads the data from the file object into the current object
* @param newFile the file to take the properties from
*/
void loadFileData(T newFile);
/**
* updates the file based on the version number of the current instance
*/
void update();
/**
* logic for the file not existing when loading, defaults to saving

View file

@ -3,16 +3,8 @@ package one.oth3r.sit.file;
import com.google.gson.annotations.SerializedName;
import net.minecraft.util.Hand;
import one.oth3r.sit.utl.Data;
import one.oth3r.sit.utl.Utl;
import org.jetbrains.annotations.NotNull;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.ArrayList;
public class SittingConfig implements CustomFile<SittingConfig> {
@SerializedName("version")
@ -37,7 +29,7 @@ public class SittingConfig implements CustomFile<SittingConfig> {
}
public SittingConfig(SittingConfig sittingConfig) {
updateToNewFile(sittingConfig);
loadFileData(sittingConfig);
}
public Double getVersion() {
@ -74,7 +66,7 @@ public class SittingConfig implements CustomFile<SittingConfig> {
@Override
public void reset() {
updateToNewFile(new SittingConfig());
loadFileData(new SittingConfig());
}
@Override
@ -83,7 +75,7 @@ public class SittingConfig implements CustomFile<SittingConfig> {
}
@Override
public void updateToNewFile(SittingConfig newFile) {
public void loadFileData(SittingConfig newFile) {
this.version = newFile.version;
this.enabled = newFile.enabled;
this.handSitting = newFile.handSitting;
@ -91,6 +83,9 @@ public class SittingConfig implements CustomFile<SittingConfig> {
this.offHand = newFile.offHand;
}
@Override
public void update() {}
@Override
public String getFileName() {
return "sitting-config.json";