Java Code Examples for cpw.mods.fml.common.eventhandler.Event#setCanceled()

The following examples show how to use cpw.mods.fml.common.eventhandler.Event#setCanceled() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProtectionManager.java    From MyTown2 with The Unlicense 6 votes vote down vote up
public static void checkBlockInteraction(Resident res, BlockPos bp, PlayerInteractEvent.Action action, Event ev) {
    if(!ev.isCancelable()) {
        return;
    }

    World world = MinecraftServer.getServer().worldServerForDimension(bp.getDim());
    Block block = world.getBlock(bp.getX(), bp.getY(), bp.getZ());

    // Bypass for SellSign
    if (block instanceof BlockSign) {
        TileEntity te = world.getTileEntity(bp.getX(), bp.getY(), bp.getZ());
        if(te instanceof TileEntitySign && SellSign.SellSignType.instance.isTileValid((TileEntitySign) te)) {
            return;
        }
    }

    for(SegmentBlock segment : segmentsBlock.get(block.getClass())) {
        if(!segment.shouldInteract(res, bp, action)) {
            ev.setCanceled(true);
        }
    }
}
 
Example 2
Source File: ProtectionManager.java    From MyTown2 with The Unlicense 5 votes vote down vote up
public static void checkImpact(Entity entity, Resident owner, MovingObjectPosition mop, Event event) {
    for(SegmentEntity segment : segmentsEntity.get(entity.getClass())) {
        if(!segment.shouldImpact(entity, owner, mop)) {
            event.setCanceled(true);
            entity.isDead = true;
            entity.setDead();
        }
    }
}
 
Example 3
Source File: ProtectionManager.java    From MyTown2 with The Unlicense 5 votes vote down vote up
public static void checkInteraction(Entity entity, Resident res, Event event) {
    if(!event.isCancelable()) {
        return;
    }

    for(SegmentEntity segment : segmentsEntity.get(entity.getClass())) {
        if(!segment.shouldInteract(entity, res)) {
            event.setCanceled(true);
        }
    }
}
 
Example 4
Source File: ProtectionManager.java    From MyTown2 with The Unlicense 5 votes vote down vote up
public static void checkPVP(Entity entity, Resident res, Event event) {
    if(!event.isCancelable()) {
        return;
    }

    for(SegmentEntity segment : segmentsEntity.get(entity.getClass())) {
        if(!segment.shouldAttack(entity, res)) {
            event.setCanceled(true);
        }
    }
}
 
Example 5
Source File: ProtectionManager.java    From MyTown2 with The Unlicense 5 votes vote down vote up
public static void checkUsage(ItemStack stack, Resident res, PlayerInteractEvent.Action action, BlockPos bp, int face, Event ev) {
    if(!ev.isCancelable()) {
        return;
    }

    for(SegmentItem segment : segmentsItem.get(stack.getItem().getClass())) {
        if(!segment.shouldInteract(stack, res, action, bp, face)) {
            ev.setCanceled(true);
        }
    }
}
 
Example 6
Source File: ProtectionManager.java    From MyTown2 with The Unlicense 5 votes vote down vote up
public static void checkBreakWithItem(ItemStack stack, Resident res, BlockPos bp, Event ev) {
    if(!ev.isCancelable()) {
        return;
    }

    for(SegmentItem segment : segmentsItem.get(stack.getItem().getClass())) {
        if(!segment.shouldBreakBlock(stack, res, bp)) {
            ev.setCanceled(true);
        }
    }
}