Java Code Examples for ninja.leaping.configurate.ConfigurationNode#getNode()

The following examples show how to use ninja.leaping.configurate.ConfigurationNode#getNode() . 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: ShapeMarkerImpl.java    From BlueMap with MIT License 6 votes vote down vote up
private static Color readColor(ConfigurationNode node) throws MarkerFileFormatException {
	ConfigurationNode nr, ng, nb, na;
	nr = node.getNode("r");
	ng = node.getNode("g");
	nb = node.getNode("b");
	na = node.getNode("a");
	
	if (nr.isVirtual() || ng.isVirtual() || nb.isVirtual()) throw new MarkerFileFormatException("Failed to read color: Node r,g or b is not set!");
	
	float alpha = na.getFloat(1);
	if (alpha < 0 || alpha > 1) throw new MarkerFileFormatException("Failed to read color: alpha value out of range (0-1)!");
	
	try {
		return new Color(nr.getInt(), ng.getInt(), nb.getInt(), (int)(alpha * 255));
	} catch (IllegalArgumentException ex) {
		throw new MarkerFileFormatException("Failed to read color: " + ex.getMessage(), ex);
	}
}
 
Example 2
Source File: GeyserSpongeConfiguration.java    From Geyser with MIT License 6 votes vote down vote up
public GeyserSpongeConfiguration(File dataFolder, ConfigurationNode node) {
    this.dataFolder = dataFolder;
    this.node = node;

    this.bedrockConfig = new SpongeBedrockConfiguration(node.getNode("bedrock"));
    this.remoteConfig = new SpongeRemoteConfiguration(node.getNode("remote"));
    this.metricsInfo = new SpongeMetricsInfo();

    if (node.getNode("userAuths").getValue() == null)
        return;

    List<String> userAuths = new ArrayList<String>(((LinkedHashMap)node.getNode("userAuths").getValue()).keySet());
    for (String key : userAuths) {
        userAuthInfo.put(key, new SpongeUserAuthenticationInfo(key));
    }
}
 
Example 3
Source File: AbstractConfigurateStorage.java    From LuckPerms with MIT License 6 votes vote down vote up
private static ImmutableContextSet readContexts(ConfigurationNode attributes) {
    ImmutableContextSet.Builder contextBuilder = new ImmutableContextSetImpl.BuilderImpl();
    ConfigurationNode contextMap = attributes.getNode("context");
    if (!contextMap.isVirtual() && contextMap.hasMapChildren()) {
        contextBuilder.addAll(ContextSetConfigurateSerializer.deserializeContextSet(contextMap));
    }

    String server = attributes.getNode("server").getString("global");
    if (!server.equals("global")) {
        contextBuilder.add(DefaultContextKeys.SERVER_KEY, server);
    }

    String world = attributes.getNode("world").getString("global");
    if (!world.equals("global")) {
        contextBuilder.add(DefaultContextKeys.WORLD_KEY, world);
    }

    return contextBuilder.build();
}
 
Example 4
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 5
Source File: BlockModelResource.java    From BlueMap with MIT License 5 votes vote down vote up
private Element buildElement(BlockModelResource model, ConfigurationNode node, String topModelPath) throws ParseResourceException {
	Element element = model.new Element();
	
	element.from = readVector3f(node.getNode("from"));
	element.to = readVector3f(node.getNode("to"));
	
	element.shade = node.getNode("shade").getBoolean(true);
	
	boolean fullElement = element.from.equals(FULL_CUBE_FROM) && element.to.equals(FULL_CUBE_TO);
	
	if (!node.getNode("rotation").isVirtual()) {
		element.rotation.angle = node.getNode("rotation", "angle").getFloat(0);
		element.rotation.axis = Axis.fromString(node.getNode("rotation", "axis").getString("x"));
		if (!node.getNode("rotation", "origin").isVirtual()) element.rotation.origin = readVector3f(node.getNode("rotation", "origin"));
		element.rotation.rescale = node.getNode("rotation", "rescale").getBoolean(false);
	}
	
	boolean allDirs = true;
	for (Direction direction : Direction.values()) {
		ConfigurationNode faceNode = node.getNode("faces", direction.name().toLowerCase());
		if (!faceNode.isVirtual()) {
			try {
				Face face = buildFace(element, direction, faceNode);
				element.faces.put(direction, face);
			} catch (ParseResourceException | IOException ex) {
				Logger.global.logDebug("Failed to parse an " + direction + " face for the model " + topModelPath + "! " + ex);
			}
		} else {
			allDirs = false;
		}
	}
	
	if (fullElement && allDirs) element.fullCube = true;
	
	return element;
}
 
Example 6
Source File: ShapeMarkerImpl.java    From BlueMap with MIT License 5 votes vote down vote up
private static Vector2d readShapePos(ConfigurationNode node) throws MarkerFileFormatException {
	ConfigurationNode nx, nz;
	nx = node.getNode("x");
	nz = node.getNode("z");
	
	if (nx.isVirtual() || nz.isVirtual()) throw new MarkerFileFormatException("Failed to read shape position: Node x or z is not set!");
	
	return new Vector2d(
			nx.getDouble(),
			nz.getDouble()
		);
}
 
Example 7
Source File: MarkerImpl.java    From BlueMap with MIT License 5 votes vote down vote up
private static Vector3d readPos(ConfigurationNode node) throws MarkerFileFormatException {
	ConfigurationNode nx, ny, nz;
	nx = node.getNode("x");
	ny = node.getNode("y");
	nz = node.getNode("z");
	
	if (nx.isVirtual() || ny.isVirtual() || nz.isVirtual()) throw new MarkerFileFormatException("Failed to read position: One of the nodes x,y or z is missing!");
	
	return new Vector3d(
			nx.getDouble(),
			ny.getDouble(),
			nz.getDouble()
		);
}
 
Example 8
Source File: Protection.java    From UltimateCore with MIT License 5 votes vote down vote up
@Override
public void serialize(TypeToken<?> type, Protection prot, ConfigurationNode node) throws ObjectMappingException {
    node.getNode("locations").setValue(new TypeToken<List<Location>>() {
    }, new ArrayList<>(prot.getLocations()));
    node.getNode("owner").setValue(prot.getOwner().toString());
    node.getNode("players").setValue(prot.getPlayers().stream().map(UUID::toString).collect(Collectors.toList()));
    node.getNode("locktype").setValue(prot.getLocktype().getId());
    if (prot.getLocktype() instanceof ValueLockType) {
        node.getNode("locktype-value", ((ValueLockType) prot.getLocktype()).getValue());
    }
}
 
Example 9
Source File: BlockPropertiesConfig.java    From BlueMap with MIT License 4 votes vote down vote up
private BlockProperties mapNoCache(BlockState bs){
	for (BlockStateMapping<BlockProperties> bm : mappings.get(bs.getFullId())){
		if (bm.fitsTo(bs)){
			return bm.getMapping();
		}
	}
	
	BlockProperties generated = BlockProperties.SOLID;
	
	if (resourcePack != null) {
		try {
			boolean culling = false;
			boolean occluding = false;

			for(TransformedBlockModelResource model : resourcePack.getBlockStateResource(bs).getModels(bs)) {
				culling = culling || model.getModel().isCulling();
				occluding = occluding || model.getModel().isOccluding();
				if (culling && occluding) break;
			}
			
			generated = new BlockProperties(culling, occluding, generated.isFlammable());
		} catch (NoSuchResourceException ignore) {} //ignoring this because it will be logged later again if we try to render that block
	}
	
	mappings.put(bs.getFullId(), new BlockStateMapping<BlockProperties>(new BlockState(bs.getFullId()), generated));
	if (autopoulationConfigLoader != null) {
		synchronized (autopoulationConfigLoader) {
			try {
				ConfigurationNode node = autopoulationConfigLoader.load();
				ConfigurationNode bpNode = node.getNode(bs.getFullId());
				bpNode.getNode("culling").setValue(generated.isCulling());
				bpNode.getNode("occluding").setValue(generated.isOccluding());
				bpNode.getNode("flammable").setValue(generated.isFlammable());
				autopoulationConfigLoader.save(node);
			} catch (IOException ex) {
				Logger.global.noFloodError("blockpropsconf-autopopulate-ioex", "Failed to auto-populate BlockPropertiesConfig!", ex);
			}
		}
	}
	
	return generated;
}
 
Example 10
Source File: CombinedConfigurateStorage.java    From LuckPerms with MIT License 4 votes vote down vote up
@Override
protected ConfigurationNode readFile(StorageLocation location, String name) throws IOException {
    ConfigurationNode root = getStorageLoader(location).getNode();
    ConfigurationNode node = root.getNode(name);
    return node.isVirtual() ? null : node;
}
 
Example 11
Source File: WebHookSerializer.java    From Web-API with MIT License 4 votes vote down vote up
@Override
public WebHook deserialize(TypeToken<?> type, ConfigurationNode value) throws ObjectMappingException {
    String address = value.getNode("address").getString();

    if (address == null) {
        throw new ObjectMappingException("No address specified for web hook!");
    }

    boolean enabled = value.getNode("enabled").getBoolean();
    String method = value.getNode("method").getString();
    WebHook.WebHookDataType dataType = value.getNode("dataType").getValue(TypeToken.of(WebHook.WebHookDataType.class));
    boolean form = value.getNode("form").getBoolean();
    List<WebHookHeader> headers = value.getNode("headers").getList(TypeToken.of(WebHookHeader.class));
    boolean details = value.getNode("details").getBoolean();

    ConfigurationNode filterBase = value.getNode("filter");
    String filterName = filterBase.getNode("name").getString();
    ConfigurationNode filterConfig = filterBase.getNode("config");

    TreeNode permissions = SecurityService.permitAllNode();

    if (headers == null) {
        headers = new ArrayList<>();
    }

    if (method == null) {
        throw new ObjectMappingException("Webhook " + address + " is missing property 'method'.");
    }

    if (dataType == null) {
        throw new ObjectMappingException("Webhook " + address + " is missing property 'dataType'.");
    }

    if (value.getNode("permissions").isVirtual()) {
        throw new ObjectMappingException("Webhook " + address + " is missing property 'permissions'.");
    } else {
        permissions = SecurityService.permissionTreeFromConfig(value.getNode("permissions"));
    }

    WebHook hook = new WebHook(address, enabled, method, dataType, form, headers, details, permissions);

    if (filterName != null) {
        Optional<Class<? extends BaseWebHookFilter>> opt = WebAPI.getWebHookService().getFilter(filterName);
        if (!opt.isPresent()) {
            throw new ObjectMappingException("Could not find filter with name '" + filterName + "'");
        } else {
            try {
                Constructor ctor = opt.get().getConstructor(WebHook.class, ConfigurationNode.class);
                hook.setFilter((BaseWebHookFilter) ctor.newInstance(hook, filterConfig));
            } catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) {
                throw new ObjectMappingException("Could not setup filter '" + filterName + "': " + e.getMessage());
            }
        }
    }

    return hook;
}
 
Example 12
Source File: WebHookSerializer.java    From Web-API with MIT License 4 votes vote down vote up
@Override
public void serialize(TypeToken<?> type, WebHook obj, ConfigurationNode value) throws ObjectMappingException {
    setValueAndComment(value.getNode("address"), obj.getAddress(),
            "This is the address of the endpoint.");

    setValueAndComment(value.getNode("enabled"), obj.isEnabled(),
            "Set to true or omit to enable the endpoint.");

    setValueAndComment(value.getNode("headers"), new TypeToken<List<WebHookHeader>>() {}, obj.getHeaders(),
            "This is a list of additional headers that is sent to the server. You can use this to e.g. specify a secret\n" +
                    "key which ensures that the server knows the requests are coming from the Web-API.\n" +
                    "Please note that the following headers will always be overridden by the Web-API:\n" +
                    "X-WebAPI-Version, X-WebAPI-Event, X-WebAPI-Source, User-Agent, Content-Type, Content-Length, accept, charset");

    setValueAndComment(value.getNode("method"), obj.getMethod(),
            "This is the http method that is used (GET, PUT, POST or DELETE)");

    setValueAndComment(value.getNode("dataType"), TypeToken.of(WebHook.WebHookDataType.class), obj.getDataType(),
            "Choose to either send the data as:\n" +
                    "JSON = application/json\n" +
                    "XML = application/xml");

    setValueAndComment(value.getNode("form"), obj.isForm(),
            "Choose to send the data wrapped as application/x-www-form-urlencoded");

    setValueAndComment(value.getNode("details"), obj.includeDetails(),
            "Set to true to send detailed json data");

    if (obj.getFilter() != null) {
        ConfigurationNode filterNode = value.getNode("filter");
        obj.getFilter().writeToConfig(filterNode);
        if (filterNode instanceof CommentedConfigurationNode) {
            ((CommentedConfigurationNode) filterNode).setComment(
                    "Filters are used to only send certain events to certain endpoints\n" +
                            "Use the 'name' property to select a filter and pass additional options in the 'config' property"
            );
        }
    }

    SecurityService.permissionTreeToConfig(value.getNode("permissions"), obj.getPermissions());
    if (value.getNode("permissions") instanceof CommentedConfigurationNode) {
        ((CommentedConfigurationNode) value.getNode("permissions")).setComment(
                "Permissions node same as the ones in the permissions.conf file,\n" +
                        "use to configure which data is sent to this node");
    }
}