mirror of
				https://github.com/mcMMO-Dev/mcMMO.git
				synced 2025-11-04 11:03:43 +01:00 
			
		
		
		
	Modified mcMMO's onEntityDamage to have better compatibility.
This commit is contained in:
		@@ -2,7 +2,7 @@ Changelog:
 | 
				
			|||||||
#Versions without changelogs probably had very small misc fixes, like tweaks to the source code
 | 
					#Versions without changelogs probably had very small misc fixes, like tweaks to the source code
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Version 1.2.12
 | 
					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 /mcgod, & /mmoedit defaulting to true
 | 
				
			||||||
 - Fixed Fishing not handing out any XP
 | 
					 - Fixed Fishing not handing out any XP
 | 
				
			||||||
 
 | 
					 
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -33,6 +33,7 @@ import org.bukkit.inventory.ItemStack;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import com.gmail.nossr50.Combat;
 | 
					import com.gmail.nossr50.Combat;
 | 
				
			||||||
import com.gmail.nossr50.Users;
 | 
					import com.gmail.nossr50.Users;
 | 
				
			||||||
 | 
					import com.gmail.nossr50.m;
 | 
				
			||||||
import com.gmail.nossr50.mcMMO;
 | 
					import com.gmail.nossr50.mcMMO;
 | 
				
			||||||
import com.gmail.nossr50.config.LoadProperties;
 | 
					import com.gmail.nossr50.config.LoadProperties;
 | 
				
			||||||
import com.gmail.nossr50.datatypes.PlayerProfile;
 | 
					import com.gmail.nossr50.datatypes.PlayerProfile;
 | 
				
			||||||
@@ -52,9 +53,13 @@ public class mcEntityListener implements Listener
 | 
				
			|||||||
        this.plugin = plugin;
 | 
					        this.plugin = plugin;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @EventHandler(priority = EventPriority.MONITOR)
 | 
					    @EventHandler(priority = EventPriority.LOW)
 | 
				
			||||||
    public void onEntityDamage(EntityDamageEvent event) 
 | 
					    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())
 | 
					    	if(event.isCancelled())
 | 
				
			||||||
    		return;
 | 
					    		return;
 | 
				
			||||||
    	
 | 
					    	
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -26,8 +26,10 @@ import org.bukkit.Location;
 | 
				
			|||||||
import org.bukkit.Material;
 | 
					import org.bukkit.Material;
 | 
				
			||||||
import org.bukkit.block.Block;
 | 
					import org.bukkit.block.Block;
 | 
				
			||||||
import org.bukkit.entity.*;
 | 
					import org.bukkit.entity.*;
 | 
				
			||||||
 | 
					import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
 | 
				
			||||||
import org.bukkit.inventory.ItemStack;
 | 
					import org.bukkit.inventory.ItemStack;
 | 
				
			||||||
import com.gmail.nossr50.config.*;
 | 
					import com.gmail.nossr50.config.*;
 | 
				
			||||||
 | 
					import com.gmail.nossr50.datatypes.FakeEntityDamageEvent;
 | 
				
			||||||
import com.gmail.nossr50.datatypes.PlayerProfile;
 | 
					import com.gmail.nossr50.datatypes.PlayerProfile;
 | 
				
			||||||
import com.gmail.nossr50.datatypes.FakeBlockBreakEvent;
 | 
					import com.gmail.nossr50.datatypes.FakeBlockBreakEvent;
 | 
				
			||||||
import com.gmail.nossr50.datatypes.SkillType;
 | 
					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)
 | 
						public static void damageTool(Player player, short damage)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		if(player.getItemInHand().getTypeId() == 0)
 | 
							if(player.getItemInHand().getTypeId() == 0)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user