[Help] Config File

Discussion in 'Plugin Development' started by F4BSE, Dec 19, 2012.

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

    F4BSE

    How can I make a config File to change the int in the Float.valueOf(int)?

    Code:
          public void onEnable()
          {
     
            setBlockResistance(Block.STONE, Float.valueOf(104.F));
              }
     
  2. Offline

    fireblast709

    (float)getConfig().getDouble()? I know, not exactly a float, but it has decimals ;3
     
  3. Offline

    F4BSE

    Can you write a sample because I should understand the way to write this
     
  4. Offline

    fireblast709

    You are trying to get a float from the config right? Apparently there is no .getFloat("path") method, so you would have to use doubles instead (which only means you have more decimals).

    Say you have a config.yml like this:
    Code:
    blockResistance: 104.5
    Then you get the blockResistance like this:
    Code:java
    1. float blockResistance = (float)getConfig().getDouble("blockResistance");

    If you only want to change a regular int to float (if the method you want to use only accepts float), you can just cast it:
    Code:java
    1. float theFloat = (float)theInt;
     
  5. Offline

    F4BSE

    So it looks like this?

    Code:
          public void onEnable()
          {
     
            float blockResistance = (float)getConfig().getDouble("Stone");
          }
    and in the config.yml

    Stone: 104.5

    And this works the same like this?

    Code:
          public void onEnable()
          {
     
            setBlockResistance(Block.STONE, Float.valueOf(104.F));
              }
     
  6. Offline

    fireblast709

    well 104.5 would get you 104.5 :p... yea works the same. Besides,
    Code:java
    1. setBlockResistance(Block.STONE, 104f);
    would have done the same (just without the config), no need for Float.valueOf(something) :3
     
  7. Offline

    F4BSE

    blockResistance is underlined with yellow color and the is the following sentence:

    the value of the local variable blockResistance is not used

    is that bad?

    Okay it don't work

    I have this:

    Code:
            float blockResistance = (float)getConfig().getDouble("Stone");
            setBlockResistance(Block.STONE, 104f);
    But the Resistance are all the time 104 and if I change the number in the config it's the same.

    I think the Plugin can't change the number with the config :/

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 30, 2016
  8. Offline

    fireblast709

    yes, but you should do
    Code:java
    1. float blockResistance = (float)getConfig().getDouble("Stone");
    2. setBlockResistance(Block.STONE, blockResistance);
    ;3
     
  9. Offline

    F4BSE

    Oh woow thanks a lot :)

    I have an other question. If I have the resistance 100, I have to wait for a long time until the block will drop.
    But I don't see the animation. How can I fix it, that the animation are slower too?
     
  10. Offline

    fireblast709

    No clue tbh. You might try the BlockDamageEvent
     
  11. Offline

    F4BSE

    Oh okay :D I have no idea :p
    I'm a noob with java

    How can I change a string like 104.5 from the config to float?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 30, 2016
  12. Offline

    fireblast709

    F4BSE if you use .getDouble("path.to.float"); and cast it to float (by using '(float)'), you don't have to :3
     
  13. Offline

    F4BSE

    Thanks for your help :)
     
Thread Status:
Not open for further replies.

Share This Page