Modified mcMMO's onEntityDamage to have better compatibility.

This commit is contained in:
nossr50 2012-02-13 08:06:46 -08:00
parent 1910b76b13
commit 786a5f9325
3 changed files with 22 additions and 2 deletions

View File

@ -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

View File

@ -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;

View File

@ -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;
@ -145,6 +147,19 @@ public class m
}
}
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)
{
if(player.getItemInHand().getTypeId() == 0)