Search in sources :

Example 1 with ObjectMappingException

use of ninja.leaping.configurate.objectmapping.ObjectMappingException in project HuskyCrates-Sponge by codeHusky.

the class CrateUtilities method generateVirtualCrates.

public void generateVirtualCrates(ConfigurationLoader<CommentedConfigurationNode> config) {
    toCheck = new ArrayList<>();
    physicalCrates = new HashMap<>();
    //System.out.println("GEN VC CALLED");
    try {
        CommentedConfigurationNode configRoot = config.load();
        crateTypes = new HashMap<>();
        Map<Object, ? extends CommentedConfigurationNode> b = configRoot.getNode("crates").getChildrenMap();
        for (Object prekey : b.keySet()) {
            String key = (String) prekey;
            crateTypes.put(key, new VirtualCrate(key, config, configRoot.getNode("crates", key)));
        }
        config.save(configRoot);
    } catch (IOException e) {
        e.printStackTrace();
    }
    try {
        CommentedConfigurationNode root = plugin.crateConfig.load();
        List<? extends CommentedConfigurationNode> cacher = root.getNode("cachedCrates").getChildrenList();
        for (CommentedConfigurationNode i : cacher) {
            try {
                toCheck.add(i.getValue(TypeToken.of(Location.class)));
            } catch (ObjectMappingException e) {
                e.printStackTrace();
                i.setValue(null);
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    hasInitalizedVirtualCrates = true;
}
Also used : CommentedConfigurationNode(ninja.leaping.configurate.commented.CommentedConfigurationNode) IOException(java.io.IOException) ObjectMappingException(ninja.leaping.configurate.objectmapping.ObjectMappingException)

Example 2 with ObjectMappingException

use of ninja.leaping.configurate.objectmapping.ObjectMappingException in project HuskyCrates-Sponge by codeHusky.

the class HuskyCrates method gameReloaded.

@Listener
public void gameReloaded(GameReloadEvent event) {
    for (World bit : Sponge.getServer().getWorlds()) {
        for (Entity ent : bit.getEntities()) {
            if (ent instanceof ArmorStand) {
                ArmorStand arm = (ArmorStand) ent;
                if (arm.getCreator().isPresent()) {
                    if (arm.getCreator().get().equals(UUID.fromString(armorStandIdentifier))) {
                        arm.remove();
                    }
                }
            }
        }
    }
    langData = new SharedLangData("", "You won %a %R&rfrom a %C&r!", "&e%p just won %a %R&r&e from a %C&r!", "You need a %K&r to open this crate.");
    CommentedConfigurationNode conf = null;
    try {
        conf = crateConfig.load();
        if (!conf.getNode("lang").isVirtual())
            langData = new SharedLangData(conf.getNode("lang"));
        else
            logger.info("Using default lang settings.");
    } catch (IOException e) {
        e.printStackTrace();
        logger.warn("Lang load failed, using defaults.");
    }
    crateUtilities.generateVirtualCrates(crateConfig);
    CommentedConfigurationNode root = null;
    try {
        root = crateConfig.load();
        for (CommentedConfigurationNode node : root.getNode("positions").getChildrenList()) {
            Location<World> ee;
            try {
                ee = node.getNode("location").getValue(TypeToken.of(Location.class));
            } catch (InvalidDataException err2) {
                logger.warn("Bug sponge developers about world UUIDs!");
                ee = new Location<World>(Sponge.getServer().getWorld(node.getNode("location", "WorldName").getString()).get(), node.getNode("location", "X").getDouble(), node.getNode("location", "Y").getDouble(), node.getNode("location", "Z").getDouble());
            }
            if (!crateUtilities.physicalCrates.containsKey(ee))
                crateUtilities.physicalCrates.put(ee, new PhysicalCrate(ee, node.getNode("crateID").getString(), HuskyCrates.instance));
        }
    } catch (IOException e) {
        e.printStackTrace();
    } catch (ObjectMappingException e) {
        e.printStackTrace();
    }
    crateUtilities.startParticleEffects();
}
Also used : Entity(org.spongepowered.api.entity.Entity) ArmorStand(org.spongepowered.api.entity.living.ArmorStand) CommentedConfigurationNode(ninja.leaping.configurate.commented.CommentedConfigurationNode) SharedLangData(pw.codehusky.huskycrates.lang.SharedLangData) InvalidDataException(org.spongepowered.api.data.persistence.InvalidDataException) PhysicalCrate(pw.codehusky.huskycrates.crate.PhysicalCrate) IOException(java.io.IOException) World(org.spongepowered.api.world.World) Location(org.spongepowered.api.world.Location) ObjectMappingException(ninja.leaping.configurate.objectmapping.ObjectMappingException) Listener(org.spongepowered.api.event.Listener)

Example 3 with ObjectMappingException

use of ninja.leaping.configurate.objectmapping.ObjectMappingException in project QuickStartModuleLoader by NucleusPowered.

the class ModuleContainer method startDiscover.

public final void startDiscover() throws QuickStartModuleDiscoveryException {
    try {
        Preconditions.checkState(currentPhase == ConstructionPhase.INITALISED);
        currentPhase = ConstructionPhase.DISCOVERING;
        Set<Class<? extends Module>> modules = discoverModules();
        HashMap<String, ModuleSpec> discovered = Maps.newHashMap();
        for (Class<? extends Module> s : modules) {
            // If we have a module annotation, we are golden.
            String id;
            ModuleSpec ms;
            if (s.isAnnotationPresent(ModuleData.class)) {
                ModuleData md = s.getAnnotation(ModuleData.class);
                id = md.id().toLowerCase();
                ms = new ModuleSpec(s, md);
            } else if (this.requireAnnotation) {
                loggerProxy.warn(MessageFormat.format("The module class {0} does not have a ModuleData annotation associated with it. " + "It is not being loaded as the module container requires the annotation to be present.", s.getClass().getName()));
                continue;
            } else {
                id = s.getClass().getName().toLowerCase();
                loggerProxy.warn(MessageFormat.format("The module {0} does not have a ModuleData annotation associated with it. We're just assuming an ID of {0}.", id));
                ms = new ModuleSpec(s, id, id, LoadingStatus.ENABLED, false);
            }
            if (discovered.containsKey(id)) {
                throw new QuickStartModuleDiscoveryException("Duplicate module ID \"" + id + "\" was discovered - loading cannot continue.");
            }
            discovered.put(id, ms);
        }
        // Create the dependency map.
        resolveDependencyOrder(discovered);
        // Modules discovered. Create the Module Config adapter.
        List<ModuleSpec> moduleSpecList = this.discoveredModules.entrySet().stream().filter(x -> !x.getValue().isMandatory()).map(Map.Entry::getValue).collect(Collectors.toList());
        // Attaches config adapter and loads in the defaults.
        config.attachModulesConfig(moduleSpecList, this.descriptionProcessor, this.moduleSection, this.moduleSectionHeader);
        config.saveAdapterDefaults(false);
        // Load what we have in config into our discovered modules.
        try {
            config.getConfigAdapter().getNode().forEach((k, v) -> {
                try {
                    ModuleSpec ms = discoveredModules.get(k);
                    if (ms != null) {
                        ms.setStatus(v);
                    } else {
                        loggerProxy.warn(String.format("Ignoring module entry %s in the configuration file: module does not exist.", k));
                    }
                } catch (IllegalStateException ex) {
                    loggerProxy.warn("A mandatory module can't have its status changed by config. Falling back to FORCELOAD for " + k);
                }
            });
        } catch (ObjectMappingException e) {
            loggerProxy.warn("Could not load modules config, falling back to defaults.");
            e.printStackTrace();
        }
        // Modules have been discovered.
        currentPhase = ConstructionPhase.DISCOVERED;
    } catch (QuickStartModuleDiscoveryException ex) {
        throw ex;
    } catch (Exception e) {
        throw new QuickStartModuleDiscoveryException("Unable to discover QuickStart modules", e);
    }
}
Also used : QuickStartModuleDiscoveryException(uk.co.drnaylor.quickstart.exceptions.QuickStartModuleDiscoveryException) NoModuleException(uk.co.drnaylor.quickstart.exceptions.NoModuleException) QuickStartModuleLoaderException(uk.co.drnaylor.quickstart.exceptions.QuickStartModuleLoaderException) IncorrectAdapterTypeException(uk.co.drnaylor.quickstart.exceptions.IncorrectAdapterTypeException) IOException(java.io.IOException) UndisableableModuleException(uk.co.drnaylor.quickstart.exceptions.UndisableableModuleException) QuickStartModuleDiscoveryException(uk.co.drnaylor.quickstart.exceptions.QuickStartModuleDiscoveryException) ObjectMappingException(ninja.leaping.configurate.objectmapping.ObjectMappingException) MissingDependencyException(uk.co.drnaylor.quickstart.exceptions.MissingDependencyException) ModuleData(uk.co.drnaylor.quickstart.annotations.ModuleData) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ObjectMappingException(ninja.leaping.configurate.objectmapping.ObjectMappingException)

Example 4 with ObjectMappingException

use of ninja.leaping.configurate.objectmapping.ObjectMappingException in project guardian by ichorpowered.

the class InternalPluginFacet method startup.

public Boolean startup() {
    this.facetState = FacetState.PREPARE;
    PropertyInjector propertyInjector = this.plugin.getPropertyInjector();
    propertyInjector.inject("state", GuardianState.POST_INITIALIZATION);
    // STATE: POST_INITIALIZATION
    this.plugin.getCommon().registerPermissions();
    this.plugin.getCommon().loadPenalties();
    this.plugin.getCommon().loadHeuristics();
    this.plugin.getCommon().loadChecks();
    this.plugin.getCommon().loadModules(this.plugin.getModuleController());
    this.logger.info(ConsoleUtil.of(this.facetPrefix + " Preparing modules."));
    this.logger.info(ConsoleUtil.of(Ansi.Color.YELLOW, "Discovered {} module(s).", String.valueOf(this.plugin.getModuleController().getModules().size())));
    this.plugin.getModuleController().enableModules(moduleWrapper -> {
        try {
            if (this.plugin.getConfiguration().getEnabledModules().contains(moduleWrapper.getId()))
                return true;
        } catch (ObjectMappingException e) {
            this.logger.error("Failed to acquire enable modules list from the configuration.", e);
        }
        return false;
    });
    AtomicInteger detections = new AtomicInteger(0);
    AtomicInteger checks = new AtomicInteger(0);
    AtomicInteger heuristics = new AtomicInteger(0);
    AtomicInteger penalties = new AtomicInteger(0);
    this.plugin.getModuleController().getModules().stream().filter(ModuleWrapper::isEnabled).forEach(moduleWrapper -> {
        if (!moduleWrapper.getModule().isPresent())
            return;
        if (moduleWrapper.getModule().get() instanceof Detection) {
            AbstractDetection detection = (AbstractDetection) moduleWrapper.getModule().get();
            // Precogs detection registration.
            Sponge.getRegistry().register(DetectionType.class, detection);
            // Register event listeners and provide detection to the manager.
            this.plugin.getEventBus().register(detection);
            this.plugin.getDetectionManager().provideDetection(detection.getClass(), detection);
            // Register the detection and inject its properties.
            detection.register(this.plugin.getDetectionManager());
            // Call the load method.
            detection.onLoad();
            if (this.plugin.getDetectionManager().getStageModel(CheckModel.class).isPresent())
                checks.addAndGet(detection.getStageCycle().sizeFor(this.plugin.getDetectionManager().getStageModel(CheckModel.class).get()));
            if (this.plugin.getDetectionManager().getStageModel(HeuristicModel.class).isPresent())
                heuristics.addAndGet(detection.getStageCycle().sizeFor(this.plugin.getDetectionManager().getStageModel(HeuristicModel.class).get()));
            if (this.plugin.getDetectionManager().getStageModel(PenaltyModel.class).isPresent())
                penalties.addAndGet(detection.getStageCycle().sizeFor(this.plugin.getDetectionManager().getStageModel(PenaltyModel.class).get()));
            detections.incrementAndGet();
        }
    });
    this.logger.info(ConsoleUtil.of(Ansi.Color.YELLOW, "Loaded {} punishment(s), {} heuristic(s) and " + "{} check(s) for {} detection(s).", String.valueOf(penalties.get()), String.valueOf(heuristics.get()), String.valueOf(checks.get()), String.valueOf(detections.get())));
    this.plugin.getEventBus().post(new GuardianPostInitialization(this.plugin, Origin.source(this.plugin.getPluginContainer()).build()));
    Sponge.getEventManager().registerListeners(this.plugin, this.plugin.getSequenceListener());
    this.facetState = FacetState.START;
    return true;
}
Also used : AbstractDetection(com.ichorpowered.guardian.detection.AbstractDetection) HeuristicModel(com.ichorpowered.guardianapi.detection.heuristic.HeuristicModel) PropertyInjector(com.ichorpowered.guardian.util.property.PropertyInjector) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PenaltyModel(com.ichorpowered.guardianapi.detection.penalty.PenaltyModel) GuardianPostInitialization(com.ichorpowered.guardian.event.GuardianPostInitialization) AbstractDetection(com.ichorpowered.guardian.detection.AbstractDetection) Detection(com.ichorpowered.guardianapi.detection.Detection) CheckModel(com.ichorpowered.guardianapi.detection.check.CheckModel) ObjectMappingException(ninja.leaping.configurate.objectmapping.ObjectMappingException)

Example 5 with ObjectMappingException

use of ninja.leaping.configurate.objectmapping.ObjectMappingException in project guardian by ichorpowered.

the class AbstractDetectionContentLoader method acquireAll.

@Override
public void acquireAll(Set<ContentKey<?>> contentKeys) {
    if (this.contentContainer == null)
        return;
    contentKeys.forEach(key -> {
        final Optional<ConfigurationAssignment> assignment = key.getAssignments().stream().filter(contentAssignment -> contentAssignment.getClass().equals(ConfigurationAssignment.class)).map(contentAssignment -> (ConfigurationAssignment) contentAssignment).findFirst();
        if (!assignment.isPresent())
            return;
        final ConfigurationAssignment configurationAssignment = assignment.get();
        final CommentedConfigurationNode node = this.configurationFile.getNode(configurationAssignment.lookup().toArray());
        if (MapValue.class.isAssignableFrom(key.getDefaultValue().getClass())) {
            final Map<Object, Object> collect = Maps.newHashMap();
            if (node.hasMapChildren()) {
                for (final Map.Entry<Object, ? extends ConfigurationNode> entry : node.getChildrenMap().entrySet()) {
                    collect.put(entry.getKey(), entry.getValue().getValue());
                    this.contentContainer.attempt(key, GuardianMapValue.builder((Key) key).defaultElement(collect).element(collect).create());
                }
                return;
            }
        }
        if (Value.class.isAssignableFrom(key.getDefaultValue().getClass())) {
            try {
                Object value = node.getValue(key.getElementToken());
                this.contentContainer.attempt(key, GuardianValue.builder((Key) key).defaultElement(value).element(value).create());
            } catch (ObjectMappingException e) {
                e.printStackTrace();
            }
        }
    });
}
Also used : ConfigFile(tech.ferus.util.config.ConfigFile) DetectionContentLoader(com.ichorpowered.guardianapi.detection.DetectionContentLoader) ConfigurationAssignment(com.ichorpowered.guardian.content.assignment.ConfigurationAssignment) CommentedConfigurationNode(ninja.leaping.configurate.commented.CommentedConfigurationNode) Set(java.util.Set) IOException(java.io.IOException) Maps(com.google.common.collect.Maps) Key(com.ichorpowered.guardianapi.util.item.key.Key) GuardianValue(com.ichorpowered.guardian.util.item.mutable.GuardianValue) GuardianMapValue(com.ichorpowered.guardian.util.item.mutable.GuardianMapValue) ContentKey(com.ichorpowered.guardianapi.content.key.ContentKey) Detection(com.ichorpowered.guardianapi.detection.Detection) ObjectMappingException(ninja.leaping.configurate.objectmapping.ObjectMappingException) Value(com.ichorpowered.guardianapi.util.item.value.mutable.Value) MapValue(com.ichorpowered.guardianapi.util.item.value.mutable.MapValue) Map(java.util.Map) ConfigurationNode(ninja.leaping.configurate.ConfigurationNode) ContentContainer(com.ichorpowered.guardianapi.content.ContentContainer) Optional(java.util.Optional) Path(java.nio.file.Path) ConfigurationAssignment(com.ichorpowered.guardian.content.assignment.ConfigurationAssignment) CommentedConfigurationNode(ninja.leaping.configurate.commented.CommentedConfigurationNode) Map(java.util.Map) ObjectMappingException(ninja.leaping.configurate.objectmapping.ObjectMappingException)

Aggregations

ObjectMappingException (ninja.leaping.configurate.objectmapping.ObjectMappingException)30 IOException (java.io.IOException)21 ConfigurationNode (ninja.leaping.configurate.ConfigurationNode)10 CommentedConfigurationNode (ninja.leaping.configurate.commented.CommentedConfigurationNode)8 Map (java.util.Map)7 GsonConfigurationLoader (ninja.leaping.configurate.gson.GsonConfigurationLoader)6 Optional (java.util.Optional)5 Detection (com.ichorpowered.guardianapi.detection.Detection)4 Path (java.nio.file.Path)4 Set (java.util.Set)4 Text (org.spongepowered.api.text.Text)4 Maps (com.google.common.collect.Maps)3 ConfigurationAssignment (com.ichorpowered.guardian.content.assignment.ConfigurationAssignment)3 GuardianMapValue (com.ichorpowered.guardian.util.item.mutable.GuardianMapValue)3 GuardianValue (com.ichorpowered.guardian.util.item.mutable.GuardianValue)3 ContentContainer (com.ichorpowered.guardianapi.content.ContentContainer)3 ContentKey (com.ichorpowered.guardianapi.content.key.ContentKey)3 DetectionContentLoader (com.ichorpowered.guardianapi.detection.DetectionContentLoader)3 Key (com.ichorpowered.guardianapi.util.item.key.Key)3 MapValue (com.ichorpowered.guardianapi.util.item.value.mutable.MapValue)3