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 Main configGetter;public Damage(Main plugin){plugin.getServer().getPluginManager().registerEvents(this, plugin);configGetter = plugin;}int Damage = configGetter.getConfig().getInt("Damage");@EventHandlerpublic void onDamage(EntityDamageByEntityEvent e) {if (!(e.getEntity() instanceof Player))return;Player entity = (Player) e.getEntity();if (entity.getItemInHand().getType() == Material.PISTON_STICKY_BASE) {e.setDamage(Damage); }} } Main Class OnEnable Code:java public void onEnable() { this.getConfig().addDefault("Damage", 0.75); this.getConfig().options().copyDefaults(true); saveConfig(); }
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.
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.
You're storing a float but reading an int. Which means the float will probably be cast to int and thus become 0.
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 Main configGetter;public Damage(Main plugin){plugin.getServer().getPluginManager().registerEvents(this, plugin);configGetter = plugin;}double Damage = configGetter.getConfig().getDouble("Damage");@EventHandlerpublic void onDamage(EntityDamageByEntityEvent e) {// First you should check if e.getEntity() is not a Player and just// return;// since it doesn't matter to youif (!(e.getEntity() instanceof Player))return;// Then as you are sure you have a Player being attacked, you can cast// entity to PlayerPlayer entity = (Player) e.getEntity();// check if he has a Piston in his handif (entity.getItemInHand().getType() == Material.PISTON_STICKY_BASE) {e.setDamage(e.getDamage()*Damage); }} } EDIT by Moderator: merged posts, please use the edit button instead of double posting.
Lazertx it is supposed to reduce the damage by using the following technique: Amount Of Damage Done X (Multiplied by) Int value
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.
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
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
ProMCKingz Well I don't use the config system built into bukkit so I can't help much with that sorry.