Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fake damage cause does not affect on damage events #3997

Closed
Jjman739 opened this issue May 13, 2021 · 1 comment
Closed

Fake damage cause does not affect on damage events #3997

Jjman739 opened this issue May 13, 2021 · 1 comment
Labels
bug An issue that needs to be fixed. Alternatively, a PR fixing an issue. completed The issue has been fully resolved and the change will be in the next Skript update. priority: medium Issues that are detrimental to user experience (prohibitive bugs or lack of useful implementation).

Comments

@Jjman739
Copy link

To reproduce this issue, create the following script:

on damage:
   message "%damage cause%" to victim

Then run the effect command !damage me by 1 with fake cause fire
image

It should say fire instead.

I think that this is caused by the damage script processing before the damage type is assigned, because the last damage cause expression still works as expected.

@TPGamesNL TPGamesNL added bug An issue that needs to be fixed. Alternatively, a PR fixing an issue. priority: medium Issues that are detrimental to user experience (prohibitive bugs or lack of useful implementation). labels May 13, 2021
@Jjman739
Copy link
Author

I don't know enough Java to reliably fix it myself, but I think I found the issue.

effects.EffHealth.java has this bit of code:

					HealthUtils.setDamageCause(entity, cause);
					HealthUtils.damage(entity, damage);

In bukkitutil.HealthUtils, the setDamageCause function sets the last damage cause:

	public static void setDamageCause(final Damageable e, final DamageCause cause) {
		e.setLastDamageCause(new EntityDamageEvent(e, cause, 0)); // Use deprecated way too keep it compatible and create cleaner code
		// Non-deprecated way is really, really bad
	}

Meanwhile, the damage function calls the damage event with the "CUSTOM" damage type:

	public static void damage(final Damageable e, final double d) {
		if (d < 0) {
			heal(e, -d);
			return;
		}
		if (!SkriptConfig.disableDamageCancelChecking.value()) {
			EntityDamageEvent event = new EntityDamageEvent(e, DamageCause.CUSTOM, d * 2);
			Bukkit.getPluginManager().callEvent(event);
			if (event.isCancelled())
				return;
		}
		e.damage(d * 2);
	}

It may break other things, but if the damage function was called with the damage cause as an argument, which is then passed into the damage event, it should fix this issue.

@TPGamesNL TPGamesNL added the PR available Issues which have a yet-to-be merged PR resolving it label May 14, 2021
@APickledWalrus APickledWalrus added completed The issue has been fully resolved and the change will be in the next Skript update. and removed PR available Issues which have a yet-to-be merged PR resolving it labels Jun 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An issue that needs to be fixed. Alternatively, a PR fixing an issue. completed The issue has been fully resolved and the change will be in the next Skript update. priority: medium Issues that are detrimental to user experience (prohibitive bugs or lack of useful implementation).
Projects
None yet
Development

No branches or pull requests

4 participants