Fix some config reloading bugs and add annotation for Simple RPC
This commit is contained in:
@@ -3,6 +3,7 @@ package com.hypherionmc.craterlib.client.gui.config;
|
||||
import com.hypherionmc.craterlib.CraterConstants;
|
||||
import com.hypherionmc.craterlib.client.gui.config.widgets.*;
|
||||
import com.hypherionmc.craterlib.core.config.ModuleConfig;
|
||||
import com.hypherionmc.craterlib.core.config.annotations.HideFromScreen;
|
||||
import com.hypherionmc.craterlib.core.config.annotations.SubConfig;
|
||||
import com.hypherionmc.craterlib.core.config.annotations.Tooltip;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
@@ -82,6 +83,8 @@ public class CraterConfigScreen extends Screen {
|
||||
if (!field.isAccessible()) {
|
||||
field.setAccessible(true);
|
||||
}
|
||||
if (field.isAnnotationPresent(HideFromScreen.class))
|
||||
return;
|
||||
Object val = field.get(object);
|
||||
|
||||
/* Lang Stuff */
|
||||
|
@@ -31,8 +31,10 @@ public final class ConfigController implements Serializable {
|
||||
FileWatcher configWatcher = new FileWatcher();
|
||||
try {
|
||||
configWatcher.setWatch(config.getConfigPath(), () -> {
|
||||
CraterConstants.LOG.info("Sending Reload Event for: " + config.getConfigPath().getName());
|
||||
config.configReloaded();
|
||||
if (!config.isSaveCalled()) {
|
||||
CraterConstants.LOG.info("Sending Reload Event for: " + config.getConfigPath().getName());
|
||||
config.configReloaded();
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
CraterConstants.LOG.error("Failed to register " + config.getConfigPath().getName() + " for auto reloading. " + e.getMessage());
|
||||
|
@@ -22,6 +22,8 @@ public class ModuleConfig {
|
||||
|
||||
private final transient String modId;
|
||||
|
||||
private transient boolean isSaveCalled = false;
|
||||
|
||||
/**
|
||||
* Set up the config
|
||||
*
|
||||
@@ -71,6 +73,7 @@ public class ModuleConfig {
|
||||
* @param conf - The config class to serialize and save
|
||||
*/
|
||||
public void saveConfig(ModuleConfig conf) {
|
||||
this.isSaveCalled = true;
|
||||
/* Set up the Serializer and Config Object */
|
||||
ObjectConverter converter = new ObjectConverter();
|
||||
CommentedFileConfig config = CommentedFileConfig.builder(configPath).build();
|
||||
@@ -78,6 +81,8 @@ public class ModuleConfig {
|
||||
/* Save the config and fire the reload events */
|
||||
converter.toConfig(conf, config);
|
||||
config.save();
|
||||
configReloaded();
|
||||
this.isSaveCalled = false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -170,4 +175,8 @@ public class ModuleConfig {
|
||||
public String getModId() {
|
||||
return modId;
|
||||
}
|
||||
|
||||
public boolean isSaveCalled() {
|
||||
return isSaveCalled;
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,8 @@
|
||||
package com.hypherionmc.craterlib.core.config.annotations;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface HideFromScreen {
|
||||
}
|
Reference in New Issue
Block a user