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

The following examples show how to use org.bukkit.configuration.ConfigurationSection#contains() . 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: Recipes.java    From ProRecipes with GNU General Public License v2.0 6 votes vote down vote up
public ItemStack checkTexture(ItemStack i, ConfigurationSection s, String path){
	if(i == null || i.getType() != MinecraftVersion.getMaterial("SKULL_ITEM","PLAYER_HEAD")){
		return i;
	}
	if(s == null){
		return i;
	}
	SkullMeta meta = (SkullMeta) i.getItemMeta();
	if(meta.hasOwner()){
		return i;
	}
	if(s.contains(path)){
		String texture = s.getString(path + ".texture");
		String id = s.getString(path + ".uuid");
		return ItemUtils.createHead(UUID.fromString(id), i, texture);
	}else{
		return i;
	}
}
 
Example 2
Source File: PriceOffer.java    From Shopkeepers with GNU General Public License v3.0 6 votes vote down vote up
public static List<PriceOffer> loadFromConfigOld(ConfigurationSection config, String node) {
	List<PriceOffer> offers = new ArrayList<PriceOffer>();
	ConfigurationSection offersSection = config.getConfigurationSection(node);
	if (offersSection != null) {
		for (String key : offersSection.getKeys(false)) {
			ConfigurationSection offerSection = offersSection.getConfigurationSection(key);
			ItemStack item = offerSection.getItemStack("item");
			if (item != null) {
				// legacy: the amount was stored separately from the item
				item.setAmount(offerSection.getInt("amount", 1));
				if (offerSection.contains("attributes")) {
					String attributes = offerSection.getString("attributes");
					if (attributes != null && !attributes.isEmpty()) {
						item = NMSManager.getProvider().loadItemAttributesFromString(item, attributes);
					}
				}
			}
			int price = offerSection.getInt("cost");
			if (Utils.isEmpty(item) || price < 0) continue; // invalid offer
			offers.add(new PriceOffer(item, price));
		}
	}
	return offers;
}
 
Example 3
Source File: JoinSign.java    From DungeonsXL with GNU General Public License v3.0 6 votes vote down vote up
protected JoinSign(DungeonsXL plugin, World world, int id, ConfigurationSection config) {
    super(plugin, world, id);

    startSign = world.getBlockAt(config.getInt("x"), config.getInt("y"), config.getInt("z"));
    String identifier = config.getString("dungeon");
    dungeon = plugin.getDungeonRegistry().get(identifier);

    // LEGACY
    if (config.contains("maxElements")) {
        maxElements = config.getInt("maxElements");
    } else if (config.contains("maxGroupsPerGame")) {
        maxElements = config.getInt("maxGroupsPerGame");
    } else if (config.contains("maxPlayersPerGroup")) {
        maxElements = config.getInt("maxPlayersPerGroup");
    }
    startIfElementsAtLeast = config.getInt("startIfElementsAtLeast", -1);

    verticalSigns = (int) Math.ceil((float) (1 + maxElements) / 4);

    update();
}
 
Example 4
Source File: WorldMatcher.java    From UHC with MIT License 6 votes vote down vote up
public WorldMatcher(ConfigurationSection section, List<String> worldsDefault, boolean isWhitelistDefault) {
    if (!section.contains(WORLDS_KEY)) {
        section.set(WORLDS_KEY, worldsDefault);
    }

    if (!section.contains(IS_WHITELIST_KEY)) {
        section.set(IS_WHITELIST_KEY, isWhitelistDefault);
    }

    worlds = ImmutableSet.copyOf(
            Iterables.filter(
                    Iterables.transform(section.getStringList(WORLDS_KEY), TO_LOWER_CASE),
                    Predicates.notNull()
            )
    );
    isWhitelist = section.getBoolean(IS_WHITELIST_KEY);
}
 
Example 5
Source File: CompassEvent.java    From BetonQuest with GNU General Public License v3.0 6 votes vote down vote up
public CompassEvent(Instruction instruction) throws InstructionParseException {
    super(instruction, true);
    persistent = true;

    action = instruction.getEnum(Action.class);
    compass = instruction.next();

    // Check if compass is valid
    for (ConfigPackage pack : Config.getPackages().values()) {
        ConfigurationSection s = pack.getMain().getConfig().getConfigurationSection("compass");
        if (s != null) {
            if (s.contains(compass)) {
                compassSection = s.getConfigurationSection(compass);
                compassPackage = pack;
                break;
            }
        }
    }
    if (compassSection == null) {
        throw new InstructionParseException("Invalid compass location: " + compass);
    }
}
 
Example 6
Source File: Rule.java    From PlayTimeTracker with MIT License 5 votes vote down vote up
public Rule(String name, ConfigurationSection s) {
    this.name = name;
    switch (s.getString("period")) {
        case "day": {
            period = PeriodType.DAY;
            break;
        }
        case "week": {
            period = PeriodType.WEEK;
            break;
        }
        case "month": {
            period = PeriodType.MONTH;
            break;
        }
        case "disposable": {
            period = PeriodType.DISPOSABLE;
            break;
        }
        case "session": {
            period = PeriodType.SESSION;
            break;
        }
        case "longtimenosee": {
            period = PeriodType.LONGTIMENOSEE;
            break;
        }
    }
    require = s.getLong("require");
    autoGive = s.getBoolean("auto-give");
    timeout = s.contains("timeout") ? s.getLong("timeout") : -1;
    group = s.contains("eligible-group") ? new HashSet<>(s.getStringList("eligible-group")) : null;
    reward = s.getString("reward");
}
 
Example 7
Source File: LivingEntityShop.java    From Shopkeepers with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void load(ConfigurationSection config) {
	super.load(config);
	if (config.contains("uuid")) {
		this.uuid = config.getString("uuid");
	}
}
 
Example 8
Source File: CitizensShop.java    From Shopkeepers with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void load(ConfigurationSection config) {
	super.load(config);
	if (config.contains("npcId")) {
		npcId = config.getInt("npcId");
	}
}
 
Example 9
Source File: AdminShopkeeper.java    From Shopkeepers with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Loads an ItemStack from a config section.
 * 
 * @param section
 * @return
 */
private ItemStack loadItemStackOld(ConfigurationSection section) {
	ItemStack item = section.getItemStack("item");
	if (item != null) {
		if (section.contains("attributes")) {
			String attributes = section.getString("attributes");
			if (attributes != null && !attributes.isEmpty()) {
				item = NMSManager.getProvider().loadItemAttributesFromString(item, attributes);
			}
		}
	}
	return item;
}
 
Example 10
Source File: TradingOffer.java    From Shopkeepers with GNU General Public License v3.0 5 votes vote down vote up
public static List<TradingOffer> loadFromConfigOld(ConfigurationSection config, String node) {
	List<TradingOffer> offers = new ArrayList<TradingOffer>();
	ConfigurationSection offersSection = config.getConfigurationSection(node);
	if (offersSection != null) {
		for (String key : offersSection.getKeys(false)) {
			ConfigurationSection offerSection = offersSection.getConfigurationSection(key);
			ItemStack resultItem = offerSection.getItemStack("item");
			if (resultItem != null) {
				// legacy: the amount was stored separately from the item
				resultItem.setAmount(offerSection.getInt("amount", 1));
				if (offerSection.contains("attributes")) {
					String attributes = offerSection.getString("attributes");
					if (attributes != null && !attributes.isEmpty()) {
						resultItem = NMSManager.getProvider().loadItemAttributesFromString(resultItem, attributes);
					}
				}
			}
			if (Utils.isEmpty(resultItem)) continue; // invalid offer
			ItemStack item1 = offerSection.getItemStack("item1");
			if (Utils.isEmpty(item1)) continue; // invalid offer
			ItemStack item2 = offerSection.getItemStack("item2");
			// legacy: no attributes were stored for item1 and item2
			offers.add(new TradingOffer(resultItem, item1, item2));
		}
	}
	return offers;
}
 
Example 11
Source File: DurabilityMaterial.java    From ObsidianDestroyer with GNU General Public License v3.0 5 votes vote down vote up
public static boolean isEnabled(ConfigurationSection section) {
    if (section.contains("Durability")) {
        if (section.contains("Durability.Enabled") && section.contains("Durability.Amount")) {
            return section.getBoolean("Durability.Enabled") && section.getInt("Durability.Amount") > 0;
        }
    }
    return false;
}
 
Example 12
Source File: DeluxeMenusMigrater.java    From TrMenu with MIT License 5 votes vote down vote up
private static String migrateMaterial(ConfigurationSection icon) {
    String material = icon.getString("material");
    String nbtInt = icon.getString("nbt_int");
    if (icon.contains("data") && icon.getInt("data", 0) > 0) {
        material += "<data-value:" + icon.getInt("data") + ">";
    }
    if (nbtInt != null && nbtInt.split(":", 2).length == 2) {
        String[] splits = nbtInt.split(":");
        if ("CustomModelData".equalsIgnoreCase(splits[0])) {
            material += "<model-data:" + splits[1] + ">";
        }
    }
    if (icon.contains("banner_meta")) {
        StringBuilder pattern = new StringBuilder();
        icon.getStringList("banner_meta").forEach(b -> {
            pattern.append(b.replace(";", " ")).append(",");
        });
        material += "<banner:" + pattern.substring(0, pattern.length() - 1) + ">";
    }
    if (icon.contains("rgb")) {
        material += "<dye:" + icon.get("rgb") + ">";
    }
    if (material.startsWith("head;")) {
        material = "<head:" + material.substring(5) + ">";
    } else if (material.startsWith("basehead-")) {
        material = "<skull:" + material.substring(9) + ">";
    } else if (material.startsWith("heads-")) {
        material = "<hdb:" + material.substring(6) + ">";
    } else if (material.startsWith("hdb-")) {
        material = "<hdb:" + material.substring(4) + ">";
    } else if (material.startsWith("placeholder-")) {
        material = material.substring(12) + "<variable>";
    }
    return material;
}
 
Example 13
Source File: Extra.java    From TradePlus with GNU General Public License v3.0 5 votes vote down vote up
Extra(String name, Player player1, Player player2, TradePlus pl, Trade trade) {
  this.pl = pl;
  this.name = name;
  ConfigurationSection section =
      Preconditions.checkNotNull(pl.getConfig().getConfigurationSection("extras." + name));
  this.displayName = section.getString("name");
  this.player1 = player1;
  this.player2 = player2;
  this.increment = section.getDouble("increment", 1D);
  this.increment1 = increment;
  this.increment2 = increment;
  ItemFactory factory =
      new ItemFactory(section.getString("material", "PAPER"), Material.PAPER)
          .display('&', section.getString("display", "&4ERROR"))
          .customModelData(section.getInt("customModelData", 0));
  if (section.contains("lore")) factory.lore('&', section.getStringList("lore"));
  this.icon = factory.flag("HIDE_ATTRIBUTES").build();
  this.theirIcon =
      new ItemFactory(section.getString("material", "PAPER"), Material.PAPER)
          .display('&', section.getString("theirdisplay", "&4ERROR"))
          .customModelData(section.getInt("customModelData", 0))
          .build();
  this.taxPercent = section.getDouble("taxpercent", 0);
  this.mode = section.getString("mode", "chat").toLowerCase();
  if (mode.equals("type") || mode.equals("anvil")) {
    mode = "chat";
    section.set("mode", "chat");
    pl.saveConfig();
  }
  this.trade = trade;
}
 
Example 14
Source File: NovaGroupImpl.java    From NovaGuilds with GNU General Public License v3.0 4 votes vote down vote up
/**
 * The constructor
 *
 * @param group group name
 */
public NovaGroupImpl(String group) {
	name = group;
	LoggerUtils.info("Loading group '" + name + "'...");

	//setting all values
	ConfigurationSection section = plugin.getConfig().getConfigurationSection("groups." + group);

	for(NovaGroup.Key<?> key : Key.values()) {
		String path = paths.get(key);

		if(!section.contains(path) && values.get(key) != null) {
			continue;
		}

		Object value = null;

		if(key.getType() == Double.class) {
			value = section.getDouble(path);
		}
		else if(key.getType() ==  Integer.class) {
			value = section.getInt(path);
		}
		else if(key.getType() == List.class) {
			value = ItemStackUtils.stringToItemStackList(section.getStringList(path));

			if(value == null) {
				value = new ArrayList<ItemStack>();
			}
		}
		else if(key.getType() == Schematic.class) {
			String schematicName = section.getString(path);
			if(schematicName != null && !schematicName.isEmpty()) {
				try {
					value = new SchematicImpl(schematicName);
				}
				catch(FileNotFoundException e) {
					LoggerUtils.error("Schematic not found: schematic/" + schematicName);
				}
			}
		}

		values.put(key, value);
	}

	int autoRegionWidth = get(Key.REGION_AUTOSIZE) * 2 + 1;
	if(autoRegionWidth > Config.REGION_MAXSIZE.getInt()) {
		values.put(Key.REGION_AUTOSIZE, Config.REGION_MAXSIZE.getInt() / 2 - 1);
		LoggerUtils.error("Group " + name + " has too big autoregion. Reset to " + get(Key.REGION_AUTOSIZE));
	}

	if(get(Key.REGION_AUTOSIZE) != 0 && autoRegionWidth < Config.REGION_MINSIZE.getInt()) {
		values.put(Key.REGION_AUTOSIZE, Config.REGION_MINSIZE.getInt() / 2);
		LoggerUtils.error("Group " + name + " has too small autoregion. Reset to " + get(Key.REGION_AUTOSIZE));
	}
}
 
Example 15
Source File: ConfigManager.java    From ObsidianDestroyer with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Translates the materials.yml from memory into a map for quick access
 *
 * @return map of materials keys and material durability data
 */
public Map<String, DurabilityMaterial> getDurabilityMaterials() {
    final long time = System.currentTimeMillis();
    final ConfigurationSection section = materials.getConfigurationSection("HandledMaterials");
    int errorDuraCount = 0;
    int invalidDuraCount = 0;
    int disabledDuraCount = 0;
    Map<String, DurabilityMaterial> durabilityMaterials = new HashMap<>();
    for (String durabilityMaterial : section.getKeys(false)) {
        try {
            final ConfigurationSection materialSection = section.getConfigurationSection(durabilityMaterial);
            Material material = Material.matchMaterial(durabilityMaterial);
            if (material == null) {
                material = Material.matchMaterial(durabilityMaterial, true);
                if (material == null) {
                    if (DurabilityMaterial.isEnabled(materialSection)) {
                        ObsidianDestroyer.LOG.log(Level.WARNING, "Invalid Material Type: Unable to load ''{0}''", durabilityMaterial);
                    }
                    invalidDuraCount++;
                    continue;
                } else {
                    ObsidianDestroyer.LOG.log(Level.WARNING, "Semi-Valid Material Type: Loaded as ''{0}''", material.name());
                }
            }
            if (!Util.isSolid(material) && !materialSection.contains("HandleNonSolid") && !materialSection.getBoolean("HandleNonSolid")) {
                ObsidianDestroyer.LOG.log(Level.WARNING, "Non-Solid Material Type: Did not load ''{0}''", durabilityMaterial);
                invalidDuraCount++;
                continue;
            }
            final DurabilityMaterial durablock;
            if (materialSection.contains("MetaData")) {
                durablock = new DurabilityMaterial(material, materialSection.getInt("MetaData"), materialSection);
            } else {
                durablock = new DurabilityMaterial(material, materialSection);
            }
            if (durablock.getEnabled()) {
                if (getVerbose() || getDebug()) {
                    ObsidianDestroyer.LOG.log(Level.INFO, "Loaded durability of ''{0}'' for ''{1}''", new Object[]{durablock.getDurability(), durablock.toString()});
                }
                durabilityMaterials.put(durablock.toString(), durablock);
            } else if (getDebug()) {
                ObsidianDestroyer.debug("Disabled durability of '" + durablock.getDurability() + "' for '" + durablock.toString() + "'");
                disabledDuraCount++;
            }
        } catch (Exception e) {
            ObsidianDestroyer.LOG.log(Level.SEVERE, "Failed loading material ''{0}''", durabilityMaterial);
            errorDuraCount++;
        }
    }
    ObsidianDestroyer.LOG.log(Level.INFO, "Loaded and enabled ''{0}'' material durabilities from config in ''{1}'' ms.", new Object[]{durabilityMaterials.size(), (System.currentTimeMillis() - time)});
    ObsidianDestroyer.LOG.log(Level.INFO, "Material in Error: ''{0}''  Invalid: ''{1}''  Disabled: ''{2}''", new Object[]{errorDuraCount, invalidDuraCount, disabledDuraCount});
    return durabilityMaterials;
}
 
Example 16
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 17
Source File: ItemStackReader.java    From helper with MIT License 4 votes vote down vote up
protected Optional<List<String>> parseLore(ConfigurationSection config) {
    if (config.contains("lore")) {
        return Optional.of(config.getStringList("lore"));
    }
    return Optional.empty();
}
 
Example 18
Source File: ItemStackReader.java    From helper with MIT License 4 votes vote down vote up
protected Optional<String> parseName(ConfigurationSection config) {
    if (config.contains("name")) {
        return Optional.of(config.getString("name"));
    }
    return Optional.empty();
}
 
Example 19
Source File: ItemStackReader.java    From helper with MIT License 4 votes vote down vote up
protected OptionalInt parseData(ConfigurationSection config) {
    if (config.contains("data")) {
        return OptionalInt.of(config.getInt("data"));
    }
    return OptionalInt.empty();
}