本文整理汇总了Java中ninja.leaping.configurate.objectmapping.ObjectMapper类的典型用法代码示例。如果您正苦于以下问题:Java ObjectMapper类的具体用法?Java ObjectMapper怎么用?Java ObjectMapper使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ObjectMapper类属于ninja.leaping.configurate.objectmapping包,在下文中一共展示了ObjectMapper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: load
import ninja.leaping.configurate.objectmapping.ObjectMapper; //导入依赖的package包/类
/**
* Loads the given configuration file.
*/
public static void load(Path path) {
System.out.println("Loading config from " + path.toString());
try {
Files.createDirectories(path.getParent());
if (Files.notExists(path)) {
Files.createFile(path);
}
loader = HoconConfigurationLoader.builder().setPath(path).build();
configMapper = ObjectMapper.forClass(ObfConfig.class).bindToNew();
node = loader.load(ConfigurationOptions.defaults().setHeader(HEADER));
config = configMapper.populate(node);
configMapper.serialize(node);
loader.save(node);
} catch (Exception e) {
System.err.println("Error loading configuration:");
e.printStackTrace();
}
}
示例2: load
import ninja.leaping.configurate.objectmapping.ObjectMapper; //导入依赖的package包/类
/**
* Loads the given configuration file.
*/
public static void load(Path path) {
System.out.println("Loading config from " + path.toString());
try {
Files.createDirectories(path.getParent());
if (Files.notExists(path)) {
Files.createFile(path);
}
loader = HoconConfigurationLoader.builder().setPath(path).build();
configMapper = ObjectMapper.forClass(ConfigBase.class).bindToNew();
node = loader.load(ConfigurationOptions.defaults().setHeader(HEADER));
config = configMapper.populate(node);
configMapper.serialize(node);
loader.save(node);
} catch (Exception e) {
System.err.println("Error loading configuration:");
e.printStackTrace();
}
}
示例3: fillExpansionConfig
import ninja.leaping.configurate.objectmapping.ObjectMapper; //导入依赖的package包/类
/**
* Super sketchy deserialization ;)
*/
public void fillExpansionConfig(Expansion<?, ?, ?> exp) throws Exception {
Class<?> fieldData = Class.forName(ObjectMapper.class.getName() + "$FieldData");
Class<?> expClass = exp.getConfiguration().getClass();
ObjectMapper<?> mapper = ObjectMapper.forClass(expClass);
Field fieldDataMap = mapper.getClass().getDeclaredField("cachedFields");
fieldDataMap.setAccessible(true);
@SuppressWarnings("unchecked")
Map<String, ?> map = (Map<String, ?>) fieldDataMap.get(mapper);
for (Map.Entry<String, ?> entry : map.entrySet()) {
Object fd = entry.getValue();
Field fx = fieldData.getDeclaredField("field");
fx.setAccessible(true);
Field actual = (Field) fx.get(fd);
actual.setAccessible(true);
if (actual.isAnnotationPresent(Attach.class)
&& actual.getAnnotation(Attach.class).value().equalsIgnoreCase(exp.id())
&& actual.getAnnotation(Attach.class).relational() == exp.relational()) {
fieldData.getDeclaredMethod("deserializeFrom", Object.class, ConfigurationNode.class).invoke(fd,
exp.getConfiguration(), getNode(exp).getNode(entry.getKey()));
} else if (!actual.isAnnotationPresent(Attach.class)) {
PlaceholderAPIPlugin.getInstance().getLogger().warn("Field " + fx.getName() + " in placeholder id="
+ exp.id() + "\'s config is not attached to a placeholder!");
}
}
}
示例4: saveExpansionConfig
import ninja.leaping.configurate.objectmapping.ObjectMapper; //导入依赖的package包/类
public void saveExpansionConfig(Expansion<?, ?, ?> exp) throws Exception {
Class<?> objectMapper = ObjectMapper.class;
Class<?> fieldData = Class.forName(objectMapper.getName() + "$FieldData");
Class<?> expClass = exp.getConfiguration().getClass();
ObjectMapper<?> mapper = ObjectMapper.forClass(expClass);
Field fieldDataMap = mapper.getClass().getDeclaredField("cachedFields");
fieldDataMap.setAccessible(true);
@SuppressWarnings("unchecked")
Map<String, ?> map = (Map<String, ?>) fieldDataMap.get(mapper);
for (Map.Entry<String, ?> entry : map.entrySet()) {
Object fd = entry.getValue();
Field fx = fieldData.getDeclaredField("field");
fx.setAccessible(true);
Field actual = (Field) fx.get(fd);
actual.setAccessible(true);
if (actual.isAnnotationPresent(Attach.class)
&& actual.getAnnotation(Attach.class).value().equalsIgnoreCase(exp.id())
&& actual.getAnnotation(Attach.class).relational() == exp.relational()) {
fieldData.getDeclaredMethod("serializeTo", Object.class, ConfigurationNode.class).invoke(fd,
exp.getConfiguration(), getNode(exp).getNode(entry.getKey()));
} else if (!actual.isAnnotationPresent(Attach.class)) {
PlaceholderAPIPlugin.getInstance().getLogger().warn("Field " + fx.getName() + " in placeholder id="
+ exp.id() + "\'s config is not attached to a placeholder!");
}
}
}
示例5: onPreInit
import ninja.leaping.configurate.objectmapping.ObjectMapper; //导入依赖的package包/类
@Listener //During this state, the plugin gets ready for initialization. Logger and config
public void onPreInit(GamePreInitializationEvent preInitEvent) {
logger.info("Setting up config");
rootNode = configManager.createEmptyNode();
try {
configMapper = ObjectMapper.forClass(ColorConsoleConfig.class).bindToNew();
rootNode = configManager.load();
configMapper.populate(rootNode);
//add and save missing values
configMapper.serialize(rootNode);
configManager.save(rootNode);
} catch (IOException | ObjectMappingException ioEx) {
logger.error("Cannot save default config", ioEx);
return;
}
installLogFormat();
}
示例6: GriefPreventionConfig
import ninja.leaping.configurate.objectmapping.ObjectMapper; //导入依赖的package包/类
@SuppressWarnings({"unchecked", "rawtypes"})
public GriefPreventionConfig(Type type, Path path) {
this.type = type;
this.path = path;
try {
Files.createDirectories(path.getParent());
if (Files.notExists(path)) {
Files.createFile(path);
}
this.loader = HoconConfigurationLoader.builder().setPath(path).build();
this.configMapper = (ObjectMapper.BoundInstance) ObjectMapper.forClass(this.type.clazz).bindToNew();
reload();
save();
} catch (Exception e) {
SpongeImpl.getLogger().error("Failed to initialize configuration", e);
}
}
示例7: ClaimTemplateStorage
import ninja.leaping.configurate.objectmapping.ObjectMapper; //导入依赖的package包/类
@SuppressWarnings({"unchecked", "rawtypes"})
public ClaimTemplateStorage(Path path) {
this.filePath = path;
try {
Files.createDirectories(path.getParent());
if (Files.notExists(path)) {
Files.createFile(path);
}
this.loader = HoconConfigurationLoader.builder().setPath(path).build();
this.configMapper = (ObjectMapper.BoundInstance) ObjectMapper.forClass(ClaimTemplateConfig.class).bindToNew();
reload();
save();
} catch (Exception e) {
SpongeImpl.getLogger().error("Failed to initialize claim template data", e);
}
}
示例8: PlayerStorageData
import ninja.leaping.configurate.objectmapping.ObjectMapper; //导入依赖的package包/类
@SuppressWarnings({"unchecked", "rawtypes"})
public PlayerStorageData(Path path) {
try {
Files.createDirectories(path.getParent());
if (Files.notExists(path)) {
Files.createFile(path);
}
this.loader = HoconConfigurationLoader.builder().setPath(path).build();
this.configMapper = (ObjectMapper.BoundInstance) ObjectMapper.forClass(PlayerDataConfig.class).bindToNew();
reload();
save();
} catch (Exception e) {
SpongeImpl.getLogger().error("Failed to initialize configuration", e);
}
}
示例9: MessageStorage
import ninja.leaping.configurate.objectmapping.ObjectMapper; //导入依赖的package包/类
@SuppressWarnings({"unchecked", "rawtypes"})
public MessageStorage(Path path) {
try {
Files.createDirectories(path.getParent());
if (Files.notExists(path)) {
Files.createFile(path);
}
this.loader = HoconConfigurationLoader.builder().setPath(path).build();
this.configMapper = (ObjectMapper.BoundInstance) ObjectMapper.forClass(MessageDataConfig.class).bindToNew();
reload();
save();
} catch (Exception e) {
SpongeImpl.getLogger().error("Failed to initialize configuration", e);
}
}
示例10: resetMessageData
import ninja.leaping.configurate.objectmapping.ObjectMapper; //导入依赖的package包/类
@SuppressWarnings({"unchecked", "rawtypes"})
public void resetMessageData(String message) {
for (Map.Entry<Object, ? extends CommentedConfigurationNode> mapEntry : this.root.getNode(GriefPreventionPlugin.MOD_ID).getChildrenMap().entrySet()) {
CommentedConfigurationNode node = (CommentedConfigurationNode) mapEntry.getValue();
String key = "";
String comment = node.getComment().orElse(null);
if (comment == null && node.getKey() instanceof String) {
key = (String) node.getKey();
if (key.equalsIgnoreCase(message)) {
this.root.getNode(GriefPreventionPlugin.MOD_ID).removeChild(mapEntry.getKey());
}
}
}
try {
this.loader.save(this.root);
this.configMapper = (ObjectMapper.BoundInstance) ObjectMapper.forClass(MessageDataConfig.class).bindToNew();
this.configBase = this.configMapper.populate(this.root.getNode(GriefPreventionPlugin.MOD_ID));
} catch (IOException | ObjectMappingException e) {
e.printStackTrace();
}
GriefPreventionPlugin.instance.messageData = this.configBase;
}
示例11: ClaimStorageData
import ninja.leaping.configurate.objectmapping.ObjectMapper; //导入依赖的package包/类
@SuppressWarnings({"unchecked", "rawtypes"})
public ClaimStorageData(Path path, UUID worldUniqueId, ClaimDataConfig claimData) {
this.filePath = path;
this.folderPath = path.getParent();
try {
Files.createDirectories(path.getParent());
if (Files.notExists(path)) {
Files.createFile(path);
}
this.loader = HoconConfigurationLoader.builder().setPath(path).build();
this.configMapper = (ObjectMapper.BoundInstance) ObjectMapper.forClass(ClaimDataConfig.class).bind(claimData);
this.configMapper.getInstance().setClaimStorageData(this);
reload();
((EconomyDataConfig) this.configMapper.getInstance().getEconomyData()).activeConfig = GriefPreventionPlugin.getActiveConfig(worldUniqueId);
} catch (Exception e) {
SpongeImpl.getLogger().error("Failed to initialize configuration", e);
}
}
示例12: loadMapper
import ninja.leaping.configurate.objectmapping.ObjectMapper; //导入依赖的package包/类
private <T> void loadMapper(ObjectMapper<T>.BoundInstance mapper
, ConfigurationLoader<CommentedConfigurationNode> loader) {
CommentedConfigurationNode rootNode;
if (mapper != null) {
try {
rootNode = loader.load(ConfigurationOptions.defaults().setShouldCopyDefaults(true));
//load the config into the object
mapper.populate(rootNode);
//add missing default values
loader.save(rootNode);
} catch (ObjectMappingException objMappingExc) {
logger.error("Error loading the configuration", objMappingExc);
} catch (IOException ioExc) {
logger.error("Error saving the default configuration", ioExc);
}
}
}
示例13: STConfig
import ninja.leaping.configurate.objectmapping.ObjectMapper; //导入依赖的package包/类
/**
* Construct a new STConfig instance
*
* @param file The file to save to
* @param clazz The type that holds the configuration values
*/
public STConfig(final Path file, final Class<T> clazz) {
this.file = file;
try {
if (!Files.exists(file.getParent())) {
Files.createDirectories(file.getParent());
}
if (!Files.exists(file)) {
Files.createFile(file);
}
this.loader = HoconConfigurationLoader.builder().setPath(file).build();
this.configMapper = ObjectMapper.forClass(clazz).bindToNew();
load();
save();
} catch (Exception e) {
log.error("Failed to create config file {}", file, e);
throw new RuntimeException(e);
}
}
示例14: classMapper
import ninja.leaping.configurate.objectmapping.ObjectMapper; //导入依赖的package包/类
@Nonnull
public static <T> ObjectMapper<T> classMapper(@Nonnull Class<T> clazz) {
try {
return ObjectMapper.forClass(clazz);
} catch (ObjectMappingException e) {
throw new RuntimeException(e);
}
}
示例15: objectMapper
import ninja.leaping.configurate.objectmapping.ObjectMapper; //导入依赖的package包/类
@Nonnull
public static <T> ObjectMapper<T>.BoundInstance objectMapper(@Nonnull T object) {
try {
return ObjectMapper.forObject(object);
} catch (ObjectMappingException e) {
throw new RuntimeException(e);
}
}