Java Code Examples for ninja.leaping.configurate.objectmapping.ObjectMapper#BoundInstance

The following examples show how to use ninja.leaping.configurate.objectmapping.ObjectMapper#BoundInstance . 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: 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 2
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 3
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 4
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 5
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 6
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 7
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 8
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 9
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 10
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 11
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 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, 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 13
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 14
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 15
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().error("Failed to initialize claim template data", e);
    }
}
 
Example 16
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 17
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 18
Source File: PlayerStorageData.java    From GriefDefender with MIT License 5 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();
        this.root = this.loader.load(ConfigurationOptions.defaults());
        CommentedConfigurationNode rootNode = this.root.getNode(GriefDefenderPlugin.MOD_ID);
        // Check if server is using existing Sponge GP data
        if (rootNode.isVirtual()) {
            // check GriefPrevention
            CommentedConfigurationNode gpRootNode = this.root.getNode("GriefPrevention");
            if (!gpRootNode.isVirtual()) {
                rootNode.setValue(gpRootNode.getValue());
                gpRootNode.setValue(null);
            }
        }
        this.configBase = this.configMapper.populate(rootNode);
        save();
    } catch (Exception e) {
        GriefDefenderPlugin.getInstance().getLogger().error("Failed to initialize configuration", e);
    }
}
 
Example 19
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(worldUniqueId);
    } catch (Exception e) {
        GriefDefenderPlugin.getInstance().getLogger().log(Level.SEVERE, "Failed to initialize configuration", e);
    }
}
 
Example 20
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);
    }
}