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;
}
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();
}
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);
}
}
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;
}
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();
}
}
});
}
Aggregations