mirror of
https://github.com/Oth3r/Sit.git
synced 2025-09-19 16:03:22 +02:00
switch to OtterLib file registry
This commit is contained in:
parent
9ac4cd5156
commit
65f7f6f6e0
5 changed files with 33 additions and 34 deletions
|
@ -2,13 +2,31 @@ package one.oth3r.sit;
|
|||
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
|
||||
import one.oth3r.otterlib.file.LanguageReader;
|
||||
import one.oth3r.otterlib.file.ResourceReader;
|
||||
import one.oth3r.otterlib.registry.CustomFileReg;
|
||||
import one.oth3r.otterlib.registry.LanguageReg;
|
||||
import one.oth3r.sit.file.FileData;
|
||||
import one.oth3r.sit.file.ServerConfig;
|
||||
import one.oth3r.sit.file.SittingConfig;
|
||||
import one.oth3r.sit.utl.Data;
|
||||
import one.oth3r.sit.utl.Events;
|
||||
|
||||
public class Sit implements ModInitializer {
|
||||
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
LanguageReg.registerLang(Data.MOD_ID, new LanguageReader(
|
||||
new ResourceReader("assets/sit-oth3r/lang/",Sit.class.getClassLoader()),
|
||||
new ResourceReader(Data.CONFIG_DIR),"en_us","en_us"));
|
||||
|
||||
/// autoload is off, we will handle loading and saving manually
|
||||
CustomFileReg.registerFile(Data.MOD_ID,new CustomFileReg.FileEntry(
|
||||
ServerConfig.ID,new ServerConfig(),false,false));
|
||||
CustomFileReg.registerFile(Data.MOD_ID,new CustomFileReg.FileEntry(
|
||||
SittingConfig.ID,new SittingConfig(),false,false));
|
||||
|
||||
|
||||
FileData.loadFiles();
|
||||
// save the files to populate all missing config options
|
||||
FileData.saveFiles();
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
package one.oth3r.sit.file;
|
||||
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import one.oth3r.otterlib.file.LanguageReader;
|
||||
import one.oth3r.otterlib.file.ResourceReader;
|
||||
import one.oth3r.sit.Sit;
|
||||
import one.oth3r.otterlib.registry.CustomFileReg;
|
||||
import one.oth3r.sit.utl.Data;
|
||||
import one.oth3r.sit.utl.Utl;
|
||||
|
||||
|
@ -13,30 +11,13 @@ import java.util.HashMap;
|
|||
import java.util.List;
|
||||
|
||||
public class FileData {
|
||||
/**
|
||||
* Sit! config file
|
||||
*/
|
||||
private static ServerConfig serverConfig = new ServerConfig();
|
||||
|
||||
/// getters for Sit! config files
|
||||
public static ServerConfig getServerConfig() {
|
||||
return serverConfig;
|
||||
return (ServerConfig) CustomFileReg.getFile(Data.MOD_ID,ServerConfig.ID);
|
||||
}
|
||||
|
||||
public static void setServerConfig(ServerConfig newServerConfig) {
|
||||
serverConfig = new ServerConfig(newServerConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
* The default sitting config for all new players
|
||||
*/
|
||||
private static SittingConfig sittingConfig = new SittingConfig();
|
||||
|
||||
public static SittingConfig getSittingConfig() {
|
||||
return sittingConfig;
|
||||
}
|
||||
|
||||
public static void setSittingConfig(SittingConfig newSittingConfig) {
|
||||
sittingConfig = new SittingConfig(newSittingConfig);
|
||||
return (SittingConfig) CustomFileReg.getFile(Data.MOD_ID,SittingConfig.ID);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -57,7 +38,7 @@ public class FileData {
|
|||
}
|
||||
|
||||
public static SittingConfig getPlayerSetting(ServerPlayerEntity player) {
|
||||
return playerSettings.getOrDefault(player, sittingConfig);
|
||||
return playerSettings.getOrDefault(player, getSittingConfig());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -8,6 +8,7 @@ import net.minecraft.util.Hand;
|
|||
import one.oth3r.otterlib.base.Num;
|
||||
import one.oth3r.otterlib.file.CustomFile;
|
||||
import one.oth3r.otterlib.file.FileSettings;
|
||||
import one.oth3r.otterlib.registry.LanguageReg;
|
||||
import one.oth3r.sit.utl.Data;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
@ -24,6 +25,7 @@ import java.util.Properties;
|
|||
import java.util.stream.Collectors;
|
||||
|
||||
public class ServerConfig implements CustomFile<ServerConfig> {
|
||||
public static final String ID = "server-config";
|
||||
|
||||
@SerializedName("version")
|
||||
private Double version = 2.3;
|
||||
|
@ -360,9 +362,6 @@ public class ServerConfig implements CustomFile<ServerConfig> {
|
|||
Data.LOGGER.error("Failed to delete the old Sit! config.");
|
||||
}
|
||||
|
||||
// save the updated configs
|
||||
FileData.saveFiles();
|
||||
|
||||
// continue loading as normal...
|
||||
}
|
||||
|
||||
|
@ -511,8 +510,12 @@ public class ServerConfig implements CustomFile<ServerConfig> {
|
|||
} catch (JsonSyntaxException ignored) {}
|
||||
}
|
||||
|
||||
FileData.setServerConfig(serverConfig);
|
||||
FileData.setSittingConfig(sittingConfig);
|
||||
// update and save the new files
|
||||
FileData.getServerConfig().copyFileData(serverConfig);
|
||||
FileData.getServerConfig().save();
|
||||
|
||||
FileData.getSittingConfig().copyFileData(sittingConfig);
|
||||
FileData.getSittingConfig().save();
|
||||
} catch (Exception e) {
|
||||
Data.LOGGER.error("Error loading legacy config: %s", e.getMessage());
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package one.oth3r.sit.file;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import net.minecraft.util.Hand;
|
||||
import one.oth3r.otterlib.file.CustomFile;
|
||||
|
@ -13,6 +12,7 @@ import java.nio.file.Path;
|
|||
import java.nio.file.Paths;
|
||||
|
||||
public class SittingConfig implements CustomFile<SittingConfig> {
|
||||
public static final String ID = "sitting-config";
|
||||
|
||||
@SerializedName("version")
|
||||
private Double version = 1.0;
|
||||
|
|
|
@ -204,7 +204,7 @@ public class Logic {
|
|||
}
|
||||
|
||||
/**
|
||||
* toggles the sit ablity config option
|
||||
* toggles the sit ability config option
|
||||
* @return returns a message, that can be sent to the player
|
||||
*/
|
||||
public static MutableText toggleSiting() {
|
||||
|
@ -213,9 +213,6 @@ public class Logic {
|
|||
SittingConfig config = FileData.getSittingConfig();
|
||||
// toggle the setting
|
||||
config.setEnabled(!config.getEnabled());
|
||||
|
||||
// set the sitting config to the new value
|
||||
FileData.setSittingConfig(config);
|
||||
// save the changes to the file
|
||||
config.save();
|
||||
// send the changes to the server
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue