mirror of
https://github.com/Oth3r/Sit.git
synced 2025-09-19 16:03:22 +02:00
add update file method to template and comment
This commit is contained in:
parent
82d999c4c5
commit
33271c4aea
3 changed files with 20 additions and 13 deletions
|
@ -51,6 +51,7 @@ public class CustomBlock {
|
||||||
boolean blockType = checkBlockType(blockState);
|
boolean blockType = checkBlockType(blockState);
|
||||||
if (!blockType) return false;
|
if (!blockType) return false;
|
||||||
|
|
||||||
|
/// BLOCK STATE CHECKER
|
||||||
// now check if the state is one of the acceptable states
|
// now check if the state is one of the acceptable states
|
||||||
for (String state : blockStates) {
|
for (String state : blockStates) {
|
||||||
// if there is a NOT (!) blockstate
|
// if there is a NOT (!) blockstate
|
||||||
|
|
|
@ -56,13 +56,24 @@ public interface CustomFile <T extends CustomFile<T>> {
|
||||||
if (file == null) throw new NullPointerException();
|
if (file == null) throw new NullPointerException();
|
||||||
|
|
||||||
// update the instance
|
// update the instance
|
||||||
updateToNewFile(file);
|
file.update();
|
||||||
|
// load the file to the current object
|
||||||
|
loadFileData(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
Class<T> getFileClass();
|
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
|
* logic for the file not existing when loading, defaults to saving
|
||||||
|
|
|
@ -3,16 +3,8 @@ package one.oth3r.sit.file;
|
||||||
import com.google.gson.annotations.SerializedName;
|
import com.google.gson.annotations.SerializedName;
|
||||||
import net.minecraft.util.Hand;
|
import net.minecraft.util.Hand;
|
||||||
import one.oth3r.sit.utl.Data;
|
import one.oth3r.sit.utl.Data;
|
||||||
import one.oth3r.sit.utl.Utl;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
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> {
|
public class SittingConfig implements CustomFile<SittingConfig> {
|
||||||
|
|
||||||
@SerializedName("version")
|
@SerializedName("version")
|
||||||
|
@ -37,7 +29,7 @@ public class SittingConfig implements CustomFile<SittingConfig> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public SittingConfig(SittingConfig sittingConfig) {
|
public SittingConfig(SittingConfig sittingConfig) {
|
||||||
updateToNewFile(sittingConfig);
|
loadFileData(sittingConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Double getVersion() {
|
public Double getVersion() {
|
||||||
|
@ -74,7 +66,7 @@ public class SittingConfig implements CustomFile<SittingConfig> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reset() {
|
public void reset() {
|
||||||
updateToNewFile(new SittingConfig());
|
loadFileData(new SittingConfig());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -83,7 +75,7 @@ public class SittingConfig implements CustomFile<SittingConfig> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateToNewFile(SittingConfig newFile) {
|
public void loadFileData(SittingConfig newFile) {
|
||||||
this.version = newFile.version;
|
this.version = newFile.version;
|
||||||
this.enabled = newFile.enabled;
|
this.enabled = newFile.enabled;
|
||||||
this.handSitting = newFile.handSitting;
|
this.handSitting = newFile.handSitting;
|
||||||
|
@ -91,6 +83,9 @@ public class SittingConfig implements CustomFile<SittingConfig> {
|
||||||
this.offHand = newFile.offHand;
|
this.offHand = newFile.offHand;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update() {}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getFileName() {
|
public String getFileName() {
|
||||||
return "sitting-config.json";
|
return "sitting-config.json";
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue