Add damage event to at least respect god modes.

This commit is contained in:
asofold 2012-08-12 06:53:32 +02:00
parent faf31c3887
commit 78f48b925f
2 changed files with 29 additions and 2 deletions

View File

@ -6,7 +6,9 @@ import net.minecraft.server.AxisAlignedBB;
import net.minecraft.server.EntityPlayer;
import net.minecraft.server.Packet10Flying;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import fr.neatmonster.nocheatplus.actions.ParameterName;
import fr.neatmonster.nocheatplus.checks.Check;
@ -75,8 +77,12 @@ public class NoFall extends Check {
// Execute the actions to find out if we need to cancel the event or not.
if (executeActions(player, data.noFallVL, cc.noFallActions)){
// Deal the fall damages to the player.
player.damage(fallDamage);
// TODO: set accurate fall damage (feather falling etc).
final NoFallDamageEvent damageEvent = new NoFallDamageEvent(player, DamageCause.FALL, fallDamage);
Bukkit.getPluginManager().callEvent(damageEvent);
if (!damageEvent.isCancelled()) player.damage(fallDamage);
data.noFallFallDistance = 0.0;
player.setFallDistance(0.0f);
}
}
@ -85,6 +91,7 @@ public class NoFall extends Check {
// If the player just touched the ground for the server.
else if (!data.noFallWasOnGroundServer && data.noFallOnGroundServer) {
// Calculate the difference between the fall distance calculated by the server and by the plugin.
// TODO: Commented out divisor, did it have significance ? Still death with 1000 blocks fall distance ...
final double difference = (data.noFallFallDistance - player.getFallDistance());// / data.noFallFallDistance;
// If the difference is too big and the fall distance calculated by the plugin should hurt the player.
@ -129,6 +136,8 @@ public class NoFall extends Check {
// Attempt to fix vehicle problems:
if (player.getBukkitEntity().isInsideVehicle()) return;
// Suggestion: use reference y position in data !
data.noFallWasOnGroundClient = data.noFallOnGroundClient;
data.noFallWasOnGroundServer = data.noFallOnGroundServer;

View File

@ -0,0 +1,18 @@
package fr.neatmonster.nocheatplus.checks.moving;
import org.bukkit.entity.Entity;
import org.bukkit.event.entity.EntityDamageEvent;
/**
* Very simple version to allow canceling.
* @author mc_dev
*
*/
public class NoFallDamageEvent extends EntityDamageEvent {
public NoFallDamageEvent(Entity damagee, DamageCause cause, int damage) {
super(damagee, cause, damage);
}
}