toggle keybinding

sit data to Data.java
client events to Events.java
This commit is contained in:
Oth3r 2024-07-23 13:49:43 -05:00
commit ddf7703693
13 changed files with 294 additions and 124 deletions

View file

@ -5,6 +5,7 @@ import com.google.gson.reflect.TypeToken;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import one.oth3r.sit.Sit;
import one.oth3r.sit.utl.Data;
import java.io.InputStream;
import java.io.InputStreamReader;
@ -98,7 +99,7 @@ public class LangReader {
// close the input stream
inputStream.close();
} catch (Exception e) {
Sit.LOGGER.error(e.getMessage());
Data.LOGGER.error(e.getMessage());
}
}
public static String getLanguageValue(String key) {

View file

@ -1,7 +1,7 @@
package one.oth3r.sit.file;
import com.google.gson.annotations.SerializedName;
import one.oth3r.sit.Sit;
import one.oth3r.sit.utl.Data;
import one.oth3r.sit.utl.Utl;
import java.io.BufferedReader;
@ -127,7 +127,7 @@ public class ServerConfig {
public static File getFile() {
return new File(Sit.CONFIG_DIR+"server-config.json");
return new File(Data.CONFIG_DIR+"server-config.json");
}
/**
@ -139,14 +139,14 @@ public class ServerConfig {
if (!file.exists()) {
// try to make the config directory
try {
Files.createDirectories(Paths.get(Sit.CONFIG_DIR));
Files.createDirectories(Paths.get(Data.CONFIG_DIR));
} catch (Exception e) {
Sit.LOGGER.error("Failed to create config directory. Canceling all config loading...");
Data.LOGGER.error("Failed to create config directory. Canceling all config loading...");
return;
}
// if loading from legacy, try checking the old config directory for the file
if (tryLegacy && Updater.ServerConfigFile.Legacy.getLegacyFile().exists()) {
Sit.LOGGER.info("Updating Sit!.properties to sit!/config.json");
Data.LOGGER.info("Updating Sit!.properties to sit!/config.json");
Updater.ServerConfigFile.Legacy.run();
}
save();
@ -155,7 +155,7 @@ public class ServerConfig {
try (BufferedReader reader = Files.newBufferedReader(file.toPath(), StandardCharsets.UTF_8)) {
Updater.ServerConfigFile.run(reader);
} catch (Exception e) {
Sit.LOGGER.error(String.format("ERROR LOADING '%s`: %s", file.getName(),e.getMessage()));
Data.LOGGER.error(String.format("ERROR LOADING '%s`: %s", file.getName(),e.getMessage()));
}
// save after loading
save();
@ -166,12 +166,12 @@ public class ServerConfig {
*/
public static void save() {
if (!getFile().exists()) {
Sit.LOGGER.info(String.format("Creating new `%s`", getFile().getName()));
Data.LOGGER.info(String.format("Creating new `%s`", getFile().getName()));
}
try (BufferedWriter writer = Files.newBufferedWriter(getFile().toPath(), StandardCharsets.UTF_8)) {
writer.write(Utl.getGson().toJson(FileData.getServerConfig()));
} catch (Exception e) {
Sit.LOGGER.info(String.format("ERROR SAVING '%s`: %s", getFile().getName(), e.getMessage()));
Data.LOGGER.info(String.format("ERROR SAVING '%s`: %s", getFile().getName(), e.getMessage()));
}
}
}

View file

@ -2,7 +2,7 @@ package one.oth3r.sit.file;
import com.google.gson.annotations.SerializedName;
import net.minecraft.util.Hand;
import one.oth3r.sit.Sit;
import one.oth3r.sit.utl.Data;
import one.oth3r.sit.utl.Utl;
import java.io.BufferedReader;
@ -48,10 +48,22 @@ public class SittingConfig {
return version;
}
public Boolean getEnabled() {
return enabled;
}
public void setEnabled(Boolean enabled) {
this.enabled = enabled;
}
public boolean canSitWithHand() {
return handSitting;
}
public void setHandSitting(Boolean handSitting) {
this.handSitting = handSitting;
}
public HandSetting getHand(Hand handType) {
return handType.equals(Hand.MAIN_HAND) ? mainHand : offHand;
}
@ -65,7 +77,7 @@ public class SittingConfig {
}
public static File getFile() {
return new File(Sit.CONFIG_DIR+"sitting-config.json");
return new File(Data.CONFIG_DIR+"sitting-config.json");
}
/**
@ -79,7 +91,7 @@ public class SittingConfig {
try (BufferedReader reader = Files.newBufferedReader(file.toPath(), StandardCharsets.UTF_8)) {
Updater.SittingConfigFile.run(reader);
} catch (Exception e) {
Sit.LOGGER.error(String.format("ERROR LOADING '%s`: %s", file.getName(),e.getMessage()));
Data.LOGGER.error(String.format("ERROR LOADING '%s`: %s", file.getName(),e.getMessage()));
}
// save after loading
save();
@ -90,12 +102,12 @@ public class SittingConfig {
*/
public static void save() {
if (!getFile().exists()) {
Sit.LOGGER.info(String.format("Creating new `%s`", getFile().getName()));
Data.LOGGER.info(String.format("Creating new `%s`", getFile().getName()));
}
try (BufferedWriter writer = Files.newBufferedWriter(getFile().toPath(), StandardCharsets.UTF_8)) {
writer.write(Utl.getGson().toJson(FileData.getSittingConfig()));
} catch (Exception e) {
Sit.LOGGER.error(String.format("ERROR SAVING '%s`: %s", getFile().getName(), e.getMessage()));
Data.LOGGER.error(String.format("ERROR SAVING '%s`: %s", getFile().getName(), e.getMessage()));
}
}
}

View file

@ -5,7 +5,7 @@ import com.google.gson.GsonBuilder;
import com.google.gson.JsonSyntaxException;
import com.google.gson.reflect.TypeToken;
import net.minecraft.util.Hand;
import one.oth3r.sit.Sit;
import one.oth3r.sit.utl.Data;
import one.oth3r.sit.utl.Utl;
import java.io.BufferedReader;
@ -108,7 +108,7 @@ public class Updater {
*/
public static File getLegacyFile() {
// strip the new directory
return new File(Sit.CONFIG_DIR.substring(0,Sit.CONFIG_DIR.length()-5)+"Sit!.properties");
return new File(Data.CONFIG_DIR.substring(0, Data.CONFIG_DIR.length()-5)+"Sit!.properties");
}
/**
@ -131,15 +131,15 @@ public class Updater {
loadVersion(properties,Double.parseDouble(ver));
} catch (Exception e) {
Sit.LOGGER.error("Error loading legacy config file: {}", e.getMessage());
Data.LOGGER.error("Error loading legacy config file: {}", e.getMessage());
}
// delete the old file
try {
Files.delete(file.toPath());
Sit.LOGGER.info("Deleted " + file.getName());
Data.LOGGER.info("Deleted " + file.getName());
} catch (Exception e) {
Sit.LOGGER.error("Failed to delete the old Sit! config.");
Data.LOGGER.error("Failed to delete the old Sit! config.");
}
}
@ -278,7 +278,7 @@ public class Updater {
ServerConfig.save();
SittingConfig.save();
} catch (Exception e) {
Sit.LOGGER.error("Error loading legacy config: {}", e.getMessage());
Data.LOGGER.error("Error loading legacy config: {}", e.getMessage());
}
}
}