Java Code Examples for org.bukkit.configuration.ConfigurationSection#createSection()

The following examples show how to use org.bukkit.configuration.ConfigurationSection#createSection() . 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: Shop.java    From AnnihilationPro with MIT License 6 votes vote down vote up
public Shop(XPSystem system, ConfigurationSection shopSection)
{
	menus = new HashMap<UUID,ItemMenu>();
	purchasedMessage = getString(shopSection,"Already-Purchased-Kit");
	forsaleMessage = getString(shopSection,"Not-Yet-Purchased-Kit");
	confirmMessage = getString(shopSection,"Confirm-Purchase-Kit");
	confirmExpired = getString(shopSection,"Confirmation-Expired");
	notEnoughXP = getString(shopSection,"Not-Enough-XP");
	kitPurchased = getString(shopSection,"Kit-Purchased");
	noKitsToPurchase = getString(shopSection,"No-Kits-To-Purchase");
	if(!shopSection.isConfigurationSection("Kits"))
		shopSection.createSection("Kits");
	ConfigurationSection kitSec = shopSection.getConfigurationSection("Kits");
	Collection<Kit> kits = Kit.getKits();
	items = new KitShopMenuItem[kits.size()];
	int c =0;
	for(Kit k : kits)
	{
		ConfigManager.setDefaultIfNotSet(kitSec, k.getName(), 10000);
		KitShopMenuItem item = new KitShopMenuItem(new KitWrapper(k,kitSec.getInt(k.getName())),system);
		items[c] = item;
		c++;
	}
}
 
Example 2
Source File: PriceOffer.java    From Shopkeepers with GNU General Public License v3.0 6 votes vote down vote up
public static void saveToConfig(ConfigurationSection config, String node, Collection<PriceOffer> offers) {
	ConfigurationSection offersSection = config.createSection(node);
	int id = 0;
	for (PriceOffer offer : offers) {
		ItemStack item = offer.getItem();
		// TODO temporary, due to a bukkit bug custom head item can currently not be saved
		if (Settings.skipCustomHeadSaving && Utils.isCustomHeadItem(item)) {
			Log.warning("Skipping saving of trade involving a head item with custom texture, which cannot be saved currently due to a bukkit bug.");
			continue;
		}
		ConfigurationSection offerSection = offersSection.createSection(String.valueOf(id));
		Utils.saveItem(offerSection, "item", item);
		offerSection.set("price", offer.getPrice());
		id++;
	}
}
 
Example 3
Source File: TradingOffer.java    From Shopkeepers with GNU General Public License v3.0 6 votes vote down vote up
public static void saveToConfig(ConfigurationSection config, String node, Collection<TradingOffer> offers) {
	ConfigurationSection offersSection = config.createSection(node);
	int id = 0;
	for (TradingOffer offer : offers) {
		// TODO temporary, due to a bukkit bug custom head item can currently not be saved
		if (Settings.skipCustomHeadSaving
				&& (Utils.isCustomHeadItem(offer.getItem1())
						|| Utils.isCustomHeadItem(offer.getItem2())
						|| Utils.isCustomHeadItem(offer.getResultItem()))) {
			Log.warning("Skipping saving of trade involving a head item with custom texture, which cannot be saved currently due to a bukkit bug.");
			continue;
		}
		ConfigurationSection offerSection = offersSection.createSection(String.valueOf(id));
		Utils.saveItem(offerSection, "resultItem", offer.getResultItem());
		Utils.saveItem(offerSection, "item1", offer.getItem1());
		Utils.saveItem(offerSection, "item2", offer.getItem2());
		id++;
	}
}
 
Example 4
Source File: SignLogic.java    From uSkyBlock with GNU General Public License v3.0 6 votes vote down vote up
void addSign(Sign block, String[] lines, Chest chest) {
    Location loc = block.getLocation();
    ConfigurationSection signs = config.getConfigurationSection("signs");
    if (signs == null) {
        signs = config.createSection("signs");
    }
    String signLocation = LocationUtil.asKey(loc);
    ConfigurationSection signSection = signs.createSection(signLocation);
    signSection.set("location", LocationUtil.asString(loc));
    signSection.set("challenge", lines[1]);
    String chestLocation = LocationUtil.asString(chest.getLocation());
    signSection.set("chest", chestLocation);
    ConfigurationSection chests = config.getConfigurationSection("chests");
    if (chests == null) {
        chests = config.createSection("chests");
    }
    String chestPath = LocationUtil.asKey(chest.getLocation());
    List<String> signList = chests.getStringList(chestPath);
    if (!signList.contains(signLocation)) {
        signList.add(signLocation);
    }
    chests.set(chestPath, signList);
    saveAsync();
    updateSignsOnContainer(chest.getLocation());
}
 
Example 5
Source File: Configuration.java    From NyaaUtils with MIT License 6 votes vote down vote up
@Override
public void serialize(ConfigurationSection config) {
    // general values save & standalone config save
    ISerializable.serialize(config, this);

    // Enchantment Max Level constraint
    ConfigurationSection list = config.createSection("enchant.max_level");
    for (Enchantment k : enchantMaxLevel.keySet()) {
        if (k == null || k.getKey() == null || k.getKey().getKey() == null) continue;
        list.set(k.getKey().getKey(), enchantMaxLevel.get(k));
    }
    config.set("particles.limits", null);
    for (ParticleType type : particlesLimits.keySet()) {
        particlesLimits.get(type).serialize(config.createSection("particles.limits." + type.name()));
    }
}
 
Example 6
Source File: Areas.java    From AnnihilationPro with MIT License 6 votes vote down vote up
public void saveToConfig(ConfigurationSection areaSection)
	{
		int counter = 1;
		for(Area a : areas.values())
		{
			ConfigurationSection sec = areaSection.createSection(counter+"");
            a.saveToConfig(sec);
//			sec.set("Name", a.getName());
//			sec.set("AllowPVP", a.isPVPAllowed());
//			//ConfigManager.saveLocation(a.getCorner1(), sec.createSection("Corner1Location"));
//			a.getCorner1().saveToConfig(sec.createSection("Corner1Location"));
//			//ConfigManager.saveLocation(a.getCorner2(), sec.createSection("Corner2Location"));
//			a.getCorner2().saveToConfig(sec.createSection("Corner2Location"));
			counter++;
		}
	}
 
Example 7
Source File: RegeneratingBlocks.java    From AnnihilationPro with MIT License 6 votes vote down vote up
public void saveToConfig(ConfigurationSection configSection)
{
	if(configSection != null)
	{
		for(Entry<Material, Map<Integer,RegeneratingBlock>> entry : blocks.entrySet())
		{
			ConfigurationSection matSection = configSection.createSection(entry.getKey().name());
			for(Entry<Integer,RegeneratingBlock> map : entry.getValue().entrySet())
			{
				ConfigurationSection dataSection = matSection.createSection(map.getKey().toString());
				RegeneratingBlock b = map.getValue();
				b.saveToConfig(dataSection);
			}
		}
	}
}
 
Example 8
Source File: AdminShopkeeper.java    From Shopkeepers with GNU General Public License v3.0 6 votes vote down vote up
private void saveRecipes(ConfigurationSection config, String node, Collection<ItemStack[]> recipes) {
	ConfigurationSection recipesSection = config.createSection(node);
	int id = 0;
	for (ItemStack[] recipe : recipes) {
		// TODO temporary, due to a bukkit bug custom head item can currently not be saved
		if (Settings.skipCustomHeadSaving && (Utils.isCustomHeadItem(recipe[0])
				|| Utils.isCustomHeadItem(recipe[1])
				|| Utils.isCustomHeadItem(recipe[2]))) {
			Log.warning("Skipping saving of trade involving a head item with custom texture, which cannot be saved currently due to a bukkit bug.");
			continue;
		}
		ConfigurationSection recipeSection = recipesSection.createSection(String.valueOf(id));
		Utils.saveItem(recipeSection, "item1", recipe[0]);
		Utils.saveItem(recipeSection, "item2", recipe[1]);
		Utils.saveItem(recipeSection, "resultItem", recipe[2]);
		id++;
	}
}
 
Example 9
Source File: AnniTeam.java    From AnnihilationPro with MIT License 5 votes vote down vote up
public void saveToConfig(ConfigurationSection configSection)
	{
		if(configSection != null)
		{
			Loc nexusLoc = Nexus.getLocation();
			if(nexusLoc != null)
				nexusLoc.saveToConfig(configSection.createSection("Nexus.Location"));
				//ConfigManager.saveLocation(nexusLoc,configSection.createSection("Nexus.Location"));
			
			Loc spectatorspawn = getSpectatorLocation();
			if(spectatorspawn != null)
				spectatorspawn.saveToConfig(configSection.createSection("SpectatorLocation"));
				//ConfigManager.saveLocation(spectatorspawn,configSection.createSection("SpectatorLocation"));
			
			ConfigurationSection spawnSection = configSection.createSection("Spawns");
			List<Loc> spawns = getSpawnList();
			if(spawns != null && !spawns.isEmpty())
			{
				for(int x = 0; x < spawns.size(); x++)
				{
					spawns.get(x).saveToConfig(spawnSection.createSection(x+""));
					//ConfigManager.savePreciseLocation(spawns.get(x), spawnSection.createSection(x+""));
				}
			}
			//ConfigurationSection signSection = configSection.createSection("Signs");
//			Map<String,JoinSign> teamsigns = SignHandler.getTeamSigns();
//			int counter = 1;
//			for(Entry<String,JoinSign> entry : teamsigns.entrySet())
//			{
//				//only save signs for this team
//				if(entry.getValue().TeamName.equals(team.getName()))
//				{
//					ConfigManager.saveLocation(Loc.fromMapKey(entry.getKey()), signSection.createSection(counter+".Location"));
//					signSection.set(counter+".Direction", entry.getValue().Face.name());
//					signSection.set(counter+".SignPost", entry.getValue().signPost);
//					counter++;
//				}
//			}
		}
	}
 
Example 10
Source File: ParticleSet.java    From NyaaUtils with MIT License 5 votes vote down vote up
@Override
public void serialize(ConfigurationSection config) {
    ISerializable.serialize(config, this);
    config.set("contents", null);
    ConfigurationSection c = config.createSection("contents");
    int i = 0;
    for (ParticleData p : contents) {
        p.serialize(c.createSection(String.valueOf(i)));
        i++;
    }
}
 
Example 11
Source File: GlobalLoreBlacklist.java    From NyaaUtils with MIT License 5 votes vote down vote up
@Override
public void serialize(ConfigurationSection config) {
    // save default
    ConfigurationSection sectionDefault = config.createSection("default");
    sectionDefault.set("enchant", this.default_enchant);
    sectionDefault.set("repair", this.default_repair);
    // save lores
    for (String lore : aclMap.keySet()) {
        aclMap.get(lore).serialize(config.createSection(lore));
    }
}
 
Example 12
Source File: RealmConfig.java    From NyaaUtils with MIT License 5 votes vote down vote up
@Override
public void serialize(ConfigurationSection config) {
    ISerializable.serialize(config, this);
    config.set("realms", null);
    if (!realmList.isEmpty()) {
        ConfigurationSection list = config.createSection("realms");
        for (String k : realmList.keySet()) {
            realmList.get(k).serialize(list.createSection(k));
        }
    }
}
 
Example 13
Source File: RepairConfig.java    From NyaaUtils with MIT License 5 votes vote down vote up
@Override
public void serialize(ConfigurationSection config) {
    Set<String> tmp = new HashSet<>(config.getKeys(false));
    for (String key : tmp) { // clear section
        config.set(key, null);
    }

    for (Map.Entry<Material, RepairConfigItem> pair : repairMap.entrySet()) {
        ConfigurationSection section = config.createSection(pair.getKey().name());
        pair.getValue().normalize().serialize(section);
    }
}
 
Example 14
Source File: EnchantSrcConfig.java    From NyaaUtils with MIT License 5 votes vote down vote up
@Override
public void serialize(ConfigurationSection config) {
    ISerializable.serialize(config, this);

    ConfigurationSection dst = config.createSection("enchantSrc");
    int idx = 0;
    for (BasicItemMatcher m : enchantSrc) {
        m.serialize(dst.createSection(Integer.toString(idx)));
        idx++;
    }
}
 
Example 15
Source File: TimerConfig.java    From NyaaUtils with MIT License 5 votes vote down vote up
@Override
public void serialize(ConfigurationSection config) {
    ISerializable.serialize(config, this);
    config.set("timers", null);
    if (!timers.isEmpty()) {
        ConfigurationSection list = config.createSection("timers");
        for (String k : timers.keySet()) {
            timers.get(k).serialize(list.createSection(k));
        }
    }

}
 
Example 16
Source File: Timer.java    From NyaaUtils with MIT License 5 votes vote down vote up
@Override
public void serialize(ConfigurationSection config) {
    ISerializable.serialize(config, this);
    config.set("checkpoint", null);
    if (!checkpointList.isEmpty()) {
        ConfigurationSection list = config.createSection("checkpoint");
        for (int i = 0; i < checkpointList.size(); i++) {
            checkpointList.get(i).serialize(list.createSection(String.valueOf(i)));
        }
    }
}
 
Example 17
Source File: ConfigUtils.java    From EffectLib with MIT License 5 votes vote down vote up
public static ConfigurationSection getConfigurationSection(ConfigurationSection base, String key)
{
    ConfigurationSection section = base.getConfigurationSection(key);
    if (section != null) {
        return section;
    }
    Object value = base.get(key);
    if (value == null) return null;

    if (value instanceof ConfigurationSection)
    {
        return (ConfigurationSection)value;
    }

    if (value instanceof Map)
    {
        ConfigurationSection newChild = base.createSection(key);
        @SuppressWarnings("unchecked")
        Map<String, Object> map = (Map<String, Object>)value;
        for (Map.Entry<String, Object> entry : map.entrySet())
        {
            newChild.set(entry.getKey(), entry.getValue());
        }
        base.set(key, newChild);
        return newChild;
    }

    return null;
}
 
Example 18
Source File: DeathItemsModule.java    From UHC with MIT License 4 votes vote down vote up
@Override
public void initialize() throws InvalidConfigurationException {
    if (!config.contains(ITEMS_KEY)) {
        final ConfigurationSection section = config.createSection(ITEMS_KEY);

        final ConfigurationSection wool = section.createSection("example wool");
        wool.set(TYPE_KEY, "WOOL");
        wool.set(AMOUNT_KEY, DEFAULT_ITEM_AMOUNT_1);
        wool.set(DATA_KEY, DEFAULT_ITEM_DATA_1);

        final ConfigurationSection dirt = section.createSection("example dirt");
        dirt.set(TYPE_KEY, "DIRT");
        dirt.set(AMOUNT_KEY, DEFAULT_ITEM_AMOUNT_2);
    }

    final ConfigurationSection itemsSection = config.getConfigurationSection(ITEMS_KEY);

    for (final String key : itemsSection.getKeys(false)) {
        final ConfigurationSection itemSection = itemsSection.getConfigurationSection(key);

        if (!itemSection.contains(AMOUNT_KEY)) {
            throw new InvalidConfigurationException("A drop item requires an `amount`");
        }

        if (!itemSection.contains(TYPE_KEY)) {
            throw new InvalidConfigurationException("A drop item requires a `type`");
        }

        final int amount = itemSection.getInt(AMOUNT_KEY);

        if (amount <= 0) throw new InvalidConfigurationException("A drop item cannot have a <= 0 amount");

        final Material type;
        try {
            type = EnumConverter.forEnum(Material.class).convert(itemSection.getString(TYPE_KEY));
        } catch (ValueConversionException ex) {
            throw new InvalidConfigurationException(
                    "Invalid material for drop item: " + itemSection.getString(TYPE_KEY),
                    ex
            );
        }

        final ItemStack stack = new ItemStack(type, amount);

        if (itemSection.contains(DATA_KEY)) {
            stack.setDurability((short) itemSection.getInt(DATA_KEY));
        }

        stacks.add(stack);
    }

    super.initialize();
}
 
Example 19
Source File: BookOffer.java    From Shopkeepers with GNU General Public License v3.0 4 votes vote down vote up
public static void saveToConfig(ConfigurationSection config, String node, Collection<BookOffer> offers) {
	ConfigurationSection offersSection = config.createSection(node);
	for (BookOffer offer : offers) {
		offersSection.set(offer.getBookTitle(), offer.getPrice());
	}
}
 
Example 20
Source File: XPMain.java    From AnnihilationPro with MIT License 4 votes vote down vote up
@Override
	public void onEnable()
	{
		configFile = new File(AnnihilationMain.getInstance().getDataFolder(),"AnnihilationXPConfig.yml");
		Bukkit.getLogger().info("[AnnihilationXPSystem] Loading XP system...");
		Bukkit.getPluginManager().registerEvents(this, this);

		checkFile(configFile);
		config = YamlConfiguration.loadConfiguration(configFile);
		
		//%# to be replaced by the number
		int x = 0;
		x += ConfigManager.setDefaultIfNotSet(config, "Nexus-Hit-XP", 1);
		x += ConfigManager.setDefaultIfNotSet(config, "Player-Kill-XP", 3);
		x += ConfigManager.setDefaultIfNotSet(config, "Winning-Team-XP", 100);
		x += ConfigManager.setDefaultIfNotSet(config, "Second-Place-Team-XP", 75);
		x += ConfigManager.setDefaultIfNotSet(config, "Third-Place-Team-XP", 50);
		x += ConfigManager.setDefaultIfNotSet(config, "Last-Place-Team-XP", 25);
		x += ConfigManager.setDefaultIfNotSet(config, "Gave-XP-Message", "&a+%# Annihilation XP");
		x += ConfigManager.setDefaultIfNotSet(config, "MyXP-Command-Message", "&dYou have &a%#&d Annihilation XP.");
		if(!config.isConfigurationSection("XP-Multipliers"))
		{
			ConfigurationSection multipliers = config.createSection("XP-Multipliers");
			multipliers.set("Multiplier-1.Permission", "Anni.XP.2");
			multipliers.set("Multiplier-1.Multiplier", 2);
			x++;
		}
		
		ConfigurationSection data = config.getConfigurationSection("Database");
		if(data == null)
			data = config.createSection("Database");
		
		x += ConfigManager.setDefaultIfNotSet(data, "Host", "Test");
		x += ConfigManager.setDefaultIfNotSet(data, "Port", "Test");
		x += ConfigManager.setDefaultIfNotSet(data, "Database", "Test");
		x += ConfigManager.setDefaultIfNotSet(data, "Username", "Test");
		x += ConfigManager.setDefaultIfNotSet(data, "Password", "Test");

//		data.set("Host", "Test");
//		data.set("Port", "Test");
//		data.set("Database", "Test");
//		data.set("Username", "Test");
//		data.set("Password", "Test");
//		x++;
		
		ConfigurationSection shopSec = config.getConfigurationSection("Kit-Shop");
		if(shopSec == null)
		{
			shopSec = config.createSection("Kit-Shop");
			shopSec.createSection("Kits");
		}
		
		x += ConfigManager.setDefaultIfNotSet(shopSec, "On", false);
		x += ConfigManager.setDefaultIfNotSet(shopSec, "Already-Purchased-Kit", "&aPURCHASED");
		x += ConfigManager.setDefaultIfNotSet(shopSec, "Not-Yet-Purchased-Kit", "&cLOCKED. PURCHASE FOR &6%# &cXP");
		x += ConfigManager.setDefaultIfNotSet(shopSec, "Confirm-Purchase-Kit", "&aPUCHASE BEGUN. CONFIRM FOR &6%# &AXP");
		x += ConfigManager.setDefaultIfNotSet(shopSec, "Confirmation-Expired", "&cThe confirmation time has expired. Please try again.");
		x += ConfigManager.setDefaultIfNotSet(shopSec, "Not-Enough-XP", "&cYou do not have enough XP to purchase this kit.");
		x += ConfigManager.setDefaultIfNotSet(shopSec, "Kit-Purchased", "&aKit %w purchased!");
		x += ConfigManager.setDefaultIfNotSet(shopSec, "No-Kits-To-Purchase", "&cNo kits left to purchase!");
		
//		shopSec.set("On", false);
//		shopSec.set("Already-Purchased-Kit", "&aPURCHASED");
//		shopSec.set("Not-Yet-Purchased-Kit", "&cLOCKED. PURCHASE FOR &6%# &cXP");
//		shopSec.set("Confirm-Purchase-Kit", "&aPUCHASE BEGUN. CONFIRM FOR &6%# &AXP");
//		shopSec.set("Confirmation-Expired", "&cThe confirmation time has expired. Please try again.");
//		shopSec.set("Not-Enough-XP", "&cYou do not have enough XP to purchase this kit.");
//		shopSec.set("Kit-Purchased", "&aKit %w purchased!");
//		shopSec.createSection("Kits");
//		x++;
		
		if(x > 0)
			this.saveConfig();
		
		this.xpSystem = new XPSystem(config.getConfigurationSection("Database"));
		if(!this.xpSystem.isActive())
		{
			Bukkit.getLogger().info("[AnnihilationXPSystem] Could NOT connect to the database");
			disable();
			return;
		}
		Bukkit.getLogger().info("[AnnihilationXPSystem] CONNECTED to the database");
		boolean useShop = config.getBoolean("Kit-Shop.On");
		if(useShop)
		{
			Bukkit.getLogger().info("[AnnihilationXPSystem] The shop is ENABLED");
			this.getCommand("Shop").setExecutor(new Shop(this.xpSystem,config.getConfigurationSection("Kit-Shop")));
			saveConfig();
		}
		else Bukkit.getLogger().info("[AnnihilationXPSystem] The shop is DISABLED");
		loadMultipliers(config.getConfigurationSection("XP-Multipliers"));
		loadXPVars(config); //This also loads the listeners with the values they need
		AnniCommand.registerArgument(new XPArgument(xpSystem));
		AnniCommand.registerArgument(new KitArgument(xpSystem));
		for(AnniPlayer p : AnniPlayer.getPlayers())
			xpSystem.loadKits(p, null);
	}