2024-07-11 13:43:54 -05:00
|
|
|
package one.oth3r.sit.file;
|
|
|
|
|
|
|
|
import com.google.gson.annotations.SerializedName;
|
|
|
|
import net.minecraft.util.Hand;
|
2024-07-23 13:49:43 -05:00
|
|
|
import one.oth3r.sit.utl.Data;
|
2024-07-11 13:43:54 -05:00
|
|
|
import one.oth3r.sit.utl.Utl;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2024-07-23 11:27:06 -05:00
|
|
|
public class SittingConfig {
|
2024-07-11 13:43:54 -05:00
|
|
|
|
|
|
|
@SerializedName("version")
|
|
|
|
private Double version = 1.0;
|
2024-07-23 11:27:06 -05:00
|
|
|
@SerializedName("enabled")
|
|
|
|
private Boolean enabled = true;
|
2024-07-11 13:43:54 -05:00
|
|
|
@SerializedName("hand-sitting")
|
2024-07-23 11:27:06 -05:00
|
|
|
private Boolean handSitting = true;
|
2024-07-11 13:43:54 -05:00
|
|
|
@SerializedName("main-hand")
|
|
|
|
private HandSetting mainHand = new HandSetting(HandSetting.SittingRequirement.EMPTY, new HandSetting.Filter());
|
|
|
|
@SerializedName("off-hand")
|
|
|
|
private HandSetting offHand = new HandSetting(HandSetting.SittingRequirement.FILTER,
|
|
|
|
new HandSetting.Filter(false,true,false,new ArrayList<>(),new ArrayList<>())); // todo fill out some fox examples sake
|
|
|
|
|
2024-07-23 11:27:06 -05:00
|
|
|
public SittingConfig() {}
|
2024-07-11 13:43:54 -05:00
|
|
|
|
2024-07-23 11:27:06 -05:00
|
|
|
public SittingConfig(double version, boolean enabled, boolean handSitting, HandSetting mainHand, HandSetting offHand) {
|
2024-07-11 13:43:54 -05:00
|
|
|
this.version = version;
|
2024-07-23 11:27:06 -05:00
|
|
|
this.enabled = enabled;
|
2024-07-11 13:43:54 -05:00
|
|
|
this.handSitting = handSitting;
|
|
|
|
this.mainHand = mainHand;
|
|
|
|
this.offHand = offHand;
|
|
|
|
}
|
|
|
|
|
2024-07-23 11:27:06 -05:00
|
|
|
public SittingConfig(SittingConfig sittingConfig) {
|
|
|
|
this.version = sittingConfig.version;
|
|
|
|
this.enabled = sittingConfig.enabled;
|
|
|
|
this.handSitting = sittingConfig.handSitting;
|
|
|
|
this.mainHand = sittingConfig.mainHand;
|
|
|
|
this.offHand = sittingConfig.offHand;
|
2024-07-11 13:43:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public Double getVersion() {
|
|
|
|
return version;
|
|
|
|
}
|
|
|
|
|
2024-07-23 13:49:43 -05:00
|
|
|
public Boolean getEnabled() {
|
|
|
|
return enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setEnabled(Boolean enabled) {
|
|
|
|
this.enabled = enabled;
|
|
|
|
}
|
|
|
|
|
2024-07-11 13:43:54 -05:00
|
|
|
public boolean canSitWithHand() {
|
|
|
|
return handSitting;
|
|
|
|
}
|
|
|
|
|
2024-07-23 13:49:43 -05:00
|
|
|
public void setHandSitting(Boolean handSitting) {
|
|
|
|
this.handSitting = handSitting;
|
|
|
|
}
|
|
|
|
|
2024-07-11 13:43:54 -05:00
|
|
|
public HandSetting getHand(Hand handType) {
|
|
|
|
return handType.equals(Hand.MAIN_HAND) ? mainHand : offHand;
|
|
|
|
}
|
|
|
|
|
|
|
|
public HandSetting getMainHand() {
|
|
|
|
return mainHand;
|
|
|
|
}
|
|
|
|
|
|
|
|
public HandSetting getOffHand() {
|
|
|
|
return offHand;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static File getFile() {
|
2024-07-23 13:49:43 -05:00
|
|
|
return new File(Data.CONFIG_DIR+"sitting-config.json");
|
2024-07-11 13:43:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* loads the Config file to Data
|
|
|
|
*/
|
|
|
|
public static void load() {
|
|
|
|
|
|
|
|
File file = getFile();
|
|
|
|
if (!file.exists()) save();
|
|
|
|
// try reading the file
|
|
|
|
try (BufferedReader reader = Files.newBufferedReader(file.toPath(), StandardCharsets.UTF_8)) {
|
2024-07-23 11:27:06 -05:00
|
|
|
Updater.SittingConfigFile.run(reader);
|
2024-07-11 13:43:54 -05:00
|
|
|
} catch (Exception e) {
|
2024-07-23 13:49:43 -05:00
|
|
|
Data.LOGGER.error(String.format("ERROR LOADING '%s`: %s", file.getName(),e.getMessage()));
|
2024-07-11 13:43:54 -05:00
|
|
|
}
|
|
|
|
// save after loading
|
|
|
|
save();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* saves Data.config to config.json
|
|
|
|
*/
|
|
|
|
public static void save() {
|
|
|
|
if (!getFile().exists()) {
|
2024-07-23 13:49:43 -05:00
|
|
|
Data.LOGGER.info(String.format("Creating new `%s`", getFile().getName()));
|
2024-07-11 13:43:54 -05:00
|
|
|
}
|
|
|
|
try (BufferedWriter writer = Files.newBufferedWriter(getFile().toPath(), StandardCharsets.UTF_8)) {
|
2024-07-23 12:27:01 -05:00
|
|
|
writer.write(Utl.getGson().toJson(FileData.getSittingConfig()));
|
2024-07-11 13:43:54 -05:00
|
|
|
} catch (Exception e) {
|
2024-07-23 13:49:43 -05:00
|
|
|
Data.LOGGER.error(String.format("ERROR SAVING '%s`: %s", getFile().getName(), e.getMessage()));
|
2024-07-11 13:43:54 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|