Java Code Examples for org.bukkit.configuration.file.YamlConfiguration#getInt()

The following examples show how to use org.bukkit.configuration.file.YamlConfiguration#getInt() . 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: TrMenuLoader.java    From TrMenu with MIT License 6 votes vote down vote up
private void updateConfig() {
    TConfig oldCfg = TrMenu.SETTINGS;
    YamlConfiguration newCfg = YamlConfiguration.loadConfiguration(new InputStreamReader(TrMenu.getPlugin().getResource("settings.yml")));
    if (newCfg.getInt("CONFIG-VERSION") == TrMenu.SETTINGS.getInt("CONFIG-VERSION")) {
        return;
    }
    oldCfg.set("CONFIG-VERSION", newCfg.getInt("CONFIG-VERSION"));
    oldCfg.getKeys(true).forEach(key -> {
        if (!newCfg.contains(key)) {
            oldCfg.set(key, null);
        }
    });
    newCfg.getKeys(true).forEach(key -> {
        if (!oldCfg.contains(key)) {
            oldCfg.set(key, newCfg.get(key));
        }
    });
    oldCfg.saveToFile();
}
 
Example 2
Source File: HelperProfilesPlugin.java    From helper with MIT License 6 votes vote down vote up
@Override
protected void enable() {
    SqlProvider sqlProvider = getService(SqlProvider.class);
    Sql sql;

    // load sql instance
    YamlConfiguration config = loadConfig("config.yml");
    if (config.getBoolean("use-global-credentials", true)) {
        sql = sqlProvider.getSql();
    } else {
        sql = sqlProvider.getSql(DatabaseCredentials.fromConfig(config));
    }

    // init the table
    String tableName = config.getString("table-name", "helper_profiles");
    int preloadAmount = config.getInt("preload-amount", 2000);

    // provide the ProfileRepository service
    provideService(ProfileRepository.class, bindModule(new HelperProfileRepository(sql, tableName, preloadAmount)));
}
 
Example 3
Source File: CustomGunItem.java    From QualityArmory with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void initIronsights(File dataFolder) {
	File ironsights = new File(dataFolder, "default_ironsightstoggleitem.yml");
	YamlConfiguration ironconfig = YamlConfiguration.loadConfiguration(ironsights);
	if (!ironconfig.contains("displayname")) {
		ironconfig.set("material", Material.CROSSBOW.name());
		ironconfig.set("id", 68);
		ironconfig.set("displayname", IronsightsHandler.ironsightsDisplay);
		try {
			ironconfig.save(ironsights);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	IronsightsHandler.ironsightsMaterial = Material.matchMaterial(ironconfig.getString("material"));
	IronsightsHandler.ironsightsData = ironconfig.getInt("id");
	IronsightsHandler.ironsightsDisplay = ironconfig.getString("displayname");

}
 
Example 4
Source File: CustomGunItem.java    From QualityArmory with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void initIronsights(File dataFolder) {
	File ironsights = new File(dataFolder,"default_ironsightstoggleitem.yml");
	YamlConfiguration ironconfig = YamlConfiguration.loadConfiguration(ironsights);
	if(!ironconfig.contains("displayname")){
		ironconfig.set("material",Material.DIAMOND_AXE.name());
		ironconfig.set("id",21);
		ironconfig.set("displayname",IronsightsHandler.ironsightsDisplay);
		try {
			ironconfig.save(ironsights);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	IronsightsHandler.ironsightsMaterial = Material.matchMaterial(ironconfig.getString("material"));
	IronsightsHandler.ironsightsData = ironconfig.getInt("id");
	IronsightsHandler.ironsightsDisplay = ironconfig.getString("displayname");
}
 
Example 5
Source File: IslandInfo.java    From uSkyBlock with GNU General Public License v3.0 6 votes vote down vote up
public IslandInfo(@NotNull String islandName, @NotNull uSkyBlock plugin) {
    Validate.notNull(islandName, "IslandName cannot be null");
    Validate.notEmpty(islandName, "IslandName cannot be empty");

    this.plugin = plugin;
    config = new YamlConfiguration();
    file = new File(directory, islandName + ".yml");
    name = islandName;
    if (file.exists()) {
        readConfig(config, file);
        if (config.getInt("version", 0) < YML_VERSION || config.contains("maxSize")) {
            updateConfig();
        }
    } else {
        log.fine("No file for " + islandName + " found, creating a fresh island!");
    }
}
 
Example 6
Source File: I18nOrigin.java    From TabooLib with MIT License 5 votes vote down vote up
@Override
public void init() {
    File localeFile = getLocaleFile(TabooLib.getPlugin());
    if (localeFile == null) {
        lang = new YamlConfiguration();
    } else {
        lang = Files.load(localeFile);
    }
    if (lang.getInt("version") < 3 && !released) {
        released = true;
        Files.deepDelete(new File(TabooLib.getPlugin().getDataFolder(), "simpleI18n"));
        init();
    }
}
 
Example 7
Source File: TopTen.java    From askyblock with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Loads the top ten from the file system topten.yml. If it does not exist
 * then the top ten is created
 */
public void topTenLoad() {
    plugin.getLogger().info("Loading Top Ten");
    topTenList.clear();
    // Check to see if the top ten list exists
    File topTenFile = new File(plugin.getDataFolder(), "topten.yml");
    if (!topTenFile.exists()) {
        plugin.getLogger().warning("Top ten file does not exist - creating it. This could take some time with a large number of players");
        topTenCreate();
    } else {
        // Load the top ten
        YamlConfiguration topTenConfig = Util.loadYamlFile("topten.yml");
        // Load the values
        if (topTenConfig.isSet("topten")) {
            for (String playerUUID : topTenConfig.getConfigurationSection("topten").getKeys(false)) {
                try {
                    UUID uuid = UUID.fromString(playerUUID);
                    int level = topTenConfig.getInt("topten." + playerUUID);
                    topTenAddEntry(uuid, level);
                } catch (Exception e) {
                    e.printStackTrace();
                    plugin.getLogger().severe("Problem loading top ten list - recreating - this may take some time");
                    topTenCreate();
                }
            }
        }
    }
}
 
Example 8
Source File: ConverterChestCommands.java    From TrMenu with MIT License 4 votes vote down vote up
private static int convert(File file, int count) {
    if (file.isDirectory()) {
        for (File f : file.listFiles()) {
            count += convert(f, count);
        }
        return count;
    } else if (!file.getName().endsWith(".yml")) {
        return count;
    }
    try {
        ListIterator<Character> buttons = Arrays.asList('#', '-', '+', '=', '<', '>', '~', '_', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z').listIterator();
        YamlConfiguration trmenu = new YamlConfiguration();
        YamlConfiguration conf = YamlConfiguration.loadConfiguration(file);
        List<String> cmds = conf.contains("menu-settings.command") ? Arrays.asList(conf.getString("menu-settings.command").split(";( )?")) : new ArrayList<>();
        for (int i = 0; i < cmds.size(); i++) {
            cmds.set(i, cmds.get(i) + "-fromCC");
        }
        int rows = conf.getInt("menu-settings.rows", 6);
        int update = conf.getInt("menu-settings.auto-refresh", -1) * 20;
        trmenu.set("Title", conf.getString("menu-settings.name"));
        trmenu.set("Open-Commands", cmds);
        trmenu.set("Open-Actions", conf.contains("menu-settings.open-action") ? conf.getString("menu-settings.open-action").split(";( )?") : "");

        List<String> shape = Lists.newArrayList();
        while (rows > 0) {
            shape.add("         ");
            rows--;
        }
        trmenu.set("Shape", shape);

        conf.getValues(false).forEach((icon, value) -> {
            if (!"menu-settings".equalsIgnoreCase(icon)) {
                MemorySection section = (MemorySection) value;
                int x = section.getInt("POSITION-X") - 1;
                int y = section.getInt("POSITION-Y") - 1;
                char[] chars = shape.get(y).toCharArray();
                char symbol = buttons.next();
                chars[x] = symbol;
                shape.set(y, new String(chars));

                if (update > 0) {
                    trmenu.set("Buttons." + symbol + ".update", update);
                }
                trmenu.set("Buttons." + symbol + ".display.mats", section.get("ID"));
                trmenu.set("Buttons." + symbol + ".display.name", section.get("NAME"));
                trmenu.set("Buttons." + symbol + ".display.lore", section.get("LORE"));
                if (section.contains("COMMAND")) {
                    trmenu.set("Buttons." + symbol + ".actions.all", section.getString("COMMAND").split(";( )?"));
                }
                if (section.contains("ENCHANTMENT")) {
                    trmenu.set("Buttons." + symbol + ".display.shiny", true);
                }
            }
        });
        trmenu.set("Shape", fixShape(shape));
        file.renameTo(new File(file.getParent(), file.getName().replace(".yml", "") + ".CONVERTED.TRMENU"));
        trmenu.save(new File(TrMenu.getPlugin().getDataFolder(), "menus/" + file.getName().replace(".yml", "") + "-fromcc.yml"));
        return count + 1;
    } catch (Throwable e) {
        e.printStackTrace();
    }
    return count;
}