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

The following examples show how to use org.bukkit.configuration.ConfigurationSection#getDouble() . 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: Util.java    From Civs with GNU General Public License v3.0 6 votes vote down vote up
public static ArrayList<Bounty> readBountyList(FileConfiguration config) {
    ArrayList<Bounty> bountyList = new ArrayList<>();
    ConfigurationSection section1 = config.getConfigurationSection("bounties");
    for (String key : section1.getKeys(false)) {
        Bounty bounty;
        if (section1.isSet(key + ".issuer")) {
            bounty = new Bounty(UUID.fromString(section1.getString(key + ".issuer")),
                    section1.getDouble(key + ".amount"));
        } else {
            bounty = new Bounty(null,
                    section1.getDouble(key + ".amount"));
        }
        bountyList.add(bounty);
    }
    return bountyList;
}
 
Example 2
Source File: FlagSection.java    From HeavySpleef with GNU General Public License v3.0 6 votes vote down vote up
public FlagSection(ConfigurationSection section) {
	this.autostartVote = section.getInt("autostart-vote", 75);
	this.anticampingWarn = section.getInt("anticamping-warn", 3);
	this.anticampingDoWarn = section.getBoolean("anticamping-do-warn", true);
	this.anticampingTeleport = section.getInt("anticamping-teleport", 6);
	
	String readyBlockStr = section.getString("ready-block", "IRON_BLOCK");
	MaterialDataMatcher matcher = MaterialDataMatcher.newMatcher(readyBlockStr);
	matcher.match();
	
	readyBlock = matcher.result();
	
	String leaveItemStr = section.getString("leave-item", "MAGMA_CREAM");
	if (!leaveItemStr.equalsIgnoreCase("NONE")) {
		matcher = MaterialDataMatcher.newMatcher(leaveItemStr);
		matcher.match();

		leaveItem = matcher.result();
	} else {
		leaveItem = null;
	}


       this.spleggEggVelocityFactor = section.getDouble("splegg-egg-velocity-factor", 1d);
       this.spleggEggCooldown = section.getInt("splegg-egg-cooldown", 0);
}
 
Example 3
Source File: RegionUtils.java    From NovaGuilds with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Converts ConfigurationSection to a location
 * valid key names are:
 * world, x, y, z, yaw, pitch
 *
 * @param section section
 * @return location
 */
public static Location sectionToLocation(ConfigurationSection section) {
	World world;
	try {
		world = NovaGuilds.getInstance().getServer().getWorld(UUID.fromString(section.getString("world")));
	}
	catch(IllegalArgumentException e) {
		world = NovaGuilds.getInstance().getServer().getWorld(section.getString("world"));
	}

	double x = section.getDouble("x");
	double y = section.getDouble("y");
	double z = section.getDouble("z");
	float yaw = (float) section.getDouble("yaw");
	float pitch = (float) section.getDouble("pitch");

	if(world == null) {
		return null;
	}

	return new Location(world, x, y, z, yaw, pitch);
}
 
Example 4
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 5
Source File: LevelConfigYmlReader.java    From uSkyBlock with GNU General Public License v3.0 6 votes vote down vote up
private BlockLevelConfig readBlockSection(ConfigurationSection section, BlockMatch blockMatch, BlockLevelConfigBuilder defaultBuilder) {
    BlockLevelConfigBuilder builder = defaultBuilder.copy()
            .base(blockMatch);
    double score = section.getDouble("score", -1);
    if (score >= 0) {
        builder.scorePerBlock(score);
    }
    int limit = section.getInt("limit", -1);
    if (limit >= 0) {
        builder.limit(limit);
    }
    int diminishingReturns = section.getInt("diminishingReturns", -1);
    if (diminishingReturns >= 0) {
        builder.diminishingReturns(diminishingReturns);
    }
    int negativeReturns = section.getInt("negativeReturns", -1);
    if (negativeReturns >= 0) {
        builder.negativeReturns(negativeReturns);
    }
    List<String> additionBlocks = section.getStringList("additionalBlocks");
    if (!additionBlocks.isEmpty()) {
        builder.additionalBlocks(additionBlocks.stream().map(s -> getBlockMatch(s)).collect(Collectors.toList()).toArray(new BlockMatch[0]));
    }
    return builder.build();
}
 
Example 6
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 7
Source File: ConfigUtils.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
public static double getPercentage(ConfigurationSection config, String key, double def) {
    double percent = config.getDouble(key, def);
    if(percent < 0 || percent > 1) {
        throw new IllegalArgumentException("Config value " + key + ": percentage must be between 0 and 1");
    }
    return percent;
}
 
Example 8
Source File: TeleportEffect.java    From Civs with GNU General Public License v3.0 5 votes vote down vote up
public TeleportEffect(Spell spell, String key, Object target, Entity origin, int level, ConfigurationSection section) {
    super(spell, key, target, origin, level, section);
    String tempTarget = section.getString("target", "not-a-string");
    this.x = section.getDouble("x",0);
    this.y = section.getDouble("y",0);
    this.z = section.getDouble("z",0);
    this.setPos = section.getBoolean("set", false);
    this.other = section.getBoolean("other", false);
    if (!tempTarget.equals("not-a-string")) {
        this.target = tempTarget;
    } else {
        this.target = "self";
    }
}
 
Example 9
Source File: SoundEffect.java    From Civs with GNU General Public License v3.0 5 votes vote down vote up
public SoundEffect(Spell spell, String key, Object target, Entity origin, int level, ConfigurationSection section) {
    super(spell, key, target, origin, level, section);
    this.soundName = section.getString("sound", "EXPLODE").toUpperCase();
    this.volume = (float) section.getDouble("volume", 1);
    this.pitch = (float) section.getDouble("pitch", 1);
    String tempTarget = section.getString("target", "not-a-string");
    if (!tempTarget.equals("not-a-string")) {
        this.target = tempTarget;
    } else {
        this.target = "self";
    }
}
 
Example 10
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 11
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 12
Source File: DurabilityMaterial.java    From ObsidianDestroyer with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Storage for a tracked material from the config
 *
 * @param type    the type of material
 * @param section the configuration section to load
 */
public DurabilityMaterial(Material type, int typeData, ConfigurationSection section) {
    this.type = type;
    this.name = type.name();
    this.typeData = typeData;
    this.blastRadius = section.getInt("BlastRadius", 2);
    this.destructible = section.getBoolean("Destructible", true);
    this.bypassFluidProtect = section.getBoolean("BypassFluidProtection", false);
    this.bypassFactionProtect = section.getBoolean("BypassFactionProtection", false);
    this.durability = section.getInt("Durability.Amount", 5);
    this.fluidDamper = section.getDouble("Durability.FluidDamper", 0);
    this.enabled = section.getBoolean("Durability.Enabled", true);
    this.chanceToDrop = section.getDouble("Durability.ChanceToDrop", 0.7);
    this.resetEnabled = section.getBoolean("Durability.ResetEnabled", false);
    this.resetTime = section.getLong("Durability.ResetAfter", 10000L);
    this.tntEnabled = section.getBoolean("EnabledFor.TNT", true);
    this.cannonsEnabled = section.getBoolean("EnabledFor.Cannons", false);
    this.creepersEnabled = section.getBoolean("EnabledFor.Creepers", false);
    this.ghastsEnabled = section.getBoolean("EnabledFor.Ghasts", false);
    this.withersEnabled = section.getBoolean("EnabledFor.Withers", false);
    this.tntMinecartsEnabled = section.getBoolean("EnabledFor.Minecarts", false);
    this.nullEnabled = section.getBoolean("EnabledFor.NullDamage", true);
    this.tntDamage = section.getInt("Damage.TNT", 1);
    this.cannonImpactDamage = section.getInt("Damage.Cannons", section.getInt("Damage.CannonsImpact", 1));
    this.cannonPierceDamage = section.getInt("Damage.CannonsPierce", 1);
    this.creeperDamage = section.getInt("Damage.Creepers", 1);
    this.chargedCreeperDamage = section.getInt("Damage.ChargedCreepers", 1);
    this.ghastDamage = section.getInt("Damage.Ghasts", 1);
    this.witherDamage = section.getInt("Damage.Withers", 1);
    this.tntMinecartDamage = section.getInt("Damage.Minecarts", 1);
    this.nullDamage = section.getInt("Damage.NullDamage", 1);
    this.enderCrystalEnabled = section.getBoolean("EnabledFor.EnderCrystal", false);
    this.enderCrystalDamage = section.getInt("Damage.EnderCrystal", 1);
    this.tallyKittens();
}
 
Example 13
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 14
Source File: SequenceTransform.java    From EffectLib with MIT License 4 votes vote down vote up
public Sequence(ConfigurationSection configuration) {
    this.transform = Transforms.loadTransform(configuration, "transform");
    this.start = configuration.getDouble("start", 0);
}
 
Example 15
Source File: ConstantTransform.java    From EffectLib with MIT License 4 votes vote down vote up
@Override
public void load(ConfigurationSection parameters) {
    value = parameters.getDouble("value");
}
 
Example 16
Source File: ControlPanel.java    From askyblock with GNU General Public License v2.0 4 votes vote down vote up
/**
 * This loads the minishop from the minishop.yml file
 */
public static void loadShop() {
    // The first parameter is the Material, then the durability (if wanted),
    // slot, descriptions
    // Minishop
    store.clear();
    miniShopFile = Util.loadYamlFile("minishop.yml");
    allowSelling = miniShopFile.getBoolean("config.allowselling", false);
    ConfigurationSection items = miniShopFile.getConfigurationSection("items");
    ASkyBlock plugin = ASkyBlock.getPlugin();
    if (items != null) {
        // Create the store
        // Get how many the store should be
        int size = items.getKeys(false).size() + 8;
        size -= (size % 9);
        miniShop = Bukkit.createInventory(null, size, plugin.myLocale().islandMiniShopTitle);
        // Run through items
        int slot = 0;
        for (String item : items.getKeys(false)) {
            try {
                String m = items.getString(item + ".material");
                Material material = Material.matchMaterial(m);
                int quantity = items.getInt(item + ".quantity", 0);
                String extra = items.getString(item + ".extra", "");
                double price = items.getDouble(item + ".price", -1D);
                double sellPrice = items.getDouble(item + ".sellprice", -1D);
                if (!allowSelling) {
                    sellPrice = -1;
                }
                String description = ChatColor.translateAlternateColorCodes('&',items.getString(item + ".description",""));
                MiniShopItem shopItem = new MiniShopItem(material, extra, slot, description, quantity, price, sellPrice);
                store.put(slot, shopItem);
                miniShop.setItem(slot, shopItem.getItem());
                slot++;
            } catch (Exception e) {
                plugin.getLogger().warning("Problem loading minishop item #" + slot);
                plugin.getLogger().warning(e.getMessage());
                e.printStackTrace();
            }
        }

    }
}
 
Example 17
Source File: RepulsionBomb.java    From NBTEditor with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void applyConfig(ConfigurationSection section) {
	super.applyConfig(section);
	_force = section.getDouble("force");
}
 
Example 18
Source File: BatBomb.java    From NBTEditor with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void applyConfig(ConfigurationSection section) {
	super.applyConfig(section);
	_power = (float) section.getDouble("power");
}
 
Example 19
Source File: FeeMoneyRequirement.java    From DungeonsXL with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void setup(ConfigurationSection config) {
    fee = config.getDouble("feeMoney");
}
 
Example 20
Source File: ParticleDisplay.java    From XSeries with MIT License 4 votes vote down vote up
/**
 * Builds particle settings from a configuration section.
 *
 * @param location the location for this particle settings.
 * @param config   the config section for the settings.
 * @return a parsed ParticleDisplay.
 * @since 1.0.0
 */
@Nonnull
public static ParticleDisplay fromConfig(@Nullable Location location, @Nonnull ConfigurationSection config) {
    Objects.requireNonNull(config, "Cannot parse ParticleDisplay from a null config section");
    Particle particle = XParticle.getParticle(config.getString("particle"));
    if (particle == null) particle = Particle.FLAME;
    int count = config.getInt("count");
    double extra = config.getDouble("extra");
    double offsetx = 0, offsety = 0, offsetz = 0;

    String offset = config.getString("offset");
    if (offset != null) {
        String[] offsets = StringUtils.split(offset, ',');
        if (offsets.length > 0) {
            offsetx = NumberUtils.toDouble(offsets[0]);
            if (offsets.length > 1) {
                offsety = NumberUtils.toDouble(offsets[1]);
                if (offsets.length > 2) {
                    offsetz = NumberUtils.toDouble(offsets[2]);
                }
            }
        }
    }

    double x = 0, y = 0, z = 0;
    String rotation = config.getString("rotation");
    if (rotation != null) {
        String[] rotations = StringUtils.split(rotation, ',');
        if (rotations.length > 0) {
            x = NumberUtils.toDouble(rotations[0]);
            if (rotations.length > 1) {
                y = NumberUtils.toDouble(rotations[1]);
                if (rotations.length > 2) {
                    z = NumberUtils.toDouble(rotations[2]);
                }
            }
        }
    }

    float[] rgbs = null;
    String color = config.getString("color");
    if (color != null) {
        String[] colors = StringUtils.split(rotation, ',');
        if (colors.length >= 3) rgbs = new float[]
                {NumberUtils.toInt(colors[0]), NumberUtils.toInt(colors[1]), NumberUtils.toInt(colors[2]),
                        (colors.length > 3 ? NumberUtils.toFloat(colors[0]) : 1.0f)};
    }

    Vector rotate = new Vector(x, y, z);
    ParticleDisplay display = new ParticleDisplay(particle, location, count, offsetx, offsety, offsetz, extra);
    display.rotation = rotate;
    display.data = rgbs;
    return display;
}