当前位置: 首页>>代码示例>>Java>>正文


Java SimpleConfigurationNode类代码示例

本文整理汇总了Java中ninja.leaping.configurate.SimpleConfigurationNode的典型用法代码示例。如果您正苦于以下问题:Java SimpleConfigurationNode类的具体用法?Java SimpleConfigurationNode怎么用?Java SimpleConfigurationNode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SimpleConfigurationNode类属于ninja.leaping.configurate包,在下文中一共展示了SimpleConfigurationNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: save

import ninja.leaping.configurate.SimpleConfigurationNode; //导入依赖的package包/类
public ConfigurationNode save() {
    try {
        ConfigurationNode node = SimpleConfigurationNode.root();
        ConfigurationNode world_node = node.getNode("WORLD");
        ConfigurationNode x_node = node.getNode("X");
        ConfigurationNode y_node = node.getNode("Y");
        ConfigurationNode z_node = node.getNode("Z");
        world_node.setValue(world_field.hasText() ? world_field.getText() : null);
        x_node.setValue(x_field.hasText() ? x_field.getText() : null);
        y_node.setValue(y_field.hasText() ? y_field.getText() : null);
        z_node.setValue(z_field.hasText() ? z_field.getText() : null);
        return node;
    } catch (Exception e) {
        throw new RuntimeException("Exception saving Location Panel!", e);
    }
}
 
开发者ID:GreWeMa,项目名称:gwm_Crates,代码行数:17,代码来源:LocationPanel.java

示例2: FlatSuperObjectPanel

import ninja.leaping.configurate.SimpleConfigurationNode; //导入依赖的package包/类
public FlatSuperObjectPanel(boolean full, SuperObjectType super_object_type, String[] strings) {
    this.super_object_type = super_object_type;
    setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
    delete_button = new DeleteButton();
    add(delete_button);
    combo_box = new AdvancedComboBox(strings);
    combo_box.setEditable(true);
    Dimension combo_box_dimension = full ? new Dimension(210, 20) : new Dimension(100, 20);
    combo_box.setPreferredSize(combo_box_dimension);
    combo_box.setMaximumSize(combo_box_dimension);
    combo_box.addActionListener(e -> {
        combo_box.setEnabled(false);
        node.getNode("TYPE").setValue(getType());
    });
    add(combo_box);
    configure_button = new AdvancedConfigurationButton(super_object_type, this::getType, this::getNode);
    add(configure_button);
    node = SimpleConfigurationNode.root();
}
 
开发者ID:GreWeMa,项目名称:gwm_Crates,代码行数:20,代码来源:FlatSuperObjectPanel.java

示例3: save

import ninja.leaping.configurate.SimpleConfigurationNode; //导入依赖的package包/类
@Override
public void save() {
    super.save();
    try {
        ConfigurationNode node = getNode();
        ConfigurationNode commands_node = node.getNode("COMMANDS");
        if (commands.isEmpty()) {
            commands_node.setValue(null);
        } else {
            List<ConfigurationNode> command_nodes = new ArrayList<ConfigurationNode>();
            for (CommandPanel command_panel : commands) {
                if (command_panel.getCommandField().hasText()) {
                    ConfigurationNode command_node = SimpleConfigurationNode.root();
                    command_node.getNode("CMD").setValue(command_panel.getCommandField().getText());
                    command_node.getNode("CONSOLE").setValue(command_panel.getConsoleCheckBox().isSelected());
                    command_nodes.add(command_node);
                }
            }
            commands_node.setValue(command_nodes);
        }
    } catch (Exception e) {
        throw new RuntimeException("Exception saving Commands Drop Configuration Dialog!", e);
    }
}
 
开发者ID:GreWeMa,项目名称:gwm_Crates,代码行数:25,代码来源:CommandsDropConfigurationDialog.java

示例4: deserializeItemEnchantment

import ninja.leaping.configurate.SimpleConfigurationNode; //导入依赖的package包/类
private Optional<Object> deserializeItemEnchantment(String s)
{
    try
    {
        int colonFirst = s.indexOf(':'), colonIndex = s.lastIndexOf(':');
        String enchantmentId = colonFirst == colonIndex ? s : s.substring(0, colonIndex);
        int enchantmentLevel = colonFirst == colonIndex ? 1 : Coerce.toInteger(s.substring(colonIndex + 1));

        ConfigurationNode node = SimpleConfigurationNode.root(/* default deserializer */);
        node.getNode(Queries.ENCHANTMENT_ID.toString()).setValue(enchantmentId);
        node.getNode(Queries.LEVEL.toString()).setValue(enchantmentLevel);
        return Optional.ofNullable(node.getValue(ITEM_ENCHANTMENT));
    }
    catch (Exception e)
    {
        return Optional.empty();
    }
}
 
开发者ID:ustc-zzzz,项目名称:VirtualChest,代码行数:19,代码来源:VirtualChestItemStackSerializer.java

示例5: resolvePath

import ninja.leaping.configurate.SimpleConfigurationNode; //导入依赖的package包/类
private ConfigurationNode resolvePath(String path) {
    Iterable<String> paths = Splitter.on('.').split(path);
    ConfigurationNode node = this.root;

    if (node == null) {
        throw new RuntimeException("Config is not loaded.");
    }

    for (String s : paths) {
        node = node.getNode(s);

        if (node == null) {
            return SimpleConfigurationNode.root();
        }
    }

    return node;
}
 
开发者ID:lucko,项目名称:LuckPerms,代码行数:19,代码来源:SpongeConfigAdapter.java

示例6: saveUser

import ninja.leaping.configurate.SimpleConfigurationNode; //导入依赖的package包/类
@Override
public void saveUser(User user) throws Exception {
    user.getIoLock().lock();
    try {
        if (!this.plugin.getUserManager().shouldSave(user)) {
            saveFile(StorageLocation.USER, user.getUuid().toString(), null);
        } else {
            ConfigurationNode data = SimpleConfigurationNode.root();
            data.getNode("uuid").setValue(user.getUuid().toString());
            data.getNode("name").setValue(user.getName().orElse("null"));
            data.getNode(this instanceof JsonDao ? "primaryGroup" : "primary-group").setValue(user.getPrimaryGroup().getStoredValue().orElse(NodeFactory.DEFAULT_GROUP_NAME));

            Set<NodeModel> nodes = user.getEnduringNodes().values().stream().map(NodeModel::fromNode).collect(Collectors.toCollection(LinkedHashSet::new));
            writeNodes(data, nodes);

            saveFile(StorageLocation.USER, user.getUuid().toString(), data);
        }
    } catch (Exception e) {
        throw reportException(user.getUuid().toString(), e);
    } finally {
        user.getIoLock().unlock();
    }
}
 
开发者ID:lucko,项目名称:LuckPerms,代码行数:24,代码来源:ConfigurateDao.java

示例7: saveGroup

import ninja.leaping.configurate.SimpleConfigurationNode; //导入依赖的package包/类
@Override
public void saveGroup(Group group) throws Exception {
    group.getIoLock().lock();
    try {
        ConfigurationNode data = SimpleConfigurationNode.root();
        data.getNode("name").setValue(group.getName());

        Set<NodeModel> nodes = group.getEnduringNodes().values().stream().map(NodeModel::fromNode).collect(Collectors.toCollection(LinkedHashSet::new));
        writeNodes(data, nodes);

        saveFile(StorageLocation.GROUP, group.getName(), data);
    } catch (Exception e) {
        throw reportException(group.getName(), e);
    } finally {
        group.getIoLock().unlock();
    }
}
 
开发者ID:lucko,项目名称:LuckPerms,代码行数:18,代码来源:ConfigurateDao.java

示例8: writeAttributes

import ninja.leaping.configurate.SimpleConfigurationNode; //导入依赖的package包/类
private static ConfigurationNode writeAttributes(NodeModel node) {
    ConfigurationNode attributes = SimpleConfigurationNode.root();
    attributes.getNode("value").setValue(node.getValue());

    if (!node.getServer().equals("global")) {
        attributes.getNode("server").setValue(node.getServer());
    }

    if (!node.getWorld().equals("global")) {
        attributes.getNode("world").setValue(node.getWorld());
    }

    if (node.getExpiry() != 0L) {
        attributes.getNode("expiry").setValue(node.getExpiry());
    }

    if (!node.getContexts().isEmpty()) {
        attributes.getNode("context").setValue(ContextSetConfigurateSerializer.serializeContextSet(node.getContexts()));
    }

    return attributes;
}
 
开发者ID:lucko,项目名称:LuckPerms,代码行数:23,代码来源:ConfigurateDao.java

示例9: serializeContextSet

import ninja.leaping.configurate.SimpleConfigurationNode; //导入依赖的package包/类
public static ConfigurationNode serializeContextSet(ContextSet contextSet) {
    ConfigurationNode data = SimpleConfigurationNode.root();
    Map<String, Collection<String>> map = contextSet.toMultimap().asMap();

    map.forEach((k, v) -> {
        List<String> values = new ArrayList<>(v);
        int size = values.size();

        if (size == 1) {
            data.getNode(k).setValue(values.get(0));
        } else if (size > 1) {
            data.getNode(k).setValue(values);
        }
    });

    return data;
}
 
开发者ID:lucko,项目名称:LuckPerms,代码行数:18,代码来源:ContextSetConfigurateSerializer.java

示例10: serialize

import ninja.leaping.configurate.SimpleConfigurationNode; //导入依赖的package包/类
@Override
public void serialize(TypeToken<?> type, Multimap obj, ConfigurationNode node) throws ObjectMappingException {
    TypeToken<?> key = type.resolveType(Multimap.class.getTypeParameters()[0]);
    TypeToken<?> value = type.resolveType(Multimap.class.getTypeParameters()[1]);
    TypeSerializer keySerial = node.getOptions().getSerializers().get(key);
    TypeSerializer valueSerial = node.getOptions().getSerializers().get(value);

    if (keySerial == null) {
        throw new ObjectMappingException("No type serializer available for type " + key);
    }

    if (valueSerial == null) {
        throw new ObjectMappingException("No type serializer available for type " + value);
    }

    node.setValue(ImmutableMap.of());
    for (Object k : obj.keySet()) {
        for (Object v : obj.get(k)) {
            SimpleConfigurationNode keyNode = SimpleConfigurationNode.root();
            keySerial.serialize(key, k, keyNode);
            valueSerial.serialize(value, v, node.getNode(keyNode.getValue()));
        }
    }
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:25,代码来源:MultimapTypeSerializer.java

示例11: serialize

import ninja.leaping.configurate.SimpleConfigurationNode; //导入依赖的package包/类
@Override
@SuppressWarnings("rawtypes")
public void serialize(TypeToken<?> type, Map<?, ?> obj, ConfigurationNode node) throws ObjectMappingException {
    if (!(type.getType() instanceof ParameterizedType)) {
        throw new ObjectMappingException("Raw types are not supported for collections");
    }
    TypeToken<?> key = type.resolveType(Map.class.getTypeParameters()[0]);
    TypeToken<?> value = type.resolveType(Map.class.getTypeParameters()[1]);
    TypeSerializer keySerial = node.getOptions().getSerializers().get(key);
    TypeSerializer valueSerial = node.getOptions().getSerializers().get(value);

    if (keySerial == null) {
        throw new ObjectMappingException("No type serializer available for type " + key);
    }

    if (valueSerial == null) {
        throw new ObjectMappingException("No type serializer available for type " + value);
    }

    node.setValue(ImmutableMap.of());
    for (Map.Entry<?, ?> ent : obj.entrySet()) {
        SimpleConfigurationNode keyNode = SimpleConfigurationNode.root();
        keySerial.serialize(key, ent.getKey(), keyNode);
        valueSerial.serialize(value, ent.getValue(), node.getNode(keyNode.getValue()));
    }
}
 
开发者ID:SpongePowered,项目名称:configurate,代码行数:27,代码来源:TypeSerializers.java

示例12: testNumberSerializer

import ninja.leaping.configurate.SimpleConfigurationNode; //导入依赖的package包/类
@Test
public void testNumberSerializer() throws ObjectMappingException {
    final TypeToken<Integer> intType = TypeToken.of(Integer.class);
    final TypeToken<Long> longType = TypeToken.of(Long.class);
    final TypeToken<Float> floatType = TypeToken.of(Float.class);
    final TypeToken<?> primitiveIntType = TypeToken.of(int.class);

    // They must all be the same serializer
    final TypeSerializer<Integer> numberSerializer = SERIALIZERS.get(intType);
    assertEquals(numberSerializer, SERIALIZERS.get(longType));
    assertEquals(numberSerializer, SERIALIZERS.get(floatType));
    assertEquals(numberSerializer, SERIALIZERS.get(primitiveIntType));

    SimpleConfigurationNode node = SimpleConfigurationNode.root().setValue(45f);
    assertEquals((Object) 45, numberSerializer.deserialize(intType, node));
    assertEquals((Object) 45L, numberSerializer.deserialize(longType, node));
    assertEquals((Object) 45f, numberSerializer.deserialize(floatType, node));
    assertEquals((Object) 45, numberSerializer.deserialize(primitiveIntType, node));

    numberSerializer.serialize(intType, 42, node);
    assertEquals(42, node.getValue());
}
 
开发者ID:SpongePowered,项目名称:configurate,代码行数:23,代码来源:TypeSerializersTest.java

示例13: testEnumValueSerializer

import ninja.leaping.configurate.SimpleConfigurationNode; //导入依赖的package包/类
@Test
public void testEnumValueSerializer() throws ObjectMappingException {
    final TypeToken<TestEnum> enumType = TypeToken.of(TestEnum.class);

    final TypeSerializer<TestEnum> enumSerializer = SERIALIZERS.get(enumType);

    SimpleConfigurationNode node = SimpleConfigurationNode.root();
    node.getNode("present_val").setValue("first");
    node.getNode("another_present_val").setValue("SECOND");
    node.getNode(("casematters_val")).setValue("tHiRd");
    node.getNode(("casematters_val_lowercase")).setValue("third");
    node.getNode("invalid_val").setValue("3rd");

    assertEquals(TestEnum.FIRST, enumSerializer.deserialize(enumType, node.getNode("present_val")));
    assertEquals(TestEnum.SECOND, enumSerializer.deserialize(enumType, node.getNode("another_present_val")));
    assertEquals(TestEnum.Third, enumSerializer.deserialize(enumType, node.getNode("casematters_val")));
    assertEquals(TestEnum.third, enumSerializer.deserialize(enumType, node.getNode("casematters_val_lowercase")));
    expectedException.expect(ObjectMappingException.class);
    enumSerializer.deserialize(enumType, node.getNode("invalid_val"));

}
 
开发者ID:SpongePowered,项目名称:configurate,代码行数:22,代码来源:TypeSerializersTest.java

示例14: testListSerializer

import ninja.leaping.configurate.SimpleConfigurationNode; //导入依赖的package包/类
@Test
public void testListSerializer() throws ObjectMappingException {
    final TypeToken<List<String>> stringListType = new TypeToken<List<String>>() {};
    final TypeSerializer<List<String>> stringListSerializer = SERIALIZERS.get(stringListType);
    final ConfigurationNode value = SimpleConfigurationNode.root();
    value.getAppendedNode().setValue("hi");
    value.getAppendedNode().setValue("there");
    value.getAppendedNode().setValue("beautiful");
    value.getAppendedNode().setValue("people");

    assertEquals(Arrays.asList("hi", "there", "beautiful", "people"), stringListSerializer.deserialize(stringListType, value));
    value.setValue(null);

    stringListSerializer.serialize(stringListType, Arrays.asList("hi", "there", "lame", "people"), value);
    assertEquals("hi", value.getNode(0).getString());
    assertEquals("there", value.getNode(1).getString());
    assertEquals("lame", value.getNode(2).getString());
    assertEquals("people", value.getNode(3).getString());
}
 
开发者ID:SpongePowered,项目名称:configurate,代码行数:20,代码来源:TypeSerializersTest.java

示例15: testMapSerializer

import ninja.leaping.configurate.SimpleConfigurationNode; //导入依赖的package包/类
@Test
public void testMapSerializer() throws ObjectMappingException {
    final TypeToken<Map<String, Integer>> mapStringIntType = new TypeToken<Map<String, Integer>>() {};
    final TypeSerializer<Map<String, Integer>> mapStringIntSerializer =
            SERIALIZERS.get(mapStringIntType);

    final ConfigurationNode value = SimpleConfigurationNode.root();
    value.getNode("fish").setValue(5);
    value.getNode("bugs").setValue("124880");
    value.getNode("time").setValue("-1");

    final Map<String, Integer> expectedValues = ImmutableMap.of("fish", 5, "bugs", 124880, "time", -1);

    assertEquals(expectedValues, mapStringIntSerializer.deserialize(mapStringIntType, value));

    value.setValue(null);

    mapStringIntSerializer.serialize(mapStringIntType, expectedValues, value);
    assertEquals(5, value.getNode("fish").getInt());
    assertEquals(124880, value.getNode("bugs").getInt());
    assertEquals(-1, value.getNode("time").getInt());
}
 
开发者ID:SpongePowered,项目名称:configurate,代码行数:23,代码来源:TypeSerializersTest.java


注:本文中的ninja.leaping.configurate.SimpleConfigurationNode类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。