ninja.leaping.configurate.objectmapping.ObjectMappingException Java Examples
The following examples show how to use
ninja.leaping.configurate.objectmapping.ObjectMappingException.
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: ConfigurationVersionUtil.java From AntiVPN with MIT License | 6 votes |
private static void to35(ConfigurationNode config) { // Remove IPDetector List<String> order; try { order = new ArrayList<>(config.getNode("sources", "order").getList(TypeToken.of(String.class))); } catch (ObjectMappingException ex) { logger.error(ex.getMessage(), ex); return; } List<String> removed = new ArrayList<>(); for (String source : order) { if (source.equalsIgnoreCase("ipdetector")) { // sources are case-insensitive when loaded removed.add(source); } } order.removeAll(removed); config.getNode("sources", "order").setValue(order); config.getNode("sources").removeChild("ipdetector"); // Version config.getNode("version").setValue(3.5d); }
Example #2
Source File: HeaderFooterHandler.java From UltimateCore with MIT License | 6 votes |
public static void handleHeaderFooter() { ModuleConfig config = Modules.TABLIST.get().getConfig().get(); boolean enablehf = config.get().getNode("headerfooter", "enable").getBoolean(); if (enablehf) { String header; String footer; try { header = StringUtil.join("\n", config.get().getNode("headerfooter", "header").getList(TypeToken.of(String.class))); footer = StringUtil.join("\n", config.get().getNode("headerfooter", "footer").getList(TypeToken.of(String.class))); } catch (ObjectMappingException e) { ErrorLogger.log(e, "Failed to load header and footer for tablist."); return; } //VariableUtil.replaceVariables(Messages.toText(header), p), VariableUtil.replaceVariables(Messages.toText(footer), p) for (Player p : Sponge.getServer().getOnlinePlayers()) { Text h = VariableUtil.replaceVariables(Messages.toText(header), p); //h = TextUtil.replace(h, "Welcome", Text.of("Welcum")); p.getTabList().setHeaderAndFooter(h, VariableUtil.replaceVariables(Messages.toText(footer), p)); } } }
Example #3
Source File: GriefDefenderConfig.java From GriefDefender with MIT License | 6 votes |
public void load() throws IOException, ObjectMappingException { // load settings from file CommentedConfigurationNode loadedNode = this.loader.load(); // store "what's in the file" separately in memory this.fileData = loadedNode; // make a copy of the file data this.data = this.fileData.copy(); // merge with settings from parent if (this.parent != null) { this.parent.load(); this.data.mergeValuesFrom(this.parent.data); } // populate the config object populateInstance(); }
Example #4
Source File: GsonTypeSerializer.java From helper with MIT License | 6 votes |
@Override public void serialize(TypeToken<?> type, JsonElement from, ConfigurationNode to) throws ObjectMappingException { if (from.isJsonPrimitive()) { JsonPrimitive primitive = from.getAsJsonPrimitive(); to.setValue(GsonConverters.IMMUTABLE.unwarpPrimitive(primitive)); } else if (from.isJsonNull()) { to.setValue(null); } else if (from.isJsonArray()) { JsonArray array = from.getAsJsonArray(); // ensure 'to' is a list node to.setValue(ImmutableList.of()); for (JsonElement element : array) { serialize(TYPE, element, to.getAppendedNode()); } } else if (from.isJsonObject()) { JsonObject object = from.getAsJsonObject(); // ensure 'to' is a map node to.setValue(ImmutableMap.of()); for (Map.Entry<String, JsonElement> ent : object.entrySet()) { serialize(TYPE, ent.getValue(), to.getNode(ent.getKey())); } } else { throw new ObjectMappingException("Unknown element type: " + from.getClass()); } }
Example #5
Source File: MessageStorage.java From GriefDefender with MIT License | 6 votes |
@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: Protection.java From UltimateCore with MIT License | 6 votes |
@Override public Protection deserialize(TypeToken<?> type, ConfigurationNode node) throws ObjectMappingException { LockTypeRegistry registry = ((BlockprotectionModule) Modules.BLOCKPROTECTION.get()).getLockTypeRegistry(); HashSet<Location<World>> locations = new HashSet<>(); locations.addAll(node.getNode("locations").getList(new TypeToken<Location<World>>() { })); UUID owner = UUID.fromString(node.getNode("owner").getString()); List<UUID> players = node.getNode("players").getList(TypeToken.of(String.class)).stream().map(UUID::fromString).collect(Collectors.toList()); LockType ltype = registry.getById(node.getNode("locktype").getString()).orElseThrow(() -> new ObjectMappingException("Invalid locktype")); if (ltype instanceof ValueLockType) { ((ValueLockType) ltype).setValue(node.getNode("locktype-value").getString()); } return new Protection(locations, owner, players, ltype); }
Example #7
Source File: ComponentConfigSerializer.java From GriefDefender with MIT License | 6 votes |
@Override public Component deserialize(TypeToken<?> type, ConfigurationNode node) throws ObjectMappingException { if (node.getString() == null || node.getString().isEmpty()) { return TextComponent.empty(); } if (node.getString().contains("text=")) { // Try sponge data StringWriter writer = new StringWriter(); GsonConfigurationLoader gsonLoader = GsonConfigurationLoader.builder() .setIndent(0) .setSink(() -> new BufferedWriter(writer)) .setHeaderMode(HeaderMode.NONE) .build(); try { gsonLoader.save(node); } catch (IOException e) { throw new ObjectMappingException(e); } return GsonComponentSerializer.INSTANCE.deserialize(writer.toString()); } return LegacyComponentSerializer.legacy().deserialize(node.getString(), '&'); }
Example #8
Source File: ClaimTypeSerializer.java From EagleFactions with MIT License | 6 votes |
@Override public Claim deserialize(TypeToken<?> type, ConfigurationNode value) throws ObjectMappingException { Vector3i chunkPosition = Vector3i.ZERO; UUID worldUniqueId = new UUID(0, 0); Set<UUID> owners; boolean isAccessibleByFaction; try { worldUniqueId = value.getNode("worldUUID").getValue(TypeTokens.UUID_TOKEN, new UUID(0, 0)); chunkPosition = value.getNode("chunkPosition").getValue(TypeTokens.VECTOR_3I_TOKEN, Vector3i.ZERO); isAccessibleByFaction = value.getNode("accessibleByFaction").getBoolean(true); owners = new HashSet<>(value.getNode("owners").getList(TypeTokens.UUID_TOKEN, Collections.EMPTY_LIST)); } catch (Exception e) { throw new ObjectMappingException("Could not deserialize the claim: " + worldUniqueId.toString() + "|" + chunkPosition, e); } return new Claim(worldUniqueId, chunkPosition, owners, isAccessibleByFaction); }
Example #9
Source File: MessageStorage.java From GriefPrevention with MIT License | 6 votes |
@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 #10
Source File: ConfigManager.java From RedProtect with GNU General Public License v3.0 | 6 votes |
public List<Location> getSigns(String rid) { List<Location> locs = new ArrayList<>(); try { for (String s : signCfgs.getNode(rid).getList(of(String.class))) { String[] val = s.split(","); if (!Sponge.getServer().getWorld(val[0]).isPresent()) { continue; } locs.add(new Location<>(Sponge.getServer().getWorld(val[0]).get(), Double.valueOf(val[1]), Double.valueOf(val[2]), Double.valueOf(val[3]))); } } catch (ObjectMappingException e) { CoreUtil.printJarVersion(); e.printStackTrace(); } return locs; }
Example #11
Source File: BloodEffects.java From UltimateCore with MIT License | 6 votes |
public static void reload() { effects.clear(); ModuleConfig config = Modules.BLOOD.get().getConfig().get(); for (EntityType type : Sponge.getRegistry().getAllOf(CatalogTypes.ENTITY_TYPE)) { CommentedConfigurationNode node = config.get().getNode("types", type.getId()); try { BloodEffect effect = node.getValue(TypeToken.of(BloodEffect.class)); if (effect == null) { continue; } effects.put(type, effect); } catch (ObjectMappingException e) { ErrorLogger.log(e, "Failed to deserialize bloodeffect for " + type.getId() + " (" + e.getMessage() + ")"); } } }
Example #12
Source File: VirtualChestItemStackSerializer.java From VirtualChest with GNU Lesser General Public License v3.0 | 6 votes |
private <T, U extends BaseValue<T>> void deserializeForKeys( ConfigurationNode node, DataQuery dataQuery, BiConsumer<Key<U>, T> consumer) throws InvalidDataException { if (KEYS.containsKey(dataQuery)) { try { @SuppressWarnings("unchecked") Key<U> key = (Key<U>) KEYS.get(dataQuery); @SuppressWarnings("unchecked") TypeToken<T> elementToken = (TypeToken<T>) key.getElementToken(); consumer.accept(key, Optional.ofNullable(node.getValue(elementToken)) .orElseThrow(() -> new InvalidDataException("No value present"))); } catch (ObjectMappingException e) { throw new InvalidDataException(e); } } else if (!EXCEPTIONS.contains(dataQuery)) { throw new InvalidDataException("No matched query present"); } }
Example #13
Source File: ComponentConfigSerializer.java From GriefDefender with MIT License | 6 votes |
@Override public Component deserialize(TypeToken<?> type, ConfigurationNode node) throws ObjectMappingException { if (node.getString() == null || node.getString().isEmpty()) { return TextComponent.empty(); } if (node.getString().contains("text=")) { // Try sponge data StringWriter writer = new StringWriter(); GsonConfigurationLoader gsonLoader = GsonConfigurationLoader.builder() .setIndent(0) .setSink(() -> new BufferedWriter(writer)) .setHeaderMode(HeaderMode.NONE) .build(); try { gsonLoader.save(node); } catch (IOException e) { throw new ObjectMappingException(e); } return GsonComponentSerializer.INSTANCE.deserialize(writer.toString()); } return LegacyComponentSerializer.legacy().deserialize(node.getString(), '&'); }
Example #14
Source File: GriefDefenderConfig.java From GriefDefender with MIT License | 6 votes |
public void load() throws IOException, ObjectMappingException { // load settings from file CommentedConfigurationNode loadedNode = this.loader.load(); // store "what's in the file" separately in memory this.fileData = loadedNode; // make a copy of the file data this.data = this.fileData.copy(); // merge with settings from parent if (this.parent != null) { this.parent.load(); this.data.mergeValuesFrom(this.parent.data); } // populate the config object populateInstance(); }
Example #15
Source File: MessageStorage.java From GriefDefender with MIT License | 6 votes |
@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 #16
Source File: BlockStateSerializer.java From UltimateCore with MIT License | 5 votes |
@Override public BlockState deserialize(TypeToken<?> type, ConfigurationNode node) throws ObjectMappingException { try { return Sponge.getRegistry().getType(BlockState.class, node.getString()).get(); } catch (Throwable t) { throw new ObjectMappingException("Can't deserialize a BlockState", t); } }
Example #17
Source File: VirtualChestItemStackSerializer.java From VirtualChest with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void serialize(TypeToken<?> t, Text o, ConfigurationNode value) throws ObjectMappingException { if (o != null) { value.setValue(TextSerializers.FORMATTING_CODE.serialize(o)); } }
Example #18
Source File: VirtualChestItemStackSerializer.java From VirtualChest with GNU Lesser General Public License v3.0 | 5 votes |
@Override public GameProfile deserialize(TypeToken<?> type, ConfigurationNode value) throws ObjectMappingException { String name = value.getNode(KEY_NAME).getString(), uuid = value.getNode(KEY_UUID).getString(); if (Objects.isNull(uuid)) { return this.nullProfile.orElseThrow(() -> new ObjectMappingException("Empty profile is not allowed")); } return getFilledGameProfileOrElseFallback(GameProfile.of(getUUIDByString(uuid), name)); }
Example #19
Source File: KitKeys.java From UltimateCore with MIT License | 5 votes |
@Override public void save(Game arg, List<Kit> kits) { ModuleConfig loader = Modules.KIT.get().getConfig().get(); CommentedConfigurationNode node = loader.get(); node.getNode("kits").getChildrenMap().keySet().forEach(node.getNode("kits")::removeChild); for (Kit kit : kits) { try { node.getNode("kits", kit.getId()).setValue(TypeToken.of(Kit.class), kit); } catch (ObjectMappingException e) { ErrorLogger.log(e, "Failed to save kits key"); } } loader.save(node); }
Example #20
Source File: CoreConfigManager.java From RedProtect with GNU General Public License v3.0 | 5 votes |
private void saveConfig() { try { configRoot.setValue(of(MainCategory.class), root); cfgLoader.save(configRoot); } catch (IOException | ObjectMappingException e) { CoreUtil.printJarVersion(); e.printStackTrace(); } }
Example #21
Source File: ClaimSetTypeSerializer.java From EagleFactions with MIT License | 5 votes |
@Override public Set<Claim> deserialize(TypeToken<?> type, ConfigurationNode value) throws ObjectMappingException { final Set<Claim> claims = new HashSet<>(); final List<? extends ConfigurationNode> nodes = value.getChildrenList(); for (final ConfigurationNode configurationNode : nodes) { final Claim claim = configurationNode.getValue(EFTypeSerializers.CLAIM_TYPE_TOKEN); if (claim != null) claims.add(claim); } return claims; }
Example #22
Source File: GsonTypeSerializer.java From helper with MIT License | 5 votes |
@Override public JsonElement deserialize(TypeToken<?> type, ConfigurationNode from) throws ObjectMappingException { if (from.getValue() == null) { return JsonNull.INSTANCE; } if (from.hasListChildren()) { List<? extends ConfigurationNode> childrenList = from.getChildrenList(); JsonArray array = new JsonArray(); for (ConfigurationNode node : childrenList) { array.add(node.getValue(TYPE)); } return array; } if (from.hasMapChildren()) { Map<Object, ? extends ConfigurationNode> childrenMap = from.getChildrenMap(); JsonObject object = new JsonObject(); for (Map.Entry<Object, ? extends ConfigurationNode> ent : childrenMap.entrySet()) { object.add(ent.getKey().toString(), ent.getValue().getValue(TYPE)); } return object; } Object val = from.getValue(); try { return GsonConverters.IMMUTABLE.wrap(val); } catch (IllegalArgumentException e) { throw new ObjectMappingException(e); } }
Example #23
Source File: JsonTreeTypeSerializer.java From helper with MIT License | 5 votes |
@Override public void serialize(TypeToken<?> typeToken, DataTree dataTree, ConfigurationNode node) throws ObjectMappingException { if (dataTree instanceof GsonDataTree) { node.setValue(JSON_ELEMENT_TYPE, ((GsonDataTree) dataTree).getElement()); } else if (dataTree instanceof ConfigurateDataTree) { node.setValue(((ConfigurateDataTree) dataTree).getNode()); } else { throw new ObjectMappingException("Unknown type: " + dataTree.getClass().getName()); } }
Example #24
Source File: Vector3dSerializer.java From UltimateCore with MIT License | 5 votes |
@Override public Vector3d deserialize(TypeToken<?> type, ConfigurationNode node) throws ObjectMappingException { double x = node.getNode("x").getDouble(); double y = node.getNode("y").getDouble(); double z = node.getNode("z").getDouble(); return new Vector3d(x, y, z); }
Example #25
Source File: KitKeys.java From UltimateCore with MIT License | 5 votes |
@Override public List<Kit> load(Game arg) { List<Kit> kits = new ArrayList<>(); CommentedConfigurationNode node = Modules.KIT.get().getConfig().get().get(); for (CommentedConfigurationNode wnode : node.getNode("kits").getChildrenMap().values()) { try { kits.add(wnode.getValue(TypeToken.of(Kit.class))); } catch (ObjectMappingException e) { Messages.log(Messages.getFormatted("kit.command.kit.invalidkit", "%kit%", wnode.getNode("name").getString())); } } return kits; }
Example #26
Source File: ConfigFactory.java From helper with MIT License | 5 votes |
@Nonnull public static <T> T populate(@Nonnull T object, @Nonnull ConfigurationNode node) { try { return objectMapper(object).populate(node); } catch (ObjectMappingException e) { throw new ConfigurationException(e); } }
Example #27
Source File: SerializableTransform.java From UltimateCore with MIT License | 5 votes |
public SerializableTransform(Transform<World> transform) { this.transform = transform; ConfigurationNode node = SimpleCommentedConfigurationNode.root(); try { ts.serialize(TypeToken.of(Transform.class), transform, node); } catch (ObjectMappingException e) { //This should never happen e.printStackTrace(); } this.node = node; }
Example #28
Source File: ConfigFactory.java From helper with MIT License | 5 votes |
@Nonnull public static <T> ObjectMapper<T>.BoundInstance objectMapper(@Nonnull T object) { try { return ObjectMapper.forObject(object); } catch (ObjectMappingException e) { throw new ConfigurationException(e); } }
Example #29
Source File: ConfigFactory.java From helper with MIT License | 5 votes |
@Nonnull public static <T> ObjectMapper<T> classMapper(@Nonnull Class<T> clazz) { try { return ObjectMapper.forClass(clazz); } catch (ObjectMappingException e) { throw new ConfigurationException(e); } }
Example #30
Source File: ConfigurationVersionUtil.java From AntiVPN with MIT License | 5 votes |
private static void to413(ConfigurationNode config) { // Add private ranges to ignore List<String> ignoredIPs; try { ignoredIPs = new ArrayList<>(config.getNode("action", "ignore").getList(TypeToken.of(String.class))); } catch (ObjectMappingException ex) { logger.error(ex.getMessage(), ex); return; } List<String> added = new ArrayList<>(); added.add("10.0.0.0/8"); added.add("172.16.0.0/12"); added.add("192.168.0.0/16"); added.add("fd00::/8"); for (Iterator<String> i = added.iterator(); i.hasNext();) { String ip = i.next(); for (String ip2 : ignoredIPs) { if (ip.equalsIgnoreCase(ip2)) { // IPs are case-insensitive when loaded i.remove(); } } } ignoredIPs.addAll(added); config.getNode("action", "ignore").setValue(ignoredIPs); // Version config.getNode("version").setValue(4.13d); }