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.CraterConstants;
|
||||||
import com.hypherionmc.craterlib.client.gui.config.widgets.*;
|
import com.hypherionmc.craterlib.client.gui.config.widgets.*;
|
||||||
import com.hypherionmc.craterlib.core.config.ModuleConfig;
|
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.SubConfig;
|
||||||
import com.hypherionmc.craterlib.core.config.annotations.Tooltip;
|
import com.hypherionmc.craterlib.core.config.annotations.Tooltip;
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
@@ -82,6 +83,8 @@ public class CraterConfigScreen extends Screen {
|
|||||||
if (!field.isAccessible()) {
|
if (!field.isAccessible()) {
|
||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
}
|
}
|
||||||
|
if (field.isAnnotationPresent(HideFromScreen.class))
|
||||||
|
return;
|
||||||
Object val = field.get(object);
|
Object val = field.get(object);
|
||||||
|
|
||||||
/* Lang Stuff */
|
/* Lang Stuff */
|
||||||
|
@@ -31,8 +31,10 @@ public final class ConfigController implements Serializable {
|
|||||||
FileWatcher configWatcher = new FileWatcher();
|
FileWatcher configWatcher = new FileWatcher();
|
||||||
try {
|
try {
|
||||||
configWatcher.setWatch(config.getConfigPath(), () -> {
|
configWatcher.setWatch(config.getConfigPath(), () -> {
|
||||||
|
if (!config.isSaveCalled()) {
|
||||||
CraterConstants.LOG.info("Sending Reload Event for: " + config.getConfigPath().getName());
|
CraterConstants.LOG.info("Sending Reload Event for: " + config.getConfigPath().getName());
|
||||||
config.configReloaded();
|
config.configReloaded();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
CraterConstants.LOG.error("Failed to register " + config.getConfigPath().getName() + " for auto reloading. " + e.getMessage());
|
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 final transient String modId;
|
||||||
|
|
||||||
|
private transient boolean isSaveCalled = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set up the config
|
* Set up the config
|
||||||
*
|
*
|
||||||
@@ -71,6 +73,7 @@ public class ModuleConfig {
|
|||||||
* @param conf - The config class to serialize and save
|
* @param conf - The config class to serialize and save
|
||||||
*/
|
*/
|
||||||
public void saveConfig(ModuleConfig conf) {
|
public void saveConfig(ModuleConfig conf) {
|
||||||
|
this.isSaveCalled = true;
|
||||||
/* Set up the Serializer and Config Object */
|
/* Set up the Serializer and Config Object */
|
||||||
ObjectConverter converter = new ObjectConverter();
|
ObjectConverter converter = new ObjectConverter();
|
||||||
CommentedFileConfig config = CommentedFileConfig.builder(configPath).build();
|
CommentedFileConfig config = CommentedFileConfig.builder(configPath).build();
|
||||||
@@ -78,6 +81,8 @@ public class ModuleConfig {
|
|||||||
/* Save the config and fire the reload events */
|
/* Save the config and fire the reload events */
|
||||||
converter.toConfig(conf, config);
|
converter.toConfig(conf, config);
|
||||||
config.save();
|
config.save();
|
||||||
|
configReloaded();
|
||||||
|
this.isSaveCalled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -170,4 +175,8 @@ public class ModuleConfig {
|
|||||||
public String getModId() {
|
public String getModId() {
|
||||||
return modId;
|
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