Development Assistance String to Int

Discussion in 'Plugin Help/Development/Requests' started by 2008Choco, Jun 11, 2015.

Thread Status:
Not open for further replies.
  1. Offline


    I am making a configuration option for my plugin to allow them to create custom equations. I have one issue. This configuration option has no choice but to contain variables. I have attempted getting the config value as an int (getConfig().getInt("StringPath")), but as you know, you cannot replace specific characters of an int with another int. I cannot use getConfig().getString("StringPath") because that would be a string and for the method I want to use it in, it must be an integer.

    Is there any possible way for me to change a String into an int, or try and replace a variable in an int to another int? My end goal is to replace f with an integer.

    Ex: f - ((f / 100) * 40), and I want to get that value from a config file and replace f with an int. Any help would be great. If I can't do it, it's not the end of the world, but there must be a way
  2. Offline


    @2008Choco parse it with the Integer class. However, initializing f to getConfig().getInt() should work in that instance.
    2008Choco likes this.
  3. Offline


    I've figured out the ParseInt function and will test this out later tonight. Let me clarify just to make sure this works before I test though. This is the code I'm using:
    int equation = Integer.parseInt(getConfig().getString("CustomFallDamageEquation"));
    And this is my config value:
    CustomFallDamageEquation: fallDamage - ((fallDamage / 100 ) * 40)
    I have "fallDamage" as a variable declared earlier in my code. Would the parseInt method replace "fallDamage" with the int it's declared as?
  4. Offline


        public void onEntityDamage(EntityDamageEvent e){
                int i = getConfig().getInt("CustomFallDamageEquation");
                int equation = (i/100)*40;
Thread Status:
Not open for further replies.

Share This Page