Example usage for net.minecraftforge.event.entity EntityMobGriefingEvent getEntity

List of usage examples for net.minecraftforge.event.entity EntityMobGriefingEvent getEntity

Introduction

In this page you can find the example usage for net.minecraftforge.event.entity EntityMobGriefingEvent getEntity.

Prototype

public Entity getEntity() 

Source Link

Usage

From source file:com.judge40.minecraft.bettermobgriefinggamerule.common.MobGriefingEventHandler.java

License:Open Source License

/**
 * When mob griefing occurs, check whether mob griefing is enabled for the griefing entity and set
 * event's result accordingly. {@link Result#ALLOW} indicates that mob griefing is enabled and
 * {@link Result#DENY} indicates that mob griefing is disabled.
 * /*ww  w  . ja va  2s. co  m*/
 * @param mobGriefingEvent The {@link EntityMobGriefingEvent} to update.
 */
@SubscribeEvent
public void onMobGriefing(EntityMobGriefingEvent mobGriefingEvent) {
    Entity griefingEntity = mobGriefingEvent.getEntity();

    if (griefingEntity != null) {
        boolean isEnabled = BetterMobGriefingGameRule.isMobGriefingEnabled(griefingEntity);

        if (isEnabled) {
            mobGriefingEvent.setResult(Result.ALLOW);
        } else {
            mobGriefingEvent.setResult(Result.DENY);
        }
    }
}