Hearts being lost by enviremental damage. (I fixed it for you.)
SirMrStep opened this issue ยท 9 comments
It seems the environmentStealHearts tag in your config wasn't getting checked at the PlayerDeathEvent, so i fixed it for you.
Here is the code (i only added one check)
@EventHandler(priority = EventPriority.HIGHEST)
public void onKill(PlayerDeathEvent event) {
Player killed = event.getEntity();
Player killer = event.getEntity().getKiller();
if(killer != null) {
modifyHealth(killer, 2);
if(shouldEliminate(killed)) {
eliminate(killed, killer);
//event.setCancelled(true);
return;
}
modifyHealth(killed, -2);
return;
} else {
if(shouldEliminate(killed)) {
eliminate(killed, null);
//event.setCancelled(true);
return;
}
if(Configuration.environmentStealsHearts()) { // < right here
modifyHealth(killed, -2);
}
}
String killerUUID = Configuration.getKiller(killed.getUniqueId());
if(killerUUID != null) {
Player player = Bukkit.getPlayer(UUID.fromString(killerUUID));
if(player != null) killed.setSpectatorTarget(player);
}
}
Indeed, however if you would have looked at the modifyHealth there should be that check already, tho I might have messed up
Indeed, however if you would have looked at the modifyHealth there should be that check already, tho I might have messed up
You did in fact NOT add this to the modifyHealth and there seems to be another problem. You did not have a minimum health check, so when the player has 2hp and you try to remove 2hp it results in a console error. This is what i am fixing atm.
new code i put for modifyHealth is
public static void modifyHealth(Player player, int scale) {
if(getMaxHealth(player).getValue() > 2) {
AttributeInstance maxHp = getMaxHealth(player);
maxHp.setBaseValue(maxHp.getValue() + scale);
if(Configuration.shouldScaleHealth()) player.setHealth(player.getHealth() + scale);
}
}
do i delete the config code and paste that in
No, this is java code, I edited the source code of the plugin. If you are not familiar with java I suggest you don't touch it and let the dev update the plugin himself to fix this issue. This is merely me informing him that the issue exist and showing him a way to fix it (mostly fixed it cause some person reached out to me saying he liked this plugin but this feature he wanted to use didn't work properly).
Oh then I forgot to commit! Wops, anyways it was already in ver 1.6 sorry for miscomunication, it should be releasing this month, hopefully