Config.yml

Discussion in 'Plugin Development' started by ProMCKingz, Jul 24, 2014.

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

    ProMCKingz

    Hey!
    Thanks for reading this.
    However I have a problem with my config - the thing that really confuses me
    Current code below - I am trying to make it so that server administrators can change the damage done by these shields in the config, which then saves it for the reload, and then applies it to the shield.
    All my plugin works fine btw, just the config bit.

    Damage Listener Class
    Code:java
    1. Main configGetter;
    2. public Damage(Main plugin){
    3. plugin.getServer().getPluginManager().registerEvents(this, plugin);
    4. configGetter = plugin;
    5. }
    6. int Damage = configGetter.getConfig().getInt("Damage");
    7. @EventHandler
    8. public void onDamage(EntityDamageByEntityEvent e) {
    9. if (!(e.getEntity() instanceof Player))
    10. return;
    11. Player entity = (Player) e.getEntity();
    12. if (entity.getItemInHand().getType() == Material.PISTON_STICKY_BASE) {
    13. e.setDamage(Damage);
    14.  
    15. }
    16. }
    17.  
    18. }


    Main Class OnEnable
    Code:java
    1. public void onEnable() {
    2.  
    3. this.getConfig().addDefault("Damage", 0.75);
    4. this.getConfig().options().copyDefaults(true);
    5. saveConfig();
    6. }
    7.  
     
  2. Offline

    TheHandfish

    Are you @Override'ing your onEnable method? Also, what is the problem?
     
  3. Offline

    Zettelkasten

    You don't need the @Override annotation, overriding will work just fine without it :)
     
  4. Offline

    TheHandfish

    It's better practice to put an @Override sign there. There are some scenarios where it is necessary.

    Anyway, we need to know the issue.
     
  5. Offline

    ProMCKingz

    TheHandfish
    All works, however when i change the config and reload my plugin, it does not update
    and yes, I do have @Override, however it just wasn't listed in this code, since I cleared up other classes to show neatened version

    Anyone?
    Please!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  6. Offline

    Saladoc

    You're storing a float but reading an int. Which means the float will probably be cast to int and thus become 0.
     
  7. Offline

    ProMCKingz

    Saladoc
    So how can I change that?
     
  8. Offline

    Lazertx

    Change line 6 to
    Code:java
    1. double Damage = configGetter.getConfig().getDouble("Damage");
     
  9. Offline

    Saladoc

    Code:java
    1. double Damage = configGetter.getConfig().getDouble("Damage");


    edit: Ninja'd
     
  10. Offline

    ProMCKingz

    Saladoc and Lazertx
    Lol, same time, same answer ;)
    Thanks!
    Hope it works

    Saladoc
    Hey!
    Config doesn't seem to change to "0" anymore, however, it doesn't seem to change the damage. Before I started to edit the damage class to do the config, all worked fine. However it doesn't seem to reduce the damage

    Saladoc Lazertx
    Now it stays at 1?
    So I went into the config.yml and changed it to 1, and reloaded. IT CHANGED FROM 0, however now it won't change from 1? And doesn't reduce damage :'(
    Code:java
    1. Main configGetter;
    2. public Damage(Main plugin){
    3. plugin.getServer().getPluginManager().registerEvents(this, plugin);
    4. configGetter = plugin;
    5. }
    6. double Damage = configGetter.getConfig().getDouble("Damage");
    7. @EventHandler
    8. public void onDamage(EntityDamageByEntityEvent e) {
    9. // First you should check if e.getEntity() is not a Player and just
    10. // return;
    11. // since it doesn't matter to you
    12. if (!(e.getEntity() instanceof Player))
    13. return;
    14. // Then as you are sure you have a Player being attacked, you can cast
    15. // entity to Player
    16. Player entity = (Player) e.getEntity();
    17. // check if he has a Piston in his hand
    18. if (entity.getItemInHand().getType() == Material.PISTON_STICKY_BASE) {
    19. e.setDamage(e.getDamage()*Damage);
    20.  
    21. }
    22. }
    23.  
    24. }
    25.  


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  11. Offline

    Lazertx

    ProMCKingz Is this supposed to reduce the damage done by 1 heart or what is it supposed to do?
     
  12. Offline

    ProMCKingz

    Lazertx it is supposed to reduce the damage by using the following technique:

    Amount Of Damage Done X (Multiplied by) Int value
     
  13. Offline

    Lazertx

    Well 1 * x is always x unless it's 0 so 100 * 1 = 100 so there is no reason for the damage to be reduced. If you would like the number to reduce damage it needs to be under 1.
     
  14. Offline

    ProMCKingz

    Lazertx
    I have acknowledged that, and knew that.
    However why does it not change when I change the number in config, and save it, then reload?
    It always comes up as 1
     
  15. Offline

    Lazertx

    ProMCKingz What are you using to see what it comes up as?
     
  16. Offline

    ProMCKingz

    Lazertx
    What do you mean?
    I am trying to put in 0.
    However whenever I change it, then save it, then reload. It changes back.
    I have used saveConfig() in both Enable and Disable, yet it still doesn't seem to save
     
  17. Offline

    Lazertx

    ProMCKingz Well I don't use the config system built into bukkit so I can't help much with that sorry.
     
Thread Status:
Not open for further replies.

Share This Page