codechicken.lib.config.ConfigTag Java Examples

The following examples show how to use codechicken.lib.config.ConfigTag. 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: ObfMapping.java    From CodeChickenLib with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static File confDirectoryGuess(int i, ConfigTag tag) {
    File mcDir = (File) FMLInjectionData.data()[6];
    switch (i) {
        case 0:
            return tag.value != null ? new File(tag.getValue()) : null;
        case 1:
            return new File(mcDir, "../conf");
        case 2:
            return new File(mcDir, "../build/unpacked/conf");
        case 3:
            return new File(System.getProperty("user.home"), ".gradle/caches/minecraft/net/minecraftforge/forge/"+
                FMLInjectionData.data()[4]+"-"+ ForgeVersion.getVersion()+"/unpacked/conf");
        default:
            JFileChooser fc = new JFileChooser(mcDir);
            fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            fc.setDialogTitle("Select an mcp conf dir for the deobfuscator.");
            int ret = fc.showDialog(null, "Select");
            return ret == JFileChooser.APPROVE_OPTION ? fc.getSelectedFile() : null;
    }
}
 
Example #2
Source File: WRCoreProxy.java    From WirelessRedstone with MIT License 6 votes vote down vote up
public void init() {
    PacketCustom.assignHandler(channel, new WRCoreSPH());

    obsidianStick = createItem("obsidianStick");
    stoneBowl = createItem("stoneBowl");
    retherPearl = createItem("retherPearl");
    wirelessTransceiver = createItem("wirelessTransceiver");
    blazeTransceiver = createItem("blazeTransceiver");
    recieverDish = createItem("recieverDish");
    blazeRecieverDish = createItem("blazeRecieverDish");

    ConfigTag coreconfig = SaveManager.config().getTag("core").useBraces().setPosition(10);
    WirelessBolt.init(coreconfig);
    damagebolt = new DamageSource("bolt");

    addRecipies();
}
 
Example #3
Source File: GuiWirelessSniffer.java    From WirelessRedstone with MIT License 6 votes vote down vote up
public static void loadColours(ConfigTag addonconfig)
{
    ConfigTag snifferconifg = addonconfig.getTag("sniffer.gui").useBraces();
    ConfigTag colourconfig = snifferconifg.getTag("colour").setPosition(0).setComment("Colours are in 0xAARRGGBB format:Alpha should be FF");
    ConfigTag borderconfig = snifferconifg.getTag("border").setPosition(1).setNewLine(true);
    
    colourOn = new ColourARGB(colourconfig.getTag("on").setPosition(0).setComment("").getHexValue(0xffFF0000));
    colourOff = new ColourARGB(colourconfig.getTag("off").setPosition(1).getHexValue(0xff700000));
    colourJammed = new ColourARGB(colourconfig.getTag("jammed").setPosition(2).getHexValue(0xff707070));
    
    colourPOn = new ColourARGB(colourconfig.getTag("private.on").setPosition(0).getHexValue(0xff40F000));
    colourPOff = new ColourARGB(colourconfig.getTag("private.off").setPosition(1).getHexValue(0xff40A000));
    
    borderOn = new ColourARGB(borderconfig.getTag("on").setPosition(0).getHexValue(0xffEE0000));
    borderOff = new ColourARGB(borderconfig.getTag("off").setPosition(1).getHexValue(0xff500000));
    borderJammed =  new ColourARGB(borderconfig.getTag("jammed").setPosition(2).getHexValue(0xff505050));
    
    borderPOn = new ColourARGB(borderconfig.getTag("private.on").setPosition(0).getHexValue(0xff20E000));
    borderPOff = new ColourARGB(borderconfig.getTag("private.off").setPosition(1).getHexValue(0xff209000));
}
 
Example #4
Source File: AbstractConfigFile.java    From CodeChickenLib with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public ConfigTag load() {
    if (Files.exists(file)) {
        try {
            serializer.parse(file, rootTag);
            return rootTag;
        } catch (IOException e) {
            rootTag.clear();
            didError = true;
            Path backupFile = null;
            try {
                backupFile = backupFile(file);
            } catch (IOException ioException) {
                logger.warn("Failed to backup config file: ", e);
            }
            logger.error("Failed to load config '{}', Backing up config to '{}' and generating a fresh one.", file, backupFile, e);
        }
    }
    return rootTag;
}
 
Example #5
Source File: ProxyClient.java    From CodeChickenLib with GNU Lesser General Public License v2.1 6 votes vote down vote up
private void loadClientConfig() {
    ConfigTag tag;
    ConfigTag clientTag = CodeChickenLib.config.getTag("client");
    clientTag.deleteTag("block_renderer_dispatcher_misc");

    tag = clientTag.getTag("catchBlockRenderExceptions")//
            .setComment(//
                    "With this enabled, CCL will catch all exceptions thrown whilst rendering blocks.",//
                    "If an exception is caught, the block will not be rendered."//
            );
    catchBlockRenderExceptions = tag.setDefaultBoolean(true).getBoolean();
    tag = clientTag.getTag("catchItemRenderExceptions")//
            .setComment(//
                    "With this enabled, CCL will catch all exceptions thrown whilst rendering items.",//
                    "By default CCL will only enhance the crash report, but with 'attemptRecoveryOnItemRenderException' enabled",//
                    " CCL will attempt to recover after the exception."//
            );
    messagePlayerOnRenderExceptionCaught = tag.setDefaultBoolean(true).getBoolean();

    clientTag.save();
}
 
Example #6
Source File: ChunkLoaderManager.java    From ChickenChunks with MIT License 5 votes vote down vote up
public static boolean allowChunkViewer(String username) {
    ConfigTag config = ChickenChunks.config.getTag("allowchunkviewer");
    if (config.containsTag(username))
        return config.getTag(username).getBooleanValue(true);

    if (ServerUtils.isPlayerOP(username))
        return config.getTag("OP").getBooleanValue(true);

    return config.getTag("DEFAULT").getBooleanValue(true);
}
 
Example #7
Source File: ChunkLoaderManager.java    From ChickenChunks with MIT License 5 votes vote down vote up
public static boolean allowOffline(String username) {
    ConfigTag config = ChickenChunks.config.getTag("allowoffline");
    if (config.containsTag(username))
        return config.getTag(username).getBooleanValue(true);

    if (ServerUtils.isPlayerOP(username))
        return config.getTag("OP").getBooleanValue(true);

    return config.getTag("DEFAULT").getBooleanValue(true);
}
 
Example #8
Source File: EnderStorage.java    From EnderStorage with MIT License 5 votes vote down vote up
private void loadPersonalItem() {
    ConfigTag tag = config.getTag("personalItemID")
            .setComment("The name of the item used to set the chest to personal. Diamond by default");
    String name = tag.getValue("diamond");
    personalItem = (Item) Item.itemRegistry.getObject(name);
    if (personalItem == null) {
        personalItem = Items.diamond;
        tag.setValue("diamond");
    }
}
 
Example #9
Source File: Option.java    From NotEnoughItems with MIT License 5 votes vote down vote up
public void copyGlobal(String s, boolean recursive) {
    if (!worldConfig()) {
        return;
    }

    ConfigTag tag = globalConfigSet().config.getTag(s);
    worldConfigSet().config.getTag(s).setValue(tag.getValue());
    if (recursive) {
        for (String s2 : tag.childTagMap().keySet()) {
            copyGlobal(s + "." + s2);
        }
    }
}
 
Example #10
Source File: HUDRenderer.java    From NotEnoughItems with MIT License 5 votes vote down vote up
@Override
public void tickKeyStates() {
    if (KeyManager.keyStates.get("world.highlight_tips").down) {
        ConfigTag tag = NEIClientConfig.getSetting("world.highlight_tips");
        tag.setBooleanValue(!tag.getBooleanValue());
    }
}
 
Example #11
Source File: NEIClientConfig.java    From NotEnoughItems with MIT License 5 votes vote down vote up
public static boolean isWorldSpecific(String setting) {
    if (world == null) {
        return false;
    }
    ConfigTag tag = world.config.getTag(setting, false);
    return tag != null && tag.value != null;
}
 
Example #12
Source File: Option.java    From NotEnoughItems with MIT License 5 votes vote down vote up
public void copyGlobal(String s, boolean recursive) {
    if (!worldConfig())
        return;

    ConfigTag tag = globalConfigSet().config.getTag(s);
    worldConfigSet().config.getTag(s).setValue(tag.getValue());
    if(recursive)
        for(String s2 : tag.childTagMap().keySet())
            copyGlobal(s+"."+s2);
}
 
Example #13
Source File: ConfigTests.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test (expected = IllegalArgumentException.class)
public void testWriteReadStreamFail() throws Throwable {
    Path dir = Files.createTempDirectory("write_read_stream_test_fail");
    Path testFile = dir.resolve("test.cfg");
    copyTestFile(testFile);
    ConfigTag configA = new StandardConfigFile(testFile).load();
    ConfigTag configB = configA.copy();
    MCDataByteBuf byteStream = new MCDataByteBuf(Unpooled.buffer());
    configA.write(byteStream);
    configB.deleteTag("Tag1");
    configB.read(byteStream);
    ensureSame(configA, configB);
}
 
Example #14
Source File: ConfigTests.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testWriteReadStream() throws Throwable {
    Path dir = Files.createTempDirectory("write_read_stream_test");
    Path testFile = dir.resolve("test.cfg");
    copyTestFile(testFile);
    ConfigTag configA = new StandardConfigFile(testFile).load();
    ConfigTag configB = configA.copy();
    MCDataByteBuf byteStream = new MCDataByteBuf(Unpooled.buffer());
    configA.write(byteStream);
    ConfigTag tag1 = configB.getTag("Tag1");
    tag1.getTag("string").setString("nope");
    tag1.getTag("boolean_array").getBooleanList().clear();
    configB.read(byteStream);
    ensureSame(configA, configB);
}
 
Example #15
Source File: ConfigTests.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testCopyFrom() throws Throwable {
    Path dir = Files.createTempDirectory("copy_from_test");
    Path testFile = dir.resolve("test.cfg");
    copyTestFile(testFile);
    ConfigTag configA = new StandardConfigFile(testFile).load();
    ConfigTag configB = configA.copy();
    ConfigTag tag1 = configB.getTag("Tag1");
    tag1.getTag("string").setString("nope");
    tag1.getTag("boolean_array").getBooleanList().clear();
    configB.copyFrom(configA);
    ensureSame(configA, configB);
}
 
Example #16
Source File: ConfigTests.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test (expected = ConfigTestException.class)
public void testCopyFail() throws Throwable {
    Path dir = Files.createTempDirectory("copy_test_fail");
    Path testFile = dir.resolve("test.cfg");
    copyTestFile(testFile);
    ConfigTag configA = new StandardConfigFile(testFile).load();
    ConfigTag configB = configA.copy();
    configB.setTagVersion("boop");
    ConfigTag tag1 = configB.getTag("Tag1");
    tag1.getTag("string").setString("nope");
    tag1.getTag("boolean_array").getBooleanList().clear();
    ensureSame(configA, configB);
}
 
Example #17
Source File: ConfigTests.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testCopy() throws Throwable {
    Path dir = Files.createTempDirectory("copy_test");
    Path testFile = dir.resolve("test.cfg");
    copyTestFile(testFile);
    ConfigTag configA = new StandardConfigFile(testFile).load();
    ConfigTag configB = configA.copy();
    ensureSame(configA, configB);
}
 
Example #18
Source File: ConfigTests.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testGeneration() throws Throwable {
    Path dir = Files.createTempDirectory("generation_test");
    ConfigTag generated_config = new StandardConfigFile(dir.resolve("generated.cfg")).load();
    generated_config.setTagVersion("1.1");
    generated_config.setComment("This is a config comment.");

    ConfigTag tag = generated_config.getTag("Tag1").setComment("Specifies a new ConfigTag");
    tag.setTagVersion("1.2.3.4");
    ConfigTag bool = tag.getTag("boolean").setDefaultBoolean(false);
    ConfigTag string = tag.getTag("string").setDefaultString("This is a string with data, Cannot be Multi Line.");
    ConfigTag integer = tag.getTag("integer").setDefaultInt(123456789);
    ConfigTag doubl_e = tag.getTag("double").setDefaultDouble(1.2345);
    ConfigTag hex = tag.getTag("hex").setDefaultHex(0xFFFFFFFF);
    ConfigTag boolArray = tag.getTag("boolean_array").setDefaultBooleanList(Arrays.asList(true, false, true, false));
    ConfigTag stringArray = tag.getTag("string_array").setDefaultStringList(Arrays.asList("value", "value2", "value33"));
    ConfigTag intArray = tag.getTag("integer_array").setDefaultIntList(Arrays.asList(1, 2, 3, 4, 5, 6));
    ConfigTag doubleArray = tag.getTag("double_array").setDefaultDoubleList(Arrays.asList(1.2, 3.4, 5.6, 7.8));
    ConfigTag hexArray = tag.getTag("hex_array").setDefaultHexList(Arrays.asList(0xFFFF, 0x00FF));

    ConfigTag tag2 = generated_config.getTag("Tag2");
    ConfigTag tag3 = tag2.getTag("Tag3");
    ConfigTag tag4 = tag3.getTag("Tag4");
    ConfigTag depthTest = tag4.getTag("depth_test").setDefaultBoolean(true);
    generated_config.save();
    Path staticFile = dir.resolve("static.cfg");
    copyTestFile(staticFile);
    ConfigTag staticConfig = new StandardConfigFile(staticFile).load();
    ensureSame(staticConfig, generated_config);
}
 
Example #19
Source File: ConfigTests.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test (expected = IllegalArgumentException.class)
public void testCopyFromFail() throws Throwable {
    Path dir = Files.createTempDirectory("copy_from_fail_test");
    Path testFile = dir.resolve("test.cfg");
    copyTestFile(testFile);
    ConfigTag configA = new StandardConfigFile(testFile).load();
    ConfigTag configB = configA.copy();
    configA.deleteTag("Tag1");
    configB.copyFrom(configA);
    ensureSame(configA, configB);
}
 
Example #20
Source File: StandardConfigSerializer.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void save(Path file, ConfigTag tag) {
    if (Files.exists(file)) {
        SneakyUtils.sneaky(() -> Files.delete(file));
    }
    if (!Files.exists(file.getParent())) {
        SneakyUtils.sneaky(() -> Files.createDirectories(file.getParent()));
    }
    try (PrintWriter writer = new PrintWriter(Files.newBufferedWriter(file, StandardOpenOption.CREATE))) {
        writeTag((ConfigTagImpl) tag, writer, 0);
    } catch (IOException e) {
        logger.error("Failed to save config file: {}", file, e);
    }
}
 
Example #21
Source File: ObfMapping.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static File[] getConfFiles() {
    
    // check for GradleStart system vars
    if (!Strings.isNullOrEmpty(System.getProperty("net.minecraftforge.gradle.GradleStart.srgDir")))
    {
        File srgDir = new File(System.getProperty("net.minecraftforge.gradle.GradleStart.srgDir"));
        File csvDir = new File(System.getProperty("net.minecraftforge.gradle.GradleStart.csvDir"));
        
        if (srgDir.exists() && csvDir.exists())
        {
            File srg = new File(srgDir, "notch-srg.srg");
            File fieldCsv = new File(csvDir, "fields.csv");
            File methodCsv = new File(csvDir, "methods.csv");
            
            if (srg.exists() && fieldCsv.exists() && methodCsv.exists())
                return new File[] {srg, fieldCsv, methodCsv};
        }
    }
    
    ConfigTag tag = ASMHelper.config.getTag("mappingDir").setComment("Path to directory holding packaged.srg, fields.csv and methods.csv for mcp remapping");
    for (int i = 0; i < DIR_GUESSES+DIR_ASKS; i++) {
        File dir = confDirectoryGuess(i, tag);
        if (dir == null || dir.isFile())
            continue;

        File[] mappings;
        try {
            mappings = parseConfDir(dir);
        } catch (Exception e) {
            if (i >= DIR_GUESSES)
                e.printStackTrace();
            continue;
        }

        tag.setValue(dir.getPath());
        return mappings;
    }

    throw new RuntimeException("Failed to select mappings directory, set it manually in the config");
}
 
Example #22
Source File: ConfigTests.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testReadWriteRead() throws Throwable {
    Path dir = Files.createTempDirectory("read_write_back_test");
    Path before = dir.resolve("before.cfg");
    Path after = dir.resolve("after.cfg");
    copyTestFile(before);
    ConfigFile beforeCFile = new StandardConfigFile(before);
    ConfigTag beforeConfig = beforeCFile.load();
    Assert.assertFalse(beforeCFile.didError());
    StandardConfigSerializer.INSTANCE.save(after, beforeConfig);
    ConfigTag afterConfig = new StandardConfigFile(after).load();
    ensureSame(beforeConfig, afterConfig);
}
 
Example #23
Source File: AbstractConfigFile.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void save(ConfigTag tag) {
    try {
        serializer.save(file, tag);
    } catch (IOException e) {
        logger.error("Unable to save config file '{}'.", file, e);
    }
}
 
Example #24
Source File: Option.java    From NotEnoughItems with MIT License 4 votes vote down vote up
/**
 * @return The tag currently being used ingame, world if a world override exists, otherwise global
 */
public ConfigTag activeTag() {
    return activeTag(configName());
}
 
Example #25
Source File: NEIClientConfig.java    From NotEnoughItems with MIT License 4 votes vote down vote up
public static boolean isWorldSpecific(String setting) {
    if(world == null) return false;
    ConfigTag tag = world.config.getTag(setting, false);
    return tag != null && tag.value != null;
}
 
Example #26
Source File: NEIClientConfig.java    From NotEnoughItems with MIT License 4 votes vote down vote up
public static ConfigTag getSetting(String s) {
    return isWorldSpecific(s) ? world.config.getTag(s) : global.config.getTag(s);
}
 
Example #27
Source File: NEIClientConfig.java    From NotEnoughItems with MIT License 4 votes vote down vote up
public static void toggleBooleanSetting(String setting) {
    ConfigTag tag = getSetting(setting);
    tag.setBooleanValue(!tag.getBooleanValue());
}
 
Example #28
Source File: WirelessBolt.java    From WirelessRedstone with MIT License 4 votes vote down vote up
public static void init(ConfigTag rpconfig) {
    ConfigTag boltconfig = rpconfig.getTag("boltEffect").useBraces();
    ConfigTag damageconfig = boltconfig.getTag("damage").setComment("Damages are in half hearts:If an entity gets knocked into another bolt it may suffer multiple hits");
    entitydamage = damageconfig.getTag("entity").setComment("").getIntValue(5);
    playerdamage = damageconfig.getTag("player").setComment("").getIntValue(3);
}
 
Example #29
Source File: NEIClientConfig.java    From NotEnoughItems with MIT License 4 votes vote down vote up
public static void cycleSetting(String setting, int max) {
    ConfigTag tag = getSetting(setting);
    tag.setIntValue((tag.getIntValue() + 1) % max);
}
 
Example #30
Source File: Option.java    From NotEnoughItems with MIT License 4 votes vote down vote up
/**
 * @return true if the world config contains a tag with this name
 */
public boolean worldSpecific(String s) {
    ConfigTag tag = worldConfigSet().config.getTag(s, false);
    return tag != null && tag.value != null;
}