From 786a5f9325d777e6b9974ddc3687060dcd37e439 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Mon, 13 Feb 2012 08:06:46 -0800 Subject: [PATCH] Modified mcMMO's onEntityDamage to have better compatibility. --- Changelog.txt | 2 +- .../gmail/nossr50/listeners/mcEntityListener.java | 7 ++++++- src/main/java/com/gmail/nossr50/m.java | 15 +++++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/Changelog.txt b/Changelog.txt index b2af2452c..c6e0e78df 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -2,7 +2,7 @@ Changelog: #Versions without changelogs probably had very small misc fixes, like tweaks to the source code Version 1.2.12 - - Changed priority of onEntityDamage to come dead last to respect other plugins event cancelling + - Modified onEntityDamage to have better compatibility with other plugins - Fixed /mcgod, & /mmoedit defaulting to true - Fixed Fishing not handing out any XP diff --git a/src/main/java/com/gmail/nossr50/listeners/mcEntityListener.java b/src/main/java/com/gmail/nossr50/listeners/mcEntityListener.java index 18a24f48e..641ebbbd8 100644 --- a/src/main/java/com/gmail/nossr50/listeners/mcEntityListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/mcEntityListener.java @@ -33,6 +33,7 @@ import org.bukkit.inventory.ItemStack; import com.gmail.nossr50.Combat; import com.gmail.nossr50.Users; +import com.gmail.nossr50.m; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.config.LoadProperties; import com.gmail.nossr50.datatypes.PlayerProfile; @@ -52,9 +53,13 @@ public class mcEntityListener implements Listener this.plugin = plugin; } - @EventHandler(priority = EventPriority.MONITOR) + @EventHandler(priority = EventPriority.LOW) public void onEntityDamage(EntityDamageEvent event) { + //Pass around a fake event to see if any plugins cancel it + if(!m.EntityDamageEventSimulate(event.getEntity(), event.getCause(), event.getDamage())) + return; + if(event.isCancelled()) return; diff --git a/src/main/java/com/gmail/nossr50/m.java b/src/main/java/com/gmail/nossr50/m.java index 11b03917d..8d0c9fc0d 100644 --- a/src/main/java/com/gmail/nossr50/m.java +++ b/src/main/java/com/gmail/nossr50/m.java @@ -26,8 +26,10 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.entity.*; +import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.inventory.ItemStack; import com.gmail.nossr50.config.*; +import com.gmail.nossr50.datatypes.FakeEntityDamageEvent; import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.FakeBlockBreakEvent; import com.gmail.nossr50.datatypes.SkillType; @@ -144,6 +146,19 @@ public class m return false; //Return false if something went wrong } } + + public static boolean EntityDamageEventSimulate(Entity damagee, DamageCause cause, int damage) + { + FakeEntityDamageEvent event = new FakeEntityDamageEvent(damagee, cause, damage); + + Bukkit.getServer().getPluginManager().callEvent(event); + if(!event.isCancelled()) + { + return true; //Return true if not cancelled + } else { + return false; //Return false if cancelled + } + } public static void damageTool(Player player, short damage) {