@Override public void serialize(TypeToken<?> type, TextTemplate obj, ConfigurationNode value) throws ObjectMappingException { value.getNode(NODE_OPTIONS, NODE_OPEN_ARG).setValue(obj.getOpenArgString()); value.getNode(NODE_OPTIONS, NODE_CLOSE_ARG).setValue(obj.getCloseArgString()); value.getNode(NODE_ARGS).setValue(TOKEN_ARGS, obj.getArguments()); value.getNode(NODE_CONTENT).setValue(TOKEN_TEXT, obj.toText()); }
@Override public BookView deserialize(TypeToken<?> type, ConfigurationNode value) throws ObjectMappingException { BookView.Builder builder = BookView.builder(); builder.author(value.getNode(NODE_AUTHOR).getValue(TOKEN_TEXT)); builder.title(value.getNode(NODE_TITLE).getValue(TOKEN_TEXT)); builder.addPages(value.getNode(NODE_PAGES).getValue(TOKEN_TEXT_LIST)); return builder.build(); }
@Override public void load() { try { ConfigurationOptions options = ConfigurationOptions.defaults(); options = options.setShouldCopyDefaults(true); node = config.load(options); } catch (IOException e) { logger.warn("Error loading WorldEdit configuration", e); profile = node.getNode("debug").getBoolean(profile); traceUnflushedSessions = node.getNode("debugging", "trace-unflushed-sessions").getBoolean(traceUnflushedSessions); wandItem = node.getNode("wand-item").getString(wandItem); try { wandItem = LegacyMapper.getInstance().getItemFromLegacy(Integer.parseInt(wandItem)).getId(); defaultChangeLimit = Math.max(-1, node.getNode("limits", "max-blocks-changed", "default").getInt(defaultChangeLimit)); maxChangeLimit = Math.max(-1, node.getNode("limits", "max-blocks-changed", "maximum").getInt(maxChangeLimit)); defaultMaxPolygonalPoints = Math.max(-1, node.getNode("limits", "max-polygonal-points", "default").getInt(defaultMaxPolygonalPoints)); maxPolygonalPoints = Math.max(-1, node.getNode("limits", "max-polygonal-points", "maximum").getInt(maxPolygonalPoints)); maxRadius = Math.max(-1, node.getNode("limits", "max-radius").getInt(maxRadius)); maxBrushRadius = node.getNode("limits", "max-brush-radius").getInt(maxBrushRadius); maxSuperPickaxeSize = Math.max(1, node.getNode("limits", "max-super-pickaxe-size").getInt(maxSuperPickaxeSize)); butcherDefaultRadius = Math.max(-1, node.getNode("limits", "butcher-radius", "default").getInt(butcherDefaultRadius)); butcherMaxRadius = Math.max(-1, node.getNode("limits", "butcher-radius", "maximum").getInt(butcherMaxRadius)); disallowedBlocks = new HashSet<>(node.getNode("limits", "disallowed-blocks").getList(TypeToken.of(String.class)));
@Override public TextTemplate deserialize(TypeToken<?> type, ConfigurationNode value) throws ObjectMappingException { this.root = value; this.openArg = value.getNode(NODE_OPEN_ARG).getString(TextTemplate.DEFAULT_OPEN_ARG); this.closeArg = value.getNode(NODE_CLOSE_ARG).getString(TextTemplate.DEFAULT_CLOSE_ARG); Text content = value.getNode(NODE_CONTENT).getValue(TypeToken.of(Text.class)); List<Object> elements = new ArrayList<>(); parse(content, elements); return TextTemplate.of(elements.toArray(new Object[elements.size()])); }
private void parseArg(LiteralText source, List<Object> into) throws ObjectMappingException { String name = unwrap(source.getContent()); boolean optional = this.root.getNode(NODE_ARGS, name, NODE_OPT).getBoolean(); Text defaultValue = this.root.getNode(NODE_ARGS, name, NODE_DEF_VAL).getValue(TypeToken.of(Text.class)); TextFormat format = source.getFormat(); into.add(TextTemplate.arg(name).format(format).optional(optional).defaultValue(defaultValue).build()); }
@Override public TextFormat deserialize(TypeToken<?> type, ConfigurationNode value) throws ObjectMappingException { TextColor color = TextColors.NONE; GameRegistry registry = Sponge.getRegistry(); String colorId = value.getNode(NODE_COLOR).getString(); if (colorId != null) { color = registry.getType(TextColor.class, colorId).orElseThrow(() -> new ObjectMappingException("Color not found: " + colorId)); } TextStyle style = TextStyles.NONE; ConfigurationNode styleNode = value.getNode(NODE_STYLE); for (TextStyle.Base component : registry.getAllOf(TextStyle.Base.class)) { if (styleNode.getNode(component.getId().toLowerCase()).getBoolean()) { style = style.and(component); } } return TextFormat.NONE.color(color).style(style); }
@Override public void serialize(TypeToken<?> type, Text obj, ConfigurationNode value) throws ObjectMappingException { String json = (String) obj.toContainer().get(Queries.JSON).get(); GsonConfigurationLoader gsonLoader = GsonConfigurationLoader.builder() .setSource(() -> new BufferedReader(new StringReader(json))) .build(); try { value.setValue(gsonLoader.load()); } catch (IOException e) { throw new ObjectMappingException(e); } }
private <T> T calculateDef(T defValue) { if (defValue != null && getOptions().shouldCopyDefaults()) { setValue(defValue); } return defValue; }
protected void clear() { synchronized (this) { ConfigValue oldValue = this.value; value = new NullConfigValue(this); oldValue.clear(); } }
@Override public Object getValue(Object def) { Object ret = value.getValue(); return ret == null ? storeDefault(def) : ret; }
@Override public Object getValue(Object def) { Object ret = value.getValue(); return ret == null ? calculateDef(def) : ret; }
@Override public void serialize(TypeToken<?> type, BookView bookView, ConfigurationNode value) throws ObjectMappingException { value.getNode(NODE_AUTHOR).setValue(TOKEN_TEXT, bookView.getAuthor()); value.getNode(NODE_TITLE).setValue(TOKEN_TEXT, bookView.getTitle()); value.getNode(NODE_PAGES).setValue(TOKEN_TEXT_LIST, bookView.getPages()); } }
private <T> T storeDefault(TypeToken<T> type, T defValue) throws ObjectMappingException { if (defValue != null && getOptions().shouldCopyDefaults()) { setValue(type, defValue); } return defValue; }
protected void clear() { synchronized (this) { ConfigValue oldValue = this.value; value = new NullConfigValue(this); oldValue.clear(); } } // }}}
@Override public Object getValue(Object def) { Object ret = value.getValue(); return ret == null ? storeDefault(def) : ret; }
@Override public void serialize(TypeToken<?> type, TextFormat obj, ConfigurationNode value) throws ObjectMappingException { value.getNode(NODE_COLOR).setValue(obj.getColor().getId()); ConfigurationNode styleNode = value.getNode(NODE_STYLE); TextStyle composite = obj.getStyle(); Sponge.getRegistry().getAllOf(TextStyle.Base.class) .forEach(style -> styleNode.getNode(style.getId().toLowerCase()).setValue(composite.contains(style))); }
protected void clear() { synchronized (this) { ConfigValue oldValue = this.value; value = new NullConfigValue(this); oldValue.clear(); } }