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

The following examples show how to use org.bukkit.configuration.ConfigurationSection#isString() . 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: Utils.java    From AreaShop with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Create a location from a map, reconstruction from the config values.
 * @param config The config section to reconstruct from
 * @return The location
 */
public static Location configToLocation(ConfigurationSection config) {
	if(config == null
			|| !config.isString("world")
			|| !config.isDouble("x")
			|| !config.isDouble("y")
			|| !config.isDouble("z")
			|| Bukkit.getWorld(config.getString("world")) == null) {
		return null;
	}
	Location result = new Location(
			Bukkit.getWorld(config.getString("world")),
			config.getDouble("x"),
			config.getDouble("y"),
			config.getDouble("z"));
	if(config.isString("yaw") && config.isString("pitch")) {
		result.setPitch(Float.parseFloat(config.getString("pitch")));
		result.setYaw(Float.parseFloat(config.getString("yaw")));
	}
	return result;
}
 
Example 2
Source File: Transforms.java    From EffectLib with MIT License 6 votes vote down vote up
public static Transform loadTransform(ConfigurationSection base, String value) {
    if (base.isConfigurationSection(value)) {
        return loadTransform(ConfigUtils.getConfigurationSection(base, value));
    }
    if (base.isDouble(value) || base.isInt(value)) {
        return new ConstantTransform(base.getDouble(value));
    }
    if (base.isString(value)) {
        String equation = base.getString(value);
        if (equation.equalsIgnoreCase("t") || equation.equalsIgnoreCase("time")) {
            return new EchoTransform();
        }
        EquationTransform transform = EquationStore.getInstance().getTransform(equation, "t");
        Exception ex = transform.getException();
        if (ex != null && effectManager != null) {
            effectManager.onError("Error parsing equation: " + equation, ex);
        }
        return transform;
    }
    return new ConstantTransform(0);
}
 
Example 3
Source File: SignShop.java    From Shopkeepers with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void load(ConfigurationSection config) {
	super.load(config);
	if (config.isString("signFacing")) {
		String signFacingName = config.getString("signFacing");
		if (signFacingName != null) {
			try {
				signFacing = BlockFace.valueOf(signFacingName);
			} catch (IllegalArgumentException e) {
			}
		}
	}

	// in case no sign facing is stored: try getting the current sign facing from sign in the world
	// if it is not possible (for ex. because the world isn't loaded yet), we will reattempt this
	// during the periodically checks
	if (signFacing == null) {
		signFacing = this.getSignFacingFromWorld();
	}
}
 
Example 4
Source File: ItemConfigurationParser.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
public ItemStack getItem(ConfigurationSection section, String key, Supplier<ItemStack> def) throws InvalidConfigurationException {
    if(section.isString(key)) {
        return new ItemStack(needItemType(section, key));
    }

    if(!section.isConfigurationSection(key)) {
        return def.get();
    }

    final ConfigurationSection itemSection = section.needSection(key);

    if(itemSection.isString("skull")) {
        return needSkull(itemSection, "skull");
    }

    final Material material = needItemType(itemSection, "id");

    final int damage = itemSection.getInt("damage", 0);
    if(damage < Short.MIN_VALUE || damage > Short.MAX_VALUE) {
        throw new InvalidConfigurationException(itemSection, "damage", "Item damage out of range");
    }

    final ItemStack stack = new ItemStack(material, 1, (short) damage);

    if(itemSection.isString("skin")) {
        needSkull(stack, itemSection, "skin");
    }

    return stack;
}
 
Example 5
Source File: NavigatorInterface.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
Button(ConfigurationSection config, ItemConfigurationParser itemParser) throws InvalidConfigurationException {
    this.slot = itemParser.needSlotByPosition(config, null, null, Slot.Container.class);
    this.icon = config.isString("skull") ? itemParser.needSkull(config, "skull")
                                          : itemParser.needItem(config, "icon");
    this.connector = navigator.combineConnectors(ConfigUtils.needValueOrList(config, "to", String.class).stream()
                                                            .map(rethrowFunction(token -> parseConnector(config, "to", token)))
                                                            .collect(Collectors.toList()));
    this.connector.startObserving(observer);
}
 
Example 6
Source File: ChallengeFactory.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
public static Challenge createChallenge(Rank rank, ConfigurationSection section, ChallengeDefaults defaults) {
    String name = section.getName().toLowerCase();
    if (section.getBoolean("disabled", false)) {
        return null; // Skip this challenge
    }
    String displayName = section.getString("name", name);
    Challenge.Type type = Challenge.Type.from(section.getString("type", "onPlayer"));
    List<String> requiredItems = section.isList("requiredItems") ? section.getStringList("requiredItems") : Arrays.asList(section.getString("requiredItems", "").split(" "));
    List<EntityMatch> requiredEntities = createEntities(section.getStringList("requiredEntities"));
    int resetInHours = section.getInt("resetInHours", rank.getResetInHours());
    String description = section.getString("description");
    ItemStack displayItem = createItemStack(
            section.getString("displayItem", defaults.displayItem),
            normalize(displayName), description);
    ItemStack lockedItem = section.isString("lockedDisplayItem") ? createItemStack(section.getString("lockedDisplayItem", "BARRIER"), displayName, description) : null;
    boolean takeItems = section.getBoolean("takeItems", true);
    int radius = section.getInt("radius", 10);
    Reward reward = createReward(section.getConfigurationSection("reward"));
    Reward repeatReward = createReward(section.getConfigurationSection("repeatReward"));
    if (repeatReward == null && section.getBoolean("repeatable", false)) {
        repeatReward = reward;
    }
    List<String> requiredChallenges = section.getStringList("requiredChallenges");
    int offset = section.getInt("offset", 0);
    int repeatLimit = section.getInt("repeatLimit", 0);
    return new Challenge(name, displayName, description, type,
            requiredItems, requiredEntities, requiredChallenges, section.getDouble("requiredLevel", 0d), rank,
            resetInHours, displayItem, section.getString("tool", null), lockedItem, offset, takeItems,
            radius, reward, repeatReward, repeatLimit);
}
 
Example 7
Source File: ToolMenuEvents.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
private void registerCommands() {
    ConfigurationSection section = plugin.getConfig().getConfigurationSection("tool-menu.commands");
    if (section != null) {
        for (String block : section.getKeys(false)) {
            ItemStack item = ItemStackUtil.createItemStack(block);
            if (item.getType().isBlock() && section.isString(block)) {
                commandMap.put(ItemStackUtil.asString(item), section.getString(block));
            }
        }
    }
}