ninja.leaping.configurate.objectmapping.ObjectMapper Java Examples

The following examples show how to use ninja.leaping.configurate.objectmapping.ObjectMapper. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ClaimStorageData.java    From GriefPrevention with MIT License 6 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
public ClaimStorageData(Path path, UUID worldUniqueId, ClaimDataConfig claimData) {
    this.filePath = path;
    this.folderPath = path.getParent();
    try {
        if (Files.notExists(path.getParent())) {
            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);
        load();
        ((EconomyDataConfig) this.configMapper.getInstance().getEconomyData()).activeConfig = GriefPreventionPlugin.getActiveConfig(worldUniqueId);
    } catch (Exception e) {
        SpongeImpl.getLogger().error("Failed to initialize configuration", e);
    }
}
 
Example #2
Source File: ClaimTemplateStorage.java    From GriefPrevention with MIT License 6 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
public ClaimTemplateStorage(Path path) {
    this.filePath = path;
    try {
        if (Files.notExists(path.getParent())) {
            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);
    }
}
 
Example #3
Source File: ConfigManager.java    From Despector with MIT License 6 votes vote down vote up
/**
 * 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();
    }
}
 
Example #4
Source File: PlayerStorageData.java    From GriefPrevention with MIT License 6 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
public PlayerStorageData(Path path) {

    try {
        if (Files.notExists(path.getParent())) {
            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();

        load();
        save();
    } catch (Exception e) {
        SpongeImpl.getLogger().error("Failed to initialize configuration", e);
    }
}
 
Example #5
Source File: MessageStorage.java    From GriefPrevention with MIT License 6 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
public MessageStorage(Path path) {

    try {
        if (Files.notExists(path.getParent())) {
            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);
    }
}
 
Example #6
Source File: ClaimStorageData.java    From GriefDefender with MIT License 6 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
public ClaimStorageData(Path path, UUID worldUniqueId, ClaimDataConfig claimData) {
    this.filePath = path;
    this.folderPath = path.getParent();
    try {
        if (Files.notExists(path.getParent())) {
            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 = GriefDefenderPlugin.getActiveConfig(worldUniqueId);
    } catch (Exception e) {
        GriefDefenderPlugin.getInstance().getLogger().error("Failed to initialize configuration", e);
    }
}
 
Example #7
Source File: MessageStorage.java    From GriefPrevention with MIT License 6 votes vote down vote up
@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;
}
 
Example #8
Source File: OptionConfig.java    From GriefDefender with MIT License 6 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
public OptionConfig(Path path) {

    try {
        if (Files.notExists(path.getParent())) {
            Files.createDirectories(path.getParent());
        }
        if (Files.notExists(path)) {
            Files.createFile(path);
        }

        this.loader = HoconConfigurationLoader.builder().setPath(path).build();
        this.configMapper = (ObjectMapper.BoundInstance) ObjectMapper.forClass(OptionStorage.class).bindToNew();

        if (reload()) {
            save();
        }
    } catch (Exception e) {
        GriefDefenderPlugin.getInstance().getLogger().error("Failed to initialize configuration", e);
    }
}
 
Example #9
Source File: MessageStorage.java    From GriefDefender with MIT License 6 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
public void resetMessageData(String message) {
    for (Map.Entry<Object, ? extends CommentedConfigurationNode> mapEntry : this.root.getNode(GriefDefenderPlugin.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(GriefDefenderPlugin.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(GriefDefenderPlugin.MOD_ID));
    } catch (IOException | ObjectMappingException e) {
        e.printStackTrace();
    }

   GriefDefenderPlugin.getInstance().messageData = this.configBase;
}
 
Example #10
Source File: MessageStorage.java    From GriefDefender with MIT License 6 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
public MessageStorage(Path path) {

    try {
        if (Files.notExists(path.getParent())) {
            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();

        if (reload()) {
            save();
        }
    } catch (Exception e) {
        GriefDefenderPlugin.getInstance().getLogger().error("Failed to initialize configuration", e);
    }
}
 
Example #11
Source File: FlagConfig.java    From GriefDefender with MIT License 6 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
public FlagConfig(Path path) {

    try {
        if (Files.notExists(path.getParent())) {
            Files.createDirectories(path.getParent());
        }
        if (Files.notExists(path)) {
            Files.createFile(path);
        }

        this.loader = HoconConfigurationLoader.builder().setPath(path).build();
        this.configMapper = (ObjectMapper.BoundInstance) ObjectMapper.forClass(FlagStorage.class).bindToNew();

        if (reload()) {
            save();
        }
    } catch (Exception e) {
        GriefDefenderPlugin.getInstance().getLogger().error("Failed to initialize configuration", e);
    }
}
 
Example #12
Source File: ClaimStorageData.java    From GriefPrevention with MIT License 6 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
public ClaimStorageData(Path path, UUID worldUniqueId) {
    this.filePath = path;
    this.folderPath = path.getParent();
    try {
        if (Files.notExists(path.getParent())) {
            Files.createDirectories(path.getParent());
        }
        if (Files.notExists(path)) {
            Files.createFile(path);
        }

        this.loader = HoconConfigurationLoader.builder().setPath(path).build();
        if (path.getParent().endsWith("town")) {
            this.configMapper = (ObjectMapper.BoundInstance) ObjectMapper.forClass(TownDataConfig.class).bindToNew();
        } else {
            this.configMapper = (ObjectMapper.BoundInstance) ObjectMapper.forClass(ClaimDataConfig.class).bindToNew();
        }
        this.configMapper.getInstance().setClaimStorageData(this);
        load();
        ((EconomyDataConfig) this.configMapper.getInstance().getEconomyData()).activeConfig = GriefPreventionPlugin.getActiveConfig(worldUniqueId);
    } catch (Exception e) {
        SpongeImpl.getLogger().error("Failed to initialize configuration", e);
    }
}
 
Example #13
Source File: ClaimTemplateStorage.java    From GriefDefender with MIT License 6 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
public ClaimTemplateStorage(Path path) {
    this.filePath = path;
    try {
        if (Files.notExists(path.getParent())) {
            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();

        if (reload()) {
            save();
        }
    } catch (Exception e) {
        GriefDefenderPlugin.getInstance().getLogger().error("Failed to initialize claim template data", e);
    }
}
 
Example #14
Source File: ClaimStorageData.java    From GriefDefender with MIT License 6 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
public ClaimStorageData(Path path, UUID worldUniqueId, ClaimDataConfig claimData) {
    this.filePath = path;
    this.folderPath = path.getParent();
    try {
        if (Files.notExists(path.getParent())) {
            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 = GriefDefenderPlugin.getActiveConfig(worldUniqueId);
    } catch (Exception e) {
        GriefDefenderPlugin.getInstance().getLogger().log(Level.SEVERE, "Failed to initialize configuration", e);
    }
}
 
Example #15
Source File: Settings.java    From FlexibleLogin with MIT License 6 votes vote down vote up
private <T> void loadMapper(ObjectMapper<T>.BoundInstance mapper, Path file, ConfigurationOptions options) {
    ConfigurationNode rootNode;
    if (mapper != null) {
        HoconConfigurationLoader loader = HoconConfigurationLoader.builder().setPath(file).build();
        try {
            rootNode = loader.load(options.setShouldCopyDefaults(true));
            ConfigurationNode hashNode = rootNode.getNode("hashAlgo");
            if ("bcrypt".equalsIgnoreCase(hashNode.getString())) {
                hashNode.setValue("BCrypt");
            }

            //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);
        }
    }
}
 
Example #16
Source File: OptionConfig.java    From GriefDefender with MIT License 6 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
public OptionConfig(Path path) {

    try {
        if (Files.notExists(path.getParent())) {
            Files.createDirectories(path.getParent());
        }
        if (Files.notExists(path)) {
            Files.createFile(path);
        }

        this.loader = HoconConfigurationLoader.builder().setPath(path).build();
        this.configMapper = (ObjectMapper.BoundInstance) ObjectMapper.forClass(OptionStorage.class).bindToNew();

        if (reload()) {
            save();
        }
    } catch (Exception e) {
        GriefDefenderPlugin.getInstance().getLogger().log(Level.SEVERE, "Failed to initialize configuration", e);
    }
}
 
Example #17
Source File: MessageStorage.java    From GriefDefender with MIT License 6 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
public void resetMessageData(String message) {
    for (Map.Entry<Object, ? extends CommentedConfigurationNode> mapEntry : this.root.getNode(GriefDefenderPlugin.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(GriefDefenderPlugin.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(GriefDefenderPlugin.MOD_ID));
    } catch (IOException | ObjectMappingException e) {
        e.printStackTrace();
    }

   GriefDefenderPlugin.getInstance().messageData = this.configBase;
}
 
Example #18
Source File: MessageStorage.java    From GriefDefender with MIT License 6 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
public MessageStorage(Path path) {

    try {
        if (Files.notExists(path.getParent())) {
            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();

        if (reload()) {
            save();
        }
    } catch (Exception e) {
        GriefDefenderPlugin.getInstance().getLogger().log(Level.SEVERE, "Failed to initialize configuration", e);
    }
}
 
Example #19
Source File: FlagConfig.java    From GriefDefender with MIT License 6 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
public FlagConfig(Path path) {

    try {
        if (Files.notExists(path.getParent())) {
            Files.createDirectories(path.getParent());
        }
        if (Files.notExists(path)) {
            Files.createFile(path);
        }

        this.loader = HoconConfigurationLoader.builder().setPath(path).build();
        this.configMapper = (ObjectMapper.BoundInstance) ObjectMapper.forClass(FlagStorage.class).bindToNew();

        if (reload()) {
            save();
        }
    } catch (Exception e) {
        GriefDefenderPlugin.getInstance().getLogger().log(Level.SEVERE, "Failed to initialize configuration", e);
    }
}
 
Example #20
Source File: PlayerStorageData.java    From GriefDefender with MIT License 6 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
public PlayerStorageData(Path path) {

    try {
        if (Files.notExists(path.getParent())) {
            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();

        if (reload()) {
            save();
        }
    } catch (Exception e) {
        GriefDefenderPlugin.getInstance().getLogger().log(Level.SEVERE, "Failed to initialize configuration", e);
    }
}
 
Example #21
Source File: ClaimTemplateStorage.java    From GriefDefender with MIT License 6 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
public ClaimTemplateStorage(Path path) {
    this.filePath = path;
    try {
        if (Files.notExists(path.getParent())) {
            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();

        if (reload()) {
            save();
        }
    } catch (Exception e) {
        GriefDefenderPlugin.getInstance().getLogger().log(Level.SEVERE, "Failed to initialize claim template data", e);
    }
}
 
Example #22
Source File: ClaimTemplateStorage.java    From GriefDefender with MIT License 5 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
public ClaimTemplateStorage(String templateName, Optional<String> description, IClaimData claimData, UUID creator) {
    this.filePath = FileStorage.rootWorldSavePath.resolve(FileStorage.claimTemplatePath.resolve(UUID.randomUUID().toString()));
    try {
        if (Files.notExists(this.filePath.getParent())) {
            Files.createDirectories(this.filePath.getParent());
        }
        if (Files.notExists(this.filePath)) {
            Files.createFile(this.filePath);
        }

        this.loader = HoconConfigurationLoader.builder().setPath(this.filePath).build();
        this.configMapper = (ObjectMapper.BoundInstance) ObjectMapper.forClass(ClaimTemplateConfig.class).bindToNew();

        reload();
        this.configBase.templateName = templateName;
        if (description.isPresent()) {
            this.configBase.templateDescription = description.get();
        }
        this.configBase.ownerUniqueId = creator;
        this.configBase.accessors = new ArrayList<UUID>(claimData.getAccessors());
        this.configBase.builders = new ArrayList<UUID>(claimData.getBuilders());
        this.configBase.containers = new ArrayList<UUID>(claimData.getContainers());
        this.configBase.coowners = new ArrayList<UUID>(claimData.getManagers());
        //this.configBase.flags = new HashMap<String, Tristate>(claimData.getFlags());
        save();
    } catch (Exception e) {
        GriefDefenderPlugin.getInstance().getLogger().log(Level.SEVERE, "Failed to initialize claim template data", e);
    }
}
 
Example #23
Source File: ClaimStorageData.java    From GriefPrevention with MIT License 5 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
public ClaimStorageData(Path path, UUID worldUniqueId, UUID ownerUniqueId, ClaimType type, boolean cuboid) {
    this.filePath = path;
    this.folderPath = path.getParent();
    try {
        if (Files.notExists(path.getParent())) {
            Files.createDirectories(path.getParent());
        }
        if (Files.notExists(path)) {
            Files.createFile(path);
        }

        this.loader = HoconConfigurationLoader.builder().setPath(path).build();
        if (type == ClaimType.TOWN) {
            this.configMapper = (ObjectMapper.BoundInstance) ObjectMapper.forClass(TownDataConfig.class).bindToNew();
        } else {
            this.configMapper = (ObjectMapper.BoundInstance) ObjectMapper.forClass(ClaimDataConfig.class).bindToNew();
        }
        this.configMapper.getInstance().setWorldUniqueId(worldUniqueId);
        this.configMapper.getInstance().setOwnerUniqueId(ownerUniqueId);
        this.configMapper.getInstance().setType(type);
        this.configMapper.getInstance().setCuboid(cuboid);
        this.configMapper.getInstance().setClaimStorageData(this);
        load();
        ((EconomyDataConfig) this.configMapper.getInstance().getEconomyData()).activeConfig = GriefPreventionPlugin.getActiveConfig(Sponge.getServer().getWorld(worldUniqueId).get().getProperties());
    } catch (Exception e) {
        SpongeImpl.getLogger().error("Failed to initialize configuration", e);
    }
}
 
Example #24
Source File: Configuration.java    From Prism with MIT License 5 votes vote down vote up
public Configuration(Path path) {
    try {
        this.configurationLoader = HoconConfigurationLoader.builder().setPath(path).build();
        this.objectMapper = ObjectMapper.forClass(Config.class).bindToNew();
    } catch (Exception ex) {
        Prism.getInstance().getLogger().error("Encountered an error while initializing configuration", ex);
    }
}
 
Example #25
Source File: ClaimTemplateStorage.java    From GriefPrevention with MIT License 5 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
public ClaimTemplateStorage(String templateName, Optional<String> description, IClaimData claimData, UUID creator) {
    this.filePath = FlatFileDataStore.rootWorldSavePath.resolve(FlatFileDataStore.claimTemplatePath.resolve(UUID.randomUUID().toString()));
    try {
        if (Files.notExists(this.filePath.getParent())) {
            Files.createDirectories(this.filePath.getParent());
        }
        if (Files.notExists(this.filePath)) {
            Files.createFile(this.filePath);
        }

        this.loader = HoconConfigurationLoader.builder().setPath(this.filePath).build();
        this.configMapper = (ObjectMapper.BoundInstance) ObjectMapper.forClass(ClaimTemplateConfig.class).bindToNew();

        reload();
        this.configBase.templateName = templateName;
        if (description.isPresent()) {
            this.configBase.templateDescription = description.get();
        }
        this.configBase.ownerUniqueId = creator;
        this.configBase.accessors = new ArrayList<UUID>(claimData.getAccessors());
        this.configBase.builders = new ArrayList<UUID>(claimData.getBuilders());
        this.configBase.containers = new ArrayList<UUID>(claimData.getContainers());
        this.configBase.coowners = new ArrayList<UUID>(claimData.getManagers());
        //this.configBase.flags = new HashMap<String, Tristate>(claimData.getFlags());
        save();
    } catch (Exception e) {
        SpongeImpl.getLogger().error("Failed to initialize claim template data", e);
    }
}
 
Example #26
Source File: GriefPreventionConfig.java    From GriefPrevention with MIT License 5 votes vote down vote up
public GriefPreventionConfig(Class<T> clazz, Path path, GriefPreventionConfig<?> parent) {
    this.parent = parent;
    this.path = path;

    try {
        if (Files.notExists(path.getParent())) {
            Files.createDirectories(path.getParent());
        }
        if (Files.notExists(path)) {
            Files.createFile(path);
        }

        this.loader = HoconConfigurationLoader.builder().setPath(path).build();
        this.configMapper = ObjectMapper.forClass(clazz).bindToNew();

        load();
        // In order for the removeDuplicates method to function properly, it is extremely
        // important to avoid running save on parent BEFORE children save. Doing so will
        // cause duplicate nodes to not be removed properly as parent would have cleaned up
        // all duplicates prior.
        // To handle the above issue, we only call save for world configs during init.
        if (parent != null && parent.parent != null) {
            save();
        }
    } catch (Exception e) {
        GriefPreventionPlugin.instance.getLogger().error("Failed to load configuration at path " + path.toAbsolutePath(), e);
    }
}
 
Example #27
Source File: ConfigFactory.java    From helper with MIT License 5 votes vote down vote up
@Nonnull
public static <T> ObjectMapper<T>.BoundInstance objectMapper(@Nonnull T object) {
    try {
        return ObjectMapper.forObject(object);
    } catch (ObjectMappingException e) {
        throw new ConfigurationException(e);
    }
}
 
Example #28
Source File: ConfigFactory.java    From helper with MIT License 5 votes vote down vote up
@Nonnull
public static <T> ObjectMapper<T> classMapper(@Nonnull Class<T> clazz) {
    try {
        return ObjectMapper.forClass(clazz);
    } catch (ObjectMappingException e) {
        throw new ConfigurationException(e);
    }
}
 
Example #29
Source File: ClaimStorageData.java    From GriefDefender with MIT License 5 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
public ClaimStorageData(Path path, UUID worldUniqueId, UUID ownerUniqueId, ClaimType type, boolean cuboid) {
    this.filePath = path;
    this.folderPath = path.getParent();
    try {
        if (Files.notExists(path.getParent())) {
            Files.createDirectories(path.getParent());
        }
        if (Files.notExists(path)) {
            Files.createFile(path);
        }

        this.loader = HoconConfigurationLoader.builder().setPath(path).build();
        if (type == ClaimTypes.TOWN) {
            this.configMapper = (ObjectMapper.BoundInstance) ObjectMapper.forClass(TownDataConfig.class).bindToNew();
        } else {
            this.configMapper = (ObjectMapper.BoundInstance) ObjectMapper.forClass(ClaimDataConfig.class).bindToNew();
        }
        this.configMapper.getInstance().setWorldUniqueId(worldUniqueId);
        this.configMapper.getInstance().setOwnerUniqueId(ownerUniqueId);
        this.configMapper.getInstance().setType(type);
        this.configMapper.getInstance().setCuboid(cuboid);
        this.configMapper.getInstance().setClaimStorageData(this);
        reload();
        ((EconomyDataConfig) this.configMapper.getInstance().getEconomyData()).activeConfig = GriefDefenderPlugin.getActiveConfig(Sponge.getServer().getWorld(worldUniqueId).get().getProperties());
    } catch (Exception e) {
        GriefDefenderPlugin.getInstance().getLogger().error("Failed to initialize configuration", e);
    }
}
 
Example #30
Source File: GriefDefenderConfig.java    From GriefDefender with MIT License 5 votes vote down vote up
public GriefDefenderConfig(Class<T> clazz, Path path, GriefDefenderConfig<?> parent) {
    this.parent = parent;
    this.path = path;

    try {
        if (Files.notExists(path.getParent())) {
            Files.createDirectories(path.getParent());
        }
        if (Files.notExists(path)) {
            Files.createFile(path);
        }

        this.loader = HoconConfigurationLoader.builder().setPath(path).build();
        this.configMapper = ObjectMapper.forClass(clazz).bindToNew();

        load();
        // In order for the removeDuplicates method to function properly, it is extremely
        // important to avoid running save on parent BEFORE children save. Doing so will
        // cause duplicate nodes to not be removed properly as parent would have cleaned up
        // all duplicates prior.
        // To handle the above issue, we only call save for world configs during init.
        if (parent != null && parent.parent != null) {
            save();
        }
    } catch (Exception e) {
        GriefDefenderPlugin.getInstance().getLogger().error("Failed to load configuration at path " + path.toAbsolutePath(), e);
    }
}