@Override public void load() { super.load(); creativeEnable = node.getNode("use-in-creative").getBoolean(false); cheatMode = node.getNode("cheat-mode").getBoolean(false); try { config.save(node); } catch (IOException e) { logger.warn("Error loading WorldEdit configuration", e); } }
@Nullable @Override protected Object parseValue(CommandSource source, CommandArgs args) throws ArgumentParseException { String argument = (String) super.parseValue(source, args); Callable<BufferedReader> reader = () -> new BufferedReader(new StringReader(argument)); ConfigurationLoader<? extends ConfigurationNode> loader = HoconConfigurationLoader.builder() .setSource(reader).build(); ConfigurationNode node; try { node = loader.load(); } catch (IOException ex) { throw args.createError(Text.of("Node parsing failed: ", ex.getMessage())); } return DataTranslators.CONFIGURATION_NODE.translate(node); }
protected AbstractConfigurationLoader(Builder<?> builder, CommentHandler[] commentHandlers) { this.source = builder.getSource(); this.sink = builder.getSink(); this.headerMode = builder.getHeaderMode(); this.defaultOptions = builder.getDefaultOptions(); this.commentHandlers = commentHandlers; }
/** * Create a new configuration node populated with the appropriate data. * * @return The newly constructed node * @throws java.io.IOException if any sort of error occurs with reading or parsing the configuration */ default NodeType load() throws IOException { return load(getDefaultOptions()); }
/** * Return an empty node of the most appropriate type for this loader, using the default options. * * @return The appropriate node type */ default NodeType createEmptyNode() { return createEmptyNode(getDefaultOptions()); }
public static BufferedWriter createAtomicBufferedWriter(Path path, Charset charset) throws IOException { path = path.toAbsolutePath(); Path writePath = getTemporaryPath(path.getParent(), path.getFileName().toString()); if (Files.exists(path)) { Files.copy(path, writePath, StandardCopyOption.COPY_ATTRIBUTES, StandardCopyOption.REPLACE_EXISTING); } BufferedWriter output = Files.newBufferedWriter(writePath, charset); return new BufferedWriter(new AtomicFileWriter(writePath, path, output)); }
public T setSink(Callable<BufferedWriter> sink) { this.sink = sink; return self(); }
@Test public void testLoadNonexistantPath(@TempDirectory.TempDir Path tempDir) throws IOException { Path tempPath = tempDir.resolve("text5.txt").getRoot().resolve("does-not-exist-dont-edit-testdir"); TestConfigurationLoader loader = TestConfigurationLoader.builder().setPath(tempPath).build(); loader.load(); }
protected TestConfigurationLoader(Builder builder) { super(builder, CommentHandlers.values()); }
public static Builder builder() { return new Builder(); }
@NonNull @Override public TestConfigurationLoader build() { return new TestConfigurationLoader(this); } }
options = options.setShouldCopyDefaults(true); node = config.load(options); } catch (IOException e) { logger.warn("Error loading WorldEdit configuration", e);
protected AbstractConfigurationLoader(@NonNull Builder<?> builder, @NonNull CommentHandler[] commentHandlers) { this.source = builder.getSource(); this.sink = builder.getSink(); this.headerMode = builder.getHeaderMode(); this.commentHandlers = commentHandlers; this.defaultOptions = builder.getDefaultOptions(); }
/** * Return an empty node of the most appropriate type for this loader, using the default options. * * @return The appropriate node type */ @NonNull default NodeType createEmptyNode() { return createEmptyNode(getDefaultOptions()); }
public T setHeaderMode(HeaderMode mode) { this.headerMode = mode; return self(); }
@Override public PermissionsExConfiguration reload() throws IOException { ConfigurationNode node = this.loader.load(); FilePermissionsExConfiguration ret = new FilePermissionsExConfiguration(this.loader, node); ret.load(); return ret; }
protected AbstractConfigurationLoader(@NonNull Builder<?> builder, @NonNull CommentHandler[] commentHandlers) { this.source = builder.getSource(); this.sink = builder.getSink(); this.headerMode = builder.getHeaderMode(); this.commentHandlers = commentHandlers; this.defaultOptions = builder.getDefaultOptions(); }
/** * Return an empty node of the most appropriate type for this loader, using the default options. * * @return The appropriate node type */ @NonNull default NodeType createEmptyNode() { return createEmptyNode(getDefaultOptions()); }
public T setSource(Callable<BufferedReader> source) { this.source = source; return self(); }
@Deprecated public T setPreservesHeader(boolean preservesHeader) { this.headerMode = preservesHeader ? HeaderMode.PRESERVE : HeaderMode.PRESET; return self(); }