-
-
Notifications
You must be signed in to change notification settings - Fork 1
Configuration
Registered Config files will be saved in the default config directory, most times config/.
Effectively every class that implements Config can be read as Configuration.
It's highly recommended to override the getName() method to save performance!
The following example configuration class...
public final class ImplConfig implements Config {
public boolean someBoolean = true;
public List<String> someList = new ArrayList<>() {
{
add("123");
}
};
@Synchronize
public String syncedValue = "";
@Override
public String getName() {
return TestMod.MODID;
}
}...will result in the following json file:
{
"someBoolean": true,
"someList": [
"123"
],
"syncedValue": ""
}You'll notice, the fields will be read and interpreted as keys. The values you defined will be the default values and will be overwritten by the values of the generated json file.
You also need to register the config file for craftedcore, to be recognized:
class TestMod {
public static final String MODID = "testmod";
public static final ImplConfig CONFIG = ConfigLoader.read(MODID, ImplConfig.class);
}To avoid duplicate configs, most modders use their modid as config name! {:.note}
By annotating config files with @Synchronize{:.language-java .highlight}, the config value will be send to the clients when they join. After they leave, their client value will be restored.
-
CONFIG.getName()--- returns the config name -
CONFIG.getPath()--- returns the path where the config file is saved -
CONFIG.save()--- saves the current values to the json file, recommended, if the values are changed on the runtime -
CONFIG.sendToPlayer(player)--- re-syncs the@Synchronize{:.language-java .highlight} fields to the specified player -
CONFIG.sendToPlayers(serverLavel)--- re-syncs the@Synchronize{:.language-java .highlight} fields to every player registered in theServerLevel{:.language-java .highlight} -
ConfigLoader.getConfigSyncTag(config)--- returns theCompoundTag{:.language-java .highlight} reads the@Synchronize{:.language-java .highlight} fields in the specified config and creates aCompoundTag{:.language-java .highlight} containing them -
ConfigLoader.sendConfigSyncPackages(player)--- rre-syncs every config to the specified player -
ConfigLoader.getConfigByName(name)--- returns the config, registered with the specified name ornull{:.language-java .highlight}, if no config was found -
ConfigLoader.getConfigNames(config)--- returns every config name, that matches the specified config UNSTABLE
Continue with Networking