-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix for handling damage event for invincible effect (#205)
* handle damage event for invincible effect * Update comment to be more informative --------- Co-authored-by: HSGamer <[email protected]> Co-authored-by: TechnicallyCoded <[email protected]>
- Loading branch information
1 parent
0afea8b
commit f2b039b
Showing
4 changed files
with
36 additions
and
1 deletion.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
src/main/java/me/SuperRonanCraft/BetterRTP/player/events/Damage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package me.SuperRonanCraft.BetterRTP.player.events; | ||
|
||
import me.SuperRonanCraft.BetterRTP.references.player.HelperPlayer; | ||
import org.bukkit.entity.Entity; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.entity.EntityDamageEvent; | ||
|
||
public class Damage { | ||
static boolean canCancel(EntityDamageEvent.DamageCause damageCause) { | ||
return true; // TODO: Allow for filtering damage causes | ||
} | ||
|
||
static boolean isInInvincibleMode(Player player) { | ||
return HelperPlayer.getData(player).getInvincibleEndTime() > System.currentTimeMillis(); | ||
} | ||
|
||
static void onEntityDamage(EntityDamageEvent event) { | ||
Entity entity = event.getEntity(); | ||
if (!(entity instanceof Player)) return; | ||
Player player = (Player) entity; | ||
|
||
if (!canCancel(event.getCause())) return; | ||
if (!isInInvincibleMode(player)) return; | ||
|
||
event.setCancelled(true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters